[compiler-rt] e43e0ff - [LSAN][NFC] Eliminated GetThreadRegistryLocked from the LSAN interface to avoid the need to implement it in HWASAN.
Kirill Stoimenov via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 13 16:15:50 PST 2022
Author: Kirill Stoimenov
Date: 2022-12-14T00:15:40Z
New Revision: e43e0ffbe77a3c6704488d341c4a0a8cb8109fb0
URL: https://github.com/llvm/llvm-project/commit/e43e0ffbe77a3c6704488d341c4a0a8cb8109fb0
DIFF: https://github.com/llvm/llvm-project/commit/e43e0ffbe77a3c6704488d341c4a0a8cb8109fb0.diff
LOG: [LSAN][NFC] Eliminated GetThreadRegistryLocked from the LSAN interface to avoid the need to implement it in HWASAN.
Reviewed By: vitalybuka
Differential Revision: https://reviews.llvm.org/D139976
Added:
Modified:
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
Removed:
################################################################################
diff --git a/compiler-rt/lib/asan/asan_thread.cpp b/compiler-rt/lib/asan/asan_thread.cpp
index 8ce6068792677..4b5e4a33fbdda 100644
--- a/compiler-rt/lib/asan/asan_thread.cpp
+++ b/compiler-rt/lib/asan/asan_thread.cpp
@@ -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
diff --git a/compiler-rt/lib/lsan/lsan_common.cpp b/compiler-rt/lib/lsan/lsan_common.cpp
index a685f7ba4f505..33c590cd40695 100644
--- a/compiler-rt/lib/lsan/lsan_common.cpp
+++ b/compiler-rt/lib/lsan/lsan_common.cpp
@@ -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
diff --git a/compiler-rt/lib/lsan/lsan_common.h b/compiler-rt/lib/lsan/lsan_common.h
index 02f533413f008..7827370aa8bb1 100644
--- 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 @@ 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.
//// --------------------------------------------------------------------------
diff --git a/compiler-rt/lib/lsan/lsan_common_fuchsia.cpp b/compiler-rt/lib/lsan/lsan_common_fuchsia.cpp
index edb4ca6c8578e..ac2eddf9cc9de 100644
--- a/compiler-rt/lib/lsan/lsan_common_fuchsia.cpp
+++ b/compiler-rt/lib/lsan/lsan_common_fuchsia.cpp
@@ -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);
diff --git a/compiler-rt/lib/lsan/lsan_fuchsia.cpp b/compiler-rt/lib/lsan/lsan_fuchsia.cpp
index 2d96206754a94..1cb0fc6491e84 100644
--- a/compiler-rt/lib/lsan/lsan_fuchsia.cpp
+++ b/compiler-rt/lib/lsan/lsan_fuchsia.cpp
@@ -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);
}
}
diff --git a/compiler-rt/lib/lsan/lsan_posix.cpp b/compiler-rt/lib/lsan/lsan_posix.cpp
index 8f277db223759..3c7bc15a851af 100644
--- 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 @@ 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();
diff --git a/compiler-rt/lib/lsan/lsan_thread.cpp b/compiler-rt/lib/lsan/lsan_thread.cpp
index ca3dfd03b109d..7309b831c7e89 100644
--- a/compiler-rt/lib/lsan/lsan_thread.cpp
+++ b/compiler-rt/lib/lsan/lsan_thread.cpp
@@ -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
diff --git a/compiler-rt/lib/lsan/lsan_thread.h b/compiler-rt/lib/lsan/lsan_thread.h
index 6ab4172092ae9..049c7e2038017 100644
--- a/compiler-rt/lib/lsan/lsan_thread.h
+++ b/compiler-rt/lib/lsan/lsan_thread.h
@@ -45,6 +45,8 @@ class ThreadContext;
void InitializeThreadRegistry();
void InitializeMainThread();
+ThreadRegistry *GetLsanThreadRegistryLocked();
+
u32 ThreadCreate(u32 tid, bool detached, void *arg = nullptr);
void ThreadFinish();
More information about the llvm-commits
mailing list