From 7694b783f48e2cc57928b61c84fd90311cb0c35a Mon Sep 17 00:00:00 2001 From: Dmitriy Ivanov Date: Thu, 17 Jul 2014 15:10:23 -0700 Subject: Pass getDexPath to Runtime.nativeLoad getDexPath is used by Runtime.nativeLoad to open libraries directly from apk. Given that libraries are not compressed and are page-aligned. Bug: 8076853 Change-Id: I1aa2c039bb2a590ae72f256acc9ba5401c2c59b1 --- luni/src/main/java/java/lang/Runtime.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'luni') diff --git a/luni/src/main/java/java/lang/Runtime.java b/luni/src/main/java/java/lang/Runtime.java index a3cb83e..73820dc 100644 --- a/luni/src/main/java/java/lang/Runtime.java +++ b/luni/src/main/java/java/lang/Runtime.java @@ -357,14 +357,11 @@ public class Runtime { */ void loadLibrary(String libraryName, ClassLoader loader) { if (loader != null) { + // TODO: We shouldn't assume that we know default linker search logic. String filename = loader.findLibrary(libraryName); if (filename == null) { - // It's not necessarily true that the ClassLoader used - // System.mapLibraryName, but the default setup does, and it's - // misleading to say we didn't find "libMyLibrary.so" when we - // actually searched for "liblibMyLibrary.so.so". - throw new UnsatisfiedLinkError(loader + " couldn't find \"" + - System.mapLibraryName(libraryName) + "\""); + // The dynamic linker might still find the library by name. + filename = System.mapLibraryName(libraryName); } String error = doLoad(filename, loader); if (error != null) { @@ -418,19 +415,23 @@ public class Runtime { // So, find out what the native library search path is for the ClassLoader in question... String ldLibraryPath = null; + String dexPath = null; if (loader != null && loader instanceof BaseDexClassLoader) { - ldLibraryPath = ((BaseDexClassLoader) loader).getLdLibraryPath(); + BaseDexClassLoader dexClassLoader = (BaseDexClassLoader) loader; + ldLibraryPath = dexClassLoader.getLdLibraryPath(); + dexPath = dexClassLoader.getDexPath(); } // nativeLoad should be synchronized so there's only one LD_LIBRARY_PATH in use regardless // of how many ClassLoaders are in the system, but dalvik doesn't support synchronized // internal natives. synchronized (this) { - return nativeLoad(name, loader, ldLibraryPath); + return nativeLoad(name, loader, ldLibraryPath, dexPath); } } // TODO: should be synchronized, but dalvik doesn't support synchronized internal natives. - private static native String nativeLoad(String filename, ClassLoader loader, String ldLibraryPath); + private static native String nativeLoad(String filename, ClassLoader loader, + String ldLibraryPath, String dexPath); /** * Provides a hint to the VM that it would be useful to attempt -- cgit v1.1