diff options
author | Sven Gothel <[email protected]> | 2015-01-30 21:09:17 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2015-01-30 21:09:17 +0100 |
commit | 12feaa7d3b1544098f684d851e3caff1ec88cbc8 (patch) | |
tree | 2d979c57cca37220bc026a8ee08ee479ae0508bf /src/java/com/jogamp/common/os/DynamicLibraryBundle.java | |
parent | 3caf446e29a3934900b9983dfd72cb8aa0d9e8d7 (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/com/jogamp/common/os/DynamicLibraryBundle.java')
-rw-r--r-- | src/java/com/jogamp/common/os/DynamicLibraryBundle.java | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/src/java/com/jogamp/common/os/DynamicLibraryBundle.java b/src/java/com/jogamp/common/os/DynamicLibraryBundle.java index 0f5ea8f..06cef6f 100644 --- a/src/java/com/jogamp/common/os/DynamicLibraryBundle.java +++ b/src/java/com/jogamp/common/os/DynamicLibraryBundle.java @@ -62,6 +62,7 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { private final DynamicLibraryBundleInfo info; protected final List<NativeLibrary> nativeLibraries; + private final DynamicLinker dynLinkGlobal; private final List<List<String>> toolLibNames; private final List<String> glueLibNames; private final boolean[] toolLibLoaded; @@ -118,11 +119,15 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { glueLibLoaded[i] = false; } - info.getLibLoaderExecutor().invoke(true, new Runnable() { - @Override - public void run() { - loadLibraries(); - } } ) ; + { + final DynamicLinker[] _dynLinkGlobal = { null }; + info.getLibLoaderExecutor().invoke(true, new Runnable() { + @Override + public void run() { + _dynLinkGlobal[0] = loadLibraries(); + } } ) ; + dynLinkGlobal = _dynLinkGlobal[0]; + } toolGetProcAddressFuncNameList = info.getToolGetProcAddressFuncNameList(); if( null != toolGetProcAddressFuncNameList ) { @@ -184,7 +189,7 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { * @see DynamicLibraryBundleInfo#getToolLibNames() */ public final boolean isToolLibComplete() { - return toolGetProcAddressComplete && getToolLibNumber() == getToolLibLoadedNumber(); + return toolGetProcAddressComplete && null != dynLinkGlobal && getToolLibNumber() == getToolLibLoadedNumber(); } public final boolean isToolLibLoaded() { @@ -241,7 +246,7 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { return aptr; } - protected final NativeLibrary loadFirstAvailable(final List<String> libNames, final ClassLoader loader, final boolean global) { + protected static final NativeLibrary loadFirstAvailable(final List<String> libNames, final ClassLoader loader, final boolean global) { for (int i=0; i < libNames.size(); i++) { final NativeLibrary lib = NativeLibrary.open(libNames.get(i), loader, global); if (lib != null) { @@ -251,11 +256,12 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { return null; } - final void loadLibraries() { + final DynamicLinker loadLibraries() { int i; toolLibLoadedNumber = 0; final ClassLoader cl = info.getClass().getClassLoader(); NativeLibrary lib = null; + DynamicLinker dynLinkGlobal = null; for (i=0; i < toolLibNames.size(); i++) { final List<String> libNames = toolLibNames.get(i); @@ -266,6 +272,9 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { System.err.println("Unable to load any Tool library of: "+libNames); } } else { + if( null == dynLinkGlobal ) { + dynLinkGlobal = lib.getDynamicLinker(); + } nativeLibraries.add(lib); toolLibLoaded[i]=true; toolLibLoadedNumber++; @@ -279,7 +288,7 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { if(DEBUG) { System.err.println("No Tool libraries loaded"); } - return; + return dynLinkGlobal; } glueLibLoadedNumber = 0; @@ -304,6 +313,8 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { glueLibLoadedNumber++; } } + + return dynLinkGlobal; } private final long dynamicLookupFunctionOnLibs(final String funcName) { @@ -318,7 +329,8 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { if( info.shallLookupGlobal() ) { // Try a global symbol lookup first .. - addr = NativeLibrary.dynamicLookupFunctionGlobal(funcName); + // addr = NativeLibrary.dynamicLookupFunctionGlobal(funcName); + addr = dynLinkGlobal.lookupSymbolGlobal(funcName); } // Look up this function name in all known libraries for (int i=0; 0==addr && i < nativeLibraries.size(); i++) { @@ -350,6 +362,20 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { } @Override + public final void claimAllLinkPermission() throws SecurityException { + for (int i=0; i < nativeLibraries.size(); i++) { + final NativeLibrary lib = nativeLibraries.get(i); + nativeLibraries.get(i).claimAllLinkPermission(); + } + } + @Override + public final void releaseAllLinkPermission() throws SecurityException { + for (int i=0; i < nativeLibraries.size(); i++) { + nativeLibraries.get(i).releaseAllLinkPermission(); + } + } + + @Override public final long dynamicLookupFunction(final String funcName) { if(!isToolLibLoaded() || null==funcName) { if(DEBUG_LOOKUP && !isToolLibLoaded()) { |