[libc-commits] [libc] badda4a - [libc] Linux threads - Set CLEAR_TID addr to 0 when exiting a detached thread.
Siva Chandra Reddy via libc-commits
libc-commits at lists.llvm.org
Sun Jul 10 21:44:19 PDT 2022
Author: Siva Chandra Reddy
Date: 2022-07-11T04:42:59Z
New Revision: badda4ac3c489a8c8cccdad1f74b9308c350a9e0
URL: https://github.com/llvm/llvm-project/commit/badda4ac3c489a8c8cccdad1f74b9308c350a9e0
DIFF: https://github.com/llvm/llvm-project/commit/badda4ac3c489a8c8cccdad1f74b9308c350a9e0.diff
LOG: [libc] Linux threads - Set CLEAR_TID addr to 0 when exiting a detached thread.
A detached thread cleans itself up at completion. So, the CLEAR_TID memory is
also gone by the time the kernel tries to signal potential waiters. By nulling
the CLEAR_TID address, we prevent the kernel from signalling at a non-existent
futex location.
Added:
Modified:
libc/src/__support/threads/linux/thread.cpp
Removed:
################################################################################
diff --git a/libc/src/__support/threads/linux/thread.cpp b/libc/src/__support/threads/linux/thread.cpp
index 30c182045eeaf..ff10a1ecbc65b 100644
--- a/libc/src/__support/threads/linux/thread.cpp
+++ b/libc/src/__support/threads/linux/thread.cpp
@@ -119,6 +119,10 @@ static void start_thread() __attribute__((noinline)) {
// Thread is detached so cleanup the resources.
if (attrib->owned_stack)
free_stack(attrib->stack, attrib->stack_size);
+
+ // Set the CLEAR_TID address to nullptr to prevent the kernel
+ // from signalling at a non-existent futex location.
+ __llvm_libc::syscall(SYS_set_tid_address, 0);
}
__llvm_libc::syscall(SYS_exit, retval);
More information about the libc-commits
mailing list