diff options
author | Lev Rumyantsev <levarum@google.com> | 2020-06-01 18:43:55 -0700 |
---|---|---|
committer | Lev Rumyantsev <levarum@google.com> | 2020-06-09 19:36:36 +0000 |
commit | 018f4a13108cd686b8745308ebf79471791706b4 (patch) | |
tree | 2229c51ec884e834cb6c30b516c81bbadc771a92 | |
parent | c3b3e869cecaafffac301b26d6fd6be821f574f9 (diff) | |
download | bionic-018f4a13108cd686b8745308ebf79471791706b4.tar.gz |
Narrow native bridge to clone_for_fork
We are removing native bridge copy of fork.cpp, but need to
replace call to clone() when it's done for bionic's fork.
The code here will run all pre-/post-clone routines for *guest*,
while native bridge implementation will need to run the
corresponding *host* routines.
Bug: 145028007
Test: bionic-unit-tests
Merged-In: Ic5524e743caa287d7aaa8dc7e5d34acd1c7e1170
Change-Id: Ic5524e743caa287d7aaa8dc7e5d34acd1c7e1170
(cherry picked from commit 41127dca3d08e5eb350b678ee03eae30ab779921)
-rw-r--r-- | libc/bionic/fork.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/libc/bionic/fork.cpp b/libc/bionic/fork.cpp index cda5e8533..c9a1ca839 100644 --- a/libc/bionic/fork.cpp +++ b/libc/bionic/fork.cpp @@ -34,22 +34,23 @@ #include "pthread_internal.h" __BIONIC_WEAK_FOR_NATIVE_BRIDGE +int __clone_for_fork() { + pthread_internal_t* self = __get_thread(); + + return clone(nullptr, nullptr, (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD), nullptr, + nullptr, nullptr, &(self->tid)); +} + +__BIONIC_WEAK_FOR_NATIVE_BRIDGE int fork() { __bionic_atfork_run_prepare(); - pthread_internal_t* self = __get_thread(); + int result = __clone_for_fork(); - int result = clone(nullptr, - nullptr, - (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD), - nullptr, - nullptr, - nullptr, - &(self->tid)); if (result == 0) { // Update the cached pid, since clone() will not set it directly (as // self->tid is updated by the kernel). - self->set_cached_pid(gettid()); + __get_thread()->set_cached_pid(gettid()); // Disable fdsan post-fork, so we don't falsely trigger on processes that // fork, close all of their fds blindly, and then exec. |