Changes in uspace/srv/loader/main.c [153c7a29:b19e892] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/loader/main.c
r153c7a29 rb19e892 48 48 #include <unistd.h> 49 49 #include <stdbool.h> 50 #include <fcntl.h>51 50 #include <sys/types.h> 52 51 #include <ipc/services.h> … … 62 61 #include <elf/elf_load.h> 63 62 #include <vfs/vfs.h> 63 #include <vfs/inbox.h> 64 64 65 65 #define DPRINTF(...) 66 66 67 /** Pathname of the file that will be loaded */ 68 static char *pathname = NULL; 67 /** File that will be loaded */ 68 static char *progname = NULL; 69 static int program_fd = -1; 69 70 70 71 /** The Program control block */ … … 81 82 static char *arg_buf = NULL; 82 83 83 /** Number of preset files */ 84 static unsigned int filc = 0; 84 /** Inbox entries. */ 85 static struct pcb_inbox_entry inbox[INBOX_MAX_ENTRIES]; 86 static int inbox_entries = 0; 85 87 86 88 static elf_info_t prog_info; … … 130 132 } 131 133 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); 134 /** Receive a call setting the program to execute. 135 * 136 * @param rid 137 * @param request 138 */ 139 static void ldr_set_program(ipc_callid_t rid, ipc_call_t *request) 140 { 141 ipc_callid_t writeid; 142 size_t namesize; 143 if (!async_data_write_receive(&writeid, &namesize)) { 144 async_answer_0(rid, EINVAL); 145 return; 146 } 147 148 char* name = malloc(namesize); 149 int rc = async_data_write_finalize(writeid, name, namesize); 150 if (rc != EOK) { 151 async_answer_0(rid, EINVAL); 152 return; 153 } 154 155 int file = vfs_receive_handle(true); 156 if (file < 0) { 157 async_answer_0(rid, EINVAL); 158 return; 159 } 160 161 progname = name; 162 program_fd = file; 163 async_answer_0(rid, EOK); 150 164 } 151 165 … … 215 229 } 216 230 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 async_exch_t *vfs_exch = vfs_exchange_begin(); 227 228 for (filc = 0; filc < count; filc++) { 229 ipc_callid_t callid; 230 int fd; 231 232 if (!async_state_change_receive(&callid, NULL, NULL, NULL)) { 233 async_answer_0(callid, EINVAL); 234 break; 235 } 236 async_state_change_finalize(callid, vfs_exch); 237 fd = vfs_fd_wait(); 238 assert(fd == (int) filc); 239 } 240 241 vfs_exchange_end(vfs_exch); 242 231 /** Receive a call setting inbox files of the program to execute. 232 * 233 * @param rid 234 * @param request 235 */ 236 static void ldr_add_inbox(ipc_callid_t rid, ipc_call_t *request) 237 { 238 if (inbox_entries == INBOX_MAX_ENTRIES) { 239 async_answer_0(rid, ERANGE); 240 return; 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 /* 264 * We need to set the root early for dynamically linked binaries so 265 * that the loader can use it too. 266 */ 267 if (str_cmp(name, "root") == 0) 268 vfs_root_set(file); 269 270 inbox[inbox_entries].name = name; 271 inbox[inbox_entries].file = file; 272 inbox_entries++; 243 273 async_answer_0(rid, EOK); 244 274 } … … 252 282 static int ldr_load(ipc_callid_t rid, ipc_call_t *request) 253 283 { 254 int rc; 255 256 rc = elf_load(pathname, &prog_info); 284 int rc = elf_load(program_fd, &prog_info); 257 285 if (rc != EE_OK) { 258 DPRINTF("Failed to load executable '%s'.\n", pathname);286 DPRINTF("Failed to load executable for '%s'.\n", progname); 259 287 async_answer_0(rid, EINVAL); 260 288 return 1; … … 268 296 pcb.argv = argv; 269 297 270 pcb.filc = filc; 298 pcb.inbox = inbox; 299 pcb.inbox_entries = inbox_entries; 271 300 272 301 async_answer_0(rid, rc); … … 282 311 static void ldr_run(ipc_callid_t rid, ipc_call_t *request) 283 312 { 284 const char *cp;285 286 313 DPRINTF("Set task name\n"); 287 314 288 315 /* Set the task name. */ 289 cp = str_rchr(pathname, '/'); 290 cp = (cp == NULL) ? pathname : (cp + 1); 291 task_set_name(cp); 316 task_set_name(progname); 292 317 293 318 /* Run program */ … … 336 361 ldr_set_cwd(callid, &call); 337 362 continue; 338 case LOADER_SET_P ATHNAME:339 ldr_set_p athname(callid, &call);363 case LOADER_SET_PROGRAM: 364 ldr_set_program(callid, &call); 340 365 continue; 341 366 case LOADER_SET_ARGS: 342 367 ldr_set_args(callid, &call); 343 368 continue; 344 case LOADER_ SET_FILES:345 ldr_ set_files(callid, &call);369 case LOADER_ADD_INBOX: 370 ldr_add_inbox(callid, &call); 346 371 continue; 347 372 case LOADER_LOAD:
Note:
See TracChangeset
for help on using the changeset viewer.