Skip to content

Commit

Permalink
android: Make a special ZygotePreload for Trichrome
Browse files Browse the repository at this point in the history
This is needed to avoid hardcoding "libmonochrome" in //content, as
discussed in http://crrev.com/c/3165931.

Also pull the guard flag from the main change to make it clear how the
two preloads are going to differ.

Bug: 1154224
Change-Id: If4b2606fe3e2c902854f235d6e83a85d4d0805ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3172621
Reviewed-by: Bo <boliu@chromium.org>
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Commit-Queue: Egor Pasko <pasko@chromium.org>
Cr-Commit-Position: refs/heads/main@{#924392}
  • Loading branch information
pasko authored and Chromium LUCI CQ committed Sep 23, 2021
1 parent fd5ce86 commit 81c2dac
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public class LibraryLoader {
private static final String REACHED_CODE_SAMPLING_INTERVAL_KEY =
"reached_code_sampling_interval";

// Compile time switch for sharing RELRO between the browser and the app zygote.
// TODO(crbug.com/1154224): remove when the issue is closed.
private static final boolean ALLOW_CHROMIUM_LINKER_IN_ZYGOTE = false;

// Default sampling interval for reached code profiler in microseconds.
private static final int DEFAULT_REACHED_CODE_SAMPLING_INTERVAL_US = 10000;

Expand Down Expand Up @@ -155,6 +159,12 @@ public class LibraryLoader {
int CHILD_WITHOUT_ZYGOTE = 2;
}

// Returns true when sharing RELRO between the browser process and the app zygote should *not*
// be attempted.
public static boolean mainProcessIntendsToProvideRelroFd() {
return !ALLOW_CHROMIUM_LINKER_IN_ZYGOTE || Build.VERSION.SDK_INT <= Build.VERSION_CODES.R;
}

/**
* Inner class encapsulating points of communication between instances of LibraryLoader in
* different processes.
Expand Down
1 change: 1 addition & 0 deletions chrome/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2456,6 +2456,7 @@ android_library("base_module_java") {
sources = [
"../browser/attribution_reporting/android/java/src/org/chromium/chrome/browser/attribution_reporting/AttributionReportingProvider.java",
"java/src/com/google/ipc/invalidation/ticl/android2/channel/GcmRegistrationTaskService.java",
"java/src/org/chromium/chrome/app/TrichromeZygotePreload.java",
"java/src/org/chromium/chrome/browser/ChromeBackgroundService.java",
"java/src/org/chromium/chrome/browser/ChromeBackupAgent.java",
"java/src/org/chromium/chrome/browser/DeferredStartupHandler.java",
Expand Down
1 change: 1 addition & 0 deletions chrome/android/chrome_public_apk_tmpl.gni
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ default_chrome_public_jinja_variables = [
"channel=$android_channel",
"enable_vr=$enable_vr",
"include_arcore_manifest_flag=false",
"zygote_preload_class=org.chromium.content_public.app.ZygotePreload",
]

# Enable stack unwinding only on official build with specific channels. It is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
android:roundIcon="@drawable/ic_launcher_round"
android:supportsRtl="true"
android:use32bitAbi="true"
android:zygotePreloadName="org.chromium.content.app.ZygotePreload">
android:zygotePreloadName="org.chromium.content_public.app.ZygotePreload">
<activity # DIFF-ANCHOR: ea1a94af
android:name="com.google.android.gms.common.api.GoogleApiActivity"
android:exported="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
android:roundIcon="@drawable/ic_launcher_round"
android:supportsRtl="true"
android:use32bitAbi="true"
android:zygotePreloadName="org.chromium.content.app.ZygotePreload">
android:zygotePreloadName="org.chromium.chrome.app.TrichromeZygotePreload">
<activity # DIFF-ANCHOR: ea1a94af
android:name="com.google.android.gms.common.api.GoogleApiActivity"
android:exported="false"
Expand Down
2 changes: 1 addition & 1 deletion chrome/android/java/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ by a child template that "extends" this file.
android:largeHeap="false"
android:manageSpaceActivity="@string/manage_space_activity"
android:supportsRtl="true"
android:zygotePreloadName="org.chromium.content.app.ZygotePreload"
android:zygotePreloadName="{{ zygote_preload_class }}"
{% if backup_key is defined %}
android:allowBackup="true"
android:backupAgent="org.chromium.chrome.browser.ChromeBackupAgent"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium.chrome.app;

import android.content.pm.ApplicationInfo;

import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.chrome.browser.ProductConfig;
import org.chromium.content_public.app.ZygotePreload;

/**
* The {@link ZygotePreload} allowing to use the ModernLinker when running Trichrome.
*/
public class TrichromeZygotePreload extends ZygotePreload {
@Override
public void doPreload(ApplicationInfo appInfo) {
// The ModernLinker is only needed when the App Zygote intends to create the RELRO region.
boolean useModernLinker = ProductConfig.USE_MODERN_LINKER
&& !LibraryLoader.mainProcessIntendsToProvideRelroFd();
doPreloadCommon(appInfo, useModernLinker);
}
}
1 change: 1 addition & 0 deletions chrome/android/trichrome.gni
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ trichrome_jinja_variables = [
"trichrome_library=$trichrome_library_package",
"trichrome_certdigest=$trichrome_certdigest",
"use32bitAbi=android:use32bitAbi=\"true\"",
"zygote_preload_class=org.chromium.chrome.app.TrichromeZygotePreload",
]

trichrome_synchronized_proguard =
Expand Down
2 changes: 1 addition & 1 deletion content/public/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ android_library("content_main_dex_java") {
"java/src/org/chromium/content/app/PrivilegedProcessService3.java",
"java/src/org/chromium/content/app/PrivilegedProcessService4.java",
"java/src/org/chromium/content/app/SandboxedProcessService.java",
"java/src/org/chromium/content/app/ZygotePreload.java",
"java/src/org/chromium/content/browser/BrowserStartupControllerImpl.java",
"java/src/org/chromium/content/browser/ChildProcessCreationParamsImpl.java",
"java/src/org/chromium/content/browser/ContentChildProcessConstants.java",
Expand All @@ -110,6 +109,7 @@ android_library("content_main_dex_java") {
"java/src/org/chromium/content/common/ContentSwitchUtils.java",
"java/src/org/chromium/content/common/SurfaceWrapper.java",
"java/src/org/chromium/content_public/app/ChildProcessServiceFactory.java",
"java/src/org/chromium/content_public/app/ZygotePreload.java",
"java/src/org/chromium/content_public/browser/BrowserStartupController.java",
"java/src/org/chromium/content_public/browser/BrowserTaskExecutor.java",
"java/src/org/chromium/content_public/browser/ChildProcessCreationParams.java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium.content.app;
package org.chromium.content_public.app;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
Expand Down Expand Up @@ -32,13 +32,19 @@ public class ZygotePreload implements android.app.ZygotePreload {
@SuppressLint("Override")
@Override
public void doPreload(ApplicationInfo appInfo) {
try {
// Using concatenation rather than %s to allow values to be inlined by R8.
Log.i(TAG,
"Loaded Zygote. version=" + VersionConstants.PRODUCT_VERSION
+ " minSdkVersion=" + BuildConfig.MIN_SDK_VERSION
+ " isBundle=" + BuildConfig.BUNDLES_SUPPORTED);
// Non-trichrome zygotes always use the system linker.
doPreloadCommon(appInfo, /* useModernLinker= */ false);
}

protected final void doPreloadCommon(ApplicationInfo appInfo, boolean useModernLinker) {
// Using concatenation rather than %s to allow values to be inlined by R8.
Log.i(TAG,
"Loaded Zygote. version=" + VersionConstants.PRODUCT_VERSION
+ " minSdkVersion=" + BuildConfig.MIN_SDK_VERSION
+ " isBundle=" + BuildConfig.BUNDLES_SUPPORTED);
try {
LibraryLoader.getInstance().setLinkerImplementation(
/* useChromiumLinker= */ useModernLinker, useModernLinker);
// The current thread time is the best approximation we have of the zygote start time
// since Process.getStartUptimeMillis() is not reliable in the zygote process. This will
// be the total CPU time the current thread has been running, and is reset on fork so
Expand Down
2 changes: 1 addition & 1 deletion content/shell/android/shell_apk/AndroidManifest.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<application android:name="org.chromium.content_shell_apk.ContentShellApplication"
android:icon="@mipmap/app_icon"
android:zygotePreloadName="org.chromium.content.app.ZygotePreload"
android:zygotePreloadName="org.chromium.content_public.app.ZygotePreload"
android:label="{% block application_label %}Content Shell{% endblock %}">
<activity android:name="org.chromium.content_shell_apk.ContentShellActivity"
android:launchMode="singleTask"
Expand Down

0 comments on commit 81c2dac

Please sign in to comment.