From 0650a59aea7223768210574129c61d790924a919 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Thu, 18 Jul 2002 11:16:34 +0000 Subject: [PATCH] - MFZE1 - MacOSX fixes by Marko Karppinen --- Zend/zend.h | 11 ++++++++ Zend/zend_extensions.c | 61 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/Zend/zend.h b/Zend/zend.h index d0c2667b6db..d948eeba4fd 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -80,6 +80,17 @@ # include #endif +#if HAVE_MACH_O_DYLD_H +#include + +/* MH_BUNDLE loading functions for Mac OS X / Darwin */ +void *zend_mh_bundle_load (char* bundle_path); +int zend_mh_bundle_unload (void *bundle_handle); +void *zend_mh_bundle_symbol(void *bundle_handle, const char *symbol_name); +const char *zend_mh_bundle_error(void); + +#endif /* HAVE_MACH_O_DYLD_H */ + #if defined(HAVE_LIBDL) # ifndef RTLD_LAZY diff --git a/Zend/zend_extensions.c b/Zend/zend_extensions.c index 45769d654a6..6e50ae13982 100644 --- a/Zend/zend_extensions.c +++ b/Zend/zend_extensions.c @@ -216,3 +216,64 @@ ZEND_API zend_extension *zend_get_extension(char *extension_name) } return NULL; } + +/* + * Support for dynamic loading of MH_BUNDLEs on Darwin / Mac OS X + * + */ + +#if HAVE_MACH_O_DYLD_H + +void *zend_mh_bundle_load(char* bundle_path) +{ + NSObjectFileImage bundle_image; + NSModule bundle_handle; + NSSymbol bundle_init_nssymbol; + void (*bundle_init)(void); + + if (NSCreateObjectFileImageFromFile(bundle_path, &bundle_image) != NSObjectFileImageSuccess) { + return NULL; + } + + bundle_handle = NSLinkModule(bundle_image, bundle_path, NSLINKMODULE_OPTION_PRIVATE); + NSDestroyObjectFileImage(bundle_image); + + /* call the init function of the bundle */ + bundle_init_nssymbol = NSLookupSymbolInModule(bundle_handle, "__init"); + if (bundle_init_nssymbol != NULL) { + bundle_init = NSAddressOfSymbol(bundle_init_nssymbol); + bundle_init(); + } + + return bundle_handle; +} + +int zend_mh_bundle_unload(void *bundle_handle) +{ + NSSymbol bundle_fini_nssymbol; + void (*bundle_fini)(void); + + /* call the fini function of the bundle */ + bundle_fini_nssymbol = NSLookupSymbolInModule(bundle_handle, "__fini"); + if (bundle_fini_nssymbol != NULL) { + bundle_fini = NSAddressOfSymbol(bundle_fini_nssymbol); + bundle_fini(); + } + + return (int) NSUnLinkModule(bundle_handle, NULL); +} + +void *zend_mh_bundle_symbol(void *bundle_handle, const char *symbol_name) +{ + NSSymbol symbol; + symbol = NSLookupSymbolInModule(bundle_handle, symbol_name); + return NSAddressOfSymbol(symbol); +} + +const char *zend_mh_bundle_error(void) +{ + /* Witness the state of the art error reporting */ + return NULL; +} + +#endif /* HAVE_MACH_O_DYLD_H */