Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3685 → Rev 3686

/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)