summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2010-08-13 07:59:23 +0200
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2010-08-13 07:59:23 +0200
commit6e7c6761ce3ed20759572d623b2c961da8b49f73 (patch)
tree7096b5763c3303cabfdffde445e0ad45149f3857 /src
parent2de1daae9e11f61400e7f6685079c491d166ac88 (diff)
parent5d9ad7276cfd9696784595314471416aba691b17 (diff)
Merge branch 'master' of /pub/repo.git/lua-modules
Diffstat (limited to 'src')
-rw-r--r--src/lua-plugin.cc26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/lua-plugin.cc b/src/lua-plugin.cc
index 3c08201..ca15cc8 100644
--- a/src/lua-plugin.cc
+++ b/src/lua-plugin.cc
@@ -48,7 +48,7 @@ void LuaLoadPlugin(Handle * h, Lua * L) throw (GeneralException) {
HMEMORYMODULE module;
if (!(module = MemoryLoadLibrary(buffer)))
- throw("Can't load library " + h->GetName() + " from memory.");
+ throw GeneralException("Can't load library " + h->GetName() + " from memory.");
init_ptr_t init_ptr = (init_ptr_t) MemoryGetProcAddress(module, "init_plugin");
@@ -94,7 +94,8 @@ void LuaLoadPlugin(const String & fname, const String & searchpath, Lua * L) thr
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>
@@ -103,16 +104,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);
@@ -158,7 +168,7 @@ void LuaLoadPlugin(Handle * h, Lua * L) throw (GeneralException) {
Base::printm(M_INFO, "Loading library " + h->GetName() + "\n");
if (!handle)
- throw("Can't load library " + h->GetName() + " from memory.");
+ throw GeneralException("Can't load library " + h->GetName() + " from memory.");
init_ptr_t init_ptr = (init_ptr_t) dlsym(handle, "init_plugin");