Changes in uspace/srv/loader/main.c [bfdb5af1:8c3bc75] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/loader/main.c
rbfdb5af1 r8c3bc75 52 52 #include <ipc/services.h> 53 53 #include <ipc/loader.h> 54 #include <ns.h> 54 #include <ipc/ns.h> 55 #include <macros.h> 55 56 #include <loader/pcb.h> 56 #include <entry_point.h>57 57 #include <errno.h> 58 58 #include <async.h> 59 59 #include <str.h> 60 60 #include <as.h> 61 #include <elf/elf.h> 62 #include <elf/elf_load.h> 63 64 #ifdef CONFIG_RTLD 65 #include <rtld/rtld.h> 66 #include <rtld/dynamic.h> 67 #include <rtld/module.h> 68 69 static int ldr_load_dyn_linked(elf_info_t *p_info); 70 #endif 61 62 #include <elf.h> 63 #include <elf_load.h> 71 64 72 65 #define DPRINTF(...) … … 96 89 97 90 static elf_info_t prog_info; 91 static elf_info_t interp_info; 92 93 static bool is_dyn_linked; 98 94 99 95 /** Used to limit number of connections to one. */ 100 96 static bool connected = false; 101 102 #ifdef CONFIG_RTLD103 /** State structure of the dynamic linker. */104 runtime_env_t dload_re;105 static module_t prog_mod;106 #endif107 97 108 98 static void ldr_get_taskid(ipc_callid_t rid, ipc_call_t *request) … … 293 283 int rc; 294 284 295 rc = elf_load_file(pathname, 0, 0,&prog_info);285 rc = elf_load_file(pathname, 0, &prog_info); 296 286 if (rc != EE_OK) { 297 287 DPRINTF("Failed to load executable '%s'.\n", pathname); … … 312 302 if (prog_info.interp == NULL) { 313 303 /* Statically linked program */ 304 is_dyn_linked = false; 314 305 async_answer_0(rid, EOK); 315 306 return 0; 316 307 } 317 308 318 DPRINTF("Binary is dynamically linked.\n"); 319 #ifdef CONFIG_RTLD 320 DPRINTF(" - pcb address: %p\n", &pcb); 321 DPRINTF( "- prog dynamic: %p\n", prog_info.dynamic); 322 323 rc = ldr_load_dyn_linked(&prog_info); 324 #else 325 rc = ENOTSUP; 326 #endif 327 async_answer_0(rid, rc); 309 rc = elf_load_file(prog_info.interp, 0, &interp_info); 310 if (rc != EE_OK) { 311 DPRINTF("Failed to load interpreter '%s.'\n", 312 prog_info.interp); 313 async_answer_0(rid, EINVAL); 314 return 1; 315 } 316 317 is_dyn_linked = true; 318 async_answer_0(rid, EOK); 319 328 320 return 0; 329 321 } 330 322 331 #ifdef CONFIG_RTLD332 333 static int ldr_load_dyn_linked(elf_info_t *p_info)334 {335 runtime_env = &dload_re;336 337 DPRINTF("Load dynamically linked program.\n");338 339 /*340 * First we need to process dynamic sections of the executable341 * program and insert it into the module graph.342 */343 344 DPRINTF("Parse program .dynamic section at %p\n", p_info->dynamic);345 dynamic_parse(p_info->dynamic, 0, &prog_mod.dyn);346 prog_mod.bias = 0;347 prog_mod.dyn.soname = "[program]";348 349 /* Initialize list of loaded modules */350 list_initialize(&runtime_env->modules);351 list_append(&prog_mod.modules_link, &runtime_env->modules);352 353 /* Pointer to program module. Used as root of the module graph. */354 runtime_env->program = &prog_mod;355 356 /* Work around non-existent memory space allocation. */357 runtime_env->next_bias = 0x1000000;358 359 /*360 * Now we can continue with loading all other modules.361 */362 363 DPRINTF("Load all program dependencies\n");364 module_load_deps(&prog_mod);365 366 /*367 * Now relocate/link all modules together.368 */369 370 /* Process relocations in all modules */371 DPRINTF("Relocate all modules\n");372 modules_process_relocs(&prog_mod);373 374 /* Pass runtime evironment pointer through PCB. */375 pcb.rtld_runtime = (void *) runtime_env;376 377 return 0;378 }379 #endif380 323 381 324 /** Run the previously loaded program. … … 389 332 const char *cp; 390 333 391 DPRINTF("Set task name\n");392 393 334 /* Set the task name. */ 394 335 cp = str_rchr(pathname, '/'); … … 396 337 task_set_name(cp); 397 338 398 /* Run program */ 399 DPRINTF("Reply OK\n"); 400 async_answer_0(rid, EOK); 401 DPRINTF("Jump to entry point at %p\n", pcb.entry); 402 entry_point_jmp(prog_info.entry, &pcb); 339 if (is_dyn_linked == true) { 340 /* Dynamically linked program */ 341 DPRINTF("Run ELF interpreter.\n"); 342 DPRINTF("Entry point: %p\n", interp_info.entry); 343 344 async_answer_0(rid, EOK); 345 elf_run(&interp_info, &pcb); 346 } else { 347 /* Statically linked program */ 348 async_answer_0(rid, EOK); 349 elf_run(&prog_info, &pcb); 350 } 403 351 404 352 /* Not reached */ … … 410 358 * to execute the loaded program). 411 359 */ 412 static void ldr_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 413 { 360 static void ldr_connection(ipc_callid_t iid, ipc_call_t *icall) 361 { 362 ipc_callid_t callid; 363 ipc_call_t call; 364 int retval; 365 414 366 /* Already have a connection? */ 415 367 if (connected) { … … 424 376 425 377 /* Ignore parameters, the connection is already open */ 378 (void) iid; 426 379 (void) icall; 427 380 428 while (true) { 429 int retval; 430 ipc_call_t call; 431 ipc_callid_t callid = async_get_call(&call); 432 433 if (!IPC_GET_IMETHOD(call)) 381 while (1) { 382 callid = async_get_call(&call); 383 384 switch (IPC_GET_IMETHOD(call)) { 385 case IPC_M_PHONE_HUNGUP: 434 386 exit(0); 435 436 switch (IPC_GET_IMETHOD(call)) {437 387 case LOADER_GET_TASKID: 438 388 ldr_get_taskid(callid, &call); … … 461 411 } 462 412 463 async_answer_0(callid, retval); 413 if (IPC_GET_IMETHOD(call) != IPC_M_PHONE_HUNGUP) 414 async_answer_0(callid, retval); 464 415 } 465 416 } … … 474 425 /* Introduce this task to the NS (give it our task ID). */ 475 426 task_id_t id = task_get_id(); 476 int rc = ns_intro(id);427 int rc = async_req_2_0(PHONE_NS, NS_ID_INTRO, LOWER32(id), UPPER32(id)); 477 428 if (rc != EOK) 478 429 return -1;
Note:
See TracChangeset
for help on using the changeset viewer.