diff options
author | Sven Gothel <[email protected]> | 2013-06-16 19:16:31 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-06-16 19:16:31 +0200 |
commit | 5d211c6fa6a0452cc4569712e436184e34504a88 (patch) | |
tree | bdd90a5b7ccad4a3b62350c0b6699d3e0c66a92a | |
parent | d01cb422c4621fbc1b5ea2bcd7d19f3ff8602715 (diff) |
Fix DynamicLinker Impl: Add Bionic specialization using Bionic's non POSIX values; Using same pattern for Mac OS X.
Add Bionic specialization using Bionic's non POSIX values
- derive from UnixDynamicLinkerImpl
- specify own flag and mode values
- use UnixDynamicLinkerImpl native code
Using same pattern for Mac OS X
- derive from UnixDynamicLinkerImpl
- specify own flag and mode values
- use UnixDynamicLinkerImpl native code
- drop MacOSXDynamicLinkerImpl native code
-rw-r--r-- | make/build.xml | 6 | ||||
-rw-r--r-- | src/java/com/jogamp/common/os/NativeLibrary.java | 8 | ||||
-rw-r--r-- | src/java/jogamp/common/os/BionicDynamicLinkerImpl.java | 54 | ||||
-rw-r--r-- | src/java/jogamp/common/os/MacOSXDynamicLinkerImpl.java | 51 | ||||
-rw-r--r-- | src/java/jogamp/common/os/UnixDynamicLinkerImpl.java | 29 | ||||
-rw-r--r-- | src/java/jogamp/common/os/WindowsDynamicLinkerImpl.java | 7 | ||||
-rw-r--r-- | src/native/macosx/MacOSXDynamicLinkerImpl_JNI.c | 91 |
7 files changed, 92 insertions, 154 deletions
diff --git a/make/build.xml b/make/build.xml index 90151c6..5f9e570 100644 --- a/make/build.xml +++ b/make/build.xml @@ -100,7 +100,6 @@ <mkdir dir="${src.generated.java}" /> <mkdir dir="${src.generated.c}" /> <mkdir dir="${src.generated.c}/Unix" /> - <mkdir dir="${src.generated.c}/MacOSX" /> <mkdir dir="${src.generated.c}/Windows" /> <mkdir dir="${classes}" /> @@ -440,7 +439,7 @@ <echo message="MacOSX" /> <property name="compiler.cfg.id" value="compiler.cfg.macosx" /> <property name="linker.cfg.id" value="linker.cfg.macosx" /> - <property name="c.src.dir.os" value="macosx" /> + <property name="c.src.dir.os" value="unix" /> </target> <target name="declare.freebsd.amd64" if="isFreeBSDAMD64"> @@ -514,7 +513,6 @@ <javah destdir="${src.generated.c}" classpath="${classes}" class="jogamp.common.jvm.JVMUtil" /> <javah destdir="${src.generated.c}" classpath="${classes}" class="com.jogamp.common.nio.PointerBuffer" /> <javah destdir="${src.generated.c}/Unix" classpath="${classes}" class="jogamp.common.os.UnixDynamicLinkerImpl" /> - <javah destdir="${src.generated.c}/MacOSX" classpath="${classes}" class="jogamp.common.os.MacOSXDynamicLinkerImpl" /> <javah destdir="${src.generated.c}/Windows" classpath="${classes}" class="jogamp.common.os.WindowsDynamicLinkerImpl"/> <echo message="Output lib name = ${output.lib.name} -> ${output.lib.name.os}" /> @@ -555,7 +553,7 @@ <includepath path="${src.generated.c}" /> <includepath path="${src.generated.c}/Unix" if="isUnix"/> - <includepath path="${src.generated.c}/MacOSX" if="isOSX"/> + <includepath path="${src.generated.c}/Unix" if="isOSX"/> <includepath path="${src.generated.c}/Windows" if="isWindows"/> </compiler> diff --git a/src/java/com/jogamp/common/os/NativeLibrary.java b/src/java/com/jogamp/common/os/NativeLibrary.java index 2351391..bfc5b07 100644 --- a/src/java/com/jogamp/common/os/NativeLibrary.java +++ b/src/java/com/jogamp/common/os/NativeLibrary.java @@ -43,6 +43,7 @@ package com.jogamp.common.os; import com.jogamp.common.util.IOUtil; import com.jogamp.common.util.cache.TempJarCache; +import jogamp.common.os.BionicDynamicLinkerImpl; import jogamp.common.os.MacOSXDynamicLinkerImpl; import jogamp.common.os.PlatformPropsImpl; import jogamp.common.os.UnixDynamicLinkerImpl; @@ -87,9 +88,14 @@ public class NativeLibrary implements DynamicLookupHelper { suffixes = new String[] { ".dylib", ".jnilib" }; break; + case ANDROID: + dynLink = new BionicDynamicLinkerImpl(); + prefixes = new String[] { "lib" }; + suffixes = new String[] { ".so" }; + break; + /* case FREEBSD: - case DALVIK: case SUNOS: case HPUX: case OPENKODE: diff --git a/src/java/jogamp/common/os/BionicDynamicLinkerImpl.java b/src/java/jogamp/common/os/BionicDynamicLinkerImpl.java new file mode 100644 index 0000000..3864ab2 --- /dev/null +++ b/src/java/jogamp/common/os/BionicDynamicLinkerImpl.java @@ -0,0 +1,54 @@ +package jogamp.common.os; + +import com.jogamp.common.util.SecurityUtil; + +/** + * Bionic specialization of {@link UnixDynamicLinkerImpl} + * utilizing Bionic's non POSIX flags and mode values. + * <p> + * Bionic is used on Android. + * </p> + */ +public class BionicDynamicLinkerImpl extends UnixDynamicLinkerImpl { + private static final long RTLD_DEFAULT = 0xffffffffL; + // static final long RTLD_NEXT = 0xfffffffeL; + + private static final int RTLD_LAZY = 0x00001; + // static final int RTLD_NOW = 0x00000; + private static final int RTLD_LOCAL = 0x00000; + private static final int RTLD_GLOBAL = 0x00002; + + // --- Begin CustomJavaCode .cfg declarations + public long openLibraryLocal(String pathname, boolean debug) throws SecurityException { + // Note we use RTLD_GLOBAL visibility to _NOT_ allow this functionality to + // be used to pre-resolve dependent libraries of JNI code without + // requiring that all references to symbols in those libraries be + // looked up dynamically via the ProcAddressTable mechanism; in + // other words, one can actually link against the library instead of + // having to dlsym all entry points. System.loadLibrary() uses + // RTLD_LOCAL visibility so can't be used for this purpose. + SecurityUtil.checkLinkPermission(pathname); + return dlopen(pathname, RTLD_LAZY | RTLD_LOCAL); + } + + public long openLibraryGlobal(String pathname, boolean debug) throws SecurityException { + // Note we use RTLD_GLOBAL visibility to allow this functionality to + // be used to pre-resolve dependent libraries of JNI code without + // requiring that all references to symbols in those libraries be + // looked up dynamically via the ProcAddressTable mechanism; in + // other words, one can actually link against the library instead of + // having to dlsym all entry points. System.loadLibrary() uses + // RTLD_LOCAL visibility so can't be used for this purpose. + SecurityUtil.checkLinkPermission(pathname); + return dlopen(pathname, RTLD_LAZY | RTLD_GLOBAL); + } + + public long lookupSymbolGlobal(String symbolName) { + final long addr = dlsym(RTLD_DEFAULT, symbolName); + if(DEBUG_LOOKUP) { + System.err.println("DynamicLinkerImpl.lookupSymbolGlobal("+symbolName+") -> 0x"+Long.toHexString(addr)); + } + return addr; + } + +} diff --git a/src/java/jogamp/common/os/MacOSXDynamicLinkerImpl.java b/src/java/jogamp/common/os/MacOSXDynamicLinkerImpl.java index 95f7e63..09ee48d 100644 --- a/src/java/jogamp/common/os/MacOSXDynamicLinkerImpl.java +++ b/src/java/jogamp/common/os/MacOSXDynamicLinkerImpl.java @@ -1,32 +1,20 @@ -/* !---- DO NOT EDIT: This file autogenerated by com\sun\gluegen\JavaEmitter.java on Mon Jul 31 16:27:00 PDT 2006 ----! */ - package jogamp.common.os; -import com.jogamp.common.os.DynamicLinker; import com.jogamp.common.util.SecurityUtil; +/** + * Mac OS X specialization of {@link UnixDynamicLinkerImpl} + * utilizing OS X 's non POSIX flags and mode values. + */ +public class MacOSXDynamicLinkerImpl extends UnixDynamicLinkerImpl { -public class MacOSXDynamicLinkerImpl implements DynamicLinker { - - public static final long RTLD_DEFAULT = -2; - - public static final int RTLD_LAZY = 0x1; - public static final int RTLD_NOW = 0x2; - public static final int RTLD_LOCAL = 0x4; - public static final int RTLD_GLOBAL = 0x8; - - /** Interface to C language function: <br> <code> int dlclose(void * __handle); </code> */ - private static native int dlclose(long __handle); - - /** Interface to C language function: <br> <code> char * dlerror(void); </code> */ - private static native java.lang.String dlerror(); - - /** Interface to C language function: <br> <code> void * dlopen(const char * __path, int __mode); </code> */ - private static native long dlopen(java.lang.String __path, int __mode); - - /** Interface to C language function: <br> <code> void * dlsym(void * __handle, const char * __symbol); </code> */ - private static native long dlsym(long __handle, java.lang.String __symbol); + private static final long RTLD_DEFAULT = -2L; + // static final long RTLD_NEXT = -1L; + private static final int RTLD_LAZY = 0x00001; + // static final int RTLD_NOW = 0x00002; + private static final int RTLD_LOCAL = 0x00004; + private static final int RTLD_GLOBAL = 0x00008; // --- Begin CustomJavaCode .cfg declarations public long openLibraryLocal(String pathname, boolean debug) throws SecurityException { @@ -53,25 +41,12 @@ public class MacOSXDynamicLinkerImpl implements DynamicLinker { return dlopen(pathname, RTLD_LAZY | RTLD_GLOBAL); } - public long lookupSymbol(long libraryHandle, String symbolName) { - final long addr = dlsym(libraryHandle, symbolName); - if(DEBUG_LOOKUP) { - System.err.println("MaxOSXDynamicLinkerImpl.lookupSymbol(0x"+Long.toHexString(libraryHandle)+", "+symbolName+") -> 0x"+Long.toHexString(addr)); - } - return addr; - } - public long lookupSymbolGlobal(String symbolName) { final long addr = dlsym(RTLD_DEFAULT, symbolName); if(DEBUG_LOOKUP) { - System.err.println("MacOSXDynamicLinkerImpl.lookupSymbolGlobal("+symbolName+") -> 0x"+Long.toHexString(addr)); + System.err.println("DynamicLinkerImpl.lookupSymbolGlobal("+symbolName+") -> 0x"+Long.toHexString(addr)); } return addr; } - public void closeLibrary(long libraryHandle) { - dlclose(libraryHandle); - } - // ---- End CustomJavaCode .cfg declarations - -} // end of class MacOSXDynamicLinkerImpl +} diff --git a/src/java/jogamp/common/os/UnixDynamicLinkerImpl.java b/src/java/jogamp/common/os/UnixDynamicLinkerImpl.java index 2258dfa..e4cdbda 100644 --- a/src/java/jogamp/common/os/UnixDynamicLinkerImpl.java +++ b/src/java/jogamp/common/os/UnixDynamicLinkerImpl.java @@ -1,5 +1,3 @@ -/* !---- DO NOT EDIT: This file autogenerated by com\sun\gluegen\JavaEmitter.java on Mon Jul 31 16:26:59 PDT 2006 ----! */ - package jogamp.common.os; import com.jogamp.common.os.DynamicLinker; @@ -8,23 +6,25 @@ import com.jogamp.common.util.SecurityUtil; public class UnixDynamicLinkerImpl implements DynamicLinker { - public static final long RTLD_DEFAULT = 0; - public static final int RTLD_LAZY = 0x00001; - public static final int RTLD_NOW = 0x00002; - public static final int RTLD_GLOBAL = 0x00100; - public static final int RTLD_LOCAL = 0x00000; + private static final long RTLD_DEFAULT = 0; + // static final long RTLD_NEXT = -1L; + + private static final int RTLD_LAZY = 0x00001; + // static final int RTLD_NOW = 0x00002; + private static final int RTLD_LOCAL = 0x00000; + private static final int RTLD_GLOBAL = 0x00100; /** Interface to C language function: <br> <code> int dlclose(void * ); </code> */ - private static native int dlclose(long arg0); + /* pp */ static native int dlclose(long arg0); /** Interface to C language function: <br> <code> char * dlerror(void); </code> */ - private static native java.lang.String dlerror(); + /* pp */ static native java.lang.String dlerror(); /** Interface to C language function: <br> <code> void * dlopen(const char * , int); </code> */ - private static native long dlopen(java.lang.String arg0, int arg1); + /* pp */ static native long dlopen(java.lang.String arg0, int arg1); /** Interface to C language function: <br> <code> void * dlsym(void * , const char * ); </code> */ - private static native long dlsym(long arg0, java.lang.String arg1); + /* pp */ static native long dlsym(long arg0, java.lang.String arg1); // --- Begin CustomJavaCode .cfg declarations @@ -55,7 +55,7 @@ public class UnixDynamicLinkerImpl implements DynamicLinker { public long lookupSymbol(long libraryHandle, String symbolName) { final long addr = dlsym(libraryHandle, symbolName); if(DEBUG_LOOKUP) { - System.err.println("UnixDynamicLinkerImpl.lookupSymbol(0x"+Long.toHexString(libraryHandle)+", "+symbolName+") -> 0x"+Long.toHexString(addr)); + System.err.println("DynamicLinkerImpl.lookupSymbol(0x"+Long.toHexString(libraryHandle)+", "+symbolName+") -> 0x"+Long.toHexString(addr)); } return addr; } @@ -63,7 +63,7 @@ public class UnixDynamicLinkerImpl implements DynamicLinker { public long lookupSymbolGlobal(String symbolName) { final long addr = dlsym(RTLD_DEFAULT, symbolName); if(DEBUG_LOOKUP) { - System.err.println("UnixDynamicLinkerImpl.lookupSymbolGlobal("+symbolName+") -> 0x"+Long.toHexString(addr)); + System.err.println("DynamicLinkerImpl.lookupSymbolGlobal("+symbolName+") -> 0x"+Long.toHexString(addr)); } return addr; } @@ -71,6 +71,5 @@ public class UnixDynamicLinkerImpl implements DynamicLinker { public void closeLibrary(long libraryHandle) { dlclose(libraryHandle); } - // ---- End CustomJavaCode .cfg declarations -} // end of class UnixDynamicLinkerImpl +} diff --git a/src/java/jogamp/common/os/WindowsDynamicLinkerImpl.java b/src/java/jogamp/common/os/WindowsDynamicLinkerImpl.java index eb02584..17d4adc 100644 --- a/src/java/jogamp/common/os/WindowsDynamicLinkerImpl.java +++ b/src/java/jogamp/common/os/WindowsDynamicLinkerImpl.java @@ -1,5 +1,3 @@ -/* !---- DO NOT EDIT: This file autogenerated by com\sun\gluegen\JavaEmitter.java on Tue May 27 02:37:55 PDT 2008 ----! */ - package jogamp.common.os; import com.jogamp.common.os.DynamicLinker; @@ -51,7 +49,7 @@ public class WindowsDynamicLinkerImpl implements DynamicLinker { } } if(DEBUG_LOOKUP) { - System.err.println("WindowsDynamicLinkerImpl.lookupSymbol(0x"+Long.toHexString(libraryHandle)+", "+symbolName+") -> "+_symbolName+", 0x"+Long.toHexString(addr)); + System.err.println("DynamicLinkerImpl.lookupSymbol(0x"+Long.toHexString(libraryHandle)+", "+symbolName+") -> "+_symbolName+", 0x"+Long.toHexString(addr)); } return addr; } @@ -67,6 +65,5 @@ public class WindowsDynamicLinkerImpl implements DynamicLinker { public void closeLibrary(long libraryHandle) { FreeLibrary(libraryHandle); } - // ---- End CustomJavaCode .cfg declarations -} // end of class WindowsDynamicLinkerImpl +} diff --git a/src/native/macosx/MacOSXDynamicLinkerImpl_JNI.c b/src/native/macosx/MacOSXDynamicLinkerImpl_JNI.c deleted file mode 100644 index 757aeb0..0000000 --- a/src/native/macosx/MacOSXDynamicLinkerImpl_JNI.c +++ /dev/null @@ -1,91 +0,0 @@ -/* !---- DO NOT EDIT: This file autogenerated by com\sun\gluegen\JavaEmitter.java on Mon Jul 31 16:27:00 PDT 2006 ----! */ - -#include <jni.h> - -#include <assert.h> - -#include "jogamp_common_os_MacOSXDynamicLinkerImpl.h" - - #include <dlfcn.h> - #include </usr/include/machine/types.h> - -/* Java->C glue code: - * Java package: jogamp.common.os.MacOSXDynamicLinkerImpl - * Java method: int dlclose(long __handle) - * C function: int dlclose(void * __handle); - */ -JNIEXPORT jint JNICALL -Java_jogamp_common_os_MacOSXDynamicLinkerImpl_dlclose__J(JNIEnv *env, jclass _unused, jlong __handle) { - int _res; - _res = dlclose((void *) (intptr_t) __handle); - return _res; -} - - -/* Java->C glue code: - * Java package: jogamp.common.os.MacOSXDynamicLinkerImpl - * Java method: java.lang.String dlerror() - * C function: char * dlerror(void); - */ -JNIEXPORT jstring JNICALL -Java_jogamp_common_os_MacOSXDynamicLinkerImpl_dlerror__(JNIEnv *env, jclass _unused) { - char * _res; - _res = dlerror(); - if (_res == NULL) return NULL; return (*env)->NewStringUTF(env, _res); -} - - -/* Java->C glue code: - * Java package: jogamp.common.os.MacOSXDynamicLinkerImpl - * Java method: long dlopen(java.lang.String __path, int __mode) - * C function: void * dlopen(const char * __path, int __mode); - */ -JNIEXPORT jlong JNICALL -Java_jogamp_common_os_MacOSXDynamicLinkerImpl_dlopen__Ljava_lang_String_2I(JNIEnv *env, jclass _unused, jstring __path, jint __mode) { - const char* _UTF8__path = NULL; - void * _res; - if (__path != NULL) { - if (__path != NULL) { - _UTF8__path = (*env)->GetStringUTFChars(env, __path, (jboolean*)NULL); - if (_UTF8__path == NULL) { - (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/OutOfMemoryError"), - "Failed to get UTF-8 chars for argument \"__path\" in native dispatcher for \"dlopen\""); - return 0; - } - } - } - _res = dlopen((char *) _UTF8__path, (int) __mode); - if (__path != NULL) { - (*env)->ReleaseStringUTFChars(env, __path, _UTF8__path); - } - return (jlong) (intptr_t) _res; -} - - -/* Java->C glue code: - * Java package: jogamp.common.os.MacOSXDynamicLinkerImpl - * Java method: long dlsym(long __handle, java.lang.String __symbol) - * C function: void * dlsym(void * __handle, const char * __symbol); - */ -JNIEXPORT jlong JNICALL -Java_jogamp_common_os_MacOSXDynamicLinkerImpl_dlsym__JLjava_lang_String_2(JNIEnv *env, jclass _unused, jlong __handle, jstring __symbol) { - const char* _UTF8__symbol = NULL; - void * _res; - if (__symbol != NULL) { - if (__symbol != NULL) { - _UTF8__symbol = (*env)->GetStringUTFChars(env, __symbol, (jboolean*)NULL); - if (_UTF8__symbol == NULL) { - (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/OutOfMemoryError"), - "Failed to get UTF-8 chars for argument \"__symbol\" in native dispatcher for \"dlsym\""); - return 0; - } - } - } - _res = dlsym((void *) (intptr_t) __handle, (char *) _UTF8__symbol); - if (__symbol != NULL) { - (*env)->ReleaseStringUTFChars(env, __symbol, _UTF8__symbol); - } - return (jlong) (intptr_t) _res; -} - - |