diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lua-plugin.cc | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/lua-plugin.cc b/src/lua-plugin.cc index 1e4ebc7..3bc7e83 100644 --- a/src/lua-plugin.cc +++ b/src/lua-plugin.cc @@ -90,7 +90,8 @@ void LuaLoadPlugin(const String & fname, Lua * L) throw (GeneralException) { init_ptr(L); } -#if defined(__APPLE__) +#if defined(__APPLE__) and 0 +// This actually requires bundles, and not dylibs... disabling it for now. #include <mach/vm_map.h> #include <mach-o/dyld.h> #include <mach/mach_init.h> @@ -99,16 +100,25 @@ void LuaLoadPlugin(Handle * h, Lua * L) throw (GeneralException) { Byte * buffer; NSObjectFileImage image; - kern_return_t result = vm_allocate(mach_task_self(), (vm_address_t *) &buffer, h->GetSize(), VM_FLAGS_ANYWHERE); + if (vm_allocate(mach_task_self(), (vm_address_t *) &buffer, h->GetSize(), VM_FLAGS_ANYWHERE) != KERN_SUCCESS) { + throw GeneralException("Can't allocate kernel memory to load library " + h->GetName()); + } h->read(buffer, h->GetSize()); - if (NSCreateObjectFileImageFromMemory(buffer, h->GetSize(), &image) != NSObjectFileImageSuccess) - throw("Can't load library " + h->GetName() + " from memory."); + if (NSCreateObjectFileImageFromMemory(buffer, h->GetSize(), &image) != NSObjectFileImageSuccess) { + vm_deallocate(mach_task_self(), (vm_address_t) buffer, h->GetSize()); + throw GeneralException("Can't load library " + h->GetName() + " from memory."); + } NSModule module; + + int o = 0; + if (h->GetName()[0] == '@') o = 1; - if (!(module = NSLinkModule(image, h->GetName().to_charp(), NSLINKMODULE_OPTION_PRIVATE))) - throw("Can't link library " + h->GetName() + " from memory."); + if (!(module = NSLinkModule(image, h->GetName().to_charp() + o, NSLINKMODULE_OPTION_PRIVATE))) { + NSDestroyObjectFileImage(image); + throw GeneralException("Can't link library " + h->GetName() + " from memory."); + } NSSymbol symbol = NSLookupSymbolInModule(module, "init_plugin"); init_ptr_t init_ptr = (init_ptr_t) NSAddressOfSymbol(symbol); |