summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Colin Cross <ccross@android.com> 2023-07-06 16:17:01 -0700
committer Cherrypicker Worker <android-build-cherrypicker-worker@google.com> 2023-07-11 17:09:17 +0000
commit00f5533c3e7581918c4ccd9e905d3abb11b0a04b (patch)
tree5f0ed05e643003b65e16b4938aee875e728a2fe6
parenteaf79c2013ccaa1899d7429815a326e2435059b3 (diff)
Enable ptrace on userdebug when JDWP is disabled
r.android.com/2217921 disabled JDWP on userdebug builds by default in order to avoid the JDWP overhead causing differences between user and userdebug builds. This had the side effect of disabling ptrace, which means libmemunreachable can no longer ptrace app processes, and app processes are no longer debuggable by gdbserver unless it is run as root. Add a new DEBUG_ENABLE_PTRACE zygote runtimeFlag for enabling ptrace, and set it anywhere DEBUG_ENABLE_JDWP was set before r.android.com/2217921. Use the flag to call EnableDebugging. Bug: 285967712 Test: adb shell dumpsys meminfo --unreachable com.android.gallery3d (cherry picked from https://android-review.googlesource.com/q/commit:990b5ec72182b117e34dce85a95868850daa7549) Merged-In: I2fb1aa0aea81400f573b8c2e2fa309b7942d9446 Change-Id: I2fb1aa0aea81400f573b8c2e2fa309b7942d9446
-rw-r--r--core/java/com/android/internal/os/Zygote.java8
-rw-r--r--core/jni/com_android_internal_os_Zygote.cpp5
-rw-r--r--services/core/java/com/android/server/am/ProcessList.java1
3 files changed, 13 insertions, 1 deletions
diff --git a/core/java/com/android/internal/os/Zygote.java b/core/java/com/android/internal/os/Zygote.java
index 20635425362b..0c6d6f98ae24 100644
--- a/core/java/com/android/internal/os/Zygote.java
+++ b/core/java/com/android/internal/os/Zygote.java
@@ -195,6 +195,11 @@ public final class Zygote {
*/
public static final int PROFILEABLE = 1 << 24;
+ /**
+ * Enable ptrace. This is enabled on eng or userdebug builds, or if the app is debuggable.
+ */
+ public static final int DEBUG_ENABLE_PTRACE = 1 << 25;
+
/** No external storage should be mounted. */
public static final int MOUNT_EXTERNAL_NONE = IVold.REMOUNT_MODE_NONE;
/** Default external storage should be mounted. */
@@ -1028,6 +1033,9 @@ public final class Zygote {
if (Build.IS_ENG || ENABLE_JDWP) {
args.mRuntimeFlags |= Zygote.DEBUG_ENABLE_JDWP;
}
+ if (RoSystemProperties.DEBUGGABLE) {
+ args.mRuntimeFlags |= Zygote.DEBUG_ENABLE_PTRACE;
+ }
}
/**
diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp
index ce806a0fcc08..c368fa85c379 100644
--- a/core/jni/com_android_internal_os_Zygote.cpp
+++ b/core/jni/com_android_internal_os_Zygote.cpp
@@ -356,6 +356,7 @@ enum RuntimeFlags : uint32_t {
GWP_ASAN_LEVEL_DEFAULT = 3 << 21,
NATIVE_HEAP_ZERO_INIT_ENABLED = 1 << 23,
PROFILEABLE = 1 << 24,
+ DEBUG_ENABLE_PTRACE = 1 << 25,
};
enum UnsolicitedZygoteMessageTypes : uint32_t {
@@ -1887,8 +1888,10 @@ 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) {
+ if ((runtime_flags & RuntimeFlags::DEBUG_ENABLE_PTRACE) != 0) {
EnableDebugger();
+ // Don't pass unknown flag to the ART runtime.
+ runtime_flags &= ~RuntimeFlags::DEBUG_ENABLE_PTRACE;
}
if ((runtime_flags & RuntimeFlags::PROFILE_FROM_SHELL) != 0) {
// simpleperf needs the process to be dumpable to profile it.
diff --git a/services/core/java/com/android/server/am/ProcessList.java b/services/core/java/com/android/server/am/ProcessList.java
index c5776d822c8f..acd9771c7750 100644
--- a/services/core/java/com/android/server/am/ProcessList.java
+++ b/services/core/java/com/android/server/am/ProcessList.java
@@ -1827,6 +1827,7 @@ public final class ProcessList {
if (debuggableFlag) {
runtimeFlags |= Zygote.DEBUG_ENABLE_JDWP;
+ runtimeFlags |= Zygote.DEBUG_ENABLE_PTRACE;
runtimeFlags |= Zygote.DEBUG_JAVA_DEBUGGABLE;
// Also turn on CheckJNI for debuggable apps. It's quite
// awkward to turn on otherwise.