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

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

Issue 2043183002: Update to Chromium //base at Chromium commit 01cb97b2e09618bbc3a60c7348f0a844eea20547. (Closed) Base URL: https://github.com/domokit/base.git@master
Patch Set: Created 4 years, 6 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: android/java/src/org/chromium/base/library_loader/LibraryLoader.java
diff --git a/android/java/src/org/chromium/base/library_loader/LibraryLoader.java b/android/java/src/org/chromium/base/library_loader/LibraryLoader.java
index e4130baee8bd4809858d618f81ef4953861b8a92..e5813009198ffcfaf918789424a6b99f3595ed1b 100644
--- a/android/java/src/org/chromium/base/library_loader/LibraryLoader.java
+++ b/android/java/src/org/chromium/base/library_loader/LibraryLoader.java
@@ -186,7 +186,33 @@ public class LibraryLoader {
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
- // Invoke System.loadLibrary(...), triggering JNI_OnLoad in native code
+ // Helper for loadAlreadyLocked(). Load a native shared library with the Chromium linker.
+ // Sets UMA flags depending on the results of loading.
+ private void loadLibrary(Linker linker, @Nullable String zipFilePath, String libFilePath) {
+ if (linker.isUsingBrowserSharedRelros()) {
+ // If the browser is set to attempt shared RELROs then we try first with shared
+ // RELROs enabled, and if that fails then retry without.
+ mIsUsingBrowserSharedRelros = true;
+ try {
+ linker.loadLibrary(zipFilePath, libFilePath);
+ } catch (UnsatisfiedLinkError e) {
+ Log.w(TAG, "Failed to load native library with shared RELRO, retrying without");
+ mLoadAtFixedAddressFailed = true;
+ linker.loadLibraryNoFixedAddress(zipFilePath, libFilePath);
+ }
+ } else {
+ // No attempt to use shared RELROs in the browser, so load as normal.
+ linker.loadLibrary(zipFilePath, libFilePath);
+ }
+
+ // Loaded successfully, so record if we loaded directly from an APK.
+ if (zipFilePath != null) {
+ mLibraryWasLoadedFromApk = true;
+ }
+ }
+
+ // Invoke either Linker.loadLibrary(...) or System.loadLibrary(...), triggering
+ // JNI_OnLoad in native code
private void loadAlreadyLocked(Context context) throws ProcessInitException {
try {
if (!mLoaded) {
@@ -217,30 +243,14 @@ public class LibraryLoader {
if (linker.isInZipFile()) {
// Load directly from the APK.
zipFilePath = apkFilePath;
- Log.i(TAG,
- "Loading " + library + " directly from within " + apkFilePath);
+ Log.i(TAG, "Loading " + library + " from within " + apkFilePath);
} else {
// The library is in its own file.
Log.i(TAG, "Loading " + library);
}
- // Load the library.
- boolean isLoaded = false;
- if (linker.isUsingBrowserSharedRelros()) {
- mIsUsingBrowserSharedRelros = true;
- try {
- loadLibrary(zipFilePath, libFilePath);
- isLoaded = true;
- } catch (UnsatisfiedLinkError e) {
- Log.w(TAG, "Failed to load native library with shared RELRO, "
- + "retrying without");
- linker.disableSharedRelros();
- mLoadAtFixedAddressFailed = true;
- }
- }
- if (!isLoaded) {
- loadLibrary(zipFilePath, libFilePath);
- }
+ // Load the library using this Linker. May throw UnsatisfiedLinkError.
+ loadLibrary(linker, zipFilePath, libFilePath);
}
linker.finishLibraryLoad();
@@ -295,15 +305,6 @@ public class LibraryLoader {
return appInfo.sourceDir;
}
- // Load a native shared library with the Chromium linker. If the zip file
- // path is not null, the library is loaded directly from the zip file.
- private void loadLibrary(@Nullable String zipFilePath, String libFilePath) {
- Linker.getInstance().loadLibrary(zipFilePath, libFilePath);
- if (zipFilePath != null) {
- mLibraryWasLoadedFromApk = true;
- }
- }
-
// The WebView requires the Command Line to be switched over before
// initialization is done. This is okay in the WebView's case since the
// JNI is already loaded by this point.

Powered by Google App Engine
This is Rietveld 408576698