Subversion Repositories HelenOS

Compare Revisions

Problem with comparison.

Ignore whitespace Rev HEAD → Rev 3562

/branches/dynload/uspace/lib/rtld/rtld.c
0,0 → 1,130
/*
* Copyright (c) 2008 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup rtld rtld
* @brief
* @{
*/
/**
* @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);
 
void _rtld_main(void)
{
static module_t prog;
// module_t *rtld;
 
DPRINTF("Hello, world! (from rtld)\n");
 
/*
* First we need to process dynamic sections of the two modules
* that have been already loaded, that is, of ourselves and of
* the executable program.
*/
 
/* rtld_dynamic and rtld->bias were filled out by the bootstrap code */
// rtld = &runtime_env.rtld;
// DPRINTF("Parse rtld .dynamic section at 0x%x\n", runtime_env.rtld_dynamic);
// dynamic_parse(runtime_env.rtld_dynamic, rtld->bias, &rtld->dyn);
 
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);
// list_append(&rtld->modules_link, &runtime_env.modules_head);
 
/* Pointer to program module. Used as root of the dependency 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%x)\n", (uintptr_t)__pcb->entry);
 
#ifndef RTLD_DEBUG
close_console();
#endif
//__pcb->entry();
program_run(__pcb->entry, __pcb);
}
 
/** Fake main to satisfy dependency from libc */
int main(int argc, char *argv[])
{
return 0;
}
/*
typedef void (*ep2)(void *);
 
void program_run(void *entry, pcb_t *pcb)
{
asm (
// "xorl %%ebx, %%ebx\n"
// "movl 0(%%ebx), %%ecx\n"
"mov %%eax, %%ebx\n"
"jmp *%0\n"
:: "m" (entry), "a" (pcb)
);
}*/
 
/** @}
*/