Merge "Narrow native bridge to clone_for_fork"

This commit is contained in:
Treehugger Robot 2020-06-05 01:24:59 +00:00 committed by Gerrit Code Review
commit 3b23cc7f72

View file

@ -33,23 +33,24 @@
#include "private/bionic_defs.h"
#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.