summaryrefslogtreecommitdiff
path: root/src/lua-plugin.cc
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2010-06-08 18:45:42 +0200
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2010-06-08 18:45:42 +0200
commit1c10438fc37d9b0e9b205f47200b7df3784a225b (patch)
tree656ae845642756b8fcfb249f7124b722d96644dd /src/lua-plugin.cc
parent4dcf73f8e320b9fd654229cd355fb645df24ed93 (diff)
Fixing a few things for the apple dll loader - mainly disabling the memory loader and fallbacking on the linux 'from-disk' loader.
Diffstat (limited to 'src/lua-plugin.cc')
-rw-r--r--src/lua-plugin.cc22
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);