diff --git a/compiler-rt/lib/lsan/lsan_fuchsia.cpp b/compiler-rt/lib/lsan/lsan_fuchsia.cpp --- a/compiler-rt/lib/lsan/lsan_fuchsia.cpp +++ b/compiler-rt/lib/lsan/lsan_fuchsia.cpp @@ -46,6 +46,7 @@ }; 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_posix.cpp b/compiler-rt/lib/lsan/lsan_posix.cpp --- a/compiler-rt/lib/lsan/lsan_posix.cpp +++ b/compiler-rt/lib/lsan/lsan_posix.cpp @@ -35,6 +35,7 @@ }; 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.h b/compiler-rt/lib/lsan/lsan_thread.h --- a/compiler-rt/lib/lsan/lsan_thread.h +++ b/compiler-rt/lib/lsan/lsan_thread.h @@ -21,6 +21,7 @@ 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_; } diff --git a/compiler-rt/lib/lsan/lsan_thread.cpp b/compiler-rt/lib/lsan/lsan_thread.cpp --- a/compiler-rt/lib/lsan/lsan_thread.cpp +++ b/compiler-rt/lib/lsan/lsan_thread.cpp @@ -39,9 +39,12 @@ 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 @@ 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() { static __attribute__((tls_model("initial-exec")))