Changeset 3375bd4 in mainline for uspace/srv/loader/main.c


Ignore:
Timestamp:
2011-05-17T07:44:17Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
04c418d, 2586860, 5e6e50b
Parents:
72cd53d (diff), 0d8a304 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

Conflicts:
kernel/generic/src/console/console.c

size of klog, taken upstream

uspace/app/klog/klog.c

taken upstream (upstream fixed the broken output on huge load)

uspace/app/tester/Makefile
uspace/app/tester/tester.c
uspace/app/tester/tester.h

merged without problems

uspace/lib/c/include/as.h

merged without problems (upstream use bare declarations)

Also needed to fix some missing includes.

File:
1 edited

Legend:

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

    r72cd53d r3375bd4  
    5555#include <macros.h>
    5656#include <loader/pcb.h>
     57#include <entry_point.h>
    5758#include <errno.h>
    5859#include <async.h>
     
    6263#include <elf.h>
    6364#include <elf_load.h>
     65
     66#ifdef CONFIG_RTLD
     67#include <rtld/rtld.h>
     68#include <rtld/dynamic.h>
     69#include <rtld/module.h>
     70
     71static int ldr_load_dyn_linked(elf_info_t *p_info);
     72#endif
    6473
    6574#define DPRINTF(...)
     
    8998
    9099static elf_info_t prog_info;
    91 static elf_info_t interp_info;
    92 
    93 static bool is_dyn_linked;
    94100
    95101/** Used to limit number of connections to one. */
    96102static bool connected = false;
     103
     104#ifdef CONFIG_RTLD
     105/** State structure of the dynamic linker. */
     106runtime_env_t dload_re;
     107static module_t prog_mod;
     108#endif
    97109
    98110static void ldr_get_taskid(ipc_callid_t rid, ipc_call_t *request)
     
    283295        int rc;
    284296       
    285         rc = elf_load_file(pathname, 0, &prog_info);
     297        rc = elf_load_file(pathname, 0, 0, &prog_info);
    286298        if (rc != EE_OK) {
    287299                DPRINTF("Failed to load executable '%s'.\n", pathname);
     
    302314        if (prog_info.interp == NULL) {
    303315                /* Statically linked program */
    304                 is_dyn_linked = false;
    305316                async_answer_0(rid, EOK);
    306317                return 0;
    307318        }
    308319       
    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        
     320        DPRINTF("Binary is dynamically linked.\n");
     321#ifdef CONFIG_RTLD
     322        DPRINTF(" - pcb address: %p\n", &pcb);
     323        DPRINTF( "- prog dynamic: %p\n", prog_info.dynamic);
     324
     325        rc = ldr_load_dyn_linked(&prog_info);
     326#else
     327        rc = ENOTSUP;
     328#endif
     329        async_answer_0(rid, rc);
    320330        return 0;
    321331}
    322332
     333#ifdef CONFIG_RTLD
     334
     335static int ldr_load_dyn_linked(elf_info_t *p_info)
     336{
     337        runtime_env = &dload_re;
     338
     339        DPRINTF("Load dynamically linked program.\n");
     340
     341        /*
     342         * First we need to process dynamic sections of the executable
     343         * program and insert it into the module graph.
     344         */
     345
     346        DPRINTF("Parse program .dynamic section at %p\n", p_info->dynamic);
     347        dynamic_parse(p_info->dynamic, 0, &prog_mod.dyn);
     348        prog_mod.bias = 0;
     349        prog_mod.dyn.soname = "[program]";
     350
     351        /* Initialize list of loaded modules */
     352        list_initialize(&runtime_env->modules_head);
     353        list_append(&prog_mod.modules_link, &runtime_env->modules_head);
     354
     355        /* Pointer to program module. Used as root of the module graph. */
     356        runtime_env->program = &prog_mod;
     357
     358        /* Work around non-existent memory space allocation. */
     359        runtime_env->next_bias = 0x1000000;
     360
     361        /*
     362         * Now we can continue with loading all other modules.
     363         */
     364
     365        DPRINTF("Load all program dependencies\n");
     366        module_load_deps(&prog_mod);
     367
     368        /*
     369         * Now relocate/link all modules together.
     370         */
     371
     372        /* Process relocations in all modules */
     373        DPRINTF("Relocate all modules\n");
     374        modules_process_relocs(&prog_mod);
     375
     376        /* Pass runtime evironment pointer through PCB. */
     377        pcb.rtld_runtime = (void *) runtime_env;
     378
     379        return 0;
     380}
     381#endif
    323382
    324383/** Run the previously loaded program.
     
    332391        const char *cp;
    333392       
     393        DPRINTF("Set task name\n");
     394
    334395        /* Set the task name. */
    335396        cp = str_rchr(pathname, '/');
     
    337398        task_set_name(cp);
    338399       
    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         }
     400        /* Run program */
     401        DPRINTF("Reply OK\n");
     402        async_answer_0(rid, EOK);
     403        DPRINTF("Jump to entry point at %p\n", pcb.entry);
     404        entry_point_jmp(prog_info.entry, &pcb);
    351405       
    352406        /* Not reached */
Note: See TracChangeset for help on using the changeset viewer.