Tad 2022-03-15 15:41:05 -04:00
parent f015dd348f
commit 209481c53e
44 changed files with 1920 additions and 1109 deletions

View File

@ -0,0 +1,164 @@
From 750efbf6bce8bbe850679eb6a90b00108314226c Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Sat, 14 Mar 2015 18:10:20 -0400
Subject: [PATCH] add exec-based spawning support
---
.../com/android/internal/os/ExecInit.java | 115 ++++++++++++++++++
.../com/android/internal/os/WrapperInit.java | 2 +-
.../android/internal/os/ZygoteConnection.java | 7 ++
3 files changed, 123 insertions(+), 1 deletion(-)
create mode 100644 core/java/com/android/internal/os/ExecInit.java
diff --git a/core/java/com/android/internal/os/ExecInit.java b/core/java/com/android/internal/os/ExecInit.java
new file mode 100644
index 000000000000..10edd64e0f95
--- /dev/null
+++ b/core/java/com/android/internal/os/ExecInit.java
@@ -0,0 +1,115 @@
+package com.android.internal.os;
+
+import android.os.Trace;
+import android.system.ErrnoException;
+import android.system.Os;
+import android.util.Slog;
+import android.util.TimingsTraceLog;
+import dalvik.system.VMRuntime;
+
+/**
+ * Startup class for the process.
+ * @hide
+ */
+public class ExecInit {
+ /**
+ * Class not instantiable.
+ */
+ private ExecInit() {
+ }
+
+ /**
+ * The main function called when starting a runtime application.
+ *
+ * The first argument is the target SDK version for the app.
+ *
+ * The remaining arguments are passed to the runtime.
+ *
+ * @param args The command-line arguments.
+ */
+ public static void main(String[] args) {
+ // Parse our mandatory argument.
+ int targetSdkVersion = Integer.parseInt(args[0], 10);
+
+ // Mimic system Zygote preloading.
+ ZygoteInit.preload(new TimingsTraceLog("ExecInitTiming",
+ Trace.TRACE_TAG_DALVIK));
+
+ // Launch the application.
+ String[] runtimeArgs = new String[args.length - 1];
+ System.arraycopy(args, 1, runtimeArgs, 0, runtimeArgs.length);
+ Runnable r = execInit(targetSdkVersion, runtimeArgs);
+
+ r.run();
+ }
+
+ /**
+ * Executes a runtime application with exec-based spawning.
+ * This method never returns.
+ *
+ * @param niceName The nice name for the application, or null if none.
+ * @param targetSdkVersion The target SDK version for the app.
+ * @param args Arguments for {@link RuntimeInit#main}.
+ */
+ public static void execApplication(String niceName, int targetSdkVersion,
+ String instructionSet, String[] args) {
+ int niceArgs = niceName == null ? 0 : 1;
+ int baseArgs = 5 + niceArgs;
+ String[] argv = new String[baseArgs + args.length];
+ if (VMRuntime.is64BitInstructionSet(instructionSet)) {
+ argv[0] = "/system/bin/app_process64";
+ } else {
+ argv[0] = "/system/bin/app_process32";
+ }
+ argv[1] = "/system/bin";
+ argv[2] = "--application";
+ if (niceName != null) {
+ argv[3] = "--nice-name=" + niceName;
+ }
+ argv[3 + niceArgs] = "com.android.internal.os.ExecInit";
+ argv[4 + niceArgs] = Integer.toString(targetSdkVersion);
+ System.arraycopy(args, 0, argv, baseArgs, args.length);
+
+ WrapperInit.preserveCapabilities();
+ try {
+ Os.execv(argv[0], argv);
+ } catch (ErrnoException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * The main function called when an application is started with exec-based spawning.
+ *
+ * When the app starts, the runtime starts {@link RuntimeInit#main}
+ * which calls {@link main} which then calls this method.
+ * So we don't need to call commonInit() here.
+ *
+ * @param targetSdkVersion target SDK version
+ * @param argv arg strings
+ */
+ private static Runnable execInit(int targetSdkVersion, String[] argv) {
+ if (RuntimeInit.DEBUG) {
+ Slog.d(RuntimeInit.TAG, "RuntimeInit: Starting application from exec");
+ }
+
+ // Check whether the first argument is a "-cp" in argv, and assume the next argument is the
+ // classpath. If found, create a PathClassLoader and use it for applicationInit.
+ ClassLoader classLoader = null;
+ if (argv != null && argv.length > 2 && argv[0].equals("-cp")) {
+ classLoader = ZygoteInit.createPathClassLoader(argv[1], targetSdkVersion);
+
+ // Install this classloader as the context classloader, too.
+ Thread.currentThread().setContextClassLoader(classLoader);
+
+ // Remove the classpath from the arguments.
+ String removedArgs[] = new String[argv.length - 2];
+ System.arraycopy(argv, 2, removedArgs, 0, argv.length - 2);
+ argv = removedArgs;
+ }
+
+ // Perform the same initialization that would happen after the Zygote forks.
+ Zygote.nativePreApplicationInit();
+ return RuntimeInit.applicationInit(targetSdkVersion, argv, classLoader);
+ }
+}
diff --git a/core/java/com/android/internal/os/WrapperInit.java b/core/java/com/android/internal/os/WrapperInit.java
index f0e779694c90..9f41a4136db9 100644
--- a/core/java/com/android/internal/os/WrapperInit.java
+++ b/core/java/com/android/internal/os/WrapperInit.java
@@ -183,7 +183,7 @@ private static Runnable wrapperInit(int targetSdkVersion, String[] argv) {
* This is acceptable here as failure will leave the wrapped app with strictly less
* capabilities, which may make it crash, but not exceed its allowances.
*/
- private static void preserveCapabilities() {
+ public static void preserveCapabilities() {
StructCapUserHeader header = new StructCapUserHeader(
OsConstants._LINUX_CAPABILITY_VERSION_3, 0);
StructCapUserData[] data;
diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java
index f537e3e2897b..7d51be259c20 100644
--- a/core/java/com/android/internal/os/ZygoteConnection.java
+++ b/core/java/com/android/internal/os/ZygoteConnection.java
@@ -880,6 +880,13 @@ private Runnable handleChildProc(Arguments parsedArgs, FileDescriptor[] descript
throw new IllegalStateException("WrapperInit.execApplication unexpectedly returned");
} else {
if (!isZygote) {
+ if (SystemProperties.getBoolean("sys.spawn.exec", true)) {
+ ExecInit.execApplication(parsedArgs.niceName, parsedArgs.targetSdkVersion,
+ VMRuntime.getCurrentInstructionSet(), parsedArgs.remainingArgs);
+
+ // Should not get here.
+ throw new IllegalStateException("ExecInit.execApplication unexpectedly returned");
+ }
return ZygoteInit.zygoteInit(parsedArgs.targetSdkVersion, parsedArgs.remainingArgs,
null /* classLoader */);
} else {

View File

@ -0,0 +1,24 @@
From 8806ec3ef166fe1fd1eeb690ace6dd5a7682195c Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 21 May 2019 23:54:20 -0400
Subject: [PATCH] disable exec spawning when using debugging options
The debugging options are not yet supported probably, so disable exec
spawning when doing debugging.
---
core/java/com/android/internal/os/ZygoteConnection.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java
index 7d51be259c20..48a68d96e84c 100644
--- a/core/java/com/android/internal/os/ZygoteConnection.java
+++ b/core/java/com/android/internal/os/ZygoteConnection.java
@@ -880,7 +880,7 @@ private Runnable handleChildProc(Arguments parsedArgs, FileDescriptor[] descript
throw new IllegalStateException("WrapperInit.execApplication unexpectedly returned");
} else {
if (!isZygote) {
- if (SystemProperties.getBoolean("sys.spawn.exec", true)) {
+ if (SystemProperties.getBoolean("sys.spawn.exec", true) && parsedArgs.runtimeFlags == 0) {
ExecInit.execApplication(parsedArgs.niceName, parsedArgs.targetSdkVersion,
VMRuntime.getCurrentInstructionSet(), parsedArgs.remainingArgs);

View File

@ -0,0 +1,47 @@
From ed563b6f26452581f9dba1c1ef245e893f5045ca Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:24:21 -0400
Subject: [PATCH] add parameter for avoiding full preload with exec
---
core/java/com/android/internal/os/ExecInit.java | 2 +-
core/java/com/android/internal/os/ZygoteInit.java | 6 +++++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/core/java/com/android/internal/os/ExecInit.java b/core/java/com/android/internal/os/ExecInit.java
index 10edd64e0f95..3ba4664ae8cf 100644
--- a/core/java/com/android/internal/os/ExecInit.java
+++ b/core/java/com/android/internal/os/ExecInit.java
@@ -33,7 +33,7 @@ public static void main(String[] args) {
// Mimic system Zygote preloading.
ZygoteInit.preload(new TimingsTraceLog("ExecInitTiming",
- Trace.TRACE_TAG_DALVIK));
+ Trace.TRACE_TAG_DALVIK), false);
// Launch the application.
String[] runtimeArgs = new String[args.length - 1];
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index da195601f725..6acaccbbc3ef 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -120,7 +120,7 @@
private static boolean sPreloadComplete;
- static void preload(TimingsTraceLog bootTimingsTraceLog) {
+ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
Log.d(TAG, "begin preload");
bootTimingsTraceLog.traceBegin("BeginIcuCachePinning");
beginIcuCachePinning();
@@ -149,6 +149,10 @@ static void preload(TimingsTraceLog bootTimingsTraceLog) {
sPreloadComplete = true;
}
+ static void preload(TimingsTraceLog bootTimingsTraceLog) {
+ preload(bootTimingsTraceLog, true);
+ }
+
public static void lazyPreload() {
Preconditions.checkState(!sPreloadComplete);
Log.i(TAG, "Lazily preloading resources.");

View File

@ -0,0 +1,28 @@
From aad3c7d750f9814344514cb187112e50574bb382 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:28:27 -0400
Subject: [PATCH] disable OpenGL preloading for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 6acaccbbc3ef..09ec9f235451 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -134,9 +134,11 @@ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadAppProcessHALs");
nativePreloadAppProcessHALs();
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
- Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadOpenGL");
- preloadOpenGL();
- Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
+ if (fullPreload) {
+ Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadOpenGL");
+ preloadOpenGL();
+ Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
+ }
preloadSharedLibraries();
preloadTextResources();
// Ask the WebViewFactory to do any initialization that must run in the zygote process,

View File

@ -0,0 +1,28 @@
From da3180f9a8e75b10826ce2faf046c0f3912dfd59 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:28:52 -0400
Subject: [PATCH] disable resource preloading for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 09ec9f235451..17bdfaa79d0b 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -128,9 +128,11 @@ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
bootTimingsTraceLog.traceBegin("PreloadClasses");
preloadClasses();
bootTimingsTraceLog.traceEnd(); // PreloadClasses
- bootTimingsTraceLog.traceBegin("PreloadResources");
- preloadResources();
- bootTimingsTraceLog.traceEnd(); // PreloadResources
+ if (fullPreload) {
+ bootTimingsTraceLog.traceBegin("PreloadResources");
+ preloadResources();
+ bootTimingsTraceLog.traceEnd(); // PreloadResources
+ }
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadAppProcessHALs");
nativePreloadAppProcessHALs();
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);

View File

@ -0,0 +1,39 @@
From 68773a29b77d6e87201b3af1b0b21e9385a1bdb0 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:29:36 -0400
Subject: [PATCH] disable ICU cache pinning for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 17bdfaa79d0b..1dfe23e32937 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -122,9 +122,11 @@
static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
Log.d(TAG, "begin preload");
- bootTimingsTraceLog.traceBegin("BeginIcuCachePinning");
- beginIcuCachePinning();
- bootTimingsTraceLog.traceEnd(); // BeginIcuCachePinning
+ if (fullPreload) {
+ bootTimingsTraceLog.traceBegin("BeginIcuCachePinning");
+ beginIcuCachePinning();
+ bootTimingsTraceLog.traceEnd(); // BeginIcuCachePinning
+ }
bootTimingsTraceLog.traceBegin("PreloadClasses");
preloadClasses();
bootTimingsTraceLog.traceEnd(); // PreloadClasses
@@ -146,7 +148,9 @@ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
// Ask the WebViewFactory to do any initialization that must run in the zygote process,
// for memory sharing purposes.
WebViewFactory.prepareWebViewInZygote();
- endIcuCachePinning();
+ if (fullPreload) {
+ endIcuCachePinning();
+ }
warmUpJcaProviders();
Log.d(TAG, "end preload");

View File

@ -0,0 +1,28 @@
From 283b3fa09c002861fa5525a2be8071953e05e794 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:30:59 -0400
Subject: [PATCH] disable class preloading for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 1dfe23e32937..fae438512d8f 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -127,9 +127,11 @@ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
beginIcuCachePinning();
bootTimingsTraceLog.traceEnd(); // BeginIcuCachePinning
}
- bootTimingsTraceLog.traceBegin("PreloadClasses");
- preloadClasses();
- bootTimingsTraceLog.traceEnd(); // PreloadClasses
+ if (fullPreload) {
+ bootTimingsTraceLog.traceBegin("PreloadClasses");
+ preloadClasses();
+ bootTimingsTraceLog.traceEnd(); // PreloadClasses
+ }
if (fullPreload) {
bootTimingsTraceLog.traceBegin("PreloadResources");
preloadResources();

View File

@ -0,0 +1,28 @@
From f133136b65841735895ec15acdd2c60ecd45e72d Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:31:29 -0400
Subject: [PATCH] disable WebView reservation for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index fae438512d8f..75d10f6d92a8 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -147,9 +147,11 @@ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
}
preloadSharedLibraries();
preloadTextResources();
- // Ask the WebViewFactory to do any initialization that must run in the zygote process,
- // for memory sharing purposes.
- WebViewFactory.prepareWebViewInZygote();
+ if (fullPreload) {
+ // Ask the WebViewFactory to do any initialization that must run in the zygote process,
+ // for memory sharing purposes.
+ WebViewFactory.prepareWebViewInZygote();
+ }
if (fullPreload) {
endIcuCachePinning();
}

View File

@ -0,0 +1,57 @@
From 01a01ce5f6570f31232bc488da5683481ca32388 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:34:32 -0400
Subject: [PATCH] disable JCA provider warm up for exec spawning
---
.../com/android/internal/os/ZygoteInit.java | 22 ++++++++++---------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 75d10f6d92a8..214dbd451099 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -155,7 +155,7 @@ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
if (fullPreload) {
endIcuCachePinning();
}
- warmUpJcaProviders();
+ warmUpJcaProviders(fullPreload);
Log.d(TAG, "end preload");
sPreloadComplete = true;
@@ -223,7 +223,7 @@ private static void preloadTextResources() {
* By doing it here we avoid that each app does it when requesting a service from the
* provider for the first time.
*/
- private static void warmUpJcaProviders() {
+ private static void warmUpJcaProviders(boolean fullPreload) {
long startTime = SystemClock.uptimeMillis();
Trace.traceBegin(
Trace.TRACE_TAG_DALVIK, "Starting installation of AndroidKeyStoreProvider");
@@ -235,15 +235,17 @@ private static void warmUpJcaProviders() {
+ (SystemClock.uptimeMillis() - startTime) + "ms.");
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
- startTime = SystemClock.uptimeMillis();
- Trace.traceBegin(
- Trace.TRACE_TAG_DALVIK, "Starting warm up of JCA providers");
- for (Provider p : Security.getProviders()) {
- p.warmUpServiceProvision();
+ if (fullPreload) {
+ startTime = SystemClock.uptimeMillis();
+ Trace.traceBegin(
+ Trace.TRACE_TAG_DALVIK, "Starting warm up of JCA providers");
+ for (Provider p : Security.getProviders()) {
+ p.warmUpServiceProvision();
+ }
+ Log.i(TAG, "Warmed up JCA providers in "
+ + (SystemClock.uptimeMillis() - startTime) + "ms.");
+ Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
}
- Log.i(TAG, "Warmed up JCA providers in "
- + (SystemClock.uptimeMillis() - startTime) + "ms.");
- Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
}
/**

View File

@ -0,0 +1,26 @@
From 17c309c0988ccea718ee0779d23387d6af40a80d Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 15:11:59 -0400
Subject: [PATCH] avoid AssetManager errors with exec spawning
This causes harmless errors and wastes time spawning a process that's
not going to succeed.
---
core/jni/android_util_AssetManager.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/core/jni/android_util_AssetManager.cpp b/core/jni/android_util_AssetManager.cpp
index fa9f44557d3f..08060163017f 100644
--- a/core/jni/android_util_AssetManager.cpp
+++ b/core/jni/android_util_AssetManager.cpp
@@ -111,6 +111,10 @@ constexpr inline static ApkAssetsCookie JavaCookieToApkAssetsCookie(jint cookie)
// This is called by zygote (running as user root) as part of preloadResources.
static void NativeVerifySystemIdmaps(JNIEnv* /*env*/, jclass /*clazz*/) {
+ // avoid triggering an error with exec-based spawning
+ if (getuid() != 0) {
+ return;
+ }
switch (pid_t pid = fork()) {
case -1:
PLOG(ERROR) << "failed to fork for idmap";

View File

@ -1,508 +0,0 @@
From 4ac855656e2df723abb5da9768b3bce77a135490 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Sat, 14 Mar 2015 18:10:20 -0400
Subject: [PATCH 01/10] add exec-based spawning support
---
.../com/android/internal/os/ExecInit.java | 115 ++++++++++++++++++
.../com/android/internal/os/WrapperInit.java | 2 +-
.../android/internal/os/ZygoteConnection.java | 7 ++
3 files changed, 123 insertions(+), 1 deletion(-)
create mode 100644 core/java/com/android/internal/os/ExecInit.java
diff --git a/core/java/com/android/internal/os/ExecInit.java b/core/java/com/android/internal/os/ExecInit.java
new file mode 100644
index 00000000000..10edd64e0f9
--- /dev/null
+++ b/core/java/com/android/internal/os/ExecInit.java
@@ -0,0 +1,115 @@
+package com.android.internal.os;
+
+import android.os.Trace;
+import android.system.ErrnoException;
+import android.system.Os;
+import android.util.Slog;
+import android.util.TimingsTraceLog;
+import dalvik.system.VMRuntime;
+
+/**
+ * Startup class for the process.
+ * @hide
+ */
+public class ExecInit {
+ /**
+ * Class not instantiable.
+ */
+ private ExecInit() {
+ }
+
+ /**
+ * The main function called when starting a runtime application.
+ *
+ * The first argument is the target SDK version for the app.
+ *
+ * The remaining arguments are passed to the runtime.
+ *
+ * @param args The command-line arguments.
+ */
+ public static void main(String[] args) {
+ // Parse our mandatory argument.
+ int targetSdkVersion = Integer.parseInt(args[0], 10);
+
+ // Mimic system Zygote preloading.
+ ZygoteInit.preload(new TimingsTraceLog("ExecInitTiming",
+ Trace.TRACE_TAG_DALVIK));
+
+ // Launch the application.
+ String[] runtimeArgs = new String[args.length - 1];
+ System.arraycopy(args, 1, runtimeArgs, 0, runtimeArgs.length);
+ Runnable r = execInit(targetSdkVersion, runtimeArgs);
+
+ r.run();
+ }
+
+ /**
+ * Executes a runtime application with exec-based spawning.
+ * This method never returns.
+ *
+ * @param niceName The nice name for the application, or null if none.
+ * @param targetSdkVersion The target SDK version for the app.
+ * @param args Arguments for {@link RuntimeInit#main}.
+ */
+ public static void execApplication(String niceName, int targetSdkVersion,
+ String instructionSet, String[] args) {
+ int niceArgs = niceName == null ? 0 : 1;
+ int baseArgs = 5 + niceArgs;
+ String[] argv = new String[baseArgs + args.length];
+ if (VMRuntime.is64BitInstructionSet(instructionSet)) {
+ argv[0] = "/system/bin/app_process64";
+ } else {
+ argv[0] = "/system/bin/app_process32";
+ }
+ argv[1] = "/system/bin";
+ argv[2] = "--application";
+ if (niceName != null) {
+ argv[3] = "--nice-name=" + niceName;
+ }
+ argv[3 + niceArgs] = "com.android.internal.os.ExecInit";
+ argv[4 + niceArgs] = Integer.toString(targetSdkVersion);
+ System.arraycopy(args, 0, argv, baseArgs, args.length);
+
+ WrapperInit.preserveCapabilities();
+ try {
+ Os.execv(argv[0], argv);
+ } catch (ErrnoException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * The main function called when an application is started with exec-based spawning.
+ *
+ * When the app starts, the runtime starts {@link RuntimeInit#main}
+ * which calls {@link main} which then calls this method.
+ * So we don't need to call commonInit() here.
+ *
+ * @param targetSdkVersion target SDK version
+ * @param argv arg strings
+ */
+ private static Runnable execInit(int targetSdkVersion, String[] argv) {
+ if (RuntimeInit.DEBUG) {
+ Slog.d(RuntimeInit.TAG, "RuntimeInit: Starting application from exec");
+ }
+
+ // Check whether the first argument is a "-cp" in argv, and assume the next argument is the
+ // classpath. If found, create a PathClassLoader and use it for applicationInit.
+ ClassLoader classLoader = null;
+ if (argv != null && argv.length > 2 && argv[0].equals("-cp")) {
+ classLoader = ZygoteInit.createPathClassLoader(argv[1], targetSdkVersion);
+
+ // Install this classloader as the context classloader, too.
+ Thread.currentThread().setContextClassLoader(classLoader);
+
+ // Remove the classpath from the arguments.
+ String removedArgs[] = new String[argv.length - 2];
+ System.arraycopy(argv, 2, removedArgs, 0, argv.length - 2);
+ argv = removedArgs;
+ }
+
+ // Perform the same initialization that would happen after the Zygote forks.
+ Zygote.nativePreApplicationInit();
+ return RuntimeInit.applicationInit(targetSdkVersion, argv, classLoader);
+ }
+}
diff --git a/core/java/com/android/internal/os/WrapperInit.java b/core/java/com/android/internal/os/WrapperInit.java
index f0e779694c9..9f41a4136db 100644
--- a/core/java/com/android/internal/os/WrapperInit.java
+++ b/core/java/com/android/internal/os/WrapperInit.java
@@ -183,7 +183,7 @@ public class WrapperInit {
* This is acceptable here as failure will leave the wrapped app with strictly less
* capabilities, which may make it crash, but not exceed its allowances.
*/
- private static void preserveCapabilities() {
+ public static void preserveCapabilities() {
StructCapUserHeader header = new StructCapUserHeader(
OsConstants._LINUX_CAPABILITY_VERSION_3, 0);
StructCapUserData[] data;
diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java
index f537e3e2897..7d51be259c2 100644
--- a/core/java/com/android/internal/os/ZygoteConnection.java
+++ b/core/java/com/android/internal/os/ZygoteConnection.java
@@ -880,6 +880,13 @@ class ZygoteConnection {
throw new IllegalStateException("WrapperInit.execApplication unexpectedly returned");
} else {
if (!isZygote) {
+ if (SystemProperties.getBoolean("sys.spawn.exec", true)) {
+ ExecInit.execApplication(parsedArgs.niceName, parsedArgs.targetSdkVersion,
+ VMRuntime.getCurrentInstructionSet(), parsedArgs.remainingArgs);
+
+ // Should not get here.
+ throw new IllegalStateException("ExecInit.execApplication unexpectedly returned");
+ }
return ZygoteInit.zygoteInit(parsedArgs.targetSdkVersion, parsedArgs.remainingArgs,
null /* classLoader */);
} else {
--
2.21.0
From 654f1cc80bd8d51a04f01c56e97bface4bce7811 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:24:21 -0400
Subject: [PATCH 02/10] add parameter for avoiding full preload with exec
---
core/java/com/android/internal/os/ExecInit.java | 2 +-
core/java/com/android/internal/os/ZygoteInit.java | 6 +++++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/core/java/com/android/internal/os/ExecInit.java b/core/java/com/android/internal/os/ExecInit.java
index 10edd64e0f9..3ba4664ae8c 100644
--- a/core/java/com/android/internal/os/ExecInit.java
+++ b/core/java/com/android/internal/os/ExecInit.java
@@ -33,7 +33,7 @@ public class ExecInit {
// Mimic system Zygote preloading.
ZygoteInit.preload(new TimingsTraceLog("ExecInitTiming",
- Trace.TRACE_TAG_DALVIK));
+ Trace.TRACE_TAG_DALVIK), false);
// Launch the application.
String[] runtimeArgs = new String[args.length - 1];
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index da195601f72..6acaccbbc3e 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -120,7 +120,7 @@ public class ZygoteInit {
private static boolean sPreloadComplete;
- static void preload(TimingsTraceLog bootTimingsTraceLog) {
+ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
Log.d(TAG, "begin preload");
bootTimingsTraceLog.traceBegin("BeginIcuCachePinning");
beginIcuCachePinning();
@@ -149,6 +149,10 @@ public class ZygoteInit {
sPreloadComplete = true;
}
+ static void preload(TimingsTraceLog bootTimingsTraceLog) {
+ preload(bootTimingsTraceLog, true);
+ }
+
public static void lazyPreload() {
Preconditions.checkState(!sPreloadComplete);
Log.i(TAG, "Lazily preloading resources.");
--
2.21.0
From fa13759a9f3c7a4860a6e2aa559cd454e31ac621 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:28:27 -0400
Subject: [PATCH 03/10] disable OpenGL preloading for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 6acaccbbc3e..09ec9f23545 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -134,9 +134,11 @@ public class ZygoteInit {
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadAppProcessHALs");
nativePreloadAppProcessHALs();
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
- Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadOpenGL");
- preloadOpenGL();
- Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
+ if (fullPreload) {
+ Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadOpenGL");
+ preloadOpenGL();
+ Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
+ }
preloadSharedLibraries();
preloadTextResources();
// Ask the WebViewFactory to do any initialization that must run in the zygote process,
--
2.21.0
From 960ccd579d883ef6426e2d84cff2982cb5e0d83b Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:28:52 -0400
Subject: [PATCH 04/10] disable resource preloading for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 09ec9f23545..17bdfaa79d0 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -128,9 +128,11 @@ public class ZygoteInit {
bootTimingsTraceLog.traceBegin("PreloadClasses");
preloadClasses();
bootTimingsTraceLog.traceEnd(); // PreloadClasses
- bootTimingsTraceLog.traceBegin("PreloadResources");
- preloadResources();
- bootTimingsTraceLog.traceEnd(); // PreloadResources
+ if (fullPreload) {
+ bootTimingsTraceLog.traceBegin("PreloadResources");
+ preloadResources();
+ bootTimingsTraceLog.traceEnd(); // PreloadResources
+ }
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadAppProcessHALs");
nativePreloadAppProcessHALs();
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
--
2.21.0
From 88e59153886fd6e1c60bdf5b0fe7ab9280cd8cae Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:29:36 -0400
Subject: [PATCH 05/10] disable ICU cache pinning for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 17bdfaa79d0..1dfe23e3293 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -122,9 +122,11 @@ public class ZygoteInit {
static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
Log.d(TAG, "begin preload");
- bootTimingsTraceLog.traceBegin("BeginIcuCachePinning");
- beginIcuCachePinning();
- bootTimingsTraceLog.traceEnd(); // BeginIcuCachePinning
+ if (fullPreload) {
+ bootTimingsTraceLog.traceBegin("BeginIcuCachePinning");
+ beginIcuCachePinning();
+ bootTimingsTraceLog.traceEnd(); // BeginIcuCachePinning
+ }
bootTimingsTraceLog.traceBegin("PreloadClasses");
preloadClasses();
bootTimingsTraceLog.traceEnd(); // PreloadClasses
@@ -146,7 +148,9 @@ public class ZygoteInit {
// Ask the WebViewFactory to do any initialization that must run in the zygote process,
// for memory sharing purposes.
WebViewFactory.prepareWebViewInZygote();
- endIcuCachePinning();
+ if (fullPreload) {
+ endIcuCachePinning();
+ }
warmUpJcaProviders();
Log.d(TAG, "end preload");
--
2.21.0
From 96fa644f641d0a90a2642219c9dcd49812ff9411 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:30:59 -0400
Subject: [PATCH 06/10] disable class preloading for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 1dfe23e3293..fae438512d8 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -127,9 +127,11 @@ public class ZygoteInit {
beginIcuCachePinning();
bootTimingsTraceLog.traceEnd(); // BeginIcuCachePinning
}
- bootTimingsTraceLog.traceBegin("PreloadClasses");
- preloadClasses();
- bootTimingsTraceLog.traceEnd(); // PreloadClasses
+ if (fullPreload) {
+ bootTimingsTraceLog.traceBegin("PreloadClasses");
+ preloadClasses();
+ bootTimingsTraceLog.traceEnd(); // PreloadClasses
+ }
if (fullPreload) {
bootTimingsTraceLog.traceBegin("PreloadResources");
preloadResources();
--
2.21.0
From 28dc5c52766abda740c25cc2650b68fa8328d8a8 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:31:29 -0400
Subject: [PATCH 07/10] disable WebView reservation for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index fae438512d8..75d10f6d92a 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -147,9 +147,11 @@ public class ZygoteInit {
}
preloadSharedLibraries();
preloadTextResources();
- // Ask the WebViewFactory to do any initialization that must run in the zygote process,
- // for memory sharing purposes.
- WebViewFactory.prepareWebViewInZygote();
+ if (fullPreload) {
+ // Ask the WebViewFactory to do any initialization that must run in the zygote process,
+ // for memory sharing purposes.
+ WebViewFactory.prepareWebViewInZygote();
+ }
if (fullPreload) {
endIcuCachePinning();
}
--
2.21.0
From 8998af03229d57b69f4dd9b2a3656ea310445568 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:34:32 -0400
Subject: [PATCH 08/10] disable JCA provider warm up for exec spawning
---
.../com/android/internal/os/ZygoteInit.java | 22 ++++++++++---------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 75d10f6d92a..214dbd45109 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -155,7 +155,7 @@ public class ZygoteInit {
if (fullPreload) {
endIcuCachePinning();
}
- warmUpJcaProviders();
+ warmUpJcaProviders(fullPreload);
Log.d(TAG, "end preload");
sPreloadComplete = true;
@@ -223,7 +223,7 @@ public class ZygoteInit {
* By doing it here we avoid that each app does it when requesting a service from the
* provider for the first time.
*/
- private static void warmUpJcaProviders() {
+ private static void warmUpJcaProviders(boolean fullPreload) {
long startTime = SystemClock.uptimeMillis();
Trace.traceBegin(
Trace.TRACE_TAG_DALVIK, "Starting installation of AndroidKeyStoreProvider");
@@ -235,15 +235,17 @@ public class ZygoteInit {
+ (SystemClock.uptimeMillis() - startTime) + "ms.");
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
- startTime = SystemClock.uptimeMillis();
- Trace.traceBegin(
- Trace.TRACE_TAG_DALVIK, "Starting warm up of JCA providers");
- for (Provider p : Security.getProviders()) {
- p.warmUpServiceProvision();
+ if (fullPreload) {
+ startTime = SystemClock.uptimeMillis();
+ Trace.traceBegin(
+ Trace.TRACE_TAG_DALVIK, "Starting warm up of JCA providers");
+ for (Provider p : Security.getProviders()) {
+ p.warmUpServiceProvision();
+ }
+ Log.i(TAG, "Warmed up JCA providers in "
+ + (SystemClock.uptimeMillis() - startTime) + "ms.");
+ Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
}
- Log.i(TAG, "Warmed up JCA providers in "
- + (SystemClock.uptimeMillis() - startTime) + "ms.");
- Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
}
/**
--
2.21.0
From a60d5e0c25c9c40eb3cab1ad89ad9f1b37c3918a Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 15:11:59 -0400
Subject: [PATCH 09/10] avoid AssetManager errors with exec spawning
This causes harmless errors and wastes time spawning a process that's
not going to succeed.
---
core/jni/android_util_AssetManager.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/core/jni/android_util_AssetManager.cpp b/core/jni/android_util_AssetManager.cpp
index fa9f44557d3..08060163017 100644
--- a/core/jni/android_util_AssetManager.cpp
+++ b/core/jni/android_util_AssetManager.cpp
@@ -111,6 +111,10 @@ constexpr inline static ApkAssetsCookie JavaCookieToApkAssetsCookie(jint cookie)
// This is called by zygote (running as user root) as part of preloadResources.
static void NativeVerifySystemIdmaps(JNIEnv* /*env*/, jclass /*clazz*/) {
+ // avoid triggering an error with exec-based spawning
+ if (getuid() != 0) {
+ return;
+ }
switch (pid_t pid = fork()) {
case -1:
PLOG(ERROR) << "failed to fork for idmap";
--
2.21.0
From b086a665c2b3b25535205d29c5dbe9bb2ba6e47a Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 21 May 2019 23:54:20 -0400
Subject: [PATCH 10/10] disable exec spawning when using debugging options
The debugging options are not yet supported probably, so disable exec
spawning when doing debugging.
---
core/java/com/android/internal/os/ZygoteConnection.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java
index 7d51be259c2..48a68d96e84 100644
--- a/core/java/com/android/internal/os/ZygoteConnection.java
+++ b/core/java/com/android/internal/os/ZygoteConnection.java
@@ -880,7 +880,7 @@ class ZygoteConnection {
throw new IllegalStateException("WrapperInit.execApplication unexpectedly returned");
} else {
if (!isZygote) {
- if (SystemProperties.getBoolean("sys.spawn.exec", true)) {
+ if (SystemProperties.getBoolean("sys.spawn.exec", true) && parsedArgs.runtimeFlags == 0) {
ExecInit.execApplication(parsedArgs.niceName, parsedArgs.targetSdkVersion,
VMRuntime.getCurrentInstructionSet(), parsedArgs.remainingArgs);
--
2.21.0

View File

@ -0,0 +1,172 @@
From 527787f3c82d385c98c2e954bbbf092937100085 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Sat, 14 Mar 2015 18:10:20 -0400
Subject: [PATCH] add exec-based spawning support
---
.../com/android/internal/os/ExecInit.java | 115 ++++++++++++++++++
.../com/android/internal/os/WrapperInit.java | 2 +-
.../android/internal/os/ZygoteConnection.java | 8 ++
3 files changed, 124 insertions(+), 1 deletion(-)
create mode 100644 core/java/com/android/internal/os/ExecInit.java
diff --git a/core/java/com/android/internal/os/ExecInit.java b/core/java/com/android/internal/os/ExecInit.java
new file mode 100644
index 000000000000..10edd64e0f95
--- /dev/null
+++ b/core/java/com/android/internal/os/ExecInit.java
@@ -0,0 +1,115 @@
+package com.android.internal.os;
+
+import android.os.Trace;
+import android.system.ErrnoException;
+import android.system.Os;
+import android.util.Slog;
+import android.util.TimingsTraceLog;
+import dalvik.system.VMRuntime;
+
+/**
+ * Startup class for the process.
+ * @hide
+ */
+public class ExecInit {
+ /**
+ * Class not instantiable.
+ */
+ private ExecInit() {
+ }
+
+ /**
+ * The main function called when starting a runtime application.
+ *
+ * The first argument is the target SDK version for the app.
+ *
+ * The remaining arguments are passed to the runtime.
+ *
+ * @param args The command-line arguments.
+ */
+ public static void main(String[] args) {
+ // Parse our mandatory argument.
+ int targetSdkVersion = Integer.parseInt(args[0], 10);
+
+ // Mimic system Zygote preloading.
+ ZygoteInit.preload(new TimingsTraceLog("ExecInitTiming",
+ Trace.TRACE_TAG_DALVIK));
+
+ // Launch the application.
+ String[] runtimeArgs = new String[args.length - 1];
+ System.arraycopy(args, 1, runtimeArgs, 0, runtimeArgs.length);
+ Runnable r = execInit(targetSdkVersion, runtimeArgs);
+
+ r.run();
+ }
+
+ /**
+ * Executes a runtime application with exec-based spawning.
+ * This method never returns.
+ *
+ * @param niceName The nice name for the application, or null if none.
+ * @param targetSdkVersion The target SDK version for the app.
+ * @param args Arguments for {@link RuntimeInit#main}.
+ */
+ public static void execApplication(String niceName, int targetSdkVersion,
+ String instructionSet, String[] args) {
+ int niceArgs = niceName == null ? 0 : 1;
+ int baseArgs = 5 + niceArgs;
+ String[] argv = new String[baseArgs + args.length];
+ if (VMRuntime.is64BitInstructionSet(instructionSet)) {
+ argv[0] = "/system/bin/app_process64";
+ } else {
+ argv[0] = "/system/bin/app_process32";
+ }
+ argv[1] = "/system/bin";
+ argv[2] = "--application";
+ if (niceName != null) {
+ argv[3] = "--nice-name=" + niceName;
+ }
+ argv[3 + niceArgs] = "com.android.internal.os.ExecInit";
+ argv[4 + niceArgs] = Integer.toString(targetSdkVersion);
+ System.arraycopy(args, 0, argv, baseArgs, args.length);
+
+ WrapperInit.preserveCapabilities();
+ try {
+ Os.execv(argv[0], argv);
+ } catch (ErrnoException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * The main function called when an application is started with exec-based spawning.
+ *
+ * When the app starts, the runtime starts {@link RuntimeInit#main}
+ * which calls {@link main} which then calls this method.
+ * So we don't need to call commonInit() here.
+ *
+ * @param targetSdkVersion target SDK version
+ * @param argv arg strings
+ */
+ private static Runnable execInit(int targetSdkVersion, String[] argv) {
+ if (RuntimeInit.DEBUG) {
+ Slog.d(RuntimeInit.TAG, "RuntimeInit: Starting application from exec");
+ }
+
+ // Check whether the first argument is a "-cp" in argv, and assume the next argument is the
+ // classpath. If found, create a PathClassLoader and use it for applicationInit.
+ ClassLoader classLoader = null;
+ if (argv != null && argv.length > 2 && argv[0].equals("-cp")) {
+ classLoader = ZygoteInit.createPathClassLoader(argv[1], targetSdkVersion);
+
+ // Install this classloader as the context classloader, too.
+ Thread.currentThread().setContextClassLoader(classLoader);
+
+ // Remove the classpath from the arguments.
+ String removedArgs[] = new String[argv.length - 2];
+ System.arraycopy(argv, 2, removedArgs, 0, argv.length - 2);
+ argv = removedArgs;
+ }
+
+ // Perform the same initialization that would happen after the Zygote forks.
+ Zygote.nativePreApplicationInit();
+ return RuntimeInit.applicationInit(targetSdkVersion, argv, classLoader);
+ }
+}
diff --git a/core/java/com/android/internal/os/WrapperInit.java b/core/java/com/android/internal/os/WrapperInit.java
index f0e779694c90..9f41a4136db9 100644
--- a/core/java/com/android/internal/os/WrapperInit.java
+++ b/core/java/com/android/internal/os/WrapperInit.java
@@ -183,7 +183,7 @@ private static Runnable wrapperInit(int targetSdkVersion, String[] argv) {
* This is acceptable here as failure will leave the wrapped app with strictly less
* capabilities, which may make it crash, but not exceed its allowances.
*/
- private static void preserveCapabilities() {
+ public static void preserveCapabilities() {
StructCapUserHeader header = new StructCapUserHeader(
OsConstants._LINUX_CAPABILITY_VERSION_3, 0);
StructCapUserData[] data;
diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java
index e556dd4d8243..1054d2fb9b13 100644
--- a/core/java/com/android/internal/os/ZygoteConnection.java
+++ b/core/java/com/android/internal/os/ZygoteConnection.java
@@ -33,6 +33,7 @@
import android.net.LocalSocket;
import android.os.Parcel;
import android.os.Process;
+import android.os.SystemProperties;
import android.os.Trace;
import android.system.ErrnoException;
import android.system.Os;
@@ -596,6 +597,13 @@ private Runnable handleChildProc(ZygoteArguments parsedArgs, FileDescriptor[] de
throw new IllegalStateException("WrapperInit.execApplication unexpectedly returned");
} else {
if (!isZygote) {
+ if (SystemProperties.getBoolean("sys.spawn.exec", true)) {
+ ExecInit.execApplication(parsedArgs.mNiceName, parsedArgs.mTargetSdkVersion,
+ VMRuntime.getCurrentInstructionSet(), parsedArgs.mRemainingArgs);
+
+ // Should not get here.
+ throw new IllegalStateException("ExecInit.execApplication unexpectedly returned");
+ }
return ZygoteInit.zygoteInit(parsedArgs.mTargetSdkVersion,
parsedArgs.mRemainingArgs, null /* classLoader */);
} else {

View File

@ -0,0 +1,57 @@
From ce6dcc2368fbf817c1c7ae2595b0367750b741dc Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:34:32 -0400
Subject: [PATCH] disable JCA provider warm up for exec spawning
---
.../com/android/internal/os/ZygoteInit.java | 22 ++++++++++---------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 94e58405ce63..dbd24ef27d26 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -166,7 +166,7 @@ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
WebViewFactory.prepareWebViewInZygote();
}
endPreload(fullPreload);
- warmUpJcaProviders();
+ warmUpJcaProviders(fullPreload);
Log.d(TAG, "end preload");
sPreloadComplete = true;
@@ -230,7 +230,7 @@ private static void preloadTextResources() {
* By doing it here we avoid that each app does it when requesting a service from the provider
* for the first time.
*/
- private static void warmUpJcaProviders() {
+ private static void warmUpJcaProviders(boolean fullPreload) {
long startTime = SystemClock.uptimeMillis();
Trace.traceBegin(
Trace.TRACE_TAG_DALVIK, "Starting installation of AndroidKeyStoreProvider");
@@ -242,15 +242,17 @@ private static void warmUpJcaProviders() {
+ (SystemClock.uptimeMillis() - startTime) + "ms.");
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
- startTime = SystemClock.uptimeMillis();
- Trace.traceBegin(
- Trace.TRACE_TAG_DALVIK, "Starting warm up of JCA providers");
- for (Provider p : Security.getProviders()) {
- p.warmUpServiceProvision();
+ if (fullPreload) {
+ startTime = SystemClock.uptimeMillis();
+ Trace.traceBegin(
+ Trace.TRACE_TAG_DALVIK, "Starting warm up of JCA providers");
+ for (Provider p : Security.getProviders()) {
+ p.warmUpServiceProvision();
+ }
+ Log.i(TAG, "Warmed up JCA providers in "
+ + (SystemClock.uptimeMillis() - startTime) + "ms.");
+ Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
}
- Log.i(TAG, "Warmed up JCA providers in "
- + (SystemClock.uptimeMillis() - startTime) + "ms.");
- Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
}
/**

View File

@ -0,0 +1,28 @@
From 3d3d5c4d38a1614ba6e9c8baa517516bdb647223 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Wed, 11 Sep 2019 06:57:24 -0400
Subject: [PATCH] disable preloading classloaders for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index dbd24ef27d26..bf6234b565e1 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -142,9 +142,11 @@ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
preloadClasses();
bootTimingsTraceLog.traceEnd(); // PreloadClasses
}
- bootTimingsTraceLog.traceBegin("CacheNonBootClasspathClassLoaders");
- cacheNonBootClasspathClassLoaders();
- bootTimingsTraceLog.traceEnd(); // CacheNonBootClasspathClassLoaders
+ if (fullPreload) {
+ bootTimingsTraceLog.traceBegin("CacheNonBootClasspathClassLoaders");
+ cacheNonBootClasspathClassLoaders();
+ bootTimingsTraceLog.traceEnd(); // CacheNonBootClasspathClassLoaders
+ }
if (fullPreload) {
bootTimingsTraceLog.traceBegin("PreloadResources");
preloadResources();

View File

@ -0,0 +1,28 @@
From 2eda592b79edd89907769fbc9e8ad175523bff0b Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Wed, 11 Sep 2019 06:58:51 -0400
Subject: [PATCH] disable preloading HALs for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index bf6234b565e1..b00fd9969a54 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -152,9 +152,11 @@ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
preloadResources();
bootTimingsTraceLog.traceEnd(); // PreloadResources
}
- Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadAppProcessHALs");
- nativePreloadAppProcessHALs();
- Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
+ if (fullPreload) {
+ Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadAppProcessHALs");
+ nativePreloadAppProcessHALs();
+ Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
+ }
if (fullPreload) {
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadGraphicsDriver");
maybePreloadGraphicsDriver();

View File

@ -0,0 +1,26 @@
From ffde474ad7e72c72367f16a231bc30ea8ee3311b Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 15:11:59 -0400
Subject: [PATCH] avoid AssetManager errors with exec spawning
This causes harmless errors and wastes time spawning a process that's
not going to succeed.
---
core/jni/android_util_AssetManager.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/core/jni/android_util_AssetManager.cpp b/core/jni/android_util_AssetManager.cpp
index 2b471fec9c8f..7a29db32808d 100644
--- a/core/jni/android_util_AssetManager.cpp
+++ b/core/jni/android_util_AssetManager.cpp
@@ -125,6 +125,10 @@ constexpr inline static ApkAssetsCookie JavaCookieToApkAssetsCookie(jint cookie)
// This is called by zygote (running as user root) as part of preloadResources.
static void NativeVerifySystemIdmaps(JNIEnv* /*env*/, jclass /*clazz*/) {
+ // avoid triggering an error with exec-based spawning
+ if (getuid() != 0) {
+ return;
+ }
switch (pid_t pid = fork()) {
case -1:
PLOG(ERROR) << "failed to fork for idmap";

View File

@ -0,0 +1,25 @@
From aa87e487c42e3f23b42ac151fc6a37f5cb4751e7 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 21 May 2019 23:54:20 -0400
Subject: [PATCH] disable exec spawning when using debugging options
The debugging options are not yet supported probably, so disable exec
spawning when doing debugging.
---
core/java/com/android/internal/os/ZygoteConnection.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java
index 1054d2fb9b13..b420385b1de6 100644
--- a/core/java/com/android/internal/os/ZygoteConnection.java
+++ b/core/java/com/android/internal/os/ZygoteConnection.java
@@ -597,7 +597,8 @@ private Runnable handleChildProc(ZygoteArguments parsedArgs, FileDescriptor[] de
throw new IllegalStateException("WrapperInit.execApplication unexpectedly returned");
} else {
if (!isZygote) {
- if (SystemProperties.getBoolean("sys.spawn.exec", true)) {
+ if (SystemProperties.getBoolean("sys.spawn.exec", true) &&
+ (parsedArgs.mRuntimeFlags & ApplicationInfo.FLAG_DEBUGGABLE) == 0) {
ExecInit.execApplication(parsedArgs.mNiceName, parsedArgs.mTargetSdkVersion,
VMRuntime.getCurrentInstructionSet(), parsedArgs.mRemainingArgs);

View File

@ -0,0 +1,47 @@
From c906fe97221c7f48d5e8a6be508fb85f8df113b1 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:24:21 -0400
Subject: [PATCH] add parameter for avoiding full preload with exec
---
core/java/com/android/internal/os/ExecInit.java | 2 +-
core/java/com/android/internal/os/ZygoteInit.java | 6 +++++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/core/java/com/android/internal/os/ExecInit.java b/core/java/com/android/internal/os/ExecInit.java
index 10edd64e0f95..3ba4664ae8cf 100644
--- a/core/java/com/android/internal/os/ExecInit.java
+++ b/core/java/com/android/internal/os/ExecInit.java
@@ -33,7 +33,7 @@ public static void main(String[] args) {
// Mimic system Zygote preloading.
ZygoteInit.preload(new TimingsTraceLog("ExecInitTiming",
- Trace.TRACE_TAG_DALVIK));
+ Trace.TRACE_TAG_DALVIK), false);
// Launch the application.
String[] runtimeArgs = new String[args.length - 1];
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 7ec8309e47de..e59cb784dc78 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -132,7 +132,7 @@
*/
private static ClassLoader sCachedSystemServerClassLoader = null;
- static void preload(TimingsTraceLog bootTimingsTraceLog) {
+ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
Log.d(TAG, "begin preload");
bootTimingsTraceLog.traceBegin("BeginPreload");
beginPreload();
@@ -164,6 +164,10 @@ static void preload(TimingsTraceLog bootTimingsTraceLog) {
sPreloadComplete = true;
}
+ static void preload(TimingsTraceLog bootTimingsTraceLog) {
+ preload(bootTimingsTraceLog, true);
+ }
+
public static void lazyPreload() {
Preconditions.checkState(!sPreloadComplete);
Log.i(TAG, "Lazily preloading resources.");

View File

@ -0,0 +1,50 @@
From c69c3eecd4f34a932760303e10e3a47798335f7e Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Wed, 11 Sep 2019 06:43:55 -0400
Subject: [PATCH] pass through fullPreload to libcore
---
core/java/com/android/internal/os/ZygoteInit.java | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index e59cb784dc78..22e3f549dad5 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -135,7 +135,7 @@
static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
Log.d(TAG, "begin preload");
bootTimingsTraceLog.traceBegin("BeginPreload");
- beginPreload();
+ beginPreload(fullPreload);
bootTimingsTraceLog.traceEnd(); // BeginPreload
bootTimingsTraceLog.traceBegin("PreloadClasses");
preloadClasses();
@@ -157,7 +157,7 @@ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
// Ask the WebViewFactory to do any initialization that must run in the zygote process,
// for memory sharing purposes.
WebViewFactory.prepareWebViewInZygote();
- endPreload();
+ endPreload(fullPreload);
warmUpJcaProviders();
Log.d(TAG, "end preload");
@@ -175,14 +175,14 @@ public static void lazyPreload() {
preload(new TimingsTraceLog("ZygoteInitTiming_lazy", Trace.TRACE_TAG_DALVIK));
}
- private static void beginPreload() {
+ private static void beginPreload(boolean fullPreload) {
Log.i(TAG, "Calling ZygoteHooks.beginPreload()");
- ZygoteHooks.onBeginPreload();
+ ZygoteHooks.onBeginPreload(fullPreload);
}
- private static void endPreload() {
- ZygoteHooks.onEndPreload();
+ private static void endPreload(boolean fullPreload) {
+ ZygoteHooks.onEndPreload(fullPreload);
Log.i(TAG, "Called ZygoteHooks.endPreload()");
}

View File

@ -0,0 +1,28 @@
From b2303adccc82b89f19a6f4af8834443fa7e01b67 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:28:27 -0400
Subject: [PATCH] disable OpenGL preloading for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 22e3f549dad5..37be8d97987a 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -149,9 +149,11 @@ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadAppProcessHALs");
nativePreloadAppProcessHALs();
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
- Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadGraphicsDriver");
- maybePreloadGraphicsDriver();
- Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
+ if (fullPreload) {
+ Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadGraphicsDriver");
+ maybePreloadGraphicsDriver();
+ Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
+ }
preloadSharedLibraries();
preloadTextResources();
// Ask the WebViewFactory to do any initialization that must run in the zygote process,

View File

@ -0,0 +1,28 @@
From 5bb05db6f73992cc345d3662652bea024f3ace3b Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:28:52 -0400
Subject: [PATCH] disable resource preloading for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 37be8d97987a..34c9f8530a72 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -143,9 +143,11 @@ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
bootTimingsTraceLog.traceBegin("CacheNonBootClasspathClassLoaders");
cacheNonBootClasspathClassLoaders();
bootTimingsTraceLog.traceEnd(); // CacheNonBootClasspathClassLoaders
- bootTimingsTraceLog.traceBegin("PreloadResources");
- preloadResources();
- bootTimingsTraceLog.traceEnd(); // PreloadResources
+ if (fullPreload) {
+ bootTimingsTraceLog.traceBegin("PreloadResources");
+ preloadResources();
+ bootTimingsTraceLog.traceEnd(); // PreloadResources
+ }
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadAppProcessHALs");
nativePreloadAppProcessHALs();
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);

View File

@ -0,0 +1,28 @@
From 536b4976880224d8518e9208f4e3caacf79e64c9 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:30:59 -0400
Subject: [PATCH] disable class preloading for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 34c9f8530a72..0404ef53ca01 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -137,9 +137,11 @@ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
bootTimingsTraceLog.traceBegin("BeginPreload");
beginPreload(fullPreload);
bootTimingsTraceLog.traceEnd(); // BeginPreload
- bootTimingsTraceLog.traceBegin("PreloadClasses");
- preloadClasses();
- bootTimingsTraceLog.traceEnd(); // PreloadClasses
+ if (fullPreload) {
+ bootTimingsTraceLog.traceBegin("PreloadClasses");
+ preloadClasses();
+ bootTimingsTraceLog.traceEnd(); // PreloadClasses
+ }
bootTimingsTraceLog.traceBegin("CacheNonBootClasspathClassLoaders");
cacheNonBootClasspathClassLoaders();
bootTimingsTraceLog.traceEnd(); // CacheNonBootClasspathClassLoaders

View File

@ -0,0 +1,28 @@
From 24802a832b514452df5cea11759be8d33a7b8bc0 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:31:29 -0400
Subject: [PATCH] disable WebView reservation for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 0404ef53ca01..94e58405ce63 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -160,9 +160,11 @@ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
}
preloadSharedLibraries();
preloadTextResources();
- // Ask the WebViewFactory to do any initialization that must run in the zygote process,
- // for memory sharing purposes.
- WebViewFactory.prepareWebViewInZygote();
+ if (fullPreload) {
+ // Ask the WebViewFactory to do any initialization that must run in the zygote process,
+ // for memory sharing purposes.
+ WebViewFactory.prepareWebViewInZygote();
+ }
endPreload(fullPreload);
warmUpJcaProviders();
Log.d(TAG, "end preload");

View File

@ -1,592 +0,0 @@
From 60e744e11be94212d0bc796d8904da4c61af60e1 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Sat, 14 Mar 2015 18:10:20 -0400
Subject: [PATCH 01/12] add exec-based spawning support
---
.../com/android/internal/os/ExecInit.java | 115 ++++++++++++++++++
.../com/android/internal/os/WrapperInit.java | 2 +-
.../android/internal/os/ZygoteConnection.java | 8 ++
3 files changed, 124 insertions(+), 1 deletion(-)
create mode 100644 core/java/com/android/internal/os/ExecInit.java
diff --git a/core/java/com/android/internal/os/ExecInit.java b/core/java/com/android/internal/os/ExecInit.java
new file mode 100644
index 00000000000..10edd64e0f9
--- /dev/null
+++ b/core/java/com/android/internal/os/ExecInit.java
@@ -0,0 +1,115 @@
+package com.android.internal.os;
+
+import android.os.Trace;
+import android.system.ErrnoException;
+import android.system.Os;
+import android.util.Slog;
+import android.util.TimingsTraceLog;
+import dalvik.system.VMRuntime;
+
+/**
+ * Startup class for the process.
+ * @hide
+ */
+public class ExecInit {
+ /**
+ * Class not instantiable.
+ */
+ private ExecInit() {
+ }
+
+ /**
+ * The main function called when starting a runtime application.
+ *
+ * The first argument is the target SDK version for the app.
+ *
+ * The remaining arguments are passed to the runtime.
+ *
+ * @param args The command-line arguments.
+ */
+ public static void main(String[] args) {
+ // Parse our mandatory argument.
+ int targetSdkVersion = Integer.parseInt(args[0], 10);
+
+ // Mimic system Zygote preloading.
+ ZygoteInit.preload(new TimingsTraceLog("ExecInitTiming",
+ Trace.TRACE_TAG_DALVIK));
+
+ // Launch the application.
+ String[] runtimeArgs = new String[args.length - 1];
+ System.arraycopy(args, 1, runtimeArgs, 0, runtimeArgs.length);
+ Runnable r = execInit(targetSdkVersion, runtimeArgs);
+
+ r.run();
+ }
+
+ /**
+ * Executes a runtime application with exec-based spawning.
+ * This method never returns.
+ *
+ * @param niceName The nice name for the application, or null if none.
+ * @param targetSdkVersion The target SDK version for the app.
+ * @param args Arguments for {@link RuntimeInit#main}.
+ */
+ public static void execApplication(String niceName, int targetSdkVersion,
+ String instructionSet, String[] args) {
+ int niceArgs = niceName == null ? 0 : 1;
+ int baseArgs = 5 + niceArgs;
+ String[] argv = new String[baseArgs + args.length];
+ if (VMRuntime.is64BitInstructionSet(instructionSet)) {
+ argv[0] = "/system/bin/app_process64";
+ } else {
+ argv[0] = "/system/bin/app_process32";
+ }
+ argv[1] = "/system/bin";
+ argv[2] = "--application";
+ if (niceName != null) {
+ argv[3] = "--nice-name=" + niceName;
+ }
+ argv[3 + niceArgs] = "com.android.internal.os.ExecInit";
+ argv[4 + niceArgs] = Integer.toString(targetSdkVersion);
+ System.arraycopy(args, 0, argv, baseArgs, args.length);
+
+ WrapperInit.preserveCapabilities();
+ try {
+ Os.execv(argv[0], argv);
+ } catch (ErrnoException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * The main function called when an application is started with exec-based spawning.
+ *
+ * When the app starts, the runtime starts {@link RuntimeInit#main}
+ * which calls {@link main} which then calls this method.
+ * So we don't need to call commonInit() here.
+ *
+ * @param targetSdkVersion target SDK version
+ * @param argv arg strings
+ */
+ private static Runnable execInit(int targetSdkVersion, String[] argv) {
+ if (RuntimeInit.DEBUG) {
+ Slog.d(RuntimeInit.TAG, "RuntimeInit: Starting application from exec");
+ }
+
+ // Check whether the first argument is a "-cp" in argv, and assume the next argument is the
+ // classpath. If found, create a PathClassLoader and use it for applicationInit.
+ ClassLoader classLoader = null;
+ if (argv != null && argv.length > 2 && argv[0].equals("-cp")) {
+ classLoader = ZygoteInit.createPathClassLoader(argv[1], targetSdkVersion);
+
+ // Install this classloader as the context classloader, too.
+ Thread.currentThread().setContextClassLoader(classLoader);
+
+ // Remove the classpath from the arguments.
+ String removedArgs[] = new String[argv.length - 2];
+ System.arraycopy(argv, 2, removedArgs, 0, argv.length - 2);
+ argv = removedArgs;
+ }
+
+ // Perform the same initialization that would happen after the Zygote forks.
+ Zygote.nativePreApplicationInit();
+ return RuntimeInit.applicationInit(targetSdkVersion, argv, classLoader);
+ }
+}
diff --git a/core/java/com/android/internal/os/WrapperInit.java b/core/java/com/android/internal/os/WrapperInit.java
index f0e779694c9..9f41a4136db 100644
--- a/core/java/com/android/internal/os/WrapperInit.java
+++ b/core/java/com/android/internal/os/WrapperInit.java
@@ -183,7 +183,7 @@ public class WrapperInit {
* This is acceptable here as failure will leave the wrapped app with strictly less
* capabilities, which may make it crash, but not exceed its allowances.
*/
- private static void preserveCapabilities() {
+ public static void preserveCapabilities() {
StructCapUserHeader header = new StructCapUserHeader(
OsConstants._LINUX_CAPABILITY_VERSION_3, 0);
StructCapUserData[] data;
diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java
index e556dd4d824..1054d2fb9b1 100644
--- a/core/java/com/android/internal/os/ZygoteConnection.java
+++ b/core/java/com/android/internal/os/ZygoteConnection.java
@@ -33,6 +33,7 @@ import android.net.Credentials;
import android.net.LocalSocket;
import android.os.Parcel;
import android.os.Process;
+import android.os.SystemProperties;
import android.os.Trace;
import android.system.ErrnoException;
import android.system.Os;
@@ -596,6 +597,13 @@ class ZygoteConnection {
throw new IllegalStateException("WrapperInit.execApplication unexpectedly returned");
} else {
if (!isZygote) {
+ if (SystemProperties.getBoolean("sys.spawn.exec", true)) {
+ ExecInit.execApplication(parsedArgs.mNiceName, parsedArgs.mTargetSdkVersion,
+ VMRuntime.getCurrentInstructionSet(), parsedArgs.mRemainingArgs);
+
+ // Should not get here.
+ throw new IllegalStateException("ExecInit.execApplication unexpectedly returned");
+ }
return ZygoteInit.zygoteInit(parsedArgs.mTargetSdkVersion,
parsedArgs.mRemainingArgs, null /* classLoader */);
} else {
--
2.26.0
From 148d6154d771cec6ff736d0f72abf192a5a35975 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 15:11:59 -0400
Subject: [PATCH 02/12] avoid AssetManager errors with exec spawning
This causes harmless errors and wastes time spawning a process that's
not going to succeed.
---
core/jni/android_util_AssetManager.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/core/jni/android_util_AssetManager.cpp b/core/jni/android_util_AssetManager.cpp
index 2b471fec9c8..7a29db32808 100644
--- a/core/jni/android_util_AssetManager.cpp
+++ b/core/jni/android_util_AssetManager.cpp
@@ -125,6 +125,10 @@ constexpr inline static ApkAssetsCookie JavaCookieToApkAssetsCookie(jint cookie)
// This is called by zygote (running as user root) as part of preloadResources.
static void NativeVerifySystemIdmaps(JNIEnv* /*env*/, jclass /*clazz*/) {
+ // avoid triggering an error with exec-based spawning
+ if (getuid() != 0) {
+ return;
+ }
switch (pid_t pid = fork()) {
case -1:
PLOG(ERROR) << "failed to fork for idmap";
--
2.26.0
From 2076c38e549f2b4032448159c1478e67a72a96b5 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 21 May 2019 23:54:20 -0400
Subject: [PATCH 03/12] disable exec spawning when using debugging options
The debugging options are not yet supported probably, so disable exec
spawning when doing debugging.
---
core/java/com/android/internal/os/ZygoteConnection.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java
index 1054d2fb9b1..b420385b1de 100644
--- a/core/java/com/android/internal/os/ZygoteConnection.java
+++ b/core/java/com/android/internal/os/ZygoteConnection.java
@@ -597,7 +597,8 @@ class ZygoteConnection {
throw new IllegalStateException("WrapperInit.execApplication unexpectedly returned");
} else {
if (!isZygote) {
- if (SystemProperties.getBoolean("sys.spawn.exec", true)) {
+ if (SystemProperties.getBoolean("sys.spawn.exec", true) &&
+ (parsedArgs.mRuntimeFlags & ApplicationInfo.FLAG_DEBUGGABLE) == 0) {
ExecInit.execApplication(parsedArgs.mNiceName, parsedArgs.mTargetSdkVersion,
VMRuntime.getCurrentInstructionSet(), parsedArgs.mRemainingArgs);
--
2.26.0
From 909317e350ea4c8874b01e73502dc0c7c78635ab Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:24:21 -0400
Subject: [PATCH 04/12] add parameter for avoiding full preload with exec
---
core/java/com/android/internal/os/ExecInit.java | 2 +-
core/java/com/android/internal/os/ZygoteInit.java | 6 +++++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/core/java/com/android/internal/os/ExecInit.java b/core/java/com/android/internal/os/ExecInit.java
index 10edd64e0f9..3ba4664ae8c 100644
--- a/core/java/com/android/internal/os/ExecInit.java
+++ b/core/java/com/android/internal/os/ExecInit.java
@@ -33,7 +33,7 @@ public class ExecInit {
// Mimic system Zygote preloading.
ZygoteInit.preload(new TimingsTraceLog("ExecInitTiming",
- Trace.TRACE_TAG_DALVIK));
+ Trace.TRACE_TAG_DALVIK), false);
// Launch the application.
String[] runtimeArgs = new String[args.length - 1];
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 7ec8309e47d..e59cb784dc7 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -132,7 +132,7 @@ public class ZygoteInit {
*/
private static ClassLoader sCachedSystemServerClassLoader = null;
- static void preload(TimingsTraceLog bootTimingsTraceLog) {
+ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
Log.d(TAG, "begin preload");
bootTimingsTraceLog.traceBegin("BeginPreload");
beginPreload();
@@ -164,6 +164,10 @@ public class ZygoteInit {
sPreloadComplete = true;
}
+ static void preload(TimingsTraceLog bootTimingsTraceLog) {
+ preload(bootTimingsTraceLog, true);
+ }
+
public static void lazyPreload() {
Preconditions.checkState(!sPreloadComplete);
Log.i(TAG, "Lazily preloading resources.");
--
2.26.0
From 4ffeae4cfb2f0acbb8080ab25ca6559c7329b80c Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Wed, 11 Sep 2019 06:43:55 -0400
Subject: [PATCH 05/12] pass through fullPreload to libcore
---
core/java/com/android/internal/os/ZygoteInit.java | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index e59cb784dc7..22e3f549dad 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -135,7 +135,7 @@ public class ZygoteInit {
static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
Log.d(TAG, "begin preload");
bootTimingsTraceLog.traceBegin("BeginPreload");
- beginPreload();
+ beginPreload(fullPreload);
bootTimingsTraceLog.traceEnd(); // BeginPreload
bootTimingsTraceLog.traceBegin("PreloadClasses");
preloadClasses();
@@ -157,7 +157,7 @@ public class ZygoteInit {
// Ask the WebViewFactory to do any initialization that must run in the zygote process,
// for memory sharing purposes.
WebViewFactory.prepareWebViewInZygote();
- endPreload();
+ endPreload(fullPreload);
warmUpJcaProviders();
Log.d(TAG, "end preload");
@@ -175,14 +175,14 @@ public class ZygoteInit {
preload(new TimingsTraceLog("ZygoteInitTiming_lazy", Trace.TRACE_TAG_DALVIK));
}
- private static void beginPreload() {
+ private static void beginPreload(boolean fullPreload) {
Log.i(TAG, "Calling ZygoteHooks.beginPreload()");
- ZygoteHooks.onBeginPreload();
+ ZygoteHooks.onBeginPreload(fullPreload);
}
- private static void endPreload() {
- ZygoteHooks.onEndPreload();
+ private static void endPreload(boolean fullPreload) {
+ ZygoteHooks.onEndPreload(fullPreload);
Log.i(TAG, "Called ZygoteHooks.endPreload()");
}
--
2.26.0
From e2166aee853fad1b84fa17936d795535eaef374b Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:28:27 -0400
Subject: [PATCH 06/12] disable OpenGL preloading for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 22e3f549dad..37be8d97987 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -149,9 +149,11 @@ public class ZygoteInit {
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadAppProcessHALs");
nativePreloadAppProcessHALs();
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
- Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadGraphicsDriver");
- maybePreloadGraphicsDriver();
- Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
+ if (fullPreload) {
+ Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadGraphicsDriver");
+ maybePreloadGraphicsDriver();
+ Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
+ }
preloadSharedLibraries();
preloadTextResources();
// Ask the WebViewFactory to do any initialization that must run in the zygote process,
--
2.26.0
From dff76e1e08bf67ebc5e4da8a2dcdf57a55e0d09b Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:28:52 -0400
Subject: [PATCH 07/12] disable resource preloading for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 37be8d97987..34c9f8530a7 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -143,9 +143,11 @@ public class ZygoteInit {
bootTimingsTraceLog.traceBegin("CacheNonBootClasspathClassLoaders");
cacheNonBootClasspathClassLoaders();
bootTimingsTraceLog.traceEnd(); // CacheNonBootClasspathClassLoaders
- bootTimingsTraceLog.traceBegin("PreloadResources");
- preloadResources();
- bootTimingsTraceLog.traceEnd(); // PreloadResources
+ if (fullPreload) {
+ bootTimingsTraceLog.traceBegin("PreloadResources");
+ preloadResources();
+ bootTimingsTraceLog.traceEnd(); // PreloadResources
+ }
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadAppProcessHALs");
nativePreloadAppProcessHALs();
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
--
2.26.0
From 872568d6c67a63c411e33699b969b5b1563e58ce Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:30:59 -0400
Subject: [PATCH 08/12] disable class preloading for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 34c9f8530a7..0404ef53ca0 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -137,9 +137,11 @@ public class ZygoteInit {
bootTimingsTraceLog.traceBegin("BeginPreload");
beginPreload(fullPreload);
bootTimingsTraceLog.traceEnd(); // BeginPreload
- bootTimingsTraceLog.traceBegin("PreloadClasses");
- preloadClasses();
- bootTimingsTraceLog.traceEnd(); // PreloadClasses
+ if (fullPreload) {
+ bootTimingsTraceLog.traceBegin("PreloadClasses");
+ preloadClasses();
+ bootTimingsTraceLog.traceEnd(); // PreloadClasses
+ }
bootTimingsTraceLog.traceBegin("CacheNonBootClasspathClassLoaders");
cacheNonBootClasspathClassLoaders();
bootTimingsTraceLog.traceEnd(); // CacheNonBootClasspathClassLoaders
--
2.26.0
From 230080cd158ef27c8fa3647dfa6f4c2cff4c70dd Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:31:29 -0400
Subject: [PATCH 09/12] disable WebView reservation for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 0404ef53ca0..94e58405ce6 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -160,9 +160,11 @@ public class ZygoteInit {
}
preloadSharedLibraries();
preloadTextResources();
- // Ask the WebViewFactory to do any initialization that must run in the zygote process,
- // for memory sharing purposes.
- WebViewFactory.prepareWebViewInZygote();
+ if (fullPreload) {
+ // Ask the WebViewFactory to do any initialization that must run in the zygote process,
+ // for memory sharing purposes.
+ WebViewFactory.prepareWebViewInZygote();
+ }
endPreload(fullPreload);
warmUpJcaProviders();
Log.d(TAG, "end preload");
--
2.26.0
From f822fe138d5841cde0b154fa6f3a3d3200b58c07 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:34:32 -0400
Subject: [PATCH 10/12] disable JCA provider warm up for exec spawning
---
.../com/android/internal/os/ZygoteInit.java | 22 ++++++++++---------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 94e58405ce6..dbd24ef27d2 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -166,7 +166,7 @@ public class ZygoteInit {
WebViewFactory.prepareWebViewInZygote();
}
endPreload(fullPreload);
- warmUpJcaProviders();
+ warmUpJcaProviders(fullPreload);
Log.d(TAG, "end preload");
sPreloadComplete = true;
@@ -230,7 +230,7 @@ public class ZygoteInit {
* By doing it here we avoid that each app does it when requesting a service from the provider
* for the first time.
*/
- private static void warmUpJcaProviders() {
+ private static void warmUpJcaProviders(boolean fullPreload) {
long startTime = SystemClock.uptimeMillis();
Trace.traceBegin(
Trace.TRACE_TAG_DALVIK, "Starting installation of AndroidKeyStoreProvider");
@@ -242,15 +242,17 @@ public class ZygoteInit {
+ (SystemClock.uptimeMillis() - startTime) + "ms.");
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
- startTime = SystemClock.uptimeMillis();
- Trace.traceBegin(
- Trace.TRACE_TAG_DALVIK, "Starting warm up of JCA providers");
- for (Provider p : Security.getProviders()) {
- p.warmUpServiceProvision();
+ if (fullPreload) {
+ startTime = SystemClock.uptimeMillis();
+ Trace.traceBegin(
+ Trace.TRACE_TAG_DALVIK, "Starting warm up of JCA providers");
+ for (Provider p : Security.getProviders()) {
+ p.warmUpServiceProvision();
+ }
+ Log.i(TAG, "Warmed up JCA providers in "
+ + (SystemClock.uptimeMillis() - startTime) + "ms.");
+ Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
}
- Log.i(TAG, "Warmed up JCA providers in "
- + (SystemClock.uptimeMillis() - startTime) + "ms.");
- Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
}
/**
--
2.26.0
From 430a93910f4a555e4e6f06b4f1634acb45e9d501 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Wed, 11 Sep 2019 06:57:24 -0400
Subject: [PATCH 11/12] disable preloading classloaders for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index dbd24ef27d2..bf6234b565e 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -142,9 +142,11 @@ public class ZygoteInit {
preloadClasses();
bootTimingsTraceLog.traceEnd(); // PreloadClasses
}
- bootTimingsTraceLog.traceBegin("CacheNonBootClasspathClassLoaders");
- cacheNonBootClasspathClassLoaders();
- bootTimingsTraceLog.traceEnd(); // CacheNonBootClasspathClassLoaders
+ if (fullPreload) {
+ bootTimingsTraceLog.traceBegin("CacheNonBootClasspathClassLoaders");
+ cacheNonBootClasspathClassLoaders();
+ bootTimingsTraceLog.traceEnd(); // CacheNonBootClasspathClassLoaders
+ }
if (fullPreload) {
bootTimingsTraceLog.traceBegin("PreloadResources");
preloadResources();
--
2.26.0
From fc75b053f8bcd15a019915f06d9ddea6c46abcec Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Wed, 11 Sep 2019 06:58:51 -0400
Subject: [PATCH 12/12] disable preloading HALs for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index bf6234b565e..b00fd9969a5 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -152,9 +152,11 @@ public class ZygoteInit {
preloadResources();
bootTimingsTraceLog.traceEnd(); // PreloadResources
}
- Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadAppProcessHALs");
- nativePreloadAppProcessHALs();
- Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
+ if (fullPreload) {
+ Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadAppProcessHALs");
+ nativePreloadAppProcessHALs();
+ Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
+ }
if (fullPreload) {
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadGraphicsDriver");
maybePreloadGraphicsDriver();
--
2.26.0

View File

@ -1,4 +1,4 @@
From d087128e25112c35cc9ca2694b503710fc43222d Mon Sep 17 00:00:00 2001
From 29f28b53c0cc85612e66485bc250fc57d82bc622 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Wed, 11 Sep 2019 06:46:38 -0400
Subject: [PATCH] add parameter for avoiding full preload with exec
@ -9,7 +9,7 @@ Subject: [PATCH] add parameter for avoiding full preload with exec
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/dalvik/src/main/java/dalvik/system/ZygoteHooks.java b/dalvik/src/main/java/dalvik/system/ZygoteHooks.java
index 13769e137..af3b9cfe8 100644
index 13769e137e..af3b9cfe8b 100644
--- a/dalvik/src/main/java/dalvik/system/ZygoteHooks.java
+++ b/dalvik/src/main/java/dalvik/system/ZygoteHooks.java
@@ -47,7 +47,7 @@ private ZygoteHooks() {
@ -31,7 +31,7 @@ index 13769e137..af3b9cfe8 100644
CacheValue.setStrength(CacheValue.Strength.SOFT);
}
diff --git a/mmodules/core_platform_api/api/platform/current-api.txt b/mmodules/core_platform_api/api/platform/current-api.txt
index b2b81df41..cca689158 100644
index b2b81df415..cca6891580 100644
--- a/mmodules/core_platform_api/api/platform/current-api.txt
+++ b/mmodules/core_platform_api/api/platform/current-api.txt
@@ -854,8 +854,8 @@ package dalvik.system {

View File

@ -1,4 +1,4 @@
From ad05afeefb51c74813daf3a99eca2b23fc553c7c Mon Sep 17 00:00:00 2001
From 13a992c716f9b39920a7b37af2f447ced8e45c15 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Wed, 11 Sep 2019 06:47:11 -0400
Subject: [PATCH] disable ICU cache pinning for exec spawning
@ -8,7 +8,7 @@ Subject: [PATCH] disable ICU cache pinning for exec spawning
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/dalvik/src/main/java/dalvik/system/ZygoteHooks.java b/dalvik/src/main/java/dalvik/system/ZygoteHooks.java
index af3b9cfe8..35e880558 100644
index af3b9cfe8b..35e880558a 100644
--- a/dalvik/src/main/java/dalvik/system/ZygoteHooks.java
+++ b/dalvik/src/main/java/dalvik/system/ZygoteHooks.java
@@ -48,15 +48,17 @@ private ZygoteHooks() {

View File

@ -0,0 +1,26 @@
From a2b51906dece2ea351b5aa4b66fa8cdefbf37ff6 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Thu, 17 Sep 2020 10:53:00 -0400
Subject: [PATCH] disable enforce RRO for mainline devices
RROs are currently incompatible with exec-based spawning. This also
impacts the wrapper spawning model for the stock OS which is available
by default, making it an upstream bug rather than a missing feature for
exec-based spawning in GrapheneOS.
---
target/product/mainline_system.mk | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/target/product/mainline_system.mk b/target/product/mainline_system.mk
index 1f22163c32..db2af7d1d2 100644
--- a/target/product/mainline_system.mk
+++ b/target/product/mainline_system.mk
@@ -115,7 +115,7 @@ PRODUCT_COPY_FILES += \
# Enable dynamic partition size
PRODUCT_USE_DYNAMIC_PARTITION_SIZE := true
-PRODUCT_ENFORCE_RRO_TARGETS := *
+#PRODUCT_ENFORCE_RRO_TARGETS := *
PRODUCT_NAME := mainline_system
PRODUCT_BRAND := generic

View File

@ -0,0 +1,172 @@
From 14c3c1d4cd2df5dde69274e76a91b42fa383e577 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Sat, 14 Mar 2015 18:10:20 -0400
Subject: [PATCH] add exec-based spawning support
---
.../com/android/internal/os/ExecInit.java | 115 ++++++++++++++++++
.../com/android/internal/os/WrapperInit.java | 2 +-
.../android/internal/os/ZygoteConnection.java | 8 ++
3 files changed, 124 insertions(+), 1 deletion(-)
create mode 100644 core/java/com/android/internal/os/ExecInit.java
diff --git a/core/java/com/android/internal/os/ExecInit.java b/core/java/com/android/internal/os/ExecInit.java
new file mode 100644
index 000000000000..2adcab7fdbe6
--- /dev/null
+++ b/core/java/com/android/internal/os/ExecInit.java
@@ -0,0 +1,115 @@
+package com.android.internal.os;
+
+import android.os.Trace;
+import android.system.ErrnoException;
+import android.system.Os;
+import android.util.Slog;
+import android.util.TimingsTraceLog;
+import dalvik.system.VMRuntime;
+
+/**
+ * Startup class for the process.
+ * @hide
+ */
+public class ExecInit {
+ /**
+ * Class not instantiable.
+ */
+ private ExecInit() {
+ }
+
+ /**
+ * The main function called when starting a runtime application.
+ *
+ * The first argument is the target SDK version for the app.
+ *
+ * The remaining arguments are passed to the runtime.
+ *
+ * @param args The command-line arguments.
+ */
+ public static void main(String[] args) {
+ // Parse our mandatory argument.
+ int targetSdkVersion = Integer.parseInt(args[0], 10);
+
+ // Mimic system Zygote preloading.
+ ZygoteInit.preload(new TimingsTraceLog("ExecInitTiming",
+ Trace.TRACE_TAG_DALVIK));
+
+ // Launch the application.
+ String[] runtimeArgs = new String[args.length - 1];
+ System.arraycopy(args, 1, runtimeArgs, 0, runtimeArgs.length);
+ Runnable r = execInit(targetSdkVersion, runtimeArgs);
+
+ r.run();
+ }
+
+ /**
+ * Executes a runtime application with exec-based spawning.
+ * This method never returns.
+ *
+ * @param niceName The nice name for the application, or null if none.
+ * @param targetSdkVersion The target SDK version for the app.
+ * @param args Arguments for {@link RuntimeInit#main}.
+ */
+ public static void execApplication(String niceName, int targetSdkVersion,
+ String instructionSet, String[] args) {
+ int niceArgs = niceName == null ? 0 : 1;
+ int baseArgs = 5 + niceArgs;
+ String[] argv = new String[baseArgs + args.length];
+ if (VMRuntime.is64BitInstructionSet(instructionSet)) {
+ argv[0] = "/system/bin/app_process64";
+ } else {
+ argv[0] = "/system/bin/app_process32";
+ }
+ argv[1] = "/system/bin";
+ argv[2] = "--application";
+ if (niceName != null) {
+ argv[3] = "--nice-name=" + niceName;
+ }
+ argv[3 + niceArgs] = "com.android.internal.os.ExecInit";
+ argv[4 + niceArgs] = Integer.toString(targetSdkVersion);
+ System.arraycopy(args, 0, argv, baseArgs, args.length);
+
+ WrapperInit.preserveCapabilities();
+ try {
+ Os.execv(argv[0], argv);
+ } catch (ErrnoException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * The main function called when an application is started with exec-based spawning.
+ *
+ * When the app starts, the runtime starts {@link RuntimeInit#main}
+ * which calls {@link main} which then calls this method.
+ * So we don't need to call commonInit() here.
+ *
+ * @param targetSdkVersion target SDK version
+ * @param argv arg strings
+ */
+ private static Runnable execInit(int targetSdkVersion, String[] argv) {
+ if (RuntimeInit.DEBUG) {
+ Slog.d(RuntimeInit.TAG, "RuntimeInit: Starting application from exec");
+ }
+
+ // Check whether the first argument is a "-cp" in argv, and assume the next argument is the
+ // classpath. If found, create a PathClassLoader and use it for applicationInit.
+ ClassLoader classLoader = null;
+ if (argv != null && argv.length > 2 && argv[0].equals("-cp")) {
+ classLoader = ZygoteInit.createPathClassLoader(argv[1], targetSdkVersion);
+
+ // Install this classloader as the context classloader, too.
+ Thread.currentThread().setContextClassLoader(classLoader);
+
+ // Remove the classpath from the arguments.
+ String removedArgs[] = new String[argv.length - 2];
+ System.arraycopy(argv, 2, removedArgs, 0, argv.length - 2);
+ argv = removedArgs;
+ }
+
+ // Perform the same initialization that would happen after the Zygote forks.
+ Zygote.nativePreApplicationInit();
+ return RuntimeInit.applicationInit(targetSdkVersion, /*disabledCompatChanges*/ null, argv, classLoader);
+ }
+}
diff --git a/core/java/com/android/internal/os/WrapperInit.java b/core/java/com/android/internal/os/WrapperInit.java
index 790d7f7ab694..4f7fd039ccd7 100644
--- a/core/java/com/android/internal/os/WrapperInit.java
+++ b/core/java/com/android/internal/os/WrapperInit.java
@@ -185,7 +185,7 @@ private static Runnable wrapperInit(int targetSdkVersion, String[] argv) {
* This is acceptable here as failure will leave the wrapped app with strictly less
* capabilities, which may make it crash, but not exceed its allowances.
*/
- private static void preserveCapabilities() {
+ public static void preserveCapabilities() {
StructCapUserHeader header = new StructCapUserHeader(
OsConstants._LINUX_CAPABILITY_VERSION_3, 0);
StructCapUserData[] data;
diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java
index e6a3029c5b2b..a702e84813fa 100644
--- a/core/java/com/android/internal/os/ZygoteConnection.java
+++ b/core/java/com/android/internal/os/ZygoteConnection.java
@@ -29,6 +29,7 @@
import android.net.LocalSocket;
import android.os.Parcel;
import android.os.Process;
+import android.os.SystemProperties;
import android.os.Trace;
import android.system.ErrnoException;
import android.system.Os;
@@ -501,6 +502,13 @@ private Runnable handleChildProc(ZygoteArguments parsedArgs,
throw new IllegalStateException("WrapperInit.execApplication unexpectedly returned");
} else {
if (!isZygote) {
+ if (SystemProperties.getBoolean("sys.spawn.exec", true)) {
+ ExecInit.execApplication(parsedArgs.mNiceName, parsedArgs.mTargetSdkVersion,
+ VMRuntime.getCurrentInstructionSet(), parsedArgs.mRemainingArgs);
+
+ // Should not get here.
+ throw new IllegalStateException("ExecInit.execApplication unexpectedly returned");
+ }
return ZygoteInit.zygoteInit(parsedArgs.mTargetSdkVersion,
parsedArgs.mDisabledCompatChanges,
parsedArgs.mRemainingArgs, null /* classLoader */);

View File

@ -0,0 +1,28 @@
From d414dcaa351e7a890d31c1da949421fb435ff168 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Wed, 11 Sep 2019 06:57:24 -0400
Subject: [PATCH] disable preloading classloaders for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index ad3b95ec67fc..0877a1668930 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -135,9 +135,11 @@ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
preloadClasses();
bootTimingsTraceLog.traceEnd(); // PreloadClasses
}
- bootTimingsTraceLog.traceBegin("CacheNonBootClasspathClassLoaders");
- cacheNonBootClasspathClassLoaders();
- bootTimingsTraceLog.traceEnd(); // CacheNonBootClasspathClassLoaders
+ if (fullPreload) {
+ bootTimingsTraceLog.traceBegin("CacheNonBootClasspathClassLoaders");
+ cacheNonBootClasspathClassLoaders();
+ bootTimingsTraceLog.traceEnd(); // CacheNonBootClasspathClassLoaders
+ }
if (fullPreload) {
bootTimingsTraceLog.traceBegin("PreloadResources");
preloadResources();

View File

@ -0,0 +1,28 @@
From b4cd877e3a0c2384b8939d5d1e2b6b734bbd13b2 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Wed, 11 Sep 2019 06:58:51 -0400
Subject: [PATCH] disable preloading HALs for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 0877a1668930..d19868ebd9ca 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -145,9 +145,11 @@ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
preloadResources();
bootTimingsTraceLog.traceEnd(); // PreloadResources
}
- Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadAppProcessHALs");
- nativePreloadAppProcessHALs();
- Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
+ if (fullPreload) {
+ Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadAppProcessHALs");
+ nativePreloadAppProcessHALs();
+ Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
+ }
if (fullPreload) {
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadGraphicsDriver");
maybePreloadGraphicsDriver();

View File

@ -0,0 +1,207 @@
From 98634286bbdffe967a9a03442e5aa324ec26986a Mon Sep 17 00:00:00 2001
From: anupritaisno1 <www.anuprita804@gmail.com>
Date: Fri, 30 Oct 2020 22:26:09 +0000
Subject: [PATCH] pass through runtime flags for exec spawning and implement
them in the child
Signed-off-by: anupritaisno1 <www.anuprita804@gmail.com>
---
.../com/android/internal/os/ExecInit.java | 14 +++-
core/java/com/android/internal/os/Zygote.java | 9 ++
.../android/internal/os/ZygoteConnection.java | 2 +-
core/jni/com_android_internal_os_Zygote.cpp | 83 ++++++++++---------
4 files changed, 66 insertions(+), 42 deletions(-)
diff --git a/core/java/com/android/internal/os/ExecInit.java b/core/java/com/android/internal/os/ExecInit.java
index 830e5b562a91..749c67abf389 100644
--- a/core/java/com/android/internal/os/ExecInit.java
+++ b/core/java/com/android/internal/os/ExecInit.java
@@ -31,15 +31,20 @@ public static void main(String[] args) {
// Parse our mandatory argument.
int targetSdkVersion = Integer.parseInt(args[0], 10);
+ // Parse the runtime_flags.
+ int runtimeFlags = Integer.parseInt(args[1], 10);
+
// Mimic system Zygote preloading.
ZygoteInit.preload(new TimingsTraceLog("ExecInitTiming",
Trace.TRACE_TAG_DALVIK), false);
// Launch the application.
- String[] runtimeArgs = new String[args.length - 1];
- System.arraycopy(args, 1, runtimeArgs, 0, runtimeArgs.length);
+ String[] runtimeArgs = new String[args.length - 2];
+ System.arraycopy(args, 2, runtimeArgs, 0, runtimeArgs.length);
Runnable r = execInit(targetSdkVersion, runtimeArgs);
+ Zygote.nativeHandleRuntimeFlags(runtimeFlags);
+
r.run();
}
@@ -52,9 +57,9 @@ public static void main(String[] args) {
* @param args Arguments for {@link RuntimeInit#main}.
*/
public static void execApplication(String niceName, int targetSdkVersion,
- String instructionSet, String[] args) {
+ String instructionSet, int runtimeFlags, String[] args) {
int niceArgs = niceName == null ? 0 : 1;
- int baseArgs = 5 + niceArgs;
+ int baseArgs = 6 + niceArgs;
String[] argv = new String[baseArgs + args.length];
if (VMRuntime.is64BitInstructionSet(instructionSet)) {
argv[0] = "/system/bin/app_process64";
@@ -68,6 +73,7 @@ public static void execApplication(String niceName, int targetSdkVersion,
}
argv[3 + niceArgs] = "com.android.internal.os.ExecInit";
argv[4 + niceArgs] = Integer.toString(targetSdkVersion);
+ argv[5 + niceArgs] = Integer.toString(runtimeFlags);
System.arraycopy(args, 0, argv, baseArgs, args.length);
WrapperInit.preserveCapabilities();
diff --git a/core/java/com/android/internal/os/Zygote.java b/core/java/com/android/internal/os/Zygote.java
index a7d9827855a2..aa874ad98a78 100644
--- a/core/java/com/android/internal/os/Zygote.java
+++ b/core/java/com/android/internal/os/Zygote.java
@@ -1097,4 +1097,13 @@ static void appendQuotedShellArgs(StringBuilder command, String[] args) {
* fully-feature Memory Tagging, rather than the static Tagged Pointers.
*/
public static native boolean nativeSupportsTaggedPointers();
+
+ /**
+ * Used on GrapheneOS to set up runtime flags
+ *
+ * @param runtimeFlags flags to be passed to the native method
+ *
+ * @hide
+ */
+ public static native void nativeHandleRuntimeFlags(int runtimeFlags);
}
diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java
index 9b4664178530..4ae69677f1dd 100644
--- a/core/java/com/android/internal/os/ZygoteConnection.java
+++ b/core/java/com/android/internal/os/ZygoteConnection.java
@@ -505,7 +505,7 @@ private Runnable handleChildProc(ZygoteArguments parsedArgs,
if (SystemProperties.getBoolean("sys.spawn.exec", true) &&
(parsedArgs.mRuntimeFlags & ApplicationInfo.FLAG_DEBUGGABLE) == 0) {
ExecInit.execApplication(parsedArgs.mNiceName, parsedArgs.mTargetSdkVersion,
- VMRuntime.getCurrentInstructionSet(), parsedArgs.mRemainingArgs);
+ VMRuntime.getCurrentInstructionSet(), parsedArgs.mRuntimeFlags, parsedArgs.mRemainingArgs);
// Should not get here.
throw new IllegalStateException("ExecInit.execApplication unexpectedly returned");
diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp
index 9eede83e21e5..cb4bde87916b 100644
--- a/core/jni/com_android_internal_os_Zygote.cpp
+++ b/core/jni/com_android_internal_os_Zygote.cpp
@@ -1599,6 +1599,46 @@ static void BindMountStorageDirs(JNIEnv* env, jobjectArray pkg_data_info_list,
}
}
+static void HandleRuntimeFlags(JNIEnv* env, jint& runtime_flags) {
+ // Set process properties to enable debugging if required.
+ if ((runtime_flags & RuntimeFlags::DEBUG_ENABLE_JDWP) != 0) {
+ EnableDebugger();
+ }
+ if ((runtime_flags & RuntimeFlags::PROFILE_FROM_SHELL) != 0) {
+ // simpleperf needs the process to be dumpable to profile it.
+ if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) {
+ ALOGE("prctl(PR_SET_DUMPABLE) failed: %s", strerror(errno));
+ RuntimeAbort(env, __LINE__, "prctl(PR_SET_DUMPABLE, 1) failed");
+ }
+ }
+
+ HeapTaggingLevel heap_tagging_level;
+ switch (runtime_flags & RuntimeFlags::MEMORY_TAG_LEVEL_MASK) {
+ case RuntimeFlags::MEMORY_TAG_LEVEL_TBI:
+ heap_tagging_level = M_HEAP_TAGGING_LEVEL_TBI;
+ break;
+ default:
+ heap_tagging_level = M_HEAP_TAGGING_LEVEL_NONE;
+ }
+ android_mallopt(M_SET_HEAP_TAGGING_LEVEL, &heap_tagging_level, sizeof(heap_tagging_level));
+ // Now that we've used the flag, clear it so that we don't pass unknown flags to the ART runtime.
+ runtime_flags &= ~RuntimeFlags::MEMORY_TAG_LEVEL_MASK;
+
+ bool forceEnableGwpAsan = false;
+ switch (runtime_flags & RuntimeFlags::GWP_ASAN_LEVEL_MASK) {
+ default:
+ case RuntimeFlags::GWP_ASAN_LEVEL_NEVER:
+ break;
+ case RuntimeFlags::GWP_ASAN_LEVEL_ALWAYS:
+ forceEnableGwpAsan = true;
+ [[fallthrough]];
+ case RuntimeFlags::GWP_ASAN_LEVEL_LOTTERY:
+ android_mallopt(M_INITIALIZE_GWP_ASAN, &forceEnableGwpAsan, sizeof(forceEnableGwpAsan));
+ }
+ // Now that we've used the flag, clear it so that we don't pass unknown flags to the ART runtime.
+ runtime_flags &= ~RuntimeFlags::GWP_ASAN_LEVEL_MASK;
+}
+
// Utility routine to specialize a zygote child process.
static void SpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray gids,
jint runtime_flags, jobjectArray rlimits,
@@ -1716,43 +1756,7 @@ static void SpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray gids,
}
}
- // Set process properties to enable debugging if required.
- if ((runtime_flags & RuntimeFlags::DEBUG_ENABLE_JDWP) != 0) {
- EnableDebugger();
- }
- if ((runtime_flags & RuntimeFlags::PROFILE_FROM_SHELL) != 0) {
- // simpleperf needs the process to be dumpable to profile it.
- if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) {
- ALOGE("prctl(PR_SET_DUMPABLE) failed: %s", strerror(errno));
- RuntimeAbort(env, __LINE__, "prctl(PR_SET_DUMPABLE, 1) failed");
- }
- }
-
- HeapTaggingLevel heap_tagging_level;
- switch (runtime_flags & RuntimeFlags::MEMORY_TAG_LEVEL_MASK) {
- case RuntimeFlags::MEMORY_TAG_LEVEL_TBI:
- heap_tagging_level = M_HEAP_TAGGING_LEVEL_TBI;
- break;
- default:
- heap_tagging_level = M_HEAP_TAGGING_LEVEL_NONE;
- }
- android_mallopt(M_SET_HEAP_TAGGING_LEVEL, &heap_tagging_level, sizeof(heap_tagging_level));
- // Now that we've used the flag, clear it so that we don't pass unknown flags to the ART runtime.
- runtime_flags &= ~RuntimeFlags::MEMORY_TAG_LEVEL_MASK;
-
- bool forceEnableGwpAsan = false;
- switch (runtime_flags & RuntimeFlags::GWP_ASAN_LEVEL_MASK) {
- default:
- case RuntimeFlags::GWP_ASAN_LEVEL_NEVER:
- break;
- case RuntimeFlags::GWP_ASAN_LEVEL_ALWAYS:
- forceEnableGwpAsan = true;
- [[fallthrough]];
- case RuntimeFlags::GWP_ASAN_LEVEL_LOTTERY:
- android_mallopt(M_INITIALIZE_GWP_ASAN, &forceEnableGwpAsan, sizeof(forceEnableGwpAsan));
- }
- // Now that we've used the flag, clear it so that we don't pass unknown flags to the ART runtime.
- runtime_flags &= ~RuntimeFlags::GWP_ASAN_LEVEL_MASK;
+ HandleRuntimeFlags(env, runtime_flags);
if (NeedsNoRandomizeWorkaround()) {
// Work around ARM kernel ASLR lossage (http://b/5817320).
@@ -2441,6 +2445,10 @@ static jboolean com_android_internal_os_Zygote_nativeSupportsTaggedPointers(JNIE
#endif
}
+static void nativeHandleRuntimeFlagsWrapper(JNIEnv* env, jclass, jint runtime_flags) {
+ HandleRuntimeFlags(env, runtime_flags);
+}
+
static const JNINativeMethod gMethods[] = {
{"nativeForkAndSpecialize",
"(II[II[[IILjava/lang/String;Ljava/lang/String;[I[IZLjava/lang/String;Ljava/lang/"
@@ -2478,6 +2486,7 @@ static const JNINativeMethod gMethods[] = {
(void*)com_android_internal_os_Zygote_nativeParseSigChld},
{"nativeSupportsTaggedPointers", "()Z",
(void*)com_android_internal_os_Zygote_nativeSupportsTaggedPointers},
+ {"nativeHandleRuntimeFlags", "(I)V", (void*)nativeHandleRuntimeFlagsWrapper},
};
int register_com_android_internal_os_Zygote(JNIEnv* env) {

View File

@ -0,0 +1,25 @@
From ac1943345ec96411ecbac3ce9b15cb371cc03551 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 21 May 2019 23:54:20 -0400
Subject: [PATCH] disable exec spawning when using debugging options
The debugging options are not yet supported probably, so disable exec
spawning when doing debugging.
---
core/java/com/android/internal/os/ZygoteConnection.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java
index a702e84813fa..9b4664178530 100644
--- a/core/java/com/android/internal/os/ZygoteConnection.java
+++ b/core/java/com/android/internal/os/ZygoteConnection.java
@@ -502,7 +502,8 @@ private Runnable handleChildProc(ZygoteArguments parsedArgs,
throw new IllegalStateException("WrapperInit.execApplication unexpectedly returned");
} else {
if (!isZygote) {
- if (SystemProperties.getBoolean("sys.spawn.exec", true)) {
+ if (SystemProperties.getBoolean("sys.spawn.exec", true) &&
+ (parsedArgs.mRuntimeFlags & ApplicationInfo.FLAG_DEBUGGABLE) == 0) {
ExecInit.execApplication(parsedArgs.mNiceName, parsedArgs.mTargetSdkVersion,
VMRuntime.getCurrentInstructionSet(), parsedArgs.mRemainingArgs);

View File

@ -0,0 +1,47 @@
From 1abb8050413dae6ac6c1a082a38fb555c88534b9 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:24:21 -0400
Subject: [PATCH] add parameter for avoiding full preload with exec
---
core/java/com/android/internal/os/ExecInit.java | 2 +-
core/java/com/android/internal/os/ZygoteInit.java | 6 +++++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/core/java/com/android/internal/os/ExecInit.java b/core/java/com/android/internal/os/ExecInit.java
index 2adcab7fdbe6..830e5b562a91 100644
--- a/core/java/com/android/internal/os/ExecInit.java
+++ b/core/java/com/android/internal/os/ExecInit.java
@@ -33,7 +33,7 @@ public static void main(String[] args) {
// Mimic system Zygote preloading.
ZygoteInit.preload(new TimingsTraceLog("ExecInitTiming",
- Trace.TRACE_TAG_DALVIK));
+ Trace.TRACE_TAG_DALVIK), false);
// Launch the application.
String[] runtimeArgs = new String[args.length - 1];
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 2e32730a6ecb..b9460f56d003 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -125,7 +125,7 @@
private static boolean sPreloadComplete;
- static void preload(TimingsTraceLog bootTimingsTraceLog) {
+ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
Log.d(TAG, "begin preload");
bootTimingsTraceLog.traceBegin("BeginPreload");
beginPreload();
@@ -157,6 +157,10 @@ static void preload(TimingsTraceLog bootTimingsTraceLog) {
sPreloadComplete = true;
}
+ static void preload(TimingsTraceLog bootTimingsTraceLog) {
+ preload(bootTimingsTraceLog, true);
+ }
+
public static void lazyPreload() {
Preconditions.checkState(!sPreloadComplete);
Log.i(TAG, "Lazily preloading resources.");

View File

@ -0,0 +1,50 @@
From 2e07ab8c242551e6847bffef84546ed5eaf345cf Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Wed, 11 Sep 2019 06:43:55 -0400
Subject: [PATCH] pass through fullPreload to libcore
---
core/java/com/android/internal/os/ZygoteInit.java | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index b9460f56d003..467183355515 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -128,7 +128,7 @@
static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
Log.d(TAG, "begin preload");
bootTimingsTraceLog.traceBegin("BeginPreload");
- beginPreload();
+ beginPreload(fullPreload);
bootTimingsTraceLog.traceEnd(); // BeginPreload
bootTimingsTraceLog.traceBegin("PreloadClasses");
preloadClasses();
@@ -150,7 +150,7 @@ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
// Ask the WebViewFactory to do any initialization that must run in the zygote process,
// for memory sharing purposes.
WebViewFactory.prepareWebViewInZygote();
- endPreload();
+ endPreload(fullPreload);
warmUpJcaProviders();
Log.d(TAG, "end preload");
@@ -168,14 +168,14 @@ public static void lazyPreload() {
preload(new TimingsTraceLog("ZygoteInitTiming_lazy", Trace.TRACE_TAG_DALVIK));
}
- private static void beginPreload() {
+ private static void beginPreload(boolean fullPreload) {
Log.i(TAG, "Calling ZygoteHooks.beginPreload()");
- ZygoteHooks.onBeginPreload();
+ ZygoteHooks.onBeginPreload(fullPreload);
}
- private static void endPreload() {
- ZygoteHooks.onEndPreload();
+ private static void endPreload(boolean fullPreload) {
+ ZygoteHooks.onEndPreload(fullPreload);
Log.i(TAG, "Called ZygoteHooks.endPreload()");
}

View File

@ -0,0 +1,28 @@
From 0044836677b9be153e04a91dddddcb74d9585643 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:28:27 -0400
Subject: [PATCH] disable OpenGL preloading for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 467183355515..e93e70443ee6 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -142,9 +142,11 @@ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadAppProcessHALs");
nativePreloadAppProcessHALs();
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
- Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadGraphicsDriver");
- maybePreloadGraphicsDriver();
- Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
+ if (fullPreload) {
+ Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadGraphicsDriver");
+ maybePreloadGraphicsDriver();
+ Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
+ }
preloadSharedLibraries();
preloadTextResources();
// Ask the WebViewFactory to do any initialization that must run in the zygote process,

View File

@ -0,0 +1,28 @@
From c561811fad950dce791ef9941753ef95076da4c0 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:28:52 -0400
Subject: [PATCH] disable resource preloading for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index e93e70443ee6..2d1f301668a4 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -136,9 +136,11 @@ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
bootTimingsTraceLog.traceBegin("CacheNonBootClasspathClassLoaders");
cacheNonBootClasspathClassLoaders();
bootTimingsTraceLog.traceEnd(); // CacheNonBootClasspathClassLoaders
- bootTimingsTraceLog.traceBegin("PreloadResources");
- preloadResources();
- bootTimingsTraceLog.traceEnd(); // PreloadResources
+ if (fullPreload) {
+ bootTimingsTraceLog.traceBegin("PreloadResources");
+ preloadResources();
+ bootTimingsTraceLog.traceEnd(); // PreloadResources
+ }
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadAppProcessHALs");
nativePreloadAppProcessHALs();
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);

View File

@ -0,0 +1,28 @@
From 7a848373efa0bd5b948af7ade19927a8706f9ea2 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:30:59 -0400
Subject: [PATCH] disable class preloading for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 2d1f301668a4..b7246d0ac5ce 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -130,9 +130,11 @@ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
bootTimingsTraceLog.traceBegin("BeginPreload");
beginPreload(fullPreload);
bootTimingsTraceLog.traceEnd(); // BeginPreload
- bootTimingsTraceLog.traceBegin("PreloadClasses");
- preloadClasses();
- bootTimingsTraceLog.traceEnd(); // PreloadClasses
+ if (fullPreload) {
+ bootTimingsTraceLog.traceBegin("PreloadClasses");
+ preloadClasses();
+ bootTimingsTraceLog.traceEnd(); // PreloadClasses
+ }
bootTimingsTraceLog.traceBegin("CacheNonBootClasspathClassLoaders");
cacheNonBootClasspathClassLoaders();
bootTimingsTraceLog.traceEnd(); // CacheNonBootClasspathClassLoaders

View File

@ -0,0 +1,28 @@
From 89646bdeb19463424158544c6942224320e9e180 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:31:29 -0400
Subject: [PATCH] disable WebView reservation for exec spawning
---
core/java/com/android/internal/os/ZygoteInit.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index b7246d0ac5ce..04a323254c72 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -153,9 +153,11 @@ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
}
preloadSharedLibraries();
preloadTextResources();
- // Ask the WebViewFactory to do any initialization that must run in the zygote process,
- // for memory sharing purposes.
- WebViewFactory.prepareWebViewInZygote();
+ if (fullPreload) {
+ // Ask the WebViewFactory to do any initialization that must run in the zygote process,
+ // for memory sharing purposes.
+ WebViewFactory.prepareWebViewInZygote();
+ }
endPreload(fullPreload);
warmUpJcaProviders();
Log.d(TAG, "end preload");

View File

@ -0,0 +1,57 @@
From 2a70bbac4a8342175971498084494845b4f24546 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Tue, 14 May 2019 14:34:32 -0400
Subject: [PATCH] disable JCA provider warm up for exec spawning
---
.../com/android/internal/os/ZygoteInit.java | 22 ++++++++++---------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 04a323254c72..ad3b95ec67fc 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -159,7 +159,7 @@ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) {
WebViewFactory.prepareWebViewInZygote();
}
endPreload(fullPreload);
- warmUpJcaProviders();
+ warmUpJcaProviders(fullPreload);
Log.d(TAG, "end preload");
sPreloadComplete = true;
@@ -229,7 +229,7 @@ private static void preloadTextResources() {
* By doing it here we avoid that each app does it when requesting a service from the provider
* for the first time.
*/
- private static void warmUpJcaProviders() {
+ private static void warmUpJcaProviders(boolean fullPreload) {
long startTime = SystemClock.uptimeMillis();
Trace.traceBegin(
Trace.TRACE_TAG_DALVIK, "Starting installation of AndroidKeyStoreProvider");
@@ -241,15 +241,17 @@ private static void warmUpJcaProviders() {
+ (SystemClock.uptimeMillis() - startTime) + "ms.");
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
- startTime = SystemClock.uptimeMillis();
- Trace.traceBegin(
- Trace.TRACE_TAG_DALVIK, "Starting warm up of JCA providers");
- for (Provider p : Security.getProviders()) {
- p.warmUpServiceProvision();
+ if (fullPreload) {
+ startTime = SystemClock.uptimeMillis();
+ Trace.traceBegin(
+ Trace.TRACE_TAG_DALVIK, "Starting warm up of JCA providers");
+ for (Provider p : Security.getProviders()) {
+ p.warmUpServiceProvision();
+ }
+ Log.i(TAG, "Warmed up JCA providers in "
+ + (SystemClock.uptimeMillis() - startTime) + "ms.");
+ Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
}
- Log.i(TAG, "Warmed up JCA providers in "
- + (SystemClock.uptimeMillis() - startTime) + "ms.");
- Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
}
/**

View File

@ -0,0 +1,47 @@
From 4c2635390c10512b0c79ee1f3658a25d6b671ca0 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Wed, 11 Sep 2019 06:46:38 -0400
Subject: [PATCH] add parameter for avoiding full preload with exec
---
dalvik/src/main/java/dalvik/system/ZygoteHooks.java | 4 ++--
mmodules/core_platform_api/api/platform/current-api.txt | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/dalvik/src/main/java/dalvik/system/ZygoteHooks.java b/dalvik/src/main/java/dalvik/system/ZygoteHooks.java
index 7e8fe3651e..de5a056143 100644
--- a/dalvik/src/main/java/dalvik/system/ZygoteHooks.java
+++ b/dalvik/src/main/java/dalvik/system/ZygoteHooks.java
@@ -48,7 +48,7 @@ private ZygoteHooks() {
* Called when the zygote begins preloading classes and data.
*/
@libcore.api.CorePlatformApi
- public static void onBeginPreload() {
+ public static void onBeginPreload(boolean fullPreload) {
// Pin ICU data in memory from this point that would normally be held by soft references.
// Without this, any references created immediately below or during class preloading
// would be collected when the Zygote GC runs in gcAndFinalize().
@@ -71,7 +71,7 @@ public static void onBeginPreload() {
* Called when the zygote has completed preloading classes and data.
*/
@libcore.api.CorePlatformApi
- public static void onEndPreload() {
+ public static void onEndPreload(boolean fullPreload) {
// All cache references created by ICU from this point will be soft.
CacheValue.setStrength(CacheValue.Strength.SOFT);
diff --git a/mmodules/core_platform_api/api/platform/current-api.txt b/mmodules/core_platform_api/api/platform/current-api.txt
index 15a0a48d8c..ac810f45fa 100644
--- a/mmodules/core_platform_api/api/platform/current-api.txt
+++ b/mmodules/core_platform_api/api/platform/current-api.txt
@@ -745,8 +745,8 @@ package dalvik.system {
public final class ZygoteHooks {
method public static void gcAndFinalize();
- method public static void onBeginPreload();
- method public static void onEndPreload();
+ method public static void onBeginPreload(boolean);
+ method public static void onEndPreload(boolean);
method public static void postForkChild(int, boolean, boolean, String);
method public static void postForkCommon();
method public static void postForkSystemServer(int);

View File

@ -0,0 +1,53 @@
From add34a4bc6aa69f21f012d62215b5af500bea551 Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Wed, 11 Sep 2019 06:47:11 -0400
Subject: [PATCH] disable ICU cache pinning for exec spawning
---
.../main/java/dalvik/system/ZygoteHooks.java | 26 +++++++++++--------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/dalvik/src/main/java/dalvik/system/ZygoteHooks.java b/dalvik/src/main/java/dalvik/system/ZygoteHooks.java
index de5a056143..e77cec2517 100644
--- a/dalvik/src/main/java/dalvik/system/ZygoteHooks.java
+++ b/dalvik/src/main/java/dalvik/system/ZygoteHooks.java
@@ -49,15 +49,17 @@ private ZygoteHooks() {
*/
@libcore.api.CorePlatformApi
public static void onBeginPreload(boolean fullPreload) {
- // Pin ICU data in memory from this point that would normally be held by soft references.
- // Without this, any references created immediately below or during class preloading
- // would be collected when the Zygote GC runs in gcAndFinalize().
- CacheValue.setStrength(CacheValue.Strength.STRONG);
-
- // Explicitly exercise code to cache data apps are likely to need.
- ULocale[] localesToPin = { ULocale.ROOT, ULocale.US, ULocale.getDefault() };
- for (ULocale uLocale : localesToPin) {
- new DecimalFormatSymbols(uLocale);
+ if (fullPreload) {
+ // Pin ICU data in memory from this point that would normally be held by soft references.
+ // Without this, any references created immediately below or during class preloading
+ // would be collected when the Zygote GC runs in gcAndFinalize().
+ CacheValue.setStrength(CacheValue.Strength.STRONG);
+
+ // Explicitly exercise code to cache data apps are likely to need.
+ ULocale[] localesToPin = { ULocale.ROOT, ULocale.US, ULocale.getDefault() };
+ for (ULocale uLocale : localesToPin) {
+ new DecimalFormatSymbols(uLocale);
+ }
}
// Framework's LocalLog is used during app start-up. It indirectly uses the current ICU time
@@ -72,8 +74,10 @@ public static void onBeginPreload(boolean fullPreload) {
*/
@libcore.api.CorePlatformApi
public static void onEndPreload(boolean fullPreload) {
- // All cache references created by ICU from this point will be soft.
- CacheValue.setStrength(CacheValue.Strength.SOFT);
+ if (fullPreload) {
+ // All cache references created by ICU from this point will be soft.
+ CacheValue.setStrength(CacheValue.Strength.SOFT);
+ }
// Clone standard descriptors as originals closed / rebound during zygote post fork.
FileDescriptor.in.cloneForFork();

View File

@ -119,7 +119,18 @@ if enterAndClear "frameworks/base"; then
applyPatch "$DOS_PATCHES/android_frameworks_base/0007-Always_Restict_Serial.patch"; #Always restrict access to Build.SERIAL (GrapheneOS)
applyPatch "$DOS_PATCHES/android_frameworks_base/0008-Browser_No_Location.patch"; #Don't grant location permission to system browsers (GrapheneOS)
applyPatch "$DOS_PATCHES/android_frameworks_base/0009-SystemUI_No_Permission_Review.patch"; #Allow SystemUI to directly manage Bluetooth/WiFi (GrapheneOS)
if [ "$DOS_GRAPHENE_EXEC" = true ]; then applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning.patch"; fi; #Add exec-based spawning support (GrapheneOS)
if [ "$DOS_GRAPHENE_EXEC" = true ]; then
applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning-1.patch"; #Add exec-based spawning support (GrapheneOS)
applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning-2.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning-3.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning-4.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning-5.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning-6.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning-7.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning-8.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning-9.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning-10.patch";
fi;
applyPatch "$DOS_PATCHES_COMMON/android_frameworks_base/0003-SUPL_No_IMSI.patch"; #Don't send IMSI to SUPL (MSe1969)
applyPatch "$DOS_PATCHES_COMMON/android_frameworks_base/0004-Fingerprint_Lockout.patch"; #Enable fingerprint lockout after three failed attempts (GrapheneOS)
applyPatch "$DOS_PATCHES_COMMON/android_frameworks_base/0005-User_Logout.patch"; #Allow user logout (GrapheneOS)

View File

@ -113,7 +113,20 @@ if enterAndClear "frameworks/base"; then
applyPatch "$DOS_PATCHES/android_frameworks_base/0007-Always_Restict_Serial.patch"; #Always restrict access to Build.SERIAL (GrapheneOS)
applyPatch "$DOS_PATCHES/android_frameworks_base/0008-Browser_No_Location.patch"; #Don't grant location permission to system browsers (GrapheneOS)
applyPatch "$DOS_PATCHES/android_frameworks_base/0009-SystemUI_No_Permission_Review.patch"; #Allow SystemUI to directly manage Bluetooth/WiFi (GrapheneOS)
if [ "$DOS_GRAPHENE_EXEC" = true ]; then applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning.patch"; fi; #add exec-based spawning support (GrapheneOS)
if [ "$DOS_GRAPHENE_EXEC" = true ]; then
applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning-1.patch"; #Add exec-based spawning support (GrapheneOS)
applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning-2.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning-3.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning-4.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning-5.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning-6.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning-7.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning-8.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning-9.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning-10.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning-11.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0010-Exec_Based_Spawning-12.patch";
fi;
applyPatch "$DOS_PATCHES/android_frameworks_base/0003-SUPL_No_IMSI.patch"; #Don't send IMSI to SUPL (MSe1969)
applyPatch "$DOS_PATCHES/android_frameworks_base/0004-Fingerprint_Lockout.patch"; #Enable fingerprint lockout after three failed attempts (GrapheneOS)
applyPatch "$DOS_PATCHES_COMMON/android_frameworks_base/0005-User_Logout.patch"; #Allow user logout (GrapheneOS)
@ -203,8 +216,10 @@ applyPatch "$DOS_PATCHES/android_hardware_qcom_audio/0001-Unused-sm8150.patch";
fi;
if enterAndClear "libcore"; then
if [ "$DOS_GRAPHENE_EXEC" = true ]; then applyPatch "$DOS_PATCHES/android_libcore/0001-Exec_Preload.patch"; fi; #Add exec-based spawning support (GrapheneOS)
if [ "$DOS_GRAPHENE_EXEC" = true ]; then applyPatch "$DOS_PATCHES/android_libcore/0002-Exec_Based_Spawning.patch"; fi;
if [ "$DOS_GRAPHENE_EXEC" = true ]; then
applyPatch "$DOS_PATCHES/android_libcore/0001-Exec_Based_Spawning-1.patch"; #Add exec-based spawning support (GrapheneOS)
applyPatch "$DOS_PATCHES/android_libcore/0001-Exec_Based_Spawning-2.patch";
fi;
if [ "$DOS_GRAPHENE_NETWORK_PERM" = true ]; then applyPatch "$DOS_PATCHES/android_libcore/0003-Network_Permission.patch"; fi; #Expose the NETWORK permission (GrapheneOS)
if [ "$DOS_GRAPHENE_CONSTIFY" = true ]; then applyPatch "$DOS_PATCHES/android_libcore/0004-constify_JNINativeMethod.patch"; fi; #Constify JNINativeMethod tables (GrapheneOS)
fi;

View File

@ -67,6 +67,7 @@ if enterAndClear "build/make"; then
git revert --no-edit def3f14af17ae92192d2cc7d22349cabfa906fd6; #Re-enable the downgrade check
applyPatch "$DOS_PATCHES/android_build/0001-Enable_fwrapv.patch"; #Use -fwrapv at a minimum (GrapheneOS)
applyPatch "$DOS_PATCHES/android_build/0002-OTA_Keys.patch"; #Add correct keys to recovery for OTA verification
if [ "$DOS_GRAPHENE_EXEC" = true ]; then applyPatch "$DOS_PATCHES/android_build/0003-Exec_Based_Spawning.patch"; fi; #Add exec-based spawning support (GrapheneOS)
sed -i '75i$(my_res_package): PRIVATE_AAPT_FLAGS += --auto-add-overlay' core/aapt2.mk; #Enable auto-add-overlay for packages, this allows the vendor overlay to easily work across all branches.
if [ "$DOS_SILENCE_INCLUDED" = true ]; then sed -i 's/messaging/Silence/' target/product/aosp_base_telephony.mk target/product/aosp_product.mk; fi; #Replace the Messaging app with Silence
awk -i inplace '!/updatable_apex.mk/' target/product/mainline_system.mk; #Disable APEX
@ -115,6 +116,20 @@ applyPatch "$DOS_PATCHES/android_frameworks_base/0014-Automatic_Reboot.patch"; #
applyPatch "$DOS_PATCHES/android_frameworks_base/0015-Bluetooth_Timeout.patch"; #Timeout for Bluetooth (GrapheneOS)
applyPatch "$DOS_PATCHES/android_frameworks_base/0016-WiFi_Timeout.patch"; #Timeout for Wi-Fi (GrapheneOS)
if [ "$DOS_GRAPHENE_CONSTIFY" = true ]; then applyPatch "$DOS_PATCHES/android_frameworks_base/0017-constify_JNINativeMethod.patch"; fi; #Constify JNINativeMethod tables (GrapheneOS)
if [ "$DOS_GRAPHENE_EXEC" = true ]; then
applyPatch "$DOS_PATCHES/android_frameworks_base/0018-Exec_Based_Spawning-1.patch"; #Add exec-based spawning support (GrapheneOS)
applyPatch "$DOS_PATCHES/android_frameworks_base/0018-Exec_Based_Spawning-2.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0018-Exec_Based_Spawning-3.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0018-Exec_Based_Spawning-4.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0018-Exec_Based_Spawning-5.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0018-Exec_Based_Spawning-6.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0018-Exec_Based_Spawning-7.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0018-Exec_Based_Spawning-8.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0018-Exec_Based_Spawning-9.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0018-Exec_Based_Spawning-10.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0018-Exec_Based_Spawning-11.patch";
applyPatch "$DOS_PATCHES/android_frameworks_base/0018-Exec_Based_Spawning-12.patch";
fi;
applyPatch "$DOS_PATCHES_COMMON/android_frameworks_base/0006-Do-not-throw-in-setAppOnInterfaceLocked.patch"; #Fix random reboots on broken kernels when an app has data restricted XXX: ugly
if [ "$DOS_MICROG_INCLUDED" = "FULL" ]; then applyPatch "$DOS_PATCHES/android_frameworks_base/0002-Signature_Spoofing.patch"; fi; #Allow packages to spoof their signature (microG)
if [ "$DOS_MICROG_INCLUDED" = "FULL" ]; then applyPatch "$DOS_PATCHES/android_frameworks_base/0003-Harden_Sig_Spoofing.patch"; fi; #Restrict signature spoofing to system apps signed with the platform key
@ -200,6 +215,10 @@ fi;
if enterAndClear "libcore"; then
if [ "$DOS_GRAPHENE_NETWORK_PERM" = true ]; then applyPatch "$DOS_PATCHES/android_libcore/0001-Network_Permission.patch"; fi; #Expose the NETWORK permission (GrapheneOS)
if [ "$DOS_GRAPHENE_CONSTIFY" = true ]; then applyPatch "$DOS_PATCHES/android_libcore/0002-constify_JNINativeMethod.patch"; fi; #Constify JNINativeMethod tables (GrapheneOS)
if [ "$DOS_GRAPHENE_EXEC" = true ]; then
applyPatch "$DOS_PATCHES/android_libcore/0003-Exec_Based_Spawning-1.patch"; #Add exec-based spawning support (GrapheneOS)
applyPatch "$DOS_PATCHES/android_libcore/0003-Exec_Based_Spawning-2.patch";
fi;
fi;
if enterAndClear "lineage-sdk"; then