From 7dce97278fb9c4738639c07db22d306fc8cdd8f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 12 Jan 2003 17:15:17 +0000 Subject: [PATCH] Implemented the unix dlfcn API; note, the RTLD_xxx modes are not yet supported by the loader. dlerror() is not thread-safe. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2439 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/libroot/posix/dlfcn.c | 55 +++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/src/kernel/libroot/posix/dlfcn.c b/src/kernel/libroot/posix/dlfcn.c index 225e45298e..aaeb60e45e 100644 --- a/src/kernel/libroot/posix/dlfcn.c +++ b/src/kernel/libroot/posix/dlfcn.c @@ -1,36 +1,67 @@ /* +** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. ** Copyright 2002, Manuel J. Petit. All rights reserved. ** Distributed under the terms of the NewOS License. */ + #include -#include -#include +#include +#include "user_runtime.h" + + +void __init__dlfcn(struct uspace_program_args const *); + +static struct rld_export const *gRuntimeLinker; +static status_t gStatus; -void __init__dlfcn(struct uspace_prog_args_t const *); -static struct rld_export_t const *rld; void * -dlopen(char const *name, unsigned flags) +dlopen(char const *name, int mode) { - return (void*)(rld->dl_open(name, flags)); + if (name == NULL) + name = MAGIC_APP_NAME; + + gStatus = gRuntimeLinker->load_add_on(name, mode); + if (gStatus < B_OK) + return NULL; + + return (void *)gStatus; } + void * -dlsym(void *img, char const *name) +dlsym(void *handle, char const *name) { - return rld->dl_sym((unsigned)img, name, 0); + void *location; + + gStatus = gRuntimeLinker->get_image_symbol((image_id)handle, name, B_SYMBOL_TYPE_ANY, &location); + if (gStatus < B_OK) + return NULL; + + return location; } + int -dlclose(void *img) +dlclose(void *handle) { - return rld->dl_close((unsigned)img, 0); + return gRuntimeLinker->unload_add_on((image_id)handle); +} + + +char * +dlerror(void) +{ + if (gStatus < B_OK) + return strerror(gStatus); + + return NULL; } void -__init__dlfcn(struct uspace_prog_args_t const *uspa) +__init__dlfcn(struct uspace_program_args const *args) { - rld= uspa->rld_export; + gRuntimeLinker = args->rld_export; }