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

Unified Diff: content/public/android/java/src/org/chromium/content/app/LibraryLoader.java

Issue 59533009: Check library version and handle library load errors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix BrowserStartupControllerTest Created 7 years, 1 month 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: content/public/android/java/src/org/chromium/content/app/LibraryLoader.java
diff --git a/content/public/android/java/src/org/chromium/content/app/LibraryLoader.java b/content/public/android/java/src/org/chromium/content/app/LibraryLoader.java
index 38165bd1a582cdc3cdde7ff5ba5a9d0f1417d319..5bae7c3e1d155d19f53b16bcc8ba953402af778b 100644
--- a/content/public/android/java/src/org/chromium/content/app/LibraryLoader.java
+++ b/content/public/android/java/src/org/chromium/content/app/LibraryLoader.java
@@ -116,7 +116,7 @@ public class LibraryLoader {
if (useContentLinker)
Linker.prepareLibraryLoad();
- for (String library : NativeLibraries.libraries) {
+ for (String library : NativeLibraries.LIBRARIES) {
Log.i(TAG, "Loading: " + library);
if (useContentLinker)
Linker.loadLibrary(library);
@@ -135,6 +135,16 @@ public class LibraryLoader {
} catch (UnsatisfiedLinkError e) {
throw new ProcessInitException(ResultCodes.RESULT_CODE_NATIVE_LIBRARY_LOAD_FAILED, e);
}
+ // Check that the version of the library we have loaded matches the version we expect
+ Log.i(TAG, String.format(
+ "Expected native library version number \"%s\"," +
+ "actual native library version number \"%s\"",
+ NativeLibraries.VERSION_NUMBER,
+ nativeGetVersionNumber()));
+ if (!NativeLibraries.VERSION_NUMBER.equals(nativeGetVersionNumber())) {
+ throw new ProcessInitException(ResultCodes.RESULT_CODE_NATIVE_LIBRARY_WRONG_VERSION);
+ }
+
}
@@ -157,13 +167,13 @@ public class LibraryLoader {
TraceEvent.setEnabledToMatchNative();
// Record histogram for the content linker.
if (Linker.isUsed())
- nativeRecordContentAndroidLinkerHistogram(Linker.loadAtFixedAddressFailed(),
+ nativeRecordContentAndroidLinkerHistogram(Linker.loadAtFixedAddressFailed(),
SysUtils.isLowEndDevice());
}
- // This is the only method that is registered during System.loadLibrary. We then call it
- // to register everything else. This process is called "initialization".
- // This method will be mapped (by generated code) to the LibraryLoaded
+ // Only methods needed before or during normal JNI registration are during System.OnLoad.
+ // nativeLibraryLoaded is then called to register everything else. This process is called
+ // "initialization". This method will be mapped (by generated code) to the LibraryLoaded
// definition in content/app/android/library_loader_hooks.cc.
//
// Return 0 on success, otherwise return the error code from
@@ -176,4 +186,8 @@ public class LibraryLoader {
private static native void nativeRecordContentAndroidLinkerHistogram(
boolean loadedAtFixedAddressFailed,
boolean isLowMemoryDevice);
+
+ // Get the version of the native library. This is needed so that we can check we
+ // have the right version before initializing the (rest of the) JNI.
+ private static native String nativeGetVersionNumber();
}

Powered by Google App Engine
This is Rietveld 408576698