34,75 → 34,9 |
* @file |
*/ |
|
#include <stdio.h> |
#include <unistd.h> |
#include <fcntl.h> |
#include <loader/pcb.h> |
|
#include <rtld.h> |
#include <dynamic.h> |
#include <elf_load.h> |
#include <module.h> |
#include <rtld_arch.h> |
|
runtime_env_t runtime_env; |
|
void program_run(void *entry, pcb_t *pcb); |
|
static void rtld_main(void) |
{ |
static module_t prog; |
|
DPRINTF("Hello, world! (from rtld)\n"); |
|
/* |
* First we need to process dynamic sections of the executable |
* program and insert it into the module graph. |
*/ |
|
DPRINTF("Parse program .dynamic section at 0x%x\n", __pcb->dynamic); |
dynamic_parse(__pcb->dynamic, 0, &prog.dyn); |
prog.bias = 0; |
prog.dyn.soname = "[program]"; |
|
/* Initialize list of loaded modules */ |
list_initialize(&runtime_env.modules_head); |
list_append(&prog.modules_link, &runtime_env.modules_head); |
|
/* Pointer to program module. Used as root of the module graph. */ |
runtime_env.program = &prog; |
|
/* |
* Now we can continue with loading all other modules. |
*/ |
|
DPRINTF("Load all program dependencies\n"); |
module_load_deps(&prog); |
|
/* |
* Now relocate/link all modules together. |
*/ |
|
/* Process relocations in all modules */ |
DPRINTF("Relocate all modules\n"); |
modules_process_relocs(); |
|
/* |
* Finally, run the main program. |
*/ |
DPRINTF("Run program.. (at 0x%lx)\n", (uintptr_t)__pcb->entry); |
|
#ifndef RTLD_DEBUG |
close_console(); |
#endif |
program_run(__pcb->entry, __pcb); |
} |
|
int main(int argc, char *argv[]) |
{ |
rtld_main(); |
return 0; |
} |
|
/** @} |
*/ |