/branches/dynload/uspace/lib/rtld/include/rtld.h |
---|
61,7 → 61,7 |
link_t modules_head; |
} runtime_env_t; |
extern runtime_env_t runtime_env; |
extern runtime_env_t *runtime_env; |
#endif |
/branches/dynload/uspace/lib/rtld/module.c |
---|
77,12 → 77,15 |
*/ |
module_t *module_find(char *name) |
{ |
link_t *head = &runtime_env.modules_head; |
link_t *head = &runtime_env->modules_head; |
link_t *cur; |
module_t *m; |
char *p, *soname; |
printf("got head ptr\n"); |
printf(" = 0x%lx\n", (long) head); |
/* |
* If name contains slashes, treat it as a pathname and |
* construct soname by chopping off the path. Otherwise |
91,8 → 94,11 |
p = strrchr(name, '/'); |
soname = p ? (p + 1) : name; |
printf("did strrchr. soname='%s'\n", soname); |
/* Traverse list of all modules. Not extremely fast, but simple */ |
for (cur = head->next; cur != head; cur = cur->next) { |
printf("get_instance...\n"); |
m = list_get_instance(cur, module_t, modules_link); |
if (strcmp(m->dyn.soname, soname) == 0) { |
return m; /* Found */ |
146,7 → 152,7 |
dynamic_parse(info.dynamic, m->bias, &m->dyn); |
/* Insert into the list of loaded modules */ |
list_append(&m->modules_link, &runtime_env.modules_head); |
list_append(&m->modules_link, &runtime_env->modules_head); |
return m; |
} |
209,7 → 215,7 |
void modules_process_relocs(void) |
{ |
link_t *head = &runtime_env.modules_head; |
link_t *head = &runtime_env->modules_head; |
link_t *cur; |
module_t *m; |
218,7 → 224,7 |
m = list_get_instance(cur, module_t, modules_link); |
/* Skip rtld, since it has already been processed */ |
if (m != &runtime_env.rtld) { |
if (m != &runtime_env->rtld) { |
module_process_relocs(m); |
} |
} |
228,7 → 234,7 |
*/ |
void modules_untag(void) |
{ |
link_t *head = &runtime_env.modules_head; |
link_t *head = &runtime_env->modules_head; |
link_t *cur; |
module_t *m; |
/branches/dynload/uspace/lib/rtld/rtld.c |
---|
36,7 → 36,7 |
#include <rtld.h> |
runtime_env_t runtime_env; |
runtime_env_t *runtime_env; |
/** @} |
*/ |
/branches/dynload/uspace/lib/rtld/symbol.c |
---|
149,8 → 149,8 |
/* Insert root (the program) into the queue and tag it */ |
list_initialize(&queue_head); |
runtime_env.program->bfs_tag = true; |
list_append(&runtime_env.program->queue_link, &queue_head); |
runtime_env->program->bfs_tag = true; |
list_append(&runtime_env->program->queue_link, &queue_head); |
/* If the symbol is found, it will be stored in 'sym' */ |
sym = NULL; |
/branches/dynload/uspace/lib/rtld/Makefile |
---|
41,6 → 41,8 |
CFLAGS += -Iinclude -I../../srv/loader/include -O0 -ggdb |
LFLAGS += |
PIC_CFLAGS := $(CFLAGS) -fPIC -D__PIC__ |
DEFS += -DRELEASE=\"$(RELEASE)\" |
ifdef REVISION |
65,9 → 67,12 |
GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES))) |
ARCH_OBJECTS := $(addsuffix .o,$(basename $(ARCH_SOURCES))) |
OBJECTS := $(GENERIC_OBJECTS) $(ARCH_OBJECTS) |
PIC_OBJECTS := $(addsuffix .pio,$(basename $(OBJECTS))) |
.PHONY: all clean depend disasm sections inc |
all: inc $(OUTPUT) |
all: inc $(OUTPUT) librtld.pic.a |
inc: |
ln -sfn ../arch/$(ARCH)/include include/arch |
75,15 → 80,18 |
-include Makefile.depend |
clean: |
-rm -f $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm $(OUTPUT).sections Makefile.depend *.o arch/$(ARCH)/_link.ld include/arch |
-rm -f $(OUTPUT) librtld.pic.a $(OUTPUT).map $(OUTPUT).disasm $(OUTPUT).sections Makefile.depend *.o $(PIC_OBJECTS) arch/$(ARCH)/_link.ld include/arch |
find arch/$(ARCH)/ -name '*.o' -follow -exec rm \{\} \; |
depend: |
$(CC) $(DEFS) $(CFLAGS) -M $(ARCH_SOURCES) $(GENERIC_SOURCES)> Makefile.depend |
$(OUTPUT): depend $(ARCH_OBJECTS) $(GENERIC_OBJECTS) |
$(AR) rc $(OUTPUT) $(ARCH_OBJECTS) $(GENERIC_OBJECTS) |
$(OUTPUT): depend $(OBJECTS) |
$(AR) rc $(OUTPUT) $(OBJECTS) |
librtld.pic.a: depend $(PIC_OBJECTS) |
$(AR) rc librtld.pic.a $(PIC_OBJECTS) |
%.o: %.S |
$(CC) $(DEFS) $(AFLAGS) $(CFLAGS) -D__ASM__ -c $< -o $@ |
92,3 → 100,6 |
%.o: %.c |
$(CC) $(DEFS) $(CFLAGS) -c $< -o $@ |
%.pio: %.c |
$(CC) $(DEFS) $(PIC_CFLAGS) -c $< -o $@ |
/branches/dynload/uspace/lib/libc/include/loader/pcb.h |
---|
60,6 → 60,8 |
*/ |
/** Pointer to ELF dynamic section of the program. */ |
void *dynamic; |
/** Pointer to dynamic linker state structure (runtime_env_t). */ |
void *rtld_runtime; |
} pcb_t; |
/** |
/branches/dynload/uspace/lib/libc/include/dlfcn.h |
---|
0,0 → 1,46 |
/* |
* 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 |
* @{ |
*/ |
/** @file |
* @brief UNIX-like dynamic linker interface. |
*/ |
#ifndef LIBC_DLFCN_H_ |
#define LIBC_DLFCN_H_ |
void *dlopen(const char *, int); |
void *dlsym(void *, const char *); |
#endif |
/** |
* @} |
*/ |
/branches/dynload/uspace/lib/libc/shared/Makefile |
---|
44,8 → 44,8 |
LIBS = \ |
$(LIBC_PREFIX)/libc.pic.a \ |
$(SOFTINT_PREFIX)/libsoftint.a \ |
$(RTLD_PREFIX)/librtld.a |
$(SOFTINT_PREFIX)/libsoftint.pic.a \ |
$(RTLD_PREFIX)/librtld.pic.a |
DEFS += -DRELEASE=\"$(RELEASE)\" |
/branches/dynload/uspace/lib/libc/generic/libc.c |
---|
50,6 → 50,10 |
#include <as.h> |
#include <loader/pcb.h> |
/* From librtld. */ |
#include <rtld.h> |
#include <string.h> |
extern char _heap; |
extern int main(int argc, char *argv[]); |
74,6 → 78,12 |
/* Save the PCB pointer */ |
__pcb = (pcb_t *)pcb_ptr; |
#ifdef __IN_SHARED_LIBC__ |
if (__pcb != NULL && __pcb->rtld_runtime != NULL) { |
runtime_env = (runtime_env_t *) __pcb->rtld_runtime; |
} |
#endif |
if (__pcb == NULL) { |
argc = 0; |
argv = NULL; |
/branches/dynload/uspace/lib/libc/generic/dlfcn.c |
---|
0,0 → 1,85 |
/* |
* 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 <stdlib.h> |
#include <dlfcn.h> |
/* From librtld. */ |
#include <module.h> |
#include <symbol.h> |
void *dlopen(const char *path, int flag) |
{ |
module_t *m; |
printf("dlopen(\"%s\", %d)\n", path, flag); |
printf("module_find('%s')\n", path); |
m = module_find(path); |
if (m == NULL) { |
printf("NULL. module_load('%s')\n", path); |
m = module_load(path); |
printf("module_load_deps(m)\n"); |
module_load_deps(m); |
} else { |
printf("not NULL\n"); |
} |
return (void *) m; |
} |
/* |
* @note Symbols with NULL values are not accounted for. |
* @note Symbol search scope is not correct. Should only |
* look in @a mod and its dependencies. |
*/ |
void *dlsym(void *mod, const char *sym_name) |
{ |
elf_symbol_t *sd; |
module_t *sm; |
printf("dlsym(0x%lx, \"%s\")\n", (long)mod, sym_name); |
sd = symbol_def_find(sym_name, (module_t *) mod, &sm); |
if (sd != NULL) { |
return symbol_get_addr(sd, sm); |
} |
return NULL; |
} |
/** @} |
*/ |
/branches/dynload/uspace/lib/libc/Makefile |
---|
35,6 → 35,7 |
LIBC_PREFIX = $(shell pwd) |
SOFTINT_PREFIX = ../softint |
CONSOLE_PREFIX = ../../srv/console |
RTLD_PREFIX = ../../lib/rtld |
## Setup toolchain |
# |
41,7 → 42,7 |
include $(LIBC_PREFIX)/Makefile.toolchain |
CFLAGS += -I$(CONSOLE_PREFIX) |
CFLAGS += -I$(CONSOLE_PREFIX) -I$(RTLD_PREFIX)/include -I../../srv/loader/include -D__32_BITS__ |
PIC_CFLAGS := $(CFLAGS) -fPIC -D__IN_SHARED_LIBC__ |
## Sources |
75,6 → 76,7 |
generic/sysinfo.c \ |
generic/ipc.c \ |
generic/async.c \ |
generic/dlfcn.c \ |
generic/loader.c \ |
generic/getopt.c \ |
generic/libadt/list.o \ |
117,7 → 119,7 |
-makedepend $(DEFS) $(PIC_CFLAGS) -o.pio -f - $(ARCH_SOURCES) $(GENERIC_SOURCES) >> Makefile.depend 2> /dev/null |
libc.a: depend $(OBJECTS) |
$(AR) rc $@ $(LIBS) $(OBJECTS) |
$(AR) rc $@ $(LIBS) $(OBJECTS) $(RTLD_PREFIX)/librtld.a |
libc.pic.a: depend $(PIC_OBJECTS) |
$(AR) rc $@ $(LIBS) $(PIC_OBJECTS) |