diff --git a/compiler-rt/lib/lsan/lsan_fuchsia.cpp b/compiler-rt/lib/lsan/lsan_fuchsia.cpp index 03ac0afbabff7..9bf18cc79b779 100644 --- a/compiler-rt/lib/lsan/lsan_fuchsia.cpp +++ b/compiler-rt/lib/lsan/lsan_fuchsia.cpp @@ -46,6 +46,7 @@ struct OnStartedArgs { }; void ThreadContext::OnStarted(void *arg) { + ThreadContextLsanBase::OnStarted(arg); auto args = reinterpret_cast(arg); cache_begin_ = args->cache_begin; cache_end_ = args->cache_end; diff --git a/compiler-rt/lib/lsan/lsan_mac.cpp b/compiler-rt/lib/lsan/lsan_mac.cpp index 6964a9ba28df5..8302efcdd400b 100644 --- a/compiler-rt/lib/lsan/lsan_mac.cpp +++ b/compiler-rt/lib/lsan/lsan_mac.cpp @@ -70,7 +70,6 @@ void lsan_register_worker_thread(int parent_tid) { if (GetCurrentThread() == kInvalidTid) { u32 tid = ThreadCreate(parent_tid, true); ThreadStart(tid, GetTid()); - SetCurrentThread(tid); } } diff --git a/compiler-rt/lib/lsan/lsan_posix.cpp b/compiler-rt/lib/lsan/lsan_posix.cpp index 3c7bc15a851af..097dfe05768a7 100644 --- a/compiler-rt/lib/lsan/lsan_posix.cpp +++ b/compiler-rt/lib/lsan/lsan_posix.cpp @@ -35,6 +35,7 @@ struct OnStartedArgs { }; void ThreadContext::OnStarted(void *arg) { + ThreadContextLsanBase::OnStarted(arg); auto args = reinterpret_cast(arg); stack_begin_ = args->stack_begin; stack_end_ = args->stack_end; diff --git a/compiler-rt/lib/lsan/lsan_thread.cpp b/compiler-rt/lib/lsan/lsan_thread.cpp index 137c7e4e4f12c..a0fe95da1a6fa 100644 --- a/compiler-rt/lib/lsan/lsan_thread.cpp +++ b/compiler-rt/lib/lsan/lsan_thread.cpp @@ -39,9 +39,12 @@ void InitializeThreadRegistry() { ThreadContextLsanBase::ThreadContextLsanBase(int tid) : ThreadContextBase(tid) {} +void ThreadContextLsanBase::OnStarted(void *arg) { SetCurrentThread(tid); } + void ThreadContextLsanBase::OnFinished() { AllocatorThreadFinish(); DTLS_Destroy(); + SetCurrentThread(kInvalidTid); } u32 ThreadCreate(u32 parent_tid, bool detached, void *arg) { @@ -51,13 +54,9 @@ u32 ThreadCreate(u32 parent_tid, bool detached, void *arg) { void ThreadContextLsanBase::ThreadStart(u32 tid, tid_t os_id, ThreadType thread_type, void *arg) { thread_registry->StartThread(tid, os_id, thread_type, arg); - SetCurrentThread(tid); } -void ThreadFinish() { - thread_registry->FinishThread(GetCurrentThread()); - SetCurrentThread(kInvalidTid); -} +void ThreadFinish() { thread_registry->FinishThread(GetCurrentThread()); } ThreadContext *CurrentThreadContext() { if (!thread_registry) diff --git a/compiler-rt/lib/lsan/lsan_thread.h b/compiler-rt/lib/lsan/lsan_thread.h index 049c7e2038017..66dbc5f35c1cf 100644 --- a/compiler-rt/lib/lsan/lsan_thread.h +++ b/compiler-rt/lib/lsan/lsan_thread.h @@ -21,6 +21,7 @@ namespace __lsan { class ThreadContextLsanBase : public ThreadContextBase { public: explicit ThreadContextLsanBase(int tid); + void OnStarted(void *arg) override; void OnFinished() override; uptr stack_begin() { return stack_begin_; } uptr stack_end() { return stack_end_; }