mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-03-06 17:41:22 +00:00
[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
This commit is contained in:
parent
cadd8d3e20
commit
e43e0ffbe7
@ -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
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
//// --------------------------------------------------------------------------
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -45,6 +45,8 @@ class ThreadContext;
|
||||
void InitializeThreadRegistry();
|
||||
void InitializeMainThread();
|
||||
|
||||
ThreadRegistry *GetLsanThreadRegistryLocked();
|
||||
|
||||
u32 ThreadCreate(u32 tid, bool detached, void *arg = nullptr);
|
||||
void ThreadFinish();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user