Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/loader/main.c

    ra6dffb8 r8c3bc75  
    6363#include <elf_load.h>
    6464
    65 /* From librtld */
    66 #include <rtld.h>
    67 #include <dynamic.h>
    68 #include <elf_load.h>
    69 #include <module.h>
    70 
    7165#define DPRINTF(...)
    72 
    73 void program_run(void *entry, pcb_t *pcb);
    74 static int ldr_load_dyn_linked(elf_info_t *p_info);
    7566
    7667/** Pathname of the file that will be loaded */
     
    9889
    9990static elf_info_t prog_info;
     91static elf_info_t interp_info;
     92
     93static bool is_dyn_linked;
    10094
    10195/** Used to limit number of connections to one. */
    10296static bool connected = false;
    103 
    104 /** State structure of the dynamic linker. */
    105 runtime_env_t dload_re;
    106 static module_t prog_mod;
    10797
    10898static void ldr_get_taskid(ipc_callid_t rid, ipc_call_t *request)
     
    293283        int rc;
    294284       
    295         rc = elf_load_file(pathname, 0, 0, &prog_info);
     285        rc = elf_load_file(pathname, 0, &prog_info);
    296286        if (rc != EE_OK) {
    297287                DPRINTF("Failed to load executable '%s'.\n", pathname);
     
    312302        if (prog_info.interp == NULL) {
    313303                /* Statically linked program */
     304                is_dyn_linked = false;
    314305                async_answer_0(rid, EOK);
    315306                return 0;
    316307        }
    317308       
    318         DPRINTF("Binary is dynamically linked.\n");
    319         DPRINTF(" - pcb address: %p\n", &pcb);
    320         DPRINTF( "- prog dynamic: %p\n", prog_info.dynamic);
    321 
    322         rc = ldr_load_dyn_linked(&prog_info);
    323 
    324         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       
    325320        return 0;
    326321}
    327322
    328 static int ldr_load_dyn_linked(elf_info_t *p_info)
    329 {
    330         runtime_env = &dload_re;
    331 
    332         DPRINTF("Load dynamically linked program.\n");
    333 
    334         /*
    335          * First we need to process dynamic sections of the executable
    336          * program and insert it into the module graph.
    337          */
    338 
    339         DPRINTF("Parse program .dynamic section at %p\n", p_info->dynamic);
    340         dynamic_parse(p_info->dynamic, 0, &prog_mod.dyn);
    341         prog_mod.bias = 0;
    342         prog_mod.dyn.soname = "[program]";
    343 
    344         /* Initialize list of loaded modules */
    345         list_initialize(&runtime_env->modules_head);
    346         list_append(&prog_mod.modules_link, &runtime_env->modules_head);
    347 
    348         /* Pointer to program module. Used as root of the module graph. */
    349         runtime_env->program = &prog_mod;
    350 
    351         /* Work around non-existent memory space allocation. */
    352         runtime_env->next_bias = 0x1000000;
    353 
    354         /*
    355          * Now we can continue with loading all other modules.
    356          */
    357 
    358         DPRINTF("Load all program dependencies\n");
    359         module_load_deps(&prog_mod);
    360 
    361         /*
    362          * Now relocate/link all modules together.
    363          */
    364 
    365         /* Process relocations in all modules */
    366         DPRINTF("Relocate all modules\n");
    367         modules_process_relocs(&prog_mod);
    368 
    369         /* Pass runtime evironment pointer through PCB. */
    370         pcb.rtld_runtime = (void *) runtime_env;
    371 
    372         return 0;
    373 }
    374323
    375324/** Run the previously loaded program.
     
    383332        const char *cp;
    384333       
    385         DPRINTF("Set task name\n");
    386 
    387334        /* Set the task name. */
    388335        cp = str_rchr(pathname, '/');
     
    390337        task_set_name(cp);
    391338       
    392         /* Run program */
    393         DPRINTF("Reply OK\n");
    394         async_answer_0(rid, EOK);
    395         DPRINTF("Jump to entry point at %p\n", pcb.entry);
    396         program_run(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        }
    397351       
    398352        /* Not reached */
Note: See TracChangeset for help on using the changeset viewer.