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

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

Issue 930333003: Fix Linker.sInBrowserProcess to avoid false negatives (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « no previous file | content/public/android/java/src/org/chromium/content/app/ChildProcessService.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 23f953c24a8c7693209374a90acc87c4eeb1d4be..c7082411ab6cd30dd61344d65370123379a2a932 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
@@ -106,16 +106,15 @@ import javax.annotation.Nullable;
* running any native code from any of the libraries (except their static
* constructors, which can't be avoided).
*
- * - A service process shall call either initServiceProcess() or
- * disableSharedRelros() early (i.e. before any loadLibrary() call).
- * Otherwise, the linker considers that it is running inside the browser
- * process. This is because various Chromium projects have vastly
- * different initialization paths.
+ * - A service process shall call initServiceProcess() early (i.e. before any
+ * loadLibrary() call). Otherwise, the linker considers that it is running
+ * inside the browser process. This is because various Chromium projects have
+ * vastly different initialization paths.
*
* disableSharedRelros() completely disables shared RELROs, and loadLibrary()
* will behave exactly like System.loadLibrary().
*
- * initServiceProcess(baseLoadAddress) indicates that shared RELROs are to be
+ * enableSharedRelros(baseLoadAddress) indicates that shared RELROs are to be
* used in this process.
*
* - The browser is in charge of deciding where in memory each library should
@@ -197,8 +196,6 @@ public class Linker {
private static boolean sRelroSharingSupported = false;
// Set to true if this runs in the browser process. Disabled by initServiceProcess().
- // TODO(petrcermak): This flag can be incorrectly set to false (even though this might run in
- // the browser process) on low-memory devices.
private static boolean sInBrowserProcess = true;
// Becomes true to indicate this process needs to wait for a shared RELRO in
@@ -487,7 +484,7 @@ public class Linker {
/**
* Call this to send a Bundle containing the shared RELRO sections to be
- * used in this process. If initServiceProcess() was previously called,
+ * used in this process. If enableSharedRelros() was previously called,
* finishLibraryLoad() will not exit until this method is called in another
* thread with a non-null value.
* @param bundle The Bundle instance containing a map of shared RELRO sections
@@ -513,7 +510,7 @@ public class Linker {
}
synchronized (Linker.class) {
// Note that in certain cases, this can be called before
- // initServiceProcess() in service processes.
+ // enableSharedRelros() in service processes.
sSharedRelros = clonedBundle;
// Tell any listener blocked in finishLibraryLoad() about it.
Linker.class.notifyAll();
@@ -540,35 +537,45 @@ public class Linker {
}
}
+ /**
+ * Call this method before enabling/disabling shared RELRO sections to
+ * indicate that this is a service process (i.e. not a browser process).
+ */
+ public static void initServiceProcess() {
+ if (DEBUG) Log.i(TAG, "initServiceProcess() called");
+ synchronized (Linker.class) {
+ sInBrowserProcess = false;
+ sBrowserUsesSharedRelro = false;
+ }
+ }
/**
* Call this method before loading any libraries to indicate that this
- * process shall neither create or reuse shared RELRO sections.
+ * process shall neither create nor reuse shared RELRO sections.
*/
public static void disableSharedRelros() {
if (DEBUG) Log.i(TAG, "disableSharedRelros() called");
synchronized (Linker.class) {
- sInBrowserProcess = false;
sWaitForSharedRelros = false;
- sBrowserUsesSharedRelro = false;
}
}
/**
* Call this method before loading any libraries to indicate that this
* process is ready to reuse shared RELRO sections from another one.
- * Typically used when starting service processes.
+ * Typically used when starting service processes. Any calls to this method
+ * must be preceded by initServiceProcess().
* @param baseLoadAddress the base library load address to use.
*/
- public static void initServiceProcess(long baseLoadAddress) {
+ public static void enableSharedRelros(long baseLoadAddress) {
if (DEBUG) {
Log.i(TAG, String.format(
- Locale.US, "initServiceProcess(0x%x) called", baseLoadAddress));
+ Locale.US, "enableSharedRelros(0x%x) called", baseLoadAddress));
}
synchronized (Linker.class) {
+ assert !sInBrowserProcess;
+ assert !sBrowserUsesSharedRelro;
rmcilroy 2015/02/17 17:30:33 As discussed, maybe we should consider packaging t
ensureInitializedLocked();
- sInBrowserProcess = false;
- sBrowserUsesSharedRelro = false;
if (sRelroSharingSupported) {
sWaitForSharedRelros = true;
sBaseLoadAddress = baseLoadAddress;
« no previous file with comments | « no previous file | content/public/android/java/src/org/chromium/content/app/ChildProcessService.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698