40#include <ucommon-config.h>
49#if defined(HAVE_DLFCN_H)
65#ifdef HAVE_MACH_O_DYLD_H
66#include <mach-o/dyld.h>
67#define oModule ((oModule)(image))
71#define hImage ((HMODULE)(image))
92#if defined(HAVE_MACH_DYLD)
97#if defined(_MSWINDOWS_)
100#elif defined(HAVE_MACH_DYLD)
104 sym = NSLookupSymbolInModule(oModule,
"__fini");
106 fini = (void (*)(void))NSAddressOfSymbol(sym);
110 NSUnLinkModule(oModule, NSUNLINKMODULE_OPTION_NONE);
111#elif defined(HAVE_SHL_LOAD)
114#elif defined(HAVE_DLFCN_H)
139#if defined(HAVE_MACH_DYLD)
140 NSObjectFileImage oImage;
145 id = strrchr(filename,
'/');
153#if defined(_MSWINDOWS_)
154 image = LoadLibrary(filename);
156#elif defined(HAVE_MACH_DYLD)
160 switch(NSCreateObjectFileImageFromFile(filename, &oImage)) {
161 case NSObjectFileImageSuccess:
164 err =
"unknown error";
168 image = NSLinkModule(oImage, filename, NSLINKMODULE_OPTION_BINDNOW | NSLINKMODULE_OPTION_RETURN_ON_ERROR);
170 image = NSLinkModule(oImage, filename, NSLINKMODULE_OPTION_RETURN_ON_ERROR);
171 NSDestroyObjectFileImage(oImage);
173 sym = NSLookupSymbolInModule(oModule,
"__init");
175 init = (void (*)(void))NSAddressOfSymbol(sym);
179#elif defined(HAVE_SHL_LOAD)
182 image = shl_load(filename, BIND_IMMEDIATE, 0L);
184 image = shl_load(filename, BIND_DEFERRED, 0L);
185#elif defined(HAVE_DLFCN_H)
187 image = dlopen(filename, RTLD_NOW | RTLD_GLOBAL);
189 image = dlopen(filename, RTLD_LAZY | RTLD_GLOBAL);
193#if defined(_MSWINDOWS_)
196#elif defined(HAVE_MACH_DYLD)
199#elif defined(HAVE_SHL_LOAD)
202#elif defined(HAVE_DLFCN_H)
207 err =
"load unsupported";
214 slog.
error() <<
"dso: " <<
id <<
": " <<
err << std::endl;
216#ifdef CCXX_EXCEPTIONS
219#ifdef COMMON_STD_EXCEPTION
241 const char *chk = strrchr(
id,
'/');
262#if defined(_MSWINDOWS_)
264#elif defined(HAVE_MACH_DYLD)
276#if defined(HAVE_SHL_LOAD)
278 shl_t handle = (shl_t)
image;
280 if(shl_findsym(&handle, sym, 0, &value) == 0)
284#elif defined(HAVE_MACH_DYLD)
285 NSSymbol oSymbol = NSLookupSymbolInModule(oModule, sym);
290#elif defined(_MSWINDOWS_)
293 err =
"symbol missing";
296#elif defined(HAVE_DLFCN_H)
304static void MyLinkError(NSLinkEditErrors c,
int errorNumber,
const char *filename,
const char *errstr)
306 slog.
error() <<
"dyld: " << filename <<
": " << errstr << std::endl;
309static void MyUndefined(
const char *symname)
311 slog.
error() <<
"dyld: undefined: " << symname << std::endl;
314static NSModule MyMultiple(NSSymbol s, NSModule oMod, NSModule nMod)
316 slog.
error() <<
"dyld: multiply defined symbols" << std::endl;
321 static NSLinkEditErrorHandlers handlers = {
326 NSInstallLinkEditErrorHandlers(&handlers);
The DSO dynamic loader class is used to load object files.
bool isValid(void)
See if DSO object is valid.
virtual ~DSO()
Detach a DSO object from running memory.
static DSO * getObject(const char *name)
Find a specific DSO object by filename.
addr_t operator[](const char *sym)
Lookup a symbol in the loaded file.
ucommon::dso::addr_t addr_t
void loader(const char *filename, bool resolve)
static void dynunload(void)
static void setDebug(void)
Install debug handler...
The MutexLock class is used to protect a section of code so that at any given time only a single thre...
void error(const char *format,...)
Print a formatted syslog string.
static Throw getException(void)
Get exception mode of the current thread.
@ throwException
throw an object relative to error
@ throwObject
throw object that cause error (throw this)
A copy-on-write string class that operates by reference count.
Convenience class for library plugins.
Export interfaces for library interfaces.
Common C++ generic string class.
int stricmp(const char *s1, const char *s2)
GNU Common C++ exception model base classes.
Files and dynamic loader services.
const struct sockaddr * addr(Socket::address &address)
A convenience function to convert a socket address list into a socket address.
System logging facilities abstraction.