[SDL] SDL_crash -- fatal error catching with user callback

Nathaniel J Fries nfries88 at yahoo.com
Sun Mar 31 08:46:44 PDT 2013


If you wanted to update mojocrash to support versions of OS X before they added libdl, you might find this useful:


Code:

void *OS_X_dlopen(const char *name)
{
    const struct mach_header *hdr = NSAddImage(name, NSADDIMAGE_OPTION_RETURN_ON_ERROR | NSADDIMAGE_OPTION_WITH_SEARCHING);
    return (void *)hdr;
}

void *OS_X_dlsym(void *handle, const char *symbol)
{
    NSSymbol sym = NSLookupSymbolInImage((struct mach_header *)(handle), symbol,
                                         NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW, NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
    if(sym != 0)
    {
        return NSAddressOfSymbol(sym);
    }

    return 0;
}

#define dlopen(name, op) OS_X_dlopen(name)
#define dlclose(handle)
#define dlsym(handle, symbol) OS_X_dlsym(handle, symbol)



The reason dlclose() doesn't do anything is because the dynamic loader for OS X wasn't built to unload dynamic libraries, apparently. There's the API for bundles, but that won't work for a library that wasn't built as a bundle (which I'd imagine libSystem.dylib wasn't).

------------------------
Nate Fries




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20130331/f7492413/attachment-0009.htm>


More information about the SDL mailing list