1 1.1 mrg //=-- lsan_thread.h -------------------------------------------------------===// 2 1.1 mrg // 3 1.3 mrg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 1.3 mrg // See https://llvm.org/LICENSE.txt for license information. 5 1.3 mrg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 1.1 mrg // 7 1.1 mrg //===----------------------------------------------------------------------===// 8 1.1 mrg // 9 1.1 mrg // This file is a part of LeakSanitizer. 10 1.1 mrg // Thread registry for standalone LSan. 11 1.1 mrg // 12 1.1 mrg //===----------------------------------------------------------------------===// 13 1.1 mrg 14 1.1 mrg #ifndef LSAN_THREAD_H 15 1.1 mrg #define LSAN_THREAD_H 16 1.1 mrg 17 1.4 mrg #include "sanitizer_common/sanitizer_thread_arg_retval.h" 18 1.1 mrg #include "sanitizer_common/sanitizer_thread_registry.h" 19 1.1 mrg 20 1.1 mrg namespace __lsan { 21 1.1 mrg 22 1.3 mrg class ThreadContextLsanBase : public ThreadContextBase { 23 1.1 mrg public: 24 1.3 mrg explicit ThreadContextLsanBase(int tid); 25 1.4 mrg void OnStarted(void *arg) override; 26 1.2 mrg void OnFinished() override; 27 1.1 mrg uptr stack_begin() { return stack_begin_; } 28 1.1 mrg uptr stack_end() { return stack_end_; } 29 1.1 mrg uptr cache_begin() { return cache_begin_; } 30 1.1 mrg uptr cache_end() { return cache_end_; } 31 1.2 mrg 32 1.3 mrg // The argument is passed on to the subclass's OnStarted member function. 33 1.3 mrg static void ThreadStart(u32 tid, tid_t os_id, ThreadType thread_type, 34 1.3 mrg void *onstarted_arg); 35 1.3 mrg 36 1.3 mrg protected: 37 1.3 mrg ~ThreadContextLsanBase() {} 38 1.3 mrg uptr stack_begin_ = 0; 39 1.3 mrg uptr stack_end_ = 0; 40 1.3 mrg uptr cache_begin_ = 0; 41 1.3 mrg uptr cache_end_ = 0; 42 1.1 mrg }; 43 1.1 mrg 44 1.3 mrg // This subclass of ThreadContextLsanBase is declared in an OS-specific header. 45 1.3 mrg class ThreadContext; 46 1.3 mrg 47 1.4 mrg void InitializeThreads(); 48 1.3 mrg void InitializeMainThread(); 49 1.1 mrg 50 1.4 mrg ThreadRegistry *GetLsanThreadRegistryLocked(); 51 1.4 mrg ThreadArgRetval &GetThreadArgRetval(); 52 1.4 mrg 53 1.4 mrg u32 ThreadCreate(u32 tid, bool detached, void *arg = nullptr); 54 1.1 mrg void ThreadFinish(); 55 1.4 mrg 56 1.4 mrg ThreadContextLsanBase *GetCurrentThread(); 57 1.4 mrg inline u32 GetCurrentThreadId() { 58 1.4 mrg ThreadContextLsanBase *ctx = GetCurrentThread(); 59 1.4 mrg return ctx ? ctx->tid : kInvalidTid; 60 1.4 mrg } 61 1.4 mrg void SetCurrentThread(ThreadContextLsanBase *tctx); 62 1.1 mrg void EnsureMainThreadIDIsCorrect(); 63 1.3 mrg 64 1.1 mrg } // namespace __lsan 65 1.1 mrg 66 1.1 mrg #endif // LSAN_THREAD_H 67