diff --git a/compiler-rt/lib/asan/asan_thread.cpp b/compiler-rt/lib/asan/asan_thread.cpp --- a/compiler-rt/lib/asan/asan_thread.cpp +++ b/compiler-rt/lib/asan/asan_thread.cpp @@ -482,7 +482,7 @@ void UnlockThreadRegistry() { __asan::asanThreadRegistry().Unlock(); } -ThreadRegistry *GetThreadRegistryLocked() { +static ThreadRegistry *GetAsanThreadRegistryLocked() { __asan::asanThreadRegistry().CheckLocked(); return &__asan::asanThreadRegistry(); } @@ -518,6 +518,15 @@ fake_stack->ForEachFakeFrame(callback, arg); } +void RunCallbackForEachThreadLocked(__sanitizer::ThreadRegistry::ThreadCallback cb, + void *arg) { + GetAsanThreadRegistryLocked()->RunCallbackForEachThreadLocked(cb, arg); +} + +void FinishThreadLocked(u32 tid) { + GetAsanThreadRegistryLocked()->FinishThread(tid); +} + } // namespace __lsan // ---------------------- Interface ---------------- {{{1 diff --git a/compiler-rt/lib/lsan/lsan_common.h b/compiler-rt/lib/lsan/lsan_common.h --- a/compiler-rt/lib/lsan/lsan_common.h +++ b/compiler-rt/lib/lsan/lsan_common.h @@ -21,6 +21,7 @@ #include "sanitizer_common/sanitizer_stackdepot.h" #include "sanitizer_common/sanitizer_stoptheworld.h" #include "sanitizer_common/sanitizer_symbolizer.h" +#include "sanitizer_common/sanitizer_thread_registry.h" // LeakSanitizer relies on some Glibc's internals (e.g. TLS machinery) on Linux. // Also, LSan doesn't like 32 bit architectures @@ -90,7 +91,6 @@ // Wrappers for ThreadRegistry access. void LockThreadRegistry() SANITIZER_NO_THREAD_SAFETY_ANALYSIS; void UnlockThreadRegistry() SANITIZER_NO_THREAD_SAFETY_ANALYSIS; -ThreadRegistry *GetThreadRegistryLocked(); // If called from the main thread, updates the main thread's TID in the thread // registry. We need this to handle processes that fork() without a subsequent // exec(), which invalidates the recorded TID. To update it, we must call @@ -106,6 +106,10 @@ void ForEachExtraStackRange(tid_t os_id, RangeIteratorCallback callback, void *arg); +void RunCallbackForEachThreadLocked(__sanitizer::ThreadRegistry::ThreadCallback cb, + void *arg); +void FinishThreadLocked(u32 tid); + //// -------------------------------------------------------------------------- //// Allocator prototypes. //// -------------------------------------------------------------------------- diff --git a/compiler-rt/lib/lsan/lsan_common.cpp b/compiler-rt/lib/lsan/lsan_common.cpp --- a/compiler-rt/lib/lsan/lsan_common.cpp +++ b/compiler-rt/lib/lsan/lsan_common.cpp @@ -371,8 +371,7 @@ static void ProcessThreadRegistry(Frontier *frontier) { InternalMmapVector ptrs; - GetThreadRegistryLocked()->RunCallbackForEachThreadLocked( - GetAdditionalThreadContextPtrs, &ptrs); + RunCallbackForEachThreadLocked(GetAdditionalThreadContextPtrs, &ptrs); for (uptr i = 0; i < ptrs.size(); ++i) { void *ptr = reinterpret_cast(ptrs[i]); @@ -697,8 +696,7 @@ Sort(threads.data(), threads.size()); - GetThreadRegistryLocked()->RunCallbackForEachThreadLocked( - &ReportIfNotSuspended, &threads); + RunCallbackForEachThreadLocked(&ReportIfNotSuspended, &threads); } # endif // !SANITIZER_FUCHSIA diff --git a/compiler-rt/lib/lsan/lsan_common_fuchsia.cpp b/compiler-rt/lib/lsan/lsan_common_fuchsia.cpp --- a/compiler-rt/lib/lsan/lsan_common_fuchsia.cpp +++ b/compiler-rt/lib/lsan/lsan_common_fuchsia.cpp @@ -146,7 +146,7 @@ // just for the allocator cache, and to call ForEachExtraStackRange, // which ASan needs. if (flags()->use_stacks) { - GetThreadRegistryLocked()->RunCallbackForEachThreadLocked( + RunCallbackForEachThreadLocked( [](ThreadContextBase *tctx, void *arg) { ForEachExtraStackRange(tctx->os_id, ForEachExtraStackRangeCb, arg); diff --git a/compiler-rt/lib/lsan/lsan_fuchsia.cpp b/compiler-rt/lib/lsan/lsan_fuchsia.cpp --- a/compiler-rt/lib/lsan/lsan_fuchsia.cpp +++ b/compiler-rt/lib/lsan/lsan_fuchsia.cpp @@ -68,7 +68,7 @@ } void GetAllThreadAllocatorCachesLocked(InternalMmapVector *caches) { - GetThreadRegistryLocked()->RunCallbackForEachThreadLocked( + RunCallbackForEachThreadLocked( [](ThreadContextBase *tctx, void *arg) { auto ctx = static_cast(tctx); static_cast(arg)->push_back(ctx->cache_begin()); @@ -110,7 +110,7 @@ // On success, there is nothing to do here. if (error != thrd_success) { // Clean up the thread registry for the thread creation that didn't happen. - GetThreadRegistryLocked()->FinishThread(tid); + FinishThreadLocked(tid); } } diff --git a/compiler-rt/lib/lsan/lsan_posix.cpp b/compiler-rt/lib/lsan/lsan_posix.cpp --- a/compiler-rt/lib/lsan/lsan_posix.cpp +++ b/compiler-rt/lib/lsan/lsan_posix.cpp @@ -16,6 +16,7 @@ #if SANITIZER_POSIX #include "lsan.h" #include "lsan_allocator.h" +#include "lsan_thread.h" #include "sanitizer_common/sanitizer_stacktrace.h" #include "sanitizer_common/sanitizer_tls_get_addr.h" @@ -61,7 +62,7 @@ uptr *tls_begin, uptr *tls_end, uptr *cache_begin, uptr *cache_end, DTLS **dtls) { ThreadContext *context = static_cast( - GetThreadRegistryLocked()->FindThreadContextByOsIDLocked(os_id)); + GetLsanThreadRegistryLocked()->FindThreadContextByOsIDLocked(os_id)); if (!context) return false; *stack_begin = context->stack_begin(); diff --git a/compiler-rt/lib/lsan/lsan_thread.h b/compiler-rt/lib/lsan/lsan_thread.h --- a/compiler-rt/lib/lsan/lsan_thread.h +++ b/compiler-rt/lib/lsan/lsan_thread.h @@ -45,6 +45,8 @@ void InitializeThreadRegistry(); void InitializeMainThread(); +ThreadRegistry *GetLsanThreadRegistryLocked(); + u32 ThreadCreate(u32 tid, bool detached, void *arg = nullptr); void ThreadFinish(); diff --git a/compiler-rt/lib/lsan/lsan_thread.cpp b/compiler-rt/lib/lsan/lsan_thread.cpp --- a/compiler-rt/lib/lsan/lsan_thread.cpp +++ b/compiler-rt/lib/lsan/lsan_thread.cpp @@ -82,9 +82,18 @@ void UnlockThreadRegistry() { thread_registry->Unlock(); } -ThreadRegistry *GetThreadRegistryLocked() { +ThreadRegistry *GetLsanThreadRegistryLocked() { thread_registry->CheckLocked(); return thread_registry; } +void RunCallbackForEachThreadLocked( + __sanitizer::ThreadRegistry::ThreadCallback cb, void *arg) { + GetLsanThreadRegistryLocked()->RunCallbackForEachThreadLocked(cb, arg); +} + +void FinishThreadLocked(u32 tid) { + GetLsanThreadRegistryLocked()->FinishThread(tid); +} + } // namespace __lsan