From 02eb818f64c3b5e20f1badfe803a9a22f9de4640 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Fri, 14 Apr 2023 16:22:54 -0700 Subject: [PATCH] [NFC][lsan] Add GetCurrentThreadId wrapper for GetCurrentThread I am going to change return type of GetCurrentThreadId() in the next patch. Differential Revision: https://reviews.llvm.org/D148394 --- compiler-rt/lib/lsan/lsan_fuchsia.cpp | 2 +- compiler-rt/lib/lsan/lsan_interceptors.cpp | 2 +- compiler-rt/lib/lsan/lsan_mac.cpp | 18 +++++++++--------- compiler-rt/lib/lsan/lsan_posix.cpp | 2 +- compiler-rt/lib/lsan/lsan_thread.cpp | 9 +++++---- compiler-rt/lib/lsan/lsan_thread.h | 1 + 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/compiler-rt/lib/lsan/lsan_fuchsia.cpp b/compiler-rt/lib/lsan/lsan_fuchsia.cpp index 9bf18cc..4edac97 100644 --- a/compiler-rt/lib/lsan/lsan_fuchsia.cpp +++ b/compiler-rt/lib/lsan/lsan_fuchsia.cpp @@ -99,7 +99,7 @@ void *__sanitizer_before_thread_create_hook(thrd_t thread, bool detached, OnCreatedArgs args; args.stack_begin = reinterpret_cast(stack_base); args.stack_end = args.stack_begin + stack_size; - u32 parent_tid = GetCurrentThread(); + u32 parent_tid = GetCurrentThreadId(); u32 tid = ThreadCreate(parent_tid, detached, &args); return reinterpret_cast(static_cast(tid)); } diff --git a/compiler-rt/lib/lsan/lsan_interceptors.cpp b/compiler-rt/lib/lsan/lsan_interceptors.cpp index 3a1b2af..3f8ef3f 100644 --- a/compiler-rt/lib/lsan/lsan_interceptors.cpp +++ b/compiler-rt/lib/lsan/lsan_interceptors.cpp @@ -468,7 +468,7 @@ INTERCEPTOR(int, pthread_create, void *th, void *attr, res = REAL(pthread_create)(th, attr, __lsan_thread_start_func, &p); } if (res == 0) { - int tid = ThreadCreate(GetCurrentThread(), IsStateDetached(detached)); + int tid = ThreadCreate(GetCurrentThreadId(), IsStateDetached(detached)); CHECK_NE(tid, kMainTid); atomic_store(&p.tid, tid, memory_order_release); while (atomic_load(&p.tid, memory_order_acquire) != 0) diff --git a/compiler-rt/lib/lsan/lsan_mac.cpp b/compiler-rt/lib/lsan/lsan_mac.cpp index 8302efc..2bcd005 100644 --- a/compiler-rt/lib/lsan/lsan_mac.cpp +++ b/compiler-rt/lib/lsan/lsan_mac.cpp @@ -67,7 +67,7 @@ typedef struct { ALWAYS_INLINE void lsan_register_worker_thread(int parent_tid) { - if (GetCurrentThread() == kInvalidTid) { + if (GetCurrentThreadId() == kInvalidTid) { u32 tid = ThreadCreate(parent_tid, true); ThreadStart(tid, GetTid()); } @@ -100,7 +100,7 @@ extern "C" lsan_block_context_t *alloc_lsan_context(void *ctxt, (lsan_block_context_t *)lsan_malloc(sizeof(lsan_block_context_t), stack); lsan_ctxt->block = ctxt; lsan_ctxt->func = func; - lsan_ctxt->parent_tid = GetCurrentThread(); + lsan_ctxt->parent_tid = GetCurrentThreadId(); return lsan_ctxt; } @@ -145,13 +145,13 @@ void dispatch_source_set_event_handler(dispatch_source_t ds, void (^work)(void)); } -#define GET_LSAN_BLOCK(work) \ - void (^lsan_block)(void); \ - int parent_tid = GetCurrentThread(); \ - lsan_block = ^(void) { \ - lsan_register_worker_thread(parent_tid); \ - work(); \ - } +# define GET_LSAN_BLOCK(work) \ + void (^lsan_block)(void); \ + int parent_tid = GetCurrentThreadId(); \ + lsan_block = ^(void) { \ + lsan_register_worker_thread(parent_tid); \ + work(); \ + } INTERCEPTOR(void, dispatch_async, dispatch_queue_t dq, void (^work)(void)) { GET_LSAN_BLOCK(work); diff --git a/compiler-rt/lib/lsan/lsan_posix.cpp b/compiler-rt/lib/lsan/lsan_posix.cpp index 097dfe0..d99e1cc 100644 --- a/compiler-rt/lib/lsan/lsan_posix.cpp +++ b/compiler-rt/lib/lsan/lsan_posix.cpp @@ -89,7 +89,7 @@ static void OnStackUnwind(const SignalContext &sig, const void *, } void LsanOnDeadlySignal(int signo, void *siginfo, void *context) { - HandleDeadlySignal(siginfo, context, GetCurrentThread(), &OnStackUnwind, + HandleDeadlySignal(siginfo, context, GetCurrentThreadId(), &OnStackUnwind, nullptr); } diff --git a/compiler-rt/lib/lsan/lsan_thread.cpp b/compiler-rt/lib/lsan/lsan_thread.cpp index a0fe95d..bc05021 100644 --- a/compiler-rt/lib/lsan/lsan_thread.cpp +++ b/compiler-rt/lib/lsan/lsan_thread.cpp @@ -56,19 +56,20 @@ void ThreadContextLsanBase::ThreadStart(u32 tid, tid_t os_id, thread_registry->StartThread(tid, os_id, thread_type, arg); } -void ThreadFinish() { thread_registry->FinishThread(GetCurrentThread()); } +void ThreadFinish() { thread_registry->FinishThread(GetCurrentThreadId()); } ThreadContext *CurrentThreadContext() { if (!thread_registry) return nullptr; - if (GetCurrentThread() == kInvalidTid) + if (GetCurrentThreadId() == kInvalidTid) return nullptr; // No lock needed when getting current thread. - return (ThreadContext *)thread_registry->GetThreadLocked(GetCurrentThread()); + return (ThreadContext *)thread_registry->GetThreadLocked( + GetCurrentThreadId()); } void EnsureMainThreadIDIsCorrect() { - if (GetCurrentThread() == kMainTid) + if (GetCurrentThreadId() == kMainTid) CurrentThreadContext()->os_id = GetTid(); } diff --git a/compiler-rt/lib/lsan/lsan_thread.h b/compiler-rt/lib/lsan/lsan_thread.h index 66dbc5f..5abbaff 100644 --- a/compiler-rt/lib/lsan/lsan_thread.h +++ b/compiler-rt/lib/lsan/lsan_thread.h @@ -52,6 +52,7 @@ u32 ThreadCreate(u32 tid, bool detached, void *arg = nullptr); void ThreadFinish(); u32 GetCurrentThread(); +inline u32 GetCurrentThreadId() { return GetCurrentThread(); } void SetCurrentThread(u32 tid); ThreadContext *CurrentThreadContext(); void EnsureMainThreadIDIsCorrect(); -- 2.7.4