Intercept __clone_for_fork directly

Test: bionic-unit-tests
Change-Id: I3b709398a543b5fc3e69304ca17448dec52aa406
diff --git a/overriding/libc/Android.bp b/overriding/libc/Android.bp
index 1038d8b..ea08fa1 100644
--- a/overriding/libc/Android.bp
+++ b/overriding/libc/Android.bp
@@ -30,7 +30,6 @@
         "__cxa_thread_atexit_impl.cpp",
         "__libc_add_main_thread.cpp",
         "exit.c",
-        "fork.cpp",
         "malloc_init.cpp",
     ],
 
diff --git a/overriding/libc/fork.cpp b/overriding/libc/fork.cpp
deleted file mode 100644
index aedf248..0000000
--- a/overriding/libc/fork.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "native_bridge_support/vdso/vdso.h"
-
-int __clone_for_fork() {
-  // Guest fork does pre- and post-clone routines for guest.
-  // Call host fork here to do the same for host.
-  return ((int (*)())(native_bridge_find_proxy_library_symbol("libc.so", "fork")))();
-}
diff --git a/overriding/libc/stubs_arm.cpp b/overriding/libc/stubs_arm.cpp
index 1ffa5a9..8823772 100644
--- a/overriding/libc/stubs_arm.cpp
+++ b/overriding/libc/stubs_arm.cpp
@@ -17,6 +17,7 @@
 // clang-format off
 #include "native_bridge_support/vdso/interceptable_functions.h"
 
+DEFINE_INTERCEPTABLE_STUB_FUNCTION(__clone_for_fork);
 DEFINE_INTERCEPTABLE_STUB_FUNCTION(__pthread_cleanup_pop);
 DEFINE_INTERCEPTABLE_STUB_FUNCTION(__pthread_cleanup_push);
 DEFINE_INTERCEPTABLE_STUB_FUNCTION(__system_properties_init);
@@ -88,6 +89,7 @@
 DEFINE_INTERCEPTABLE_STUB_VARIABLE(environ);
 
 static void __attribute__((constructor(0))) init_stub_library() {
+  INIT_INTERCEPTABLE_STUB_FUNCTION("libc.so", __clone_for_fork);
   INIT_INTERCEPTABLE_STUB_FUNCTION("libc.so", __pthread_cleanup_pop);
   INIT_INTERCEPTABLE_STUB_FUNCTION("libc.so", __pthread_cleanup_push);
   INIT_INTERCEPTABLE_STUB_FUNCTION("libc.so", __system_properties_init);
diff --git a/overriding/libc/stubs_arm64.cpp b/overriding/libc/stubs_arm64.cpp
index 1ffa5a9..8823772 100644
--- a/overriding/libc/stubs_arm64.cpp
+++ b/overriding/libc/stubs_arm64.cpp
@@ -17,6 +17,7 @@
 // clang-format off
 #include "native_bridge_support/vdso/interceptable_functions.h"
 
+DEFINE_INTERCEPTABLE_STUB_FUNCTION(__clone_for_fork);
 DEFINE_INTERCEPTABLE_STUB_FUNCTION(__pthread_cleanup_pop);
 DEFINE_INTERCEPTABLE_STUB_FUNCTION(__pthread_cleanup_push);
 DEFINE_INTERCEPTABLE_STUB_FUNCTION(__system_properties_init);
@@ -88,6 +89,7 @@
 DEFINE_INTERCEPTABLE_STUB_VARIABLE(environ);
 
 static void __attribute__((constructor(0))) init_stub_library() {
+  INIT_INTERCEPTABLE_STUB_FUNCTION("libc.so", __clone_for_fork);
   INIT_INTERCEPTABLE_STUB_FUNCTION("libc.so", __pthread_cleanup_pop);
   INIT_INTERCEPTABLE_STUB_FUNCTION("libc.so", __pthread_cleanup_push);
   INIT_INTERCEPTABLE_STUB_FUNCTION("libc.so", __system_properties_init);