[vmkit-commits] [vmkit] r63314 - /vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Thu Jan 29 08:46:37 PST 2009
Author: geoffray
Date: Thu Jan 29 10:46:36 2009
New Revision: 63314
URL: http://llvm.org/viewvc/llvm-project?rev=63314&view=rev
Log:
Take some precaution when calling JNI_OnLoad of a dynamic library.
Modified:
vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp
Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp?rev=63314&r1=63313&r2=63314&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp Thu Jan 29 10:46:36 2009
@@ -21,6 +21,7 @@
#include "JavaUpcalls.h"
#include "Jnjvm.h"
+#include <csetjmp>
#include <cstring>
using namespace jnjvm;
@@ -68,7 +69,28 @@
}
typedef int (*onLoad_t)(const void**, void*);
+extern "C" void jniProceedPendingException();
+// Calls the JNI_OnLoad function of a dynamic library.
+void callOnLoad(void* res, JnjvmClassLoader* loader, Jnjvm* vm) {
+
+ onLoad_t onLoad = (onLoad_t)loader->loadInLib("JNI_OnLoad", res);
+
+ if (onLoad) {
+ JavaThread* th = JavaThread::get();
+ mvm::Allocator& allocator = th->getJVM()->gcAllocator;
+ void** buf = (void**)allocator.allocateTemporaryMemory(sizeof(jmp_buf));
+ th->sjlj_buffers.push_back((jmp_buf*)buf);
+
+ th->startNative(1);
+ if (setjmp((__jmp_buf_tag*)buf) == 0) {
+ onLoad(&vm->javavmEnv, res);
+ }
+ jniProceedPendingException();
+ }
+}
+
+// Never throws.
JNIEXPORT jint JNICALL Java_java_lang_VMRuntime_nativeLoad(
#ifdef NATIVE_JNI
JNIEnv *env,
@@ -77,9 +99,7 @@
jobject _str,
jobject _loader) {
- jint result = 0;
-
- BEGIN_NATIVE_EXCEPTION(0)
+ void* res = 0;
JavaString* str = (JavaString*)_str;
Jnjvm* vm = JavaThread::get()->getJVM();
@@ -88,19 +108,11 @@
char* buf = str->strToAsciiz();
- void* res = loader->loadLib(buf);
-
- if (res != 0) {
- onLoad_t onLoad = (onLoad_t)loader->loadInLib("JNI_OnLoad", res);
- if (onLoad) onLoad(&vm->javavmEnv, 0);
- result = 1;
- } else {
- result = 0;
- }
-
- END_NATIVE_EXCEPTION
+ res = loader->loadLib(buf);
+
+ if (res) callOnLoad(res, loader, vm);
- return result;
+ return res != 0;
}
More information about the vmkit-commits
mailing list