nativebridge: Add PreZygoteFork callback
It's required to clean-up the emulated enviroment (e.g. close file
descriptors) after emulated execution in doPreload() in app-zygote.
Test: NativeBridge6PreZygoteFork_test
Test: CtsSeccompHostTestCases
android.seccomp.cts.SeccompHostJUnit4DeviceTest
testAppZygoteSyscalls
both for Q.sdk_gphone_x86_arm.armeabi-v7a
Bug: 146904103
Change-Id: Id192a1647c2f405570bf196daf65b3f2a9faca42
diff --git a/libnativebridge/native_bridge.cc b/libnativebridge/native_bridge.cc
index 1a54ace..b24d14a 100644
--- a/libnativebridge/native_bridge.cc
+++ b/libnativebridge/native_bridge.cc
@@ -103,6 +103,8 @@
VENDOR_NAMESPACE_VERSION = 4,
// The version with runtime namespaces
RUNTIME_NAMESPACE_VERSION = 5,
+ // The version with pre-zygote-fork hook to support app-zygotes.
+ PRE_ZYGOTE_FORK_VERSION = 6,
};
// Whether we had an error at some point.
@@ -328,6 +330,17 @@
return true;
}
+void PreZygoteForkNativeBridge() {
+ if (NativeBridgeInitialized()) {
+ if (isCompatibleWith(PRE_ZYGOTE_FORK_VERSION)) {
+ return callbacks->preZygoteFork();
+ } else {
+ ALOGE("not compatible with version %d, preZygoteFork() isn't invoked",
+ PRE_ZYGOTE_FORK_VERSION);
+ }
+ }
+}
+
static void SetCpuAbi(JNIEnv* env, jclass build_class, const char* field, const char* value) {
if (value != nullptr) {
jfieldID field_id = env->GetStaticFieldID(build_class, field, "Ljava/lang/String;");