Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3103)

Unified Diff: base/android/java/src/org/chromium/base/library_loader/Linker.java

Issue 683113005: Update from chromium https://crrev.com/302282 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/android/java/src/org/chromium/base/library_loader/Linker.java
diff --git a/base/android/java/src/org/chromium/base/library_loader/Linker.java b/base/android/java/src/org/chromium/base/library_loader/Linker.java
index 997b67c4b024b189a55dc9546b71d1032e25926b..dbd780b658a6e78da87663e265fd21b49fb1a406 100644
--- a/base/android/java/src/org/chromium/base/library_loader/Linker.java
+++ b/base/android/java/src/org/chromium/base/library_loader/Linker.java
@@ -243,8 +243,8 @@ public class Linker {
}
if (sMemoryDeviceConfig == MEMORY_DEVICE_CONFIG_INIT) {
- sMemoryDeviceConfig = SysUtils.isLowEndDevice() ?
- MEMORY_DEVICE_CONFIG_LOW : MEMORY_DEVICE_CONFIG_NORMAL;
+ sMemoryDeviceConfig = SysUtils.isLowEndDevice()
+ ? MEMORY_DEVICE_CONFIG_LOW : MEMORY_DEVICE_CONFIG_NORMAL;
}
switch (BROWSER_SHARED_RELRO_CONFIG) {
@@ -341,8 +341,8 @@ public class Linker {
assert NativeLibraries.sEnableLinkerTests;
synchronized (Linker.class) {
assert sMemoryDeviceConfig == MEMORY_DEVICE_CONFIG_INIT;
- assert memoryDeviceConfig == MEMORY_DEVICE_CONFIG_LOW ||
- memoryDeviceConfig == MEMORY_DEVICE_CONFIG_NORMAL;
+ assert memoryDeviceConfig == MEMORY_DEVICE_CONFIG_LOW
+ || memoryDeviceConfig == MEMORY_DEVICE_CONFIG_NORMAL;
if (DEBUG) {
if (memoryDeviceConfig == MEMORY_DEVICE_CONFIG_LOW)
Log.i(TAG, "Simulating a low-memory device");
@@ -507,8 +507,8 @@ public class Linker {
parcel.recycle();
}
if (DEBUG) {
- Log.i(TAG, "useSharedRelros() called with " + bundle +
- ", cloned " + clonedBundle);
+ Log.i(TAG, "useSharedRelros() called with " + bundle
+ + ", cloned " + clonedBundle);
}
synchronized (Linker.class) {
// Note that in certain cases, this can be called before
@@ -640,8 +640,7 @@ public class Linker {
final long maxExpectedBytes = 192 * 1024 * 1024;
final long address = nativeGetRandomBaseLoadAddress(maxExpectedBytes);
if (DEBUG) {
- Log.i(TAG,
- String.format(Locale.US, "Random native base load address: 0x%x", address));
+ Log.i(TAG, String.format(Locale.US, "Random native base load address: 0x%x", address));
}
return address;
}
@@ -703,7 +702,8 @@ public class Linker {
* Load a native shared library with the Chromium linker.
* The shared library is uncompressed and page aligned inside the zipfile.
* Note the crazy linker treats libraries and files as equivalent,
- * so you can only open one library in a given zip file.
+ * so you can only open one library in a given zip file. The library must
+ * not be the Chromium linker library.
*
* @param zipfile The filename of the zipfile contain the library.
* @param library The library's base name.
@@ -713,7 +713,8 @@ public class Linker {
}
/**
- * Load a native shared library with the Chromium linker.
+ * Load a native shared library with the Chromium linker. The library must
+ * not be the Chromium linker library.
*
* @param library The library's base name.
*/
@@ -724,15 +725,7 @@ public class Linker {
private static void loadLibraryMaybeInZipFile(
@Nullable String zipFile, String library) {
if (DEBUG) Log.i(TAG, "loadLibrary: " + library);
-
- // Don't self-load the linker. This is because the build system is
- // not clever enough to understand that all the libraries packaged
- // in the final .apk don't need to be explicitly loaded.
- // Also deal with the component build that adds a .cr suffix to the name.
- if (library.equals(TAG) || library.equals(TAG + ".cr")) {
- if (DEBUG) Log.i(TAG, "ignoring self-linker load");
- return;
- }
+ assert !isChromiumLinkerLibrary(library);
synchronized (Linker.class) {
ensureInitializedLocked();
@@ -762,8 +755,8 @@ public class Linker {
String sharedRelRoName = libName;
if (zipFile != null) {
if (!nativeLoadLibraryInZipFile(zipFile, libName, loadAddress, libInfo)) {
- String errorMessage = "Unable to load library: " + libName +
- ", in: " + zipFile;
+ String errorMessage = "Unable to load library: " + libName
+ + ", in: " + zipFile;
Log.e(TAG, errorMessage);
throw new UnsatisfiedLinkError(errorMessage);
}
@@ -822,6 +815,14 @@ public class Linker {
}
/**
+ * Determine whether a library is the linker library. Also deal with the
+ * component build that adds a .cr suffix to the name.
+ */
+ public static boolean isChromiumLinkerLibrary(String library) {
+ return library.equals(TAG) || library.equals(TAG + ".cr");
+ }
+
+ /**
* Check whether the device supports loading a library directly from the APK file.
*
* @param apkFile Filename of the APK.
@@ -834,13 +835,32 @@ public class Linker {
if (DEBUG) Log.i(TAG, "checkLibraryLoadFromApkSupported: " + apkFile);
boolean supported = nativeCheckLibraryLoadFromApkSupport(apkFile);
- if (DEBUG) Log.i(TAG, "Loading a library directly from the APK file " +
- (supported ? "" : "NOT ") + "supported");
+ if (DEBUG) Log.i(TAG, "Loading a library directly from the APK file "
+ + (supported ? "" : "NOT ") + "supported");
return supported;
}
}
/**
+ * Check whether a library is page aligned in the APK file.
+ *
+ * @param apkFile Filename of the APK.
+ * @param library The library's base name.
+ * @return true if page aligned.
+ */
+ public static boolean checkLibraryAlignedInApk(String apkFile, String library) {
+ synchronized (Linker.class) {
+ ensureInitializedLocked();
+
+ if (DEBUG) Log.i(TAG, "checkLibraryAlignedInApk: " + apkFile + ", " + library);
+ boolean aligned = nativeCheckLibraryAlignedInApk(apkFile, library);
+ if (DEBUG) Log.i(TAG, library + " is " + (aligned ? "" : "NOT ") +
+ "page aligned in " + apkFile);
+ return aligned;
+ }
+ }
+
+ /**
* Move activity from the native thread to the main UI thread.
* Called from native code on its own thread. Posts a callback from
* the UI thread back to native code.
@@ -885,11 +905,10 @@ public class Linker {
* of this LibInfo instance will set on success.
* @return true for success, false otherwise.
*/
- private static native boolean nativeLoadLibraryInZipFile(
- String zipfileName,
- String libraryName,
- long loadAddress,
- LibInfo libInfo);
+ private static native boolean nativeLoadLibraryInZipFile(String zipfileName,
+ String libraryName,
+ long loadAddress,
+ LibInfo libInfo);
/**
* Native method used to create a shared RELRO section.
@@ -943,11 +962,19 @@ public class Linker {
*
* @param apkFile Filename of the APK.
* @return true if supported.
- *
*/
private static native boolean nativeCheckLibraryLoadFromApkSupport(String apkFile);
/**
+ * Native method which checks whether a library is page aligned in the APK file.
+ *
+ * @param apkFile Filename of the APK.
+ * @param library The library's base name.
+ * @return true if page aligned.
+ */
+ private static native boolean nativeCheckLibraryAlignedInApk(String apkFile, String library);
+
+ /**
* Record information for a given library.
* IMPORTANT: Native code knows about this class's fields, so
* don't change them without modifying the corresponding C++ sources.
@@ -1080,5 +1107,5 @@ public class Linker {
// Used to pass the shared RELRO Bundle through Binder.
public static final String EXTRA_LINKER_SHARED_RELROS =
- "org.chromium.base.android.linker.shared_relros";
+ "org.chromium.base.android.linker.shared_relros";
}

Powered by Google App Engine
This is Rietveld 408576698