Changeset bb9ec2d in mainline
- Timestamp:
- 2017-03-07T20:47:35Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a737667e
- Parents:
- e796dc8
- git-author:
- Jiri Zarevucky <zarevucky.jiri@…> (2017-03-07 20:47:35)
- git-committer:
- Jakub Jermar <jakub@…> (2017-03-07 20:47:35)
- Location:
- uspace
- Files:
-
- 2 added
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/exec.c
re796dc8 rbb9ec2d 101 101 char *tmp; 102 102 int rc, retval, i; 103 int file_handles[3]; 104 int *file_handles_p[4]; 103 int file_handles[3] = { -1, -1, -1 }; 105 104 FILE *files[3]; 106 105 … … 113 112 114 113 for (i = 0; i < 3 && files[i] != NULL; i++) { 115 if (vfs_fhandle(files[i], &file_handles[i]) == EOK) { 116 file_handles_p[i] = &file_handles[i]; 117 } 118 else { 119 file_handles_p[i] = NULL; 120 } 114 vfs_fhandle(files[i], &file_handles[i]); 121 115 } 122 file_handles_p[i] = NULL;123 116 124 rc = task_spawnvf(&tid, &twait, tmp, (const char **) argv, file_handles_p); 117 rc = task_spawnvf(&tid, &twait, tmp, (const char **) argv, 118 file_handles[0], file_handles[1], file_handles[2]); 125 119 free(tmp); 126 120 -
uspace/app/trace/trace.c
re796dc8 rbb9ec2d 513 513 514 514 /* Send program pathname */ 515 rc = loader_set_p athname(ldr, path);515 rc = loader_set_program_path(ldr, path); 516 516 if (rc != EOK) 517 517 goto error; … … 523 523 524 524 /* Send default files */ 525 int *files[4];526 525 int fd_stdin; 527 526 int fd_stdout; 528 527 int fd_stderr; 529 528 530 if ((stdin != NULL) && (vfs_fhandle(stdin, &fd_stdin) == EOK)) 531 files[0] = &fd_stdin; 532 else 533 files[0] = NULL; 534 535 if ((stdout != NULL) && (vfs_fhandle(stdout, &fd_stdout) == EOK)) 536 files[1] = &fd_stdout; 537 else 538 files[1] = NULL; 539 540 if ((stderr != NULL) && (vfs_fhandle(stderr, &fd_stderr) == EOK)) 541 files[2] = &fd_stderr; 542 else 543 files[2] = NULL; 544 545 files[3] = NULL; 546 547 rc = loader_set_files(ldr, files); 548 if (rc != EOK) 549 goto error; 550 529 if ((stdin != NULL) && (vfs_fhandle(stdin, &fd_stdin) == EOK)) { 530 rc = loader_add_inbox(ldr, "stdin", fd_stdin); 531 if (rc != EOK) 532 goto error; 533 } 534 535 if ((stdout != NULL) && (vfs_fhandle(stdout, &fd_stdout) == EOK)) { 536 rc = loader_add_inbox(ldr, "stdout", fd_stdout); 537 if (rc != EOK) 538 goto error; 539 } 540 541 if ((stderr != NULL) && (vfs_fhandle(stderr, &fd_stderr) == EOK)) { 542 rc = loader_add_inbox(ldr, "stderr", fd_stderr); 543 if (rc != EOK) 544 goto error; 545 } 546 551 547 /* Load the program. */ 552 548 rc = loader_load_program(ldr); -
uspace/lib/c/Makefile
re796dc8 rbb9ec2d 151 151 generic/rcu.c \ 152 152 generic/setjmp.c \ 153 generic/vfs/inbox.c \ 153 154 generic/stack.c \ 154 155 generic/stacktrace.c \ -
uspace/lib/c/generic/elf/elf_load.c
re796dc8 rbb9ec2d 41 41 #include <stdio.h> 42 42 #include <stdlib.h> 43 #include <vfs/vfs.h> 43 44 44 45 #ifdef CONFIG_RTLD … … 50 51 /** Load ELF program. 51 52 * 52 * @param file _name File name53 * @param file File handle 53 54 * @param info Place to store ELF program information 54 55 * @return EOK on success or non-zero error code 55 56 */ 56 int elf_load( const char *file_name, elf_info_t *info)57 int elf_load(int file, elf_info_t *info) 57 58 { 58 59 #ifdef CONFIG_RTLD … … 61 62 int rc; 62 63 63 rc = elf_load_file(file _name, 0, 0, &info->finfo);64 rc = elf_load_file(file, 0, 0, &info->finfo); 64 65 if (rc != EE_OK) { 65 66 DPRINTF("Failed to load executable '%s'.\n", file_name); -
uspace/lib/c/generic/elf/elf_mod.c
re796dc8 rbb9ec2d 92 92 * 93 93 */ 94 static int elf_load_file2(int file, size_t so_bias, eld_flags_t flags, elf_finfo_t *info)94 int elf_load_file(int file, size_t so_bias, eld_flags_t flags, elf_finfo_t *info) 95 95 { 96 96 elf_ld_t elf; … … 112 112 } 113 113 114 int elf_load_file(const char *path, size_t so_bias, eld_flags_t flags, elf_finfo_t *info) 114 int elf_load_file_name(const char *path, size_t so_bias, eld_flags_t flags, 115 elf_finfo_t *info) 115 116 { 116 117 int file = vfs_lookup(path); 117 int rc = elf_load_file 2(file, so_bias, flags, info);118 int rc = elf_load_file(file, so_bias, flags, info); 118 119 close(file); 119 120 return rc; -
uspace/lib/c/generic/io/io.c
re796dc8 rbb9ec2d 45 45 #include <vfs/vfs.h> 46 46 #include <vfs/vfs_sess.h> 47 #include <vfs/inbox.h> 47 48 #include <ipc/loc.h> 48 49 #include <adt/list.h> … … 101 102 static LIST_INITIALIZE(files); 102 103 103 void __stdio_init(int filc) 104 { 105 if (filc > 0) { 106 stdin = fdopen(0, "r"); 104 void __stdio_init(void) 105 { 106 /* The first three standard file descriptors are assigned for compatibility. 107 * This will probably be removed later. 108 */ 109 110 int infd = inbox_get("stdin"); 111 if (infd >= 0) { 112 int stdinfd = vfs_clone(infd, false); 113 assert(stdinfd == 0); 114 _vfs_open(stdinfd, MODE_READ); 115 stdin = fdopen(stdinfd, "r"); 107 116 } else { 108 117 stdin = &stdin_null; … … 110 119 } 111 120 112 if (filc > 1) { 113 stdout = fdopen(1, "w"); 121 int outfd = inbox_get("stdout"); 122 if (outfd >= 0) { 123 int stdoutfd = vfs_clone(outfd, false); 124 assert(stdoutfd <= 1); 125 while (stdoutfd < 1) { 126 stdoutfd = vfs_clone(outfd, false); 127 } 128 _vfs_open(stdoutfd, MODE_APPEND); 129 stdout = fdopen(stdoutfd, "a"); 114 130 } else { 115 131 stdout = &stdout_kio; … … 117 133 } 118 134 119 if (filc > 2) { 120 stderr = fdopen(2, "w"); 135 int errfd = inbox_get("stderr"); 136 if (errfd >= 0) { 137 int stderrfd = vfs_clone(errfd, false); 138 assert(stderrfd <= 2); 139 while (stderrfd < 2) { 140 stderrfd = vfs_clone(errfd, false); 141 } 142 _vfs_open(stderrfd, MODE_APPEND); 143 stderr = fdopen(stderrfd, "a"); 121 144 } else { 122 145 stderr = &stderr_kio; -
uspace/lib/c/generic/libc.c
re796dc8 rbb9ec2d 107 107 argc = 0; 108 108 argv = NULL; 109 __stdio_init( 0);109 __stdio_init(); 110 110 } else { 111 111 argc = __pcb->argc; 112 112 argv = __pcb->argv; 113 __stdio_init(__pcb->filc); 113 __inbox_init(__pcb->inbox, __pcb->inbox_entries); 114 __stdio_init(); 114 115 (void) chdir(__pcb->cwd); 115 116 } -
uspace/lib/c/generic/loader.c
re796dc8 rbb9ec2d 147 147 } 148 148 149 /** Set pathname of the program to load. 150 * 151 * Sets the name of the program file to load. The name can be relative 152 * to the current working directory (it will be absolutized before 153 * sending to the loader). 149 /** Set the program to load. 154 150 * 155 151 * @param ldr Loader connection structure. 156 * @param path Pathname of the program file. 157 * 158 * @return Zero on success or negative error code. 159 * 160 */ 161 int loader_set_pathname(loader_t *ldr, const char *path) 162 { 163 size_t pa_len; 164 char *pa = vfs_absolutize(path, &pa_len); 165 if (!pa) 166 return ENOMEM; 167 168 /* Send program pathname */ 169 async_exch_t *exch = async_exchange_begin(ldr->sess); 170 152 * @param name Name to set for the spawned program. 153 * @param file Program file. 154 * 155 * @return Zero on success or negative error code. 156 * 157 */ 158 int loader_set_program(loader_t *ldr, const char *name, int file) 159 { 160 async_exch_t *exch = async_exchange_begin(ldr->sess); 161 171 162 ipc_call_t answer; 172 aid_t req = async_send_0(exch, LOADER_SET_PATHNAME, &answer); 173 sysarg_t rc = async_data_write_start(exch, (void *) pa, pa_len); 174 175 async_exchange_end(exch); 176 free(pa); 177 163 aid_t req = async_send_0(exch, LOADER_SET_PROGRAM, &answer); 164 165 sysarg_t rc = async_data_write_start(exch, name, str_size(name) + 1); 166 if (rc == EOK) { 167 async_exch_t *vfs_exch = vfs_exchange_begin(); 168 rc = vfs_pass_handle(vfs_exch, file, exch); 169 vfs_exchange_end(vfs_exch); 170 } 171 172 async_exchange_end(exch); 173 178 174 if (rc != EOK) { 179 175 async_forget(req); 180 176 return (int) rc; 181 177 } 182 178 183 179 async_wait_for(req, &rc); 184 180 return (int) rc; 185 181 } 182 183 /** Set the program to load by path. 184 * 185 * @param ldr Loader connection structure. 186 * @param path Program path. 187 * 188 * @return Zero on success or negative error code. 189 * 190 */ 191 int loader_set_program_path(loader_t *ldr, const char *path) 192 { 193 const char *name = str_rchr(path, '/'); 194 if (name == NULL) { 195 name = path; 196 } else { 197 name++; 198 } 199 200 int fd = vfs_lookup(path); 201 if (fd < 0) { 202 return fd; 203 } 204 205 int rc = loader_set_program(ldr, name, fd); 206 close(fd); 207 return rc; 208 } 209 186 210 187 211 /** Set command-line arguments for the program. … … 244 268 } 245 269 246 /** Set preset files for the program. 247 * 248 * Sets the vector of preset files to be passed to the loaded 249 * program. By convention, the first three files represent stdin, 250 * stdout and stderr respectively. 251 * 252 * @param ldr Loader connection structure. 253 * @param files NULL-terminated array of pointers to files. 254 * 255 * @return Zero on success or negative error code. 256 * 257 */ 258 int loader_set_files(loader_t *ldr, int * const files[]) 259 { 260 /* Send serialized files to the loader */ 270 /** Add a file to the task's inbox. 271 * 272 * @param ldr Loader connection structure. 273 * @param name Identification of the file. 274 * @param file The file's descriptor. 275 * 276 * @return Zero on success or negative error code. 277 * 278 */ 279 int loader_add_inbox(loader_t *ldr, const char *name, int file) 280 { 261 281 async_exch_t *exch = async_exchange_begin(ldr->sess); 262 282 async_exch_t *vfs_exch = vfs_exchange_begin(); 263 283 264 int i; 265 for (i = 0; files[i]; i++); 266 267 ipc_call_t answer; 268 aid_t req = async_send_1(exch, LOADER_SET_FILES, i, &answer); 269 270 sysarg_t rc = EOK; 271 272 for (i = 0; files[i]; i++) { 273 rc = vfs_pass_handle(vfs_exch, *files[i], exch); 274 if (rc != EOK) 275 break; 276 } 277 278 vfs_exchange_end(vfs_exch); 279 async_exchange_end(exch); 280 281 if (rc != EOK) { 282 async_forget(req); 283 return (int) rc; 284 } 285 286 async_wait_for(req, &rc); 284 aid_t req = async_send_0(exch, LOADER_ADD_INBOX, NULL); 285 286 sysarg_t rc = async_data_write_start(exch, name, str_size(name) + 1); 287 if (rc == EOK) { 288 rc = vfs_pass_handle(vfs_exch, file, exch); 289 } 290 291 async_exchange_end(vfs_exch); 292 async_exchange_end(exch); 293 294 if (rc == EOK) { 295 async_wait_for(req, &rc); 296 } else { 297 async_forget(req); 298 } 299 287 300 return (int) rc; 288 301 } -
uspace/lib/c/generic/private/io.h
re796dc8 rbb9ec2d 36 36 #define LIBC_PRIVATE_IO_H_ 37 37 38 extern void __stdio_init(int); 38 #include <loader/pcb.h> 39 40 extern void __stdio_init(void); 39 41 extern void __stdio_done(void); 42 43 extern void __inbox_init(struct pcb_inbox_entry *entries, int count); 40 44 41 45 #endif -
uspace/lib/c/generic/rtld/module.c
re796dc8 rbb9ec2d 196 196 DPRINTF("load '%s' at 0x%x\n", name_buf, m->bias); 197 197 198 rc = elf_load_file (name_buf, m->bias, ELDF_RW, &info);198 rc = elf_load_file_name(name_buf, m->bias, ELDF_RW, &info); 199 199 if (rc != EE_OK) { 200 200 printf("Failed to load '%s'\n", name_buf); -
uspace/lib/c/generic/task.c
re796dc8 rbb9ec2d 107 107 { 108 108 /* Send default files */ 109 int *files[4]; 110 int fd_stdin; 111 int fd_stdout; 112 int fd_stderr; 113 114 if ((stdin != NULL) && (vfs_fhandle(stdin, &fd_stdin) == EOK)) 115 files[0] = &fd_stdin; 116 else 117 files[0] = NULL; 118 119 if ((stdout != NULL) && (vfs_fhandle(stdout, &fd_stdout) == EOK)) 120 files[1] = &fd_stdout; 121 else 122 files[1] = NULL; 123 124 if ((stderr != NULL) && (vfs_fhandle(stderr, &fd_stderr) == EOK)) 125 files[2] = &fd_stderr; 126 else 127 files[2] = NULL; 128 129 files[3] = NULL; 130 131 return task_spawnvf(id, wait, path, args, files); 109 110 int fd_stdin = -1; 111 int fd_stdout = -1; 112 int fd_stderr = -1; 113 114 if (stdin != NULL) { 115 (void) vfs_fhandle(stdin, &fd_stdin); 116 } 117 118 if (stdout != NULL) { 119 (void) vfs_fhandle(stdout, &fd_stdout); 120 } 121 122 if (stderr != NULL) { 123 (void) vfs_fhandle(stderr, &fd_stderr); 124 } 125 126 return task_spawnvf(id, wait, path, args, fd_stdin, fd_stdout, 127 fd_stderr); 132 128 } 133 129 … … 138 134 * Files are passed as null-terminated array of pointers to fdi_node_t. 139 135 * 140 * @param id If not NULL, the ID of the task is stored here on success. 141 * @param wait If not NULL, setup waiting for task's return value and store 142 * the information necessary for waiting here on success. 143 * @param path Pathname of the binary to execute. 144 * @param argv Command-line arguments. 145 * @param files Standard files to use. 136 * @param id If not NULL, the ID of the task is stored here on success. 137 * @param wait If not NULL, setup waiting for task's return value and store 138 * @param path Pathname of the binary to execute. 139 * @param argv Command-line arguments. 140 * @param std_in File to use as stdin. 141 * @param std_out File to use as stdout. 142 * @param std_err File to use as stderr. 146 143 * 147 144 * @return Zero on success or negative error code. … … 149 146 */ 150 147 int task_spawnvf(task_id_t *id, task_wait_t *wait, const char *path, 151 const char *const args[], int *const files[])148 const char *const args[], int fd_stdin, int fd_stdout, int fd_stderr) 152 149 { 153 150 /* Connect to a program loader. */ … … 169 166 goto error; 170 167 171 /* Send program pathname. */172 rc = loader_set_p athname(ldr, path);168 /* Send program binary. */ 169 rc = loader_set_program_path(ldr, path); 173 170 if (rc != EOK) 174 171 goto error; … … 180 177 181 178 /* Send files */ 182 rc = loader_set_files(ldr, files); 183 if (rc != EOK) 184 goto error; 179 if (fd_stdin >= 0) { 180 rc = loader_add_inbox(ldr, "stdin", fd_stdin); 181 if (rc != EOK) 182 goto error; 183 } 184 185 if (fd_stdout >= 0) { 186 rc = loader_add_inbox(ldr, "stdout", fd_stdout); 187 if (rc != EOK) 188 goto error; 189 } 190 191 if (fd_stderr >= 0) { 192 rc = loader_add_inbox(ldr, "stderr", fd_stderr); 193 if (rc != EOK) 194 goto error; 195 } 185 196 186 197 /* Load the program. */ -
uspace/lib/c/generic/vfs/vfs.c
re796dc8 rbb9ec2d 1162 1162 } 1163 1163 1164 int vfs_receive_handle( )1164 int vfs_receive_handle(bool high_descriptor) 1165 1165 { 1166 1166 ipc_callid_t callid; … … 1175 1175 1176 1176 sysarg_t ret; 1177 sysarg_t rc = async_req_ 0_1(vfs_exch, VFS_IN_WAIT_HANDLE, &ret);1177 sysarg_t rc = async_req_1_1(vfs_exch, VFS_IN_WAIT_HANDLE, high_descriptor, &ret); 1178 1178 1179 1179 async_exchange_end(vfs_exch); -
uspace/lib/c/include/elf/elf_load.h
re796dc8 rbb9ec2d 45 45 } elf_info_t; 46 46 47 extern int elf_load( const char *, elf_info_t *);47 extern int elf_load(int, elf_info_t *); 48 48 extern void elf_set_pcb(elf_info_t *, pcb_t *); 49 49 -
uspace/lib/c/include/elf/elf_mod.h
re796dc8 rbb9ec2d 108 108 109 109 extern const char *elf_error(unsigned int); 110 extern int elf_load_file(const char *, size_t, eld_flags_t, elf_finfo_t *); 110 extern int elf_load_file(int, size_t, eld_flags_t, elf_finfo_t *); 111 extern int elf_load_file_name(const char *, size_t, eld_flags_t, elf_finfo_t *); 111 112 112 113 #endif -
uspace/lib/c/include/ipc/loader.h
re796dc8 rbb9ec2d 42 42 LOADER_GET_TASKID, 43 43 LOADER_SET_CWD, 44 LOADER_SET_P ATHNAME,44 LOADER_SET_PROGRAM, 45 45 LOADER_SET_ARGS, 46 LOADER_ SET_FILES,46 LOADER_ADD_INBOX, 47 47 LOADER_LOAD, 48 48 LOADER_RUN -
uspace/lib/c/include/loader/loader.h
re796dc8 rbb9ec2d 47 47 extern int loader_get_task_id(loader_t *, task_id_t *); 48 48 extern int loader_set_cwd(loader_t *); 49 extern int loader_set_pathname(loader_t *, const char *); 49 extern int loader_set_program(loader_t *, const char *, int); 50 extern int loader_set_program_path(loader_t *, const char *); 50 51 extern int loader_set_args(loader_t *, const char *const[]); 51 extern int loader_ set_files(loader_t *, int *const[]);52 extern int loader_add_inbox(loader_t *, const char *, int); 52 53 extern int loader_load_program(loader_t *); 53 54 extern int loader_run(loader_t *); -
uspace/lib/c/include/loader/pcb.h
re796dc8 rbb9ec2d 41 41 typedef void (*entry_point_t)(void); 42 42 43 struct pcb_inbox_entry { 44 char *name; 45 int file; 46 }; 47 43 48 /** Program Control Block. 44 49 * … … 60 65 char **argv; 61 66 62 /** Number of preset files. */ 63 unsigned int filc; 67 /** List of inbox files. */ 68 struct pcb_inbox_entry *inbox; 69 int inbox_entries; 64 70 65 71 /* -
uspace/lib/c/include/task.h
re796dc8 rbb9ec2d 57 57 const char *const []); 58 58 extern int task_spawnvf(task_id_t *, task_wait_t *, const char *path, 59 const char *const [], int *const []);59 const char *const [], int, int, int); 60 60 extern int task_spawn(task_id_t *, task_wait_t *, const char *path, int, 61 61 va_list ap); -
uspace/lib/c/include/vfs/vfs.h
re796dc8 rbb9ec2d 63 63 extern void vfs_exchange_end(async_exch_t *); 64 64 65 extern int _vfs_walk(int parent, const char *path, int flags);66 extern int _vfs_open(int file, int mode);67 extern int vfs_lookup(const char * path);65 extern int _vfs_walk(int, const char *, int); 66 extern int _vfs_open(int, int); 67 extern int vfs_lookup(const char *); 68 68 69 extern int vfs_pass_handle(async_exch_t * vfs_exch, int file, async_exch_t *exch);70 extern int vfs_receive_handle( void);69 extern int vfs_pass_handle(async_exch_t *, int, async_exch_t *); 70 extern int vfs_receive_handle(bool); 71 71 72 extern int vfs_clone(int file, bool high_descriptor); 73 72 extern int vfs_clone(int, bool); 74 73 75 74 #endif -
uspace/lib/pcut/src/os/helenos.c
re796dc8 rbb9ec2d 170 170 snprintf(test_number_argument, MAX_TEST_NUMBER_WIDTH, "-t%d", test->id); 171 171 172 int *files[4];173 int fd_stdin = fileno(stdin);174 files[0] = &fd_stdin;175 files[1] = &tempfile;176 files[2] = &tempfile;177 files[3] = NULL;178 179 172 const char *const arguments[3] = { 180 173 self_path, … … 186 179 187 180 task_wait_t test_task_wait; 188 int rc = task_spawnvf(&test_task_id, &test_task_wait, self_path, arguments, files); 181 int rc = task_spawnvf(&test_task_id, &test_task_wait, self_path, arguments, 182 fileno(stdin), tempfile, tempfile); 189 183 if (rc != EOK) { 190 184 status = TEST_OUTCOME_ERROR; -
uspace/srv/loader/main.c
re796dc8 rbb9ec2d 62 62 #include <elf/elf_load.h> 63 63 #include <vfs/vfs.h> 64 #include <vfs/inbox.h> 64 65 65 66 #define DPRINTF(...) 66 67 67 /** Pathname of the file that will be loaded */ 68 static char *pathname = NULL; 68 /** File that will be loaded */ 69 static char *progname = NULL; 70 static int program_fd = -1; 69 71 70 72 /** The Program control block */ … … 81 83 static char *arg_buf = NULL; 82 84 83 /** Number of preset files */ 84 static unsigned int filc = 0; 85 /** Inbox entries. */ 86 static struct pcb_inbox_entry inbox[INBOX_MAX_ENTRIES]; 87 static int inbox_entries = 0; 85 88 86 89 static elf_info_t prog_info; … … 130 133 } 131 134 132 /** Receive a call setting pathname of the program to execute. 133 * 134 * @param rid 135 * @param request 136 */ 137 static void ldr_set_pathname(ipc_callid_t rid, ipc_call_t *request) 138 { 139 char *buf; 140 int rc = async_data_write_accept((void **) &buf, true, 0, 0, 0, NULL); 141 142 if (rc == EOK) { 143 if (pathname != NULL) 144 free(pathname); 145 146 pathname = buf; 147 } 148 149 async_answer_0(rid, rc); 135 /** Receive a call setting the program to execute. 136 * 137 * @param rid 138 * @param request 139 */ 140 static void ldr_set_program(ipc_callid_t rid, ipc_call_t *request) 141 { 142 ipc_callid_t writeid; 143 size_t namesize; 144 if (!async_data_write_receive(&writeid, &namesize)) { 145 async_answer_0(rid, EINVAL); 146 return; 147 } 148 149 char* name = malloc(namesize); 150 int rc = async_data_write_finalize(writeid, name, namesize); 151 if (rc != EOK) { 152 async_answer_0(rid, EINVAL); 153 return; 154 } 155 156 int file = vfs_receive_handle(true); 157 if (file < 0) { 158 async_answer_0(rid, EINVAL); 159 return; 160 } 161 162 progname = name; 163 program_fd = file; 164 async_answer_0(rid, EOK); 150 165 } 151 166 … … 215 230 } 216 231 217 /** Receive a call setting preset files of the program to execute. 218 * 219 * @param rid 220 * @param request 221 */ 222 static void ldr_set_files(ipc_callid_t rid, ipc_call_t *request) 223 { 224 size_t count = IPC_GET_ARG1(*request); 225 226 for (filc = 0; filc < count; filc++) { 227 int fd = vfs_receive_handle(); 228 if (fd < 0) { 229 break; 230 } 231 assert(fd == (int) filc); 232 } 233 232 /** Receive a call setting inbox files of the program to execute. 233 * 234 * @param rid 235 * @param request 236 */ 237 static void ldr_add_inbox(ipc_callid_t rid, ipc_call_t *request) 238 { 239 if (inbox_entries == INBOX_MAX_ENTRIES) { 240 async_answer_0(rid, ERANGE); 241 } 242 243 ipc_callid_t writeid; 244 size_t namesize; 245 if (!async_data_write_receive(&writeid, &namesize)) { 246 async_answer_0(rid, EINVAL); 247 return; 248 } 249 250 char* name = malloc(namesize); 251 int rc = async_data_write_finalize(writeid, name, namesize); 252 if (rc != EOK) { 253 async_answer_0(rid, EINVAL); 254 return; 255 } 256 257 int file = vfs_receive_handle(true); 258 if (file < 0) { 259 async_answer_0(rid, EINVAL); 260 return; 261 } 262 263 inbox[inbox_entries].name = name; 264 inbox[inbox_entries].file = file; 265 inbox_entries++; 234 266 async_answer_0(rid, EOK); 235 267 } … … 243 275 static int ldr_load(ipc_callid_t rid, ipc_call_t *request) 244 276 { 245 int rc; 246 247 rc = elf_load(pathname, &prog_info); 277 int rc = elf_load(program_fd, &prog_info); 248 278 if (rc != EE_OK) { 249 DPRINTF("Failed to load executable '%s'.\n", pathname);279 DPRINTF("Failed to load executable for '%s'.\n", progname); 250 280 async_answer_0(rid, EINVAL); 251 281 return 1; … … 259 289 pcb.argv = argv; 260 290 261 pcb.filc = filc; 291 pcb.inbox = inbox; 292 pcb.inbox_entries = inbox_entries; 262 293 263 294 async_answer_0(rid, rc); … … 273 304 static void ldr_run(ipc_callid_t rid, ipc_call_t *request) 274 305 { 275 const char *cp;276 277 306 DPRINTF("Set task name\n"); 278 307 279 308 /* Set the task name. */ 280 cp = str_rchr(pathname, '/'); 281 cp = (cp == NULL) ? pathname : (cp + 1); 282 task_set_name(cp); 309 task_set_name(progname); 283 310 284 311 /* Run program */ … … 327 354 ldr_set_cwd(callid, &call); 328 355 continue; 329 case LOADER_SET_P ATHNAME:330 ldr_set_p athname(callid, &call);356 case LOADER_SET_PROGRAM: 357 ldr_set_program(callid, &call); 331 358 continue; 332 359 case LOADER_SET_ARGS: 333 360 ldr_set_args(callid, &call); 334 361 continue; 335 case LOADER_ SET_FILES:336 ldr_ set_files(callid, &call);362 case LOADER_ADD_INBOX: 363 ldr_add_inbox(callid, &call); 337 364 continue; 338 365 case LOADER_LOAD: -
uspace/srv/vfs/vfs.h
re796dc8 rbb9ec2d 197 197 198 198 extern void vfs_op_pass_handle(task_id_t, task_id_t, int); 199 extern int vfs_wait_handle_internal( void);199 extern int vfs_wait_handle_internal(bool); 200 200 201 201 extern vfs_file_t *vfs_file_get(int); -
uspace/srv/vfs/vfs_file.c
re796dc8 rbb9ec2d 59 59 typedef struct { 60 60 link_t link; 61 int handle; 61 vfs_node_t *node; 62 int permissions; 62 63 } vfs_boxed_handle_t; 63 64 … … 365 366 vfs_client_data_t *acceptor_data = NULL; 366 367 vfs_file_t *donor_file = NULL; 367 vfs_file_t *acceptor_file = NULL;368 368 vfs_boxed_handle_t *bh; 369 int acceptor_fd;370 369 371 370 acceptor_data = async_get_client_data_by_id(acceptor_id); … … 377 376 378 377 link_initialize(&bh->link); 379 bh-> handle = -1;378 bh->node = NULL; 380 379 381 380 donor_data = async_get_client_data_by_id(donor_id); … … 386 385 if (!donor_file) 387 386 goto out; 388 389 acceptor_fd = _vfs_fd_alloc(acceptor_data, &acceptor_file, false);390 if (acceptor_fd < 0)391 goto out;392 393 bh->handle = acceptor_fd;394 387 395 388 /* … … 397 390 */ 398 391 vfs_node_addref(donor_file->node); 399 400 assert(acceptor_file); 401 402 /* 403 * Inherit attributes from the donor. 404 */ 405 acceptor_file->node = donor_file->node; 406 acceptor_file->permissions = donor_file->permissions; 407 408 // TODO: The file should not inherit its open status, but clients depend on this. 409 acceptor_file->pos = donor_file->pos; 410 acceptor_file->append = donor_file->append; 411 acceptor_file->open_read = donor_file->open_read; 412 acceptor_file->open_write = donor_file->open_write; 413 414 if (acceptor_file->open_read || acceptor_file->open_write) { 415 (void) vfs_open_node_remote(acceptor_file->node); 416 } 392 bh->node = donor_file->node; 393 bh->permissions = donor_file->permissions; 417 394 418 395 out: … … 428 405 if (donor_file) 429 406 _vfs_file_put(donor_data, donor_file); 430 if (acceptor_file) 431 _vfs_file_put(acceptor_data, acceptor_file); 432 433 } 434 435 int vfs_wait_handle_internal(void) 407 } 408 409 int vfs_wait_handle_internal(bool high_fd) 436 410 { 437 411 vfs_client_data_t *vfs_data = VFS_DATA; 438 int fd;439 412 440 413 fibril_mutex_lock(&vfs_data->lock); … … 446 419 447 420 vfs_boxed_handle_t *bh = list_get_instance(lnk, vfs_boxed_handle_t, link); 448 fd = bh->handle; 421 422 vfs_file_t *file; 423 int fd = _vfs_fd_alloc(vfs_data, &file, high_fd); 424 if (fd < 0) { 425 vfs_node_delref(bh->node); 426 free(bh); 427 return fd; 428 } 429 430 file->node = bh->node; 431 file->permissions = bh->permissions; 432 vfs_file_put(file); 449 433 free(bh); 450 451 434 return fd; 452 435 } -
uspace/srv/vfs/vfs_ops.c
re796dc8 rbb9ec2d 1248 1248 void vfs_wait_handle(ipc_callid_t rid, ipc_call_t *request) 1249 1249 { 1250 int fd = vfs_wait_handle_internal(); 1250 bool high_fd = IPC_GET_ARG1(*request); 1251 int fd = vfs_wait_handle_internal(high_fd); 1251 1252 async_answer_1(rid, EOK, fd); 1252 1253 }
Note:
See TracChangeset
for help on using the changeset viewer.