diff options
author | Lev Rumyantsev <levarum@google.com> | 2020-06-09 23:21:36 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-06-09 23:21:36 +0000 |
commit | afacee21d9d0816f44d420ae4e0bac56b0ebfe2f (patch) | |
tree | 0836a0c8dce0e15b31fe3a9ac5e15c7f32ac2d41 | |
parent | 4c52de5ce8276ea9403a16a03230b57680427378 (diff) | |
parent | 936dc784c809e9f25b0e26685ba915a360516cfa (diff) |
Move set_cached_pid() to __clone_for_fork() am: c8c3bc58a1 am: 936dc784c8
Original change: https://googleplex-android-review.googlesource.com/c/platform/bionic/+/11800686
Change-Id: Id373e1024fae0aef271b7655413567a31e026781
-rw-r--r-- | libc/bionic/fork.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/libc/bionic/fork.cpp b/libc/bionic/fork.cpp index a3fdcd2d5..3814ed0ac 100644 --- a/libc/bionic/fork.cpp +++ b/libc/bionic/fork.cpp @@ -37,8 +37,16 @@ __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)); + int result = clone(nullptr, nullptr, (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD), + nullptr, nullptr, nullptr, &(self->tid)); + + if (result == 0) { + // Update the cached pid in child, since clone() will not set it directly (as + // self->tid is updated by the kernel). + self->set_cached_pid(gettid()); + } + + return result; } int fork() { @@ -47,10 +55,6 @@ int fork() { int result = __clone_for_fork(); if (result == 0) { - // Update the cached pid, since clone() will not set it directly (as - // self->tid is updated by the kernel). - __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. android_fdsan_set_error_level(ANDROID_FDSAN_ERROR_LEVEL_DISABLED); |