summaryrefslogtreecommitdiff
path: root/compiler-rt
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2023-05-16 10:41:14 -0700
committerVitaly Buka <vitalybuka@google.com>2023-05-16 10:49:45 -0700
commit0d846d206e709797a8bbe65ec648878dc2853434 (patch)
tree1dc4be2913887b3b9f8e95054b494640ebc3de95 /compiler-rt
parent4d84ed528358996f1aea120ddf8a7a556163993b (diff)
downloadllvm-0d846d206e709797a8bbe65ec648878dc2853434.tar.gz
Revert "[NFC][LSAN] Move ThreadCreate into child thread"
https://bugs.chromium.org/p/chromium/issues/detail?id=1445676 This reverts commit 6d7b26ae49b9273d9aea4e53a96901caeb09efe0.
Diffstat (limited to 'compiler-rt')
-rw-r--r--compiler-rt/lib/lsan/lsan_interceptors.cpp28
1 files changed, 17 insertions, 11 deletions
diff --git a/compiler-rt/lib/lsan/lsan_interceptors.cpp b/compiler-rt/lib/lsan/lsan_interceptors.cpp
index 2a35572edfec..4be34db28c77 100644
--- a/compiler-rt/lib/lsan/lsan_interceptors.cpp
+++ b/compiler-rt/lib/lsan/lsan_interceptors.cpp
@@ -415,10 +415,8 @@ INTERCEPTOR(char *, strerror, int errnum) {
#if SANITIZER_POSIX
-template <bool Detached>
-static void *ThreadStartFunc(void *arg) {
- u32 parent_tid = (uptr)arg;
- uptr tid = ThreadCreate(parent_tid, Detached);
+extern "C" void *__lsan_thread_start_func(void *arg) {
+ atomic_uintptr_t *atomic_tid = (atomic_uintptr_t *)arg;
// Wait until the last iteration to maximize the chance that we are the last
// destructor to run.
#if !SANITIZER_NETBSD && !SANITIZER_FREEBSD
@@ -427,8 +425,12 @@ static void *ThreadStartFunc(void *arg) {
Report("LeakSanitizer: failed to set thread key.\n");
Die();
}
-# endif
+#endif
+ int tid = 0;
+ while ((tid = atomic_load(atomic_tid, memory_order_acquire)) == 0)
+ internal_sched_yield();
ThreadStart(tid, GetTid());
+ atomic_store(atomic_tid, 0, memory_order_release);
auto self = GetThreadSelf();
auto args = GetThreadArgRetval().GetArgs(self);
void *retval = (*args.routine)(args.arg_retval);
@@ -448,7 +450,7 @@ INTERCEPTOR(int, pthread_create, void *th, void *attr,
AdjustStackSize(attr);
int detached = 0;
pthread_attr_getdetachstate(attr, &detached);
- uptr this_tid = GetCurrentThreadId();
+ atomic_uintptr_t atomic_tid = {};
int result;
{
// Ignore all allocations made by pthread_create: thread stack/TLS may be
@@ -457,14 +459,18 @@ INTERCEPTOR(int, pthread_create, void *th, void *attr,
// objects, the latter are calculated by obscure pointer arithmetic.
ScopedInterceptorDisabler disabler;
GetThreadArgRetval().Create(detached, {callback, param}, [&]() -> uptr {
- result = REAL(pthread_create)(th, attr,
- IsStateDetached(detached)
- ? ThreadStartFunc<true>
- : ThreadStartFunc<false>,
- (void *)this_tid);
+ result =
+ REAL(pthread_create)(th, attr, __lsan_thread_start_func, &atomic_tid);
return result ? 0 : *(uptr *)(th);
});
}
+ if (result == 0) {
+ int tid = ThreadCreate(GetCurrentThreadId(), IsStateDetached(detached));
+ CHECK_NE(tid, kMainTid);
+ atomic_store(&atomic_tid, tid, memory_order_release);
+ while (atomic_load(&atomic_tid, memory_order_acquire) != 0)
+ internal_sched_yield();
+ }
if (attr == &myattr)
pthread_attr_destroy(&myattr);
return result;