Block signals in pthread_create.
HWASan-instrumented code needs TLS_SLOT_SANITIZER set up to run, and
that is not done until the new thread calls __hwasan_thread_enter. Block
all signals until that time to prevent hwasan-instrumented signal
handlers running (and crashing) on the new thread.
Bug: 141893397
Test: seq 0 10000000 | xargs -n 1 -P 200 adb shell am instrument \
-w -r -e command grant-all \
com.android.permissionutils/.PermissionInstrumentation
(cherry picked from commit d181585dd575383ec12c1856efc1bffda24d9a32)
Change-Id: Id65fae836edcacdf057327ccf16cf0b5e0f9474a
diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp
index 0dbf539..1dc1066 100644
--- a/libc/bionic/pthread_create.cpp
+++ b/libc/bionic/pthread_create.cpp
@@ -344,6 +344,8 @@
name);
}
+extern "C" int __rt_sigprocmask(int, const sigset64_t*, sigset64_t*, size_t);
+
__attribute__((no_sanitize("hwaddress")))
static int __pthread_start(void* arg) {
pthread_internal_t* thread = reinterpret_cast<pthread_internal_t*>(arg);
@@ -358,6 +360,7 @@
__set_stack_and_tls_vma_name(false);
__init_additional_stacks(thread);
+ __rt_sigprocmask(SIG_SETMASK, &thread->start_mask, nullptr, sizeof(thread->start_mask));
void* result = thread->start_routine(thread->start_routine_arg);
pthread_exit(result);
@@ -420,7 +423,12 @@
__init_user_desc(&tls_descriptor, false, tls);
tls = &tls_descriptor;
#endif
+
+ sigset64_t block_all_mask;
+ sigfillset64(&block_all_mask);
+ __rt_sigprocmask(SIG_SETMASK, &block_all_mask, &thread->start_mask, sizeof(thread->start_mask));
int rc = clone(__pthread_start, child_stack, flags, thread, &(thread->tid), tls, &(thread->tid));
+ __rt_sigprocmask(SIG_SETMASK, &thread->start_mask, nullptr, sizeof(thread->start_mask));
if (rc == -1) {
int clone_errno = errno;
// We don't have to unlock the mutex at all because clone(2) failed so there's no child waiting to