10b57cec5SDimitry Andric //=-- lsan_thread.h -------------------------------------------------------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // This file is a part of LeakSanitizer. 100b57cec5SDimitry Andric // Thread registry for standalone LSan. 110b57cec5SDimitry Andric // 120b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 130b57cec5SDimitry Andric 140b57cec5SDimitry Andric #ifndef LSAN_THREAD_H 150b57cec5SDimitry Andric #define LSAN_THREAD_H 160b57cec5SDimitry Andric 17*06c3fb27SDimitry Andric #include "sanitizer_common/sanitizer_thread_arg_retval.h" 180b57cec5SDimitry Andric #include "sanitizer_common/sanitizer_thread_registry.h" 190b57cec5SDimitry Andric 200b57cec5SDimitry Andric namespace __lsan { 210b57cec5SDimitry Andric 225ffd83dbSDimitry Andric class ThreadContextLsanBase : public ThreadContextBase { 230b57cec5SDimitry Andric public: 245ffd83dbSDimitry Andric explicit ThreadContextLsanBase(int tid); 25*06c3fb27SDimitry Andric void OnStarted(void *arg) override; 260b57cec5SDimitry Andric void OnFinished() override; stack_begin()270b57cec5SDimitry Andric uptr stack_begin() { return stack_begin_; } stack_end()280b57cec5SDimitry Andric uptr stack_end() { return stack_end_; } cache_begin()290b57cec5SDimitry Andric uptr cache_begin() { return cache_begin_; } cache_end()300b57cec5SDimitry Andric uptr cache_end() { return cache_end_; } 310b57cec5SDimitry Andric 325ffd83dbSDimitry Andric // The argument is passed on to the subclass's OnStarted member function. 335ffd83dbSDimitry Andric static void ThreadStart(u32 tid, tid_t os_id, ThreadType thread_type, 345ffd83dbSDimitry Andric void *onstarted_arg); 355ffd83dbSDimitry Andric 365ffd83dbSDimitry Andric protected: ~ThreadContextLsanBase()37e8d8bef9SDimitry Andric ~ThreadContextLsanBase() {} 385ffd83dbSDimitry Andric uptr stack_begin_ = 0; 395ffd83dbSDimitry Andric uptr stack_end_ = 0; 405ffd83dbSDimitry Andric uptr cache_begin_ = 0; 415ffd83dbSDimitry Andric uptr cache_end_ = 0; 420b57cec5SDimitry Andric }; 430b57cec5SDimitry Andric 445ffd83dbSDimitry Andric // This subclass of ThreadContextLsanBase is declared in an OS-specific header. 455ffd83dbSDimitry Andric class ThreadContext; 460b57cec5SDimitry Andric 47*06c3fb27SDimitry Andric void InitializeThreads(); 485ffd83dbSDimitry Andric void InitializeMainThread(); 495ffd83dbSDimitry Andric 50bdd1243dSDimitry Andric ThreadRegistry *GetLsanThreadRegistryLocked(); 51*06c3fb27SDimitry Andric ThreadArgRetval &GetThreadArgRetval(); 52bdd1243dSDimitry Andric 53349cc55cSDimitry Andric u32 ThreadCreate(u32 tid, bool detached, void *arg = nullptr); 540b57cec5SDimitry Andric void ThreadFinish(); 550b57cec5SDimitry Andric 56*06c3fb27SDimitry Andric ThreadContextLsanBase *GetCurrentThread(); GetCurrentThreadId()57*06c3fb27SDimitry Andricinline u32 GetCurrentThreadId() { 58*06c3fb27SDimitry Andric ThreadContextLsanBase *ctx = GetCurrentThread(); 59*06c3fb27SDimitry Andric return ctx ? ctx->tid : kInvalidTid; 60*06c3fb27SDimitry Andric } 61*06c3fb27SDimitry Andric void SetCurrentThread(ThreadContextLsanBase *tctx); 620b57cec5SDimitry Andric void EnsureMainThreadIDIsCorrect(); 635ffd83dbSDimitry Andric 640b57cec5SDimitry Andric } // namespace __lsan 650b57cec5SDimitry Andric 660b57cec5SDimitry Andric #endif // LSAN_THREAD_H 67