Propagate an is_zygote flag through nativePostForkChild.
This flag is used to skip calling into Runtime::InitNonZygoteOrPostFork()
in child-zygote processes. Doing so would spin up threads for Binder,
which would make the process unable to fork like a zygote.
Bug: 63749735
Test: m (with multi-project commits landed)
Change-Id: I352af061e0ce6bd32e6f30b15ff2f8d3f4b58222
diff --git a/runtime/native/dalvik_system_ZygoteHooks.cc b/runtime/native/dalvik_system_ZygoteHooks.cc
index 12400e2..08e471b 100644
--- a/runtime/native/dalvik_system_ZygoteHooks.cc
+++ b/runtime/native/dalvik_system_ZygoteHooks.cc
@@ -277,7 +277,10 @@
jlong token,
jint runtime_flags,
jboolean is_system_server,
+ jboolean is_zygote,
jstring instruction_set) {
+ DCHECK(!(is_system_server && is_zygote));
+
Thread* thread = reinterpret_cast<Thread*>(token);
// Our system thread ID, etc, has changed so reset Thread state.
thread->InitAfterFork();
@@ -346,13 +349,22 @@
}
}
- DCHECK(!is_system_server || !do_hidden_api_checks)
- << "SystemServer should be forked with DISABLE_HIDDEN_API_CHECKS";
+ DCHECK(!(is_system_server && do_hidden_api_checks))
+ << "SystemServer should be forked with ENABLE_HIDDEN_API_CHECKS";
+ DCHECK(!(is_zygote && do_hidden_api_checks))
+ << "Child zygote processes should be forked with ENABLE_HIDDEN_API_CHECKS";
Runtime::Current()->SetHiddenApiChecksEnabled(do_hidden_api_checks);
// Clear the hidden API warning flag, in case it was set.
Runtime::Current()->SetPendingHiddenApiWarning(false);
+ if (is_zygote) {
+ // If creating a child-zygote, do not call into the runtime's post-fork logic.
+ // Doing so would spin up threads for Binder and JDWP. Instead, the Java side
+ // of the child process will call a static main in a class specified by the parent.
+ return;
+ }
+
if (instruction_set != nullptr && !is_system_server) {
ScopedUtfChars isa_string(env, instruction_set);
InstructionSet isa = GetInstructionSetFromString(isa_string.c_str());
@@ -380,7 +392,7 @@
static JNINativeMethod gMethods[] = {
NATIVE_METHOD(ZygoteHooks, nativePreFork, "()J"),
- NATIVE_METHOD(ZygoteHooks, nativePostForkChild, "(JIZLjava/lang/String;)V"),
+ NATIVE_METHOD(ZygoteHooks, nativePostForkChild, "(JIZZLjava/lang/String;)V"),
NATIVE_METHOD(ZygoteHooks, startZygoteNoThreadCreation, "()V"),
NATIVE_METHOD(ZygoteHooks, stopZygoteNoThreadCreation, "()V"),
};