summaryrefslogtreecommitdiffstats
path: root/src/java/jogamp/common
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-01-30 21:09:17 +0100
committerSven Gothel <[email protected]>2015-01-30 21:09:17 +0100
commit12feaa7d3b1544098f684d851e3caff1ec88cbc8 (patch)
tree2d979c57cca37220bc026a8ee08ee479ae0508bf /src/java/jogamp/common
parent3caf446e29a3934900b9983dfd72cb8aa0d9e8d7 (diff)
Refine Native Library Code: Bulk Permissions, Cleanup DynamicLinker impl. - and fix Android AArch64 BionicDynamicLinker (Bug 1122)
- Bulk Permissions ProcAddressTable.reset(..) performs address lookup in one block. Now claiming all permissions upfront once, and releasing them afterwards. - Cleanup DynamicLinker impl. Proper top-down impl. of DynamicLinkerImpl, handling all security code and validations. - Fix Android AArch64 BionicDynamicLinker (Bug 1122) Dalvik uses diff RTLD_* defines for AArch64!
Diffstat (limited to 'src/java/jogamp/common')
-rw-r--r--src/java/jogamp/common/os/BionicDynamicLinker32bitImpl.java (renamed from src/java/jogamp/common/os/BionicDynamicLinkerImpl.java)26
-rw-r--r--src/java/jogamp/common/os/BionicDynamicLinker64BitImpl.java63
-rw-r--r--src/java/jogamp/common/os/DynamicLinkerImpl.java182
-rw-r--r--src/java/jogamp/common/os/MacOSXDynamicLinkerImpl.java12
-rw-r--r--src/java/jogamp/common/os/PosixDynamicLinkerImpl.java12
-rw-r--r--src/java/jogamp/common/os/UnixDynamicLinkerImpl.java41
-rw-r--r--src/java/jogamp/common/os/WindowsDynamicLinkerImpl.java47
7 files changed, 260 insertions, 123 deletions
diff --git a/src/java/jogamp/common/os/BionicDynamicLinkerImpl.java b/src/java/jogamp/common/os/BionicDynamicLinker32bitImpl.java
index b293776..e51ae69 100644
--- a/src/java/jogamp/common/os/BionicDynamicLinkerImpl.java
+++ b/src/java/jogamp/common/os/BionicDynamicLinker32bitImpl.java
@@ -28,34 +28,36 @@
package jogamp.common.os;
/**
- * Bionic specialization of {@link UnixDynamicLinkerImpl}
+ * Bionic 32bit specialization of {@link UnixDynamicLinkerImpl}
* utilizing Bionic's non POSIX flags and mode values.
* <p>
* Bionic is used on Android.
* </p>
*/
-public final class BionicDynamicLinkerImpl extends UnixDynamicLinkerImpl {
- private static final long RTLD_DEFAULT = 0xffffffffL;
- // static final long RTLD_NEXT = 0xfffffffeL;
+public final class BionicDynamicLinker32bitImpl extends UnixDynamicLinkerImpl {
- private static final int RTLD_LAZY = 0x00001;
// static final int RTLD_NOW = 0x00000;
+ private static final int RTLD_LAZY = 0x00001;
+
private static final int RTLD_LOCAL = 0x00000;
private static final int RTLD_GLOBAL = 0x00002;
+ // static final int RTLD_NOLOAD = 0x00004;
+
+ private static final long RTLD_DEFAULT = 0xffffffffL;
+ // static final long RTLD_NEXT = 0xfffffffeL;
@Override
- public final long openLibraryLocal(final String pathname, final boolean debug) throws SecurityException {
- return this.openLibraryImpl(pathname, RTLD_LAZY | RTLD_LOCAL, debug);
+ protected final long openLibraryLocalImpl(final String pathname) throws SecurityException {
+ return dlopen(pathname, RTLD_LAZY | RTLD_LOCAL);
}
@Override
- public final long openLibraryGlobal(final String pathname, final boolean debug) throws SecurityException {
- return this.openLibraryImpl(pathname, RTLD_LAZY | RTLD_GLOBAL, debug);
+ protected final long openLibraryGlobalImpl(final String pathname) throws SecurityException {
+ return dlopen(pathname, RTLD_LAZY | RTLD_GLOBAL);
}
@Override
- public final long lookupSymbolGlobal(final String symbolName) throws SecurityException {
- return this.lookupSymbolGlobalImpl(RTLD_DEFAULT, symbolName);
+ protected final long lookupSymbolGlobalImpl(final String symbolName) throws SecurityException {
+ return dlsym(RTLD_DEFAULT, symbolName);
}
-
}
diff --git a/src/java/jogamp/common/os/BionicDynamicLinker64BitImpl.java b/src/java/jogamp/common/os/BionicDynamicLinker64BitImpl.java
new file mode 100644
index 0000000..d8d3134
--- /dev/null
+++ b/src/java/jogamp/common/os/BionicDynamicLinker64BitImpl.java
@@ -0,0 +1,63 @@
+/**
+ * Copyright 2015 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package jogamp.common.os;
+
+/**
+ * Bionic 64bit specialization of {@link UnixDynamicLinkerImpl}
+ * utilizing Bionic's non POSIX flags and mode values.
+ * <p>
+ * Bionic is used on Android.
+ * </p>
+ */
+public final class BionicDynamicLinker64BitImpl extends UnixDynamicLinkerImpl {
+ // static final int RTLD_NOW = 0x00002;
+ private static final int RTLD_LAZY = 0x00001;
+
+ private static final int RTLD_LOCAL = 0x00000;
+ private static final int RTLD_GLOBAL = 0x00100;
+ // static final int RTLD_NOLOAD = 0x00004;
+
+ private static final long RTLD_DEFAULT = 0x00000000L;
+ // static final long RTLD_NEXT = -1L;
+
+ @Override
+ protected final long openLibraryLocalImpl(final String pathname) throws SecurityException {
+ return dlopen(pathname, RTLD_LAZY | RTLD_LOCAL);
+ }
+
+ @Override
+ protected final long openLibraryGlobalImpl(final String pathname) throws SecurityException {
+ return dlopen(pathname, RTLD_LAZY | RTLD_GLOBAL);
+ }
+
+ @Override
+ protected final long lookupSymbolGlobalImpl(final String symbolName) throws SecurityException {
+ return dlsym(RTLD_DEFAULT, symbolName);
+ }
+
+}
diff --git a/src/java/jogamp/common/os/DynamicLinkerImpl.java b/src/java/jogamp/common/os/DynamicLinkerImpl.java
index 392d906..56a909e 100644
--- a/src/java/jogamp/common/os/DynamicLinkerImpl.java
+++ b/src/java/jogamp/common/os/DynamicLinkerImpl.java
@@ -29,6 +29,7 @@ package jogamp.common.os;
import com.jogamp.common.os.DynamicLinker;
import com.jogamp.common.util.LongObjectHashMap;
+import com.jogamp.common.util.SecurityUtil;
/* pp */ abstract class DynamicLinkerImpl implements DynamicLinker {
@@ -38,18 +39,134 @@ import com.jogamp.common.util.LongObjectHashMap;
// ensuring no abuse via subclassing.
//
- private final LongObjectHashMap libHandle2Name = new LongObjectHashMap( 16 /* initialCapacity */ );
+ private final Object secSync = new Object();
+ private boolean allLinkPermissionGranted = false;
- protected static final class LibRef {
- public LibRef(final String name) {
+ /**
+ * @throws SecurityException if user is not granted global access
+ */
+ public final void claimAllLinkPermission() throws SecurityException {
+ synchronized( secSync ) {
+ allLinkPermissionGranted = true;
+ }
+ }
+
+ /**
+ * @throws SecurityException if user is not granted global access
+ */
+ public final void releaseAllLinkPermission() throws SecurityException {
+ synchronized( secSync ) {
+ allLinkPermissionGranted = false;
+ }
+ }
+
+ private final void checkLinkPermission(final String pathname) throws SecurityException {
+ synchronized( secSync ) {
+ if( !allLinkPermissionGranted ) {
+ SecurityUtil.checkLinkPermission(pathname);
+ }
+ }
+ }
+ private final void checkLinkPermission(final long libraryHandle) throws SecurityException {
+ synchronized( secSync ) {
+ if( !allLinkPermissionGranted ) {
+ final LibRef libRef = getLibRef( libraryHandle );
+ if( null == libRef ) {
+ throw new IllegalArgumentException("Library handle 0x"+Long.toHexString(libraryHandle)+" unknown.");
+ }
+ SecurityUtil.checkLinkPermission(libRef.getName());
+ }
+ }
+ }
+
+ private final void checkAllLinkPermission() throws SecurityException {
+ synchronized( secSync ) {
+ if( !allLinkPermissionGranted ) {
+ SecurityUtil.checkAllLinkPermission();
+ }
+ }
+ }
+
+ @Override
+ public final long openLibraryGlobal(final String pathname, final boolean debug) throws SecurityException {
+ checkLinkPermission(pathname);
+ final long handle = openLibraryGlobalImpl(pathname);
+ if( 0 != handle ) {
+ final LibRef libRef = incrLibRefCount(handle, pathname);
+ if( DEBUG || debug ) {
+ System.err.println("DynamicLinkerImpl.openLibraryGlobal \""+pathname+"\": 0x"+Long.toHexString(handle)+" -> "+libRef+")");
+ }
+ } else if ( DEBUG || debug ) {
+ System.err.println("DynamicLinkerImpl.openLibraryGlobal \""+pathname+"\" failed, error: "+getLastError());
+ }
+ return handle;
+ }
+ protected abstract long openLibraryGlobalImpl(final String pathname) throws SecurityException;
+
+ @Override
+ public final long openLibraryLocal(final String pathname, final boolean debug) throws SecurityException {
+ checkLinkPermission(pathname);
+ final long handle = openLibraryLocalImpl(pathname);
+ if( 0 != handle ) {
+ final LibRef libRef = incrLibRefCount(handle, pathname);
+ if( DEBUG || debug ) {
+ System.err.println("DynamicLinkerImpl.openLibraryLocal \""+pathname+"\": 0x"+Long.toHexString(handle)+" -> "+libRef+")");
+ }
+ } else if ( DEBUG || debug ) {
+ System.err.println("DynamicLinkerImpl.openLibraryLocal \""+pathname+"\" failed, error: "+getLastError());
+ }
+ return handle;
+ }
+ protected abstract long openLibraryLocalImpl(final String pathname) throws SecurityException;
+
+ @Override
+ public final long lookupSymbolGlobal(final String symbolName) throws SecurityException {
+ checkAllLinkPermission();
+ final long addr = lookupSymbolGlobalImpl(symbolName);
+ if(DEBUG_LOOKUP) {
+ System.err.println("DynamicLinkerImpl.lookupSymbolGlobal("+symbolName+") -> 0x"+Long.toHexString(addr));
+ }
+ return addr;
+ }
+ protected abstract long lookupSymbolGlobalImpl(final String symbolName) throws SecurityException;
+
+ @Override
+ public final long lookupSymbol(final long libraryHandle, final String symbolName) throws SecurityException, IllegalArgumentException {
+ checkLinkPermission(libraryHandle);
+ final long addr = lookupSymbolLocalImpl(libraryHandle, symbolName);
+ if(DEBUG_LOOKUP) {
+ System.err.println("DynamicLinkerImpl.lookupSymbol(0x"+Long.toHexString(libraryHandle)+", "+symbolName+") -> 0x"+Long.toHexString(addr));
+ }
+ return addr;
+ }
+ protected abstract long lookupSymbolLocalImpl(final long libraryHandle, final String symbolName) throws SecurityException;
+
+ @Override
+ public final void closeLibrary(final long libraryHandle, final boolean debug) throws SecurityException, IllegalArgumentException {
+ final LibRef libRef = decrLibRefCount( libraryHandle );
+ if( null == libRef ) {
+ throw new IllegalArgumentException("Library handle 0x"+Long.toHexString(libraryHandle)+" unknown.");
+ }
+ checkLinkPermission(libRef.getName());
+ if( DEBUG || debug ) {
+ System.err.println("DynamicLinkerImpl.closeLibrary(0x"+Long.toHexString(libraryHandle)+" -> "+libRef+")");
+ }
+ closeLibraryImpl(libraryHandle);
+ }
+ protected abstract void closeLibraryImpl(final long libraryHandle) throws SecurityException;
+
+ private static final LongObjectHashMap libHandle2Name = new LongObjectHashMap( 16 /* initialCapacity */ );
+
+ static final class LibRef {
+ LibRef(final String name) {
this.name = name;
this.refCount = 1;
}
- public final int incrRefCount() { return ++refCount; }
- public final int decrRefCount() { return --refCount; }
- public final int getRefCount() { return refCount; }
+ final int incrRefCount() { return ++refCount; }
+ final int decrRefCount() { return --refCount; }
+ final int getRefCount() { return refCount; }
- public final String getName() { return name; }
+ final String getName() { return name; }
@Override
public final String toString() { return "LibRef["+name+", refCount "+refCount+"]"; }
@@ -57,35 +174,40 @@ import com.jogamp.common.util.LongObjectHashMap;
private int refCount;
}
- protected final synchronized LibRef getLibRef(final long handle) {
- return (LibRef) libHandle2Name.get(handle);
+ private final LibRef getLibRef(final long handle) {
+ synchronized( libHandle2Name ) {
+ return (LibRef) libHandle2Name.get(handle);
+ }
}
- protected final synchronized LibRef incrLibRefCount(final long handle, final String libName) {
- LibRef libRef = getLibRef(handle);
- if( null == libRef ) {
- libRef = new LibRef(libName);
- libHandle2Name.put(handle, libRef);
- } else {
- libRef.incrRefCount();
- }
- if(DEBUG) {
- System.err.println("DynamicLinkerImpl.incrLibRefCount 0x"+Long.toHexString(handle)+ " -> "+libRef+", libs loaded "+libHandle2Name.size());
+ private final LibRef incrLibRefCount(final long handle, final String libName) {
+ synchronized( libHandle2Name ) {
+ LibRef libRef = getLibRef(handle);
+ if( null == libRef ) {
+ libRef = new LibRef(libName);
+ libHandle2Name.put(handle, libRef);
+ } else {
+ libRef.incrRefCount();
+ }
+ if(DEBUG) {
+ System.err.println("DynamicLinkerImpl.incrLibRefCount 0x"+Long.toHexString(handle)+ " -> "+libRef+", libs loaded "+libHandle2Name.size());
+ }
+ return libRef;
}
- return libRef;
}
- protected final synchronized LibRef decrLibRefCount(final long handle) {
- final LibRef libRef = getLibRef(handle);
- if( null != libRef ) {
- if( 0 == libRef.decrRefCount() ) {
- libHandle2Name.remove(handle);
+ private final LibRef decrLibRefCount(final long handle) {
+ synchronized( libHandle2Name ) {
+ final LibRef libRef = getLibRef(handle);
+ if( null != libRef ) {
+ if( 0 == libRef.decrRefCount() ) {
+ libHandle2Name.remove(handle);
+ }
}
+ if(DEBUG) {
+ System.err.println("DynamicLinkerImpl.decrLibRefCount 0x"+Long.toHexString(handle)+ " -> "+libRef+", libs loaded "+libHandle2Name.size());
+ }
+ return libRef;
}
- if(DEBUG) {
- System.err.println("DynamicLinkerImpl.decrLibRefCount 0x"+Long.toHexString(handle)+ " -> "+libRef+", libs loaded "+libHandle2Name.size());
- }
- return libRef;
}
-
}
diff --git a/src/java/jogamp/common/os/MacOSXDynamicLinkerImpl.java b/src/java/jogamp/common/os/MacOSXDynamicLinkerImpl.java
index 0fdfc8b..d724f9a 100644
--- a/src/java/jogamp/common/os/MacOSXDynamicLinkerImpl.java
+++ b/src/java/jogamp/common/os/MacOSXDynamicLinkerImpl.java
@@ -42,18 +42,18 @@ public final class MacOSXDynamicLinkerImpl extends UnixDynamicLinkerImpl {
private static final int RTLD_GLOBAL = 0x00008;
@Override
- public final long openLibraryLocal(final String pathname, final boolean debug) throws SecurityException {
- return this.openLibraryImpl(pathname, RTLD_LAZY | RTLD_LOCAL, debug);
+ protected final long openLibraryLocalImpl(final String pathname) throws SecurityException {
+ return dlopen(pathname, RTLD_LAZY | RTLD_LOCAL);
}
@Override
- public final long openLibraryGlobal(final String pathname, final boolean debug) throws SecurityException {
- return this.openLibraryImpl(pathname, RTLD_LAZY | RTLD_GLOBAL, debug);
+ protected final long openLibraryGlobalImpl(final String pathname) throws SecurityException {
+ return dlopen(pathname, RTLD_LAZY | RTLD_GLOBAL);
}
@Override
- public final long lookupSymbolGlobal(final String symbolName) throws SecurityException {
- return this.lookupSymbolGlobalImpl(RTLD_DEFAULT, symbolName);
+ protected final long lookupSymbolGlobalImpl(final String symbolName) throws SecurityException {
+ return dlsym(RTLD_DEFAULT, symbolName);
}
}
diff --git a/src/java/jogamp/common/os/PosixDynamicLinkerImpl.java b/src/java/jogamp/common/os/PosixDynamicLinkerImpl.java
index f929e03..a022f01 100644
--- a/src/java/jogamp/common/os/PosixDynamicLinkerImpl.java
+++ b/src/java/jogamp/common/os/PosixDynamicLinkerImpl.java
@@ -38,17 +38,17 @@ public final class PosixDynamicLinkerImpl extends UnixDynamicLinkerImpl {
private static final int RTLD_GLOBAL = 0x00100;
@Override
- public final long openLibraryLocal(final String pathname, final boolean debug) throws SecurityException {
- return this.openLibraryImpl(pathname, RTLD_LAZY | RTLD_LOCAL, debug);
+ protected final long openLibraryLocalImpl(final String pathname) throws SecurityException {
+ return dlopen(pathname, RTLD_LAZY | RTLD_LOCAL);
}
@Override
- public final long openLibraryGlobal(final String pathname, final boolean debug) throws SecurityException {
- return this.openLibraryImpl(pathname, RTLD_LAZY | RTLD_GLOBAL, debug);
+ protected final long openLibraryGlobalImpl(final String pathname) throws SecurityException {
+ return dlopen(pathname, RTLD_LAZY | RTLD_GLOBAL);
}
@Override
- public final long lookupSymbolGlobal(final String symbolName) throws SecurityException {
- return this.lookupSymbolGlobalImpl(RTLD_DEFAULT, symbolName);
+ protected final long lookupSymbolGlobalImpl(final String symbolName) throws SecurityException {
+ return dlsym(RTLD_DEFAULT, symbolName);
}
}
diff --git a/src/java/jogamp/common/os/UnixDynamicLinkerImpl.java b/src/java/jogamp/common/os/UnixDynamicLinkerImpl.java
index 59be76c..5e8ba9d 100644
--- a/src/java/jogamp/common/os/UnixDynamicLinkerImpl.java
+++ b/src/java/jogamp/common/os/UnixDynamicLinkerImpl.java
@@ -27,8 +27,6 @@
*/
package jogamp.common.os;
-import com.jogamp.common.util.SecurityUtil;
-
/* pp */ abstract class UnixDynamicLinkerImpl extends DynamicLinkerImpl {
//
@@ -49,46 +47,17 @@ import com.jogamp.common.util.SecurityUtil;
/** Interface to C language function: <br> <code> void * dlsym(void * , const char * ); </code> */
protected static native long dlsym(long arg0, java.lang.String arg1);
- protected final long openLibraryImpl(final String pathname, final int dlSymFlags, final boolean debug) throws SecurityException {
- SecurityUtil.checkLinkPermission(pathname);
- final long handle = dlopen(pathname, dlSymFlags);
- if( 0 != handle ) {
- incrLibRefCount(handle, pathname);
- } else if ( DEBUG || debug ) {
- System.err.println("dlopen \""+pathname+"\" failed, error: "+dlerror());
- }
- return handle;
- }
-
- protected final long lookupSymbolGlobalImpl(final long dlSymGlobalFlag, final String symbolName) throws SecurityException {
- SecurityUtil.checkAllLinkPermission();
- final long addr = dlsym(dlSymGlobalFlag, symbolName);
- if(DEBUG_LOOKUP) {
- System.err.println("DynamicLinkerImpl.lookupSymbolGlobal("+symbolName+") -> 0x"+Long.toHexString(addr));
- }
- return addr;
- }
-
@Override
- public final long lookupSymbol(final long libraryHandle, final String symbolName) throws IllegalArgumentException {
- if( null == getLibRef( libraryHandle ) ) {
- throw new IllegalArgumentException("Library handle 0x"+Long.toHexString(libraryHandle)+" unknown.");
- }
- final long addr = dlsym(libraryHandle, symbolName);
- if(DEBUG_LOOKUP) {
- System.err.println("DynamicLinkerImpl.lookupSymbol(0x"+Long.toHexString(libraryHandle)+", "+symbolName+") -> 0x"+Long.toHexString(addr));
- }
- return addr;
+ protected final long lookupSymbolLocalImpl(final long libraryHandle, final String symbolName) throws SecurityException {
+ return dlsym(libraryHandle, symbolName);
}
@Override
- public final void closeLibrary(final long libraryHandle) throws IllegalArgumentException {
- if( null == decrLibRefCount( libraryHandle ) ) {
- throw new IllegalArgumentException("Library handle 0x"+Long.toHexString(libraryHandle)+" unknown.");
- }
- dlclose(libraryHandle);
+ protected final void closeLibraryImpl(final long libraryHandle) throws SecurityException {
+ dlclose(libraryHandle);
}
+
@Override
public final String getLastError() {
return dlerror();
diff --git a/src/java/jogamp/common/os/WindowsDynamicLinkerImpl.java b/src/java/jogamp/common/os/WindowsDynamicLinkerImpl.java
index de69d0c..04f13fb 100644
--- a/src/java/jogamp/common/os/WindowsDynamicLinkerImpl.java
+++ b/src/java/jogamp/common/os/WindowsDynamicLinkerImpl.java
@@ -27,8 +27,6 @@
*/
package jogamp.common.os;
-import com.jogamp.common.util.SecurityUtil;
-
public final class WindowsDynamicLinkerImpl extends DynamicLinkerImpl {
/** Interface to C language function: <br> <code> BOOL FreeLibrary(HANDLE hLibModule); </code> */
@@ -44,28 +42,19 @@ public final class WindowsDynamicLinkerImpl extends DynamicLinkerImpl {
private static native long LoadLibraryW(java.lang.String lpLibFileName);
@Override
- public final long openLibraryLocal(final String libraryName, final boolean debug) throws SecurityException {
+ protected final long openLibraryLocalImpl(final String libraryName) throws SecurityException {
// How does that work under Windows ?
- // Don't know .. so it's an alias for the time being
- return openLibraryGlobal(libraryName, debug);
+ // Don't know .. so it's an alias to global, for the time being
+ return LoadLibraryW(libraryName);
}
@Override
- public final long openLibraryGlobal(final String libraryName, final boolean debug) throws SecurityException {
- SecurityUtil.checkLinkPermission(libraryName);
- final long handle = LoadLibraryW(libraryName);
- if( 0 != handle ) {
- incrLibRefCount(handle, libraryName);
- } else if ( DEBUG || debug ) {
- final int err = GetLastError();
- System.err.println("LoadLibraryW \""+libraryName+"\" failed, error code: 0x"+Integer.toHexString(err)+", "+err);
- }
- return handle;
+ protected final long openLibraryGlobalImpl(final String libraryName) throws SecurityException {
+ return LoadLibraryW(libraryName);
}
@Override
- public final long lookupSymbolGlobal(final String symbolName) throws SecurityException {
- SecurityUtil.checkAllLinkPermission();
+ protected final long lookupSymbolGlobalImpl(final String symbolName) throws SecurityException {
if(DEBUG_LOOKUP) {
System.err.println("lookupSymbolGlobal: Not supported on Windows");
}
@@ -73,34 +62,26 @@ public final class WindowsDynamicLinkerImpl extends DynamicLinkerImpl {
return 0;
}
+ private static final int symbolArgAlignment=4; // 4 byte alignment of each argument
+ private static final int symbolMaxArguments=12; // experience ..
+
@Override
- public final long lookupSymbol(final long libraryHandle, final String symbolName) throws IllegalArgumentException {
- if( null == getLibRef( libraryHandle ) ) {
- throw new IllegalArgumentException("Library handle 0x"+Long.toHexString(libraryHandle)+" unknown.");
- }
+ protected final long lookupSymbolLocalImpl(final long libraryHandle, final String symbolName) throws IllegalArgumentException {
String _symbolName = symbolName;
long addr = GetProcAddressA(libraryHandle, _symbolName);
- if(0==addr) {
+ if( 0 == addr ) {
// __stdcall hack: try some @nn decorations,
// the leading '_' must not be added (same with cdecl)
- final int argAlignment=4; // 4 byte alignment of each argument
- final int maxArguments=12; // experience ..
- for(int arg=0; 0==addr && arg<=maxArguments; arg++) {
- _symbolName = symbolName+"@"+(arg*argAlignment);
+ for(int arg=0; 0==addr && arg<=symbolMaxArguments; arg++) {
+ _symbolName = symbolName+"@"+(arg*symbolArgAlignment);
addr = GetProcAddressA(libraryHandle, _symbolName);
}
}
- if(DEBUG_LOOKUP) {
- System.err.println("DynamicLinkerImpl.lookupSymbol(0x"+Long.toHexString(libraryHandle)+", "+symbolName+") -> "+_symbolName+", 0x"+Long.toHexString(addr));
- }
return addr;
}
@Override
- public final void closeLibrary(final long libraryHandle) throws IllegalArgumentException {
- if( null == decrLibRefCount( libraryHandle ) ) {
- throw new IllegalArgumentException("Library handle 0x"+Long.toHexString(libraryHandle)+" unknown.");
- }
+ protected final void closeLibraryImpl(final long libraryHandle) throws IllegalArgumentException {
FreeLibrary(libraryHandle);
}