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