[LSAN][NFC] Eliminated GetThreadRegistryLocked from the LSAN interface to avoid the...
authorKirill Stoimenov <kstoimenov@google.com>
Tue, 13 Dec 2022 23:03:48 +0000 (23:03 +0000)
committerKirill Stoimenov <kstoimenov@google.com>
Wed, 14 Dec 2022 00:15:40 +0000 (00:15 +0000)
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D139976

compiler-rt/lib/asan/asan_thread.cpp
compiler-rt/lib/lsan/lsan_common.cpp
compiler-rt/lib/lsan/lsan_common.h
compiler-rt/lib/lsan/lsan_common_fuchsia.cpp
compiler-rt/lib/lsan/lsan_fuchsia.cpp
compiler-rt/lib/lsan/lsan_posix.cpp
compiler-rt/lib/lsan/lsan_thread.cpp
compiler-rt/lib/lsan/lsan_thread.h

index 8ce6068792677b120b4d24ef278f4c346424d42c..4b5e4a33fbdda6931483deebeeeb238442ee893b 100644 (file)
@@ -482,7 +482,7 @@ void LockThreadRegistry() { __asan::asanThreadRegistry().Lock(); }
 
 void UnlockThreadRegistry() { __asan::asanThreadRegistry().Unlock(); }
 
-ThreadRegistry *GetThreadRegistryLocked() {
+static ThreadRegistry *GetAsanThreadRegistryLocked() {
   __asan::asanThreadRegistry().CheckLocked();
   return &__asan::asanThreadRegistry();
 }
@@ -518,6 +518,15 @@ void ForEachExtraStackRange(tid_t os_id, RangeIteratorCallback callback,
   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
index a685f7ba4f505ca6772c2b50af0232458e4f2a4f..33c590cd406952aedce117d74f45dc94eeb03aea 100644 (file)
@@ -371,8 +371,7 @@ extern "C" SANITIZER_WEAK_ATTRIBUTE void __libc_iterate_dynamic_tls(
 
 static void ProcessThreadRegistry(Frontier *frontier) {
   InternalMmapVector<uptr> ptrs;
-  GetThreadRegistryLocked()->RunCallbackForEachThreadLocked(
-      GetAdditionalThreadContextPtrs, &ptrs);
+  RunCallbackForEachThreadLocked(GetAdditionalThreadContextPtrs, &ptrs);
 
   for (uptr i = 0; i < ptrs.size(); ++i) {
     void *ptr = reinterpret_cast<void *>(ptrs[i]);
@@ -697,8 +696,7 @@ static void ReportUnsuspendedThreads(
 
   Sort(threads.data(), threads.size());
 
-  GetThreadRegistryLocked()->RunCallbackForEachThreadLocked(
-      &ReportIfNotSuspended, &threads);
+  RunCallbackForEachThreadLocked(&ReportIfNotSuspended, &threads);
 }
 
 #  endif  // !SANITIZER_FUCHSIA
index 02f533413f008090ad61a2d12019ec51c92260e8..7827370aa8bb1e7bc246fa8f2c1ddcadf72ca654 100644 (file)
@@ -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 @@ bool WordIsPoisoned(uptr addr);
 // 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 GetAllThreadAllocatorCachesLocked(InternalMmapVector<uptr> *caches);
 void ForEachExtraStackRange(tid_t os_id, RangeIteratorCallback callback,
                             void *arg);
 
+void RunCallbackForEachThreadLocked(__sanitizer::ThreadRegistry::ThreadCallback cb,
+                                    void *arg);
+void FinishThreadLocked(u32 tid);
+
 //// --------------------------------------------------------------------------
 //// Allocator prototypes.
 //// --------------------------------------------------------------------------
index edb4ca6c8578e03c2c266f6e970ec6b67e34c164..ac2eddf9cc9deeb39c5c6306938b8eb229bdd635 100644 (file)
@@ -146,7 +146,7 @@ void LockStuffAndStopTheWorld(StopTheWorldCallback callback,
         // 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);
index 2d96206754a94d6a24d049450e0b9718c0c4269e..1cb0fc6491e8479fcc517c3fe877edad9a8c7717 100644 (file)
@@ -68,7 +68,7 @@ void InitializeMainThread() {
 }
 
 void GetAllThreadAllocatorCachesLocked(InternalMmapVector<uptr> *caches) {
-  GetThreadRegistryLocked()->RunCallbackForEachThreadLocked(
+  RunCallbackForEachThreadLocked(
       [](ThreadContextBase *tctx, void *arg) {
         auto ctx = static_cast<ThreadContext *>(tctx);
         static_cast<decltype(caches)>(arg)->push_back(ctx->cache_begin());
@@ -110,7 +110,7 @@ void __sanitizer_thread_create_hook(void *hook, thrd_t thread, int error) {
   // 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);
   }
 }
 
index 8f277db22375956b21d0dad89f195c4a0d8871dd..3c7bc15a851af0f785f97eeb70a782f70eed8ca1 100644 (file)
@@ -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 @@ bool GetThreadRangesLocked(tid_t os_id, uptr *stack_begin, uptr *stack_end,
                            uptr *tls_begin, uptr *tls_end, uptr *cache_begin,
                            uptr *cache_end, DTLS **dtls) {
   ThreadContext *context = static_cast<ThreadContext *>(
-      GetThreadRegistryLocked()->FindThreadContextByOsIDLocked(os_id));
+      GetLsanThreadRegistryLocked()->FindThreadContextByOsIDLocked(os_id));
   if (!context)
     return false;
   *stack_begin = context->stack_begin();
index ca3dfd03b109df8b983462224834dd1f3a643f18..7309b831c7e89cc2e816db172576a5c15e45bb9e 100644 (file)
@@ -82,9 +82,18 @@ void LockThreadRegistry() { thread_registry->Lock(); }
 
 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
index 6ab4172092ae9bdc970e60dd0ade48db93bdb0a9..049c7e2038017012342dff074ed4764952c6b75a 100644 (file)
@@ -45,6 +45,8 @@ class ThreadContext;
 void InitializeThreadRegistry();
 void InitializeMainThread();
 
+ThreadRegistry *GetLsanThreadRegistryLocked();
+
 u32 ThreadCreate(u32 tid, bool detached, void *arg = nullptr);
 void ThreadFinish();