Ignore:
File:
1 edited

Legend:

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

    r3e6a98c5 r153c7a29  
    6363#include <vfs/vfs.h>
    6464
    65 #ifdef CONFIG_RTLD
    66 #include <rtld/rtld.h>
    67 #include <rtld/dynamic.h>
    68 #include <rtld/module.h>
    69 
    70 static int ldr_load_dyn_linked(elf_info_t *p_info);
    71 #endif
    72 
    7365#define DPRINTF(...)
    7466
     
    9688/** Used to limit number of connections to one. */
    9789static bool connected = false;
    98 
    99 #ifdef CONFIG_RTLD
    100 /** State structure of the dynamic linker. */
    101 runtime_env_t dload_re;
    102 static module_t prog_mod;
    103 #endif
    10490
    10591static void ldr_get_taskid(ipc_callid_t rid, ipc_call_t *request)
     
    249235                }
    250236                async_state_change_finalize(callid, vfs_exch);
    251                 fd = fd_wait();
     237                fd = vfs_fd_wait();
    252238                assert(fd == (int) filc);
    253239        }
     
    268254        int rc;
    269255       
    270         rc = elf_load_file(pathname, 0, 0, &prog_info);
     256        rc = elf_load(pathname, &prog_info);
    271257        if (rc != EE_OK) {
    272258                DPRINTF("Failed to load executable '%s'.\n", pathname);
     
    275261        }
    276262       
    277         elf_create_pcb(&prog_info, &pcb);
     263        elf_set_pcb(&prog_info, &pcb);
    278264       
    279265        pcb.cwd = cwd;
     
    284270        pcb.filc = filc;
    285271       
    286         if (prog_info.interp == NULL) {
    287                 /* Statically linked program */
    288                 async_answer_0(rid, EOK);
    289                 return 0;
    290         }
    291        
    292         DPRINTF("Binary is dynamically linked.\n");
    293 #ifdef CONFIG_RTLD
    294         DPRINTF(" - pcb address: %p\n", &pcb);
    295         DPRINTF( "- prog dynamic: %p\n", prog_info.dynamic);
    296 
    297         rc = ldr_load_dyn_linked(&prog_info);
    298 #else
    299         rc = ENOTSUP;
    300 #endif
    301272        async_answer_0(rid, rc);
    302273        return 0;
    303274}
    304 
    305 #ifdef CONFIG_RTLD
    306 
    307 static int ldr_load_dyn_linked(elf_info_t *p_info)
    308 {
    309         runtime_env = &dload_re;
    310 
    311         DPRINTF("Load dynamically linked program.\n");
    312 
    313         /*
    314          * First we need to process dynamic sections of the executable
    315          * program and insert it into the module graph.
    316          */
    317 
    318         DPRINTF("Parse program .dynamic section at %p\n", p_info->dynamic);
    319         dynamic_parse(p_info->dynamic, 0, &prog_mod.dyn);
    320         prog_mod.bias = 0;
    321         prog_mod.dyn.soname = "[program]";
    322 
    323         /* Initialize list of loaded modules */
    324         list_initialize(&runtime_env->modules);
    325         list_append(&prog_mod.modules_link, &runtime_env->modules);
    326 
    327         /* Pointer to program module. Used as root of the module graph. */
    328         runtime_env->program = &prog_mod;
    329 
    330         /* Work around non-existent memory space allocation. */
    331         runtime_env->next_bias = 0x1000000;
    332 
    333         /*
    334          * Now we can continue with loading all other modules.
    335          */
    336 
    337         DPRINTF("Load all program dependencies\n");
    338         module_load_deps(&prog_mod);
    339 
    340         /*
    341          * Now relocate/link all modules together.
    342          */
    343 
    344         /* Process relocations in all modules */
    345         DPRINTF("Relocate all modules\n");
    346         modules_process_relocs(&prog_mod);
    347 
    348         /* Pass runtime evironment pointer through PCB. */
    349         pcb.rtld_runtime = (void *) runtime_env;
    350 
    351         return 0;
    352 }
    353 #endif
    354275
    355276/** Run the previously loaded program.
     
    374295        async_answer_0(rid, EOK);
    375296        DPRINTF("Jump to entry point at %p\n", pcb.entry);
    376         entry_point_jmp(prog_info.entry, &pcb);
     297        entry_point_jmp(prog_info.finfo.entry, &pcb);
    377298       
    378299        /* Not reached */
     
    443364int main(int argc, char *argv[])
    444365{
    445         /* Set a handler of incomming connections. */
    446         async_set_client_connection(ldr_connection);
     366        async_set_fallback_port_handler(ldr_connection, NULL);
    447367       
    448368        /* Introduce this task to the NS (give it our task ID). */
     
    452372                return rc;
    453373       
    454         /* Register at naming service. */
    455         rc = service_register(SERVICE_LOAD);
     374        /* Create port */
     375        port_id_t port;
     376        rc = async_create_port(INTERFACE_LOADER, ldr_connection, NULL, &port);
    456377        if (rc != EOK)
    457378                return rc;
    458379       
     380        /* Register at naming service. */
     381        rc = service_register(SERVICE_LOADER);
     382        if (rc != EOK)
     383                return rc;
     384       
    459385        async_manager();
    460386       
Note: See TracChangeset for help on using the changeset viewer.