Changeset 984a9ba in mainline for uspace/srv/loader/main.c
- Timestamp:
- 2018-07-05T09:34:09Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 63d46341
- Parents:
- 76f566d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/loader/main.c
r76f566d r984a9ba 90 90 static bool connected = false; 91 91 92 static void ldr_get_taskid( cap_call_handle_t req_handle, ipc_call_t *request)93 { 94 cap_call_handle_t chandle;92 static void ldr_get_taskid(ipc_call_t *req) 93 { 94 ipc_call_t call; 95 95 task_id_t task_id; 96 96 size_t len; … … 98 98 task_id = task_get_id(); 99 99 100 if (!async_data_read_receive(&c handle, &len)) {101 async_answer_0( chandle, EINVAL);102 async_answer_0(req _handle, EINVAL);100 if (!async_data_read_receive(&call, &len)) { 101 async_answer_0(&call, EINVAL); 102 async_answer_0(req, EINVAL); 103 103 return; 104 104 } … … 107 107 len = sizeof(task_id); 108 108 109 async_data_read_finalize( chandle, &task_id, len);110 async_answer_0(req _handle, EOK);109 async_data_read_finalize(&call, &task_id, len); 110 async_answer_0(req, EOK); 111 111 } 112 112 113 113 /** Receive a call setting the current working directory. 114 114 * 115 * @param req_handle 116 * @param request 117 */ 118 static void ldr_set_cwd(cap_call_handle_t req_handle, ipc_call_t *request) 115 */ 116 static void ldr_set_cwd(ipc_call_t *req) 119 117 { 120 118 char *buf; … … 128 126 } 129 127 130 async_answer_0(req _handle, rc);128 async_answer_0(req, rc); 131 129 } 132 130 133 131 /** Receive a call setting the program to execute. 134 132 * 135 * @param req_handle 136 * @param request 137 */ 138 static void ldr_set_program(cap_call_handle_t req_handle, ipc_call_t *request) 139 { 140 cap_call_handle_t write_chandle; 133 */ 134 static void ldr_set_program(ipc_call_t *req) 135 { 136 ipc_call_t call; 141 137 size_t namesize; 142 if (!async_data_write_receive(& write_chandle, &namesize)) {143 async_answer_0(req _handle, EINVAL);138 if (!async_data_write_receive(&call, &namesize)) { 139 async_answer_0(req, EINVAL); 144 140 return; 145 141 } 146 142 147 143 char *name = malloc(namesize); 148 errno_t rc = async_data_write_finalize(write_chandle, name, namesize); 144 // FIXME: check return value 145 146 errno_t rc = async_data_write_finalize(&call, name, namesize); 149 147 if (rc != EOK) { 150 async_answer_0(req _handle, EINVAL);148 async_answer_0(req, EINVAL); 151 149 return; 152 150 } … … 155 153 rc = vfs_receive_handle(true, &file); 156 154 if (rc != EOK) { 157 async_answer_0(req _handle, EINVAL);155 async_answer_0(req, EINVAL); 158 156 return; 159 157 } … … 161 159 progname = name; 162 160 program_fd = file; 163 async_answer_0(req _handle, EOK);161 async_answer_0(req, EOK); 164 162 } 165 163 166 164 /** Receive a call setting arguments of the program to execute. 167 165 * 168 * @param req_handle 169 * @param request 170 */ 171 static void ldr_set_args(cap_call_handle_t req_handle, ipc_call_t *request) 166 */ 167 static void ldr_set_args(ipc_call_t *req) 172 168 { 173 169 char *buf; … … 194 190 if (_argv == NULL) { 195 191 free(buf); 196 async_answer_0(req _handle, ENOMEM);192 async_answer_0(req, ENOMEM); 197 193 return; 198 194 } … … 226 222 } 227 223 228 async_answer_0(req _handle, rc);224 async_answer_0(req, rc); 229 225 } 230 226 231 227 /** Receive a call setting inbox files of the program to execute. 232 228 * 233 * @param req_handle 234 * @param request 235 */ 236 static void ldr_add_inbox(cap_call_handle_t req_handle, ipc_call_t *request) 229 */ 230 static void ldr_add_inbox(ipc_call_t *req) 237 231 { 238 232 if (inbox_entries == INBOX_MAX_ENTRIES) { 239 async_answer_0(req _handle, ERANGE);240 return; 241 } 242 243 cap_call_handle_t write_chandle;233 async_answer_0(req, ERANGE); 234 return; 235 } 236 237 ipc_call_t call; 244 238 size_t namesize; 245 if (!async_data_write_receive(& write_chandle, &namesize)) {246 async_answer_0(req _handle, EINVAL);239 if (!async_data_write_receive(&call, &namesize)) { 240 async_answer_0(req, EINVAL); 247 241 return; 248 242 } 249 243 250 244 char *name = malloc(namesize); 251 errno_t rc = async_data_write_finalize( write_chandle, name, namesize);245 errno_t rc = async_data_write_finalize(&call, name, namesize); 252 246 if (rc != EOK) { 253 async_answer_0(req _handle, EINVAL);247 async_answer_0(req, EINVAL); 254 248 return; 255 249 } … … 258 252 rc = vfs_receive_handle(true, &file); 259 253 if (rc != EOK) { 260 async_answer_0(req _handle, EINVAL);254 async_answer_0(req, EINVAL); 261 255 return; 262 256 } … … 272 266 inbox[inbox_entries].file = file; 273 267 inbox_entries++; 274 async_answer_0(req _handle, EOK);268 async_answer_0(req, EOK); 275 269 } 276 270 277 271 /** Load the previously selected program. 278 272 * 279 * @param req_handle280 * @param request281 273 * @return 0 on success, !0 on error. 282 */ 283 static int ldr_load(cap_call_handle_t req_handle, ipc_call_t *request) 274 * 275 */ 276 static int ldr_load(ipc_call_t *req) 284 277 { 285 278 int rc = elf_load(program_fd, &prog_info); 286 279 if (rc != EE_OK) { 287 280 DPRINTF("Failed to load executable for '%s'.\n", progname); 288 async_answer_0(req _handle, EINVAL);281 async_answer_0(req, EINVAL); 289 282 return 1; 290 283 } … … 300 293 pcb.inbox_entries = inbox_entries; 301 294 302 async_answer_0(req _handle, EOK);295 async_answer_0(req, EOK); 303 296 return 0; 304 297 } … … 306 299 /** Run the previously loaded program. 307 300 * 308 * @param req_handle309 * @param request310 301 * @return 0 on success, !0 on error. 311 * /312 static __attribute__((noreturn)) void ldr_run(cap_call_handle_t req_handle, 313 ipc_call_t *request)302 * 303 */ 304 static __attribute__((noreturn)) void ldr_run(ipc_call_t *req) 314 305 { 315 306 DPRINTF("Set task name\n"); … … 320 311 /* Run program */ 321 312 DPRINTF("Reply OK\n"); 322 async_answer_0(req _handle, EOK);313 async_answer_0(req, EOK); 323 314 DPRINTF("Jump to entry point at %p\n", pcb.entry); 324 315 entry_point_jmp(prog_info.finfo.entry, &pcb); … … 331 322 * Receive and carry out commands (of which the last one should be 332 323 * to execute the loaded program). 333 * /334 static void ldr_connection(cap_call_handle_t icall_handle, ipc_call_t *icall, 335 324 * 325 */ 326 static void ldr_connection(ipc_call_t *icall, void *arg) 336 327 { 337 328 /* Already have a connection? */ 338 329 if (connected) { 339 async_answer_0(icall _handle, ELIMIT);330 async_answer_0(icall, ELIMIT); 340 331 return; 341 332 } … … 344 335 345 336 /* Accept the connection */ 346 async_answer_0(icall _handle, EOK);337 async_answer_0(icall, EOK); 347 338 348 339 /* Ignore parameters, the connection is already open */ … … 352 343 errno_t retval; 353 344 ipc_call_t call; 354 cap_call_handle_t chandle =async_get_call(&call);345 async_get_call(&call); 355 346 356 347 if (!IPC_GET_IMETHOD(call)) … … 359 350 switch (IPC_GET_IMETHOD(call)) { 360 351 case LOADER_GET_TASKID: 361 ldr_get_taskid( chandle,&call);352 ldr_get_taskid(&call); 362 353 continue; 363 354 case LOADER_SET_CWD: 364 ldr_set_cwd( chandle,&call);355 ldr_set_cwd(&call); 365 356 continue; 366 357 case LOADER_SET_PROGRAM: 367 ldr_set_program( chandle,&call);358 ldr_set_program(&call); 368 359 continue; 369 360 case LOADER_SET_ARGS: 370 ldr_set_args( chandle,&call);361 ldr_set_args(&call); 371 362 continue; 372 363 case LOADER_ADD_INBOX: 373 ldr_add_inbox( chandle,&call);364 ldr_add_inbox(&call); 374 365 continue; 375 366 case LOADER_LOAD: 376 ldr_load( chandle,&call);367 ldr_load(&call); 377 368 continue; 378 369 case LOADER_RUN: 379 ldr_run( chandle,&call);370 ldr_run(&call); 380 371 /* Not reached */ 381 372 default: … … 384 375 } 385 376 386 async_answer_0( chandle, retval);377 async_answer_0(&call, retval); 387 378 } 388 379 }
Note:
See TracChangeset
for help on using the changeset viewer.