2 * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2003-2010, Axel Dörfler, axeld@pinc-software.de.
4 * Distributed under the terms of the MIT License.
6 * Copyright 2002, Manuel J. Petit. All rights reserved.
7 * Distributed under the terms of the NewOS License.
11 #include <libroot_private.h>
16 #include <runtime_loader.h>
17 #include <user_runtime.h>
20 static status_t sStatus
;
21 // Note, this is not thread-safe
25 dlopen(char const *name
, int mode
)
28 image_id imageID
= __gRuntimeLoader
->load_library(name
, mode
, &handle
);
30 sStatus
= imageID
>= 0 ? B_OK
: imageID
;
32 return imageID
>= 0 ? handle
: NULL
;
37 dlsym(void *handle
, char const *name
)
43 if (handle
== RTLD_NEXT
)
44 caller
= __arch_get_caller();
46 status
= __gRuntimeLoader
->get_library_symbol(handle
, caller
, name
,
60 return sStatus
= __gRuntimeLoader
->unload_library(handle
);
68 return strerror(sStatus
);
75 dladdr(const void *address
, Dl_info
*info
)
83 sStatus
= __gRuntimeLoader
->get_nearest_symbol_at_address(address
, &image
,
84 &imagePath
, NULL
, &symbolName
, NULL
, &location
, NULL
);
88 sStatus
= get_image_info(image
, &imageInfo
);
92 info
->dli_fname
= imagePath
;
93 info
->dli_fbase
= imageInfo
.text
;
94 info
->dli_sname
= symbolName
;
95 info
->dli_saddr
= location
;
101 // __libc_dl*** wrappers
102 // We use a mixed glibc / bsd libc, and glibc wants these
103 void *__libc_dlopen(const char *name
);
104 void *__libc_dlsym(void *handle
, const char *name
);
105 void __libc_dlclose(void *handle
);
108 __libc_dlopen(const char *name
)
110 return dlopen(name
, 0);
115 __libc_dlsym(void *handle
, const char *name
)
117 return dlsym(handle
, name
);
122 __libc_dlclose(void *handle
)