Changeset bb9ec2d in mainline for uspace/srv/loader/main.c
- 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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:
Note:
See TracChangeset
for help on using the changeset viewer.