]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/hwasan/hwasan_thread.h
Merge compiler-rt trunk r321017 to contrib/compiler-rt.
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / hwasan / hwasan_thread.h
1 //===-- hwasan_thread.h -------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file is a part of HWAddressSanitizer.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef HWASAN_THREAD_H
15 #define HWASAN_THREAD_H
16
17 #include "hwasan_allocator.h"
18 #include "sanitizer_common/sanitizer_common.h"
19
20 namespace __hwasan {
21
22 class HwasanThread {
23  public:
24   static HwasanThread *Create(thread_callback_t start_routine, void *arg);
25   static void TSDDtor(void *tsd);
26   void Destroy();
27
28   void Init();  // Should be called from the thread itself.
29   thread_return_t ThreadStart();
30
31   uptr stack_top() { return stack_top_; }
32   uptr stack_bottom() { return stack_bottom_; }
33   uptr tls_begin() { return tls_begin_; }
34   uptr tls_end() { return tls_end_; }
35   bool IsMainThread() { return start_routine_ == nullptr; }
36
37   bool AddrIsInStack(uptr addr) {
38     return addr >= stack_bottom_ && addr < stack_top_;
39   }
40
41   bool InSignalHandler() { return in_signal_handler_; }
42   void EnterSignalHandler() { in_signal_handler_++; }
43   void LeaveSignalHandler() { in_signal_handler_--; }
44
45   bool InSymbolizer() { return in_symbolizer_; }
46   void EnterSymbolizer() { in_symbolizer_++; }
47   void LeaveSymbolizer() { in_symbolizer_--; }
48
49   bool InInterceptorScope() { return in_interceptor_scope_; }
50   void EnterInterceptorScope() { in_interceptor_scope_++; }
51   void LeaveInterceptorScope() { in_interceptor_scope_--; }
52
53   HwasanThreadLocalMallocStorage &malloc_storage() { return malloc_storage_; }
54
55   int destructor_iterations_;
56
57  private:
58   // NOTE: There is no HwasanThread constructor. It is allocated
59   // via mmap() and *must* be valid in zero-initialized state.
60   void SetThreadStackAndTls();
61   void ClearShadowForThreadStackAndTLS();
62   thread_callback_t start_routine_;
63   void *arg_;
64   uptr stack_top_;
65   uptr stack_bottom_;
66   uptr tls_begin_;
67   uptr tls_end_;
68
69   unsigned in_signal_handler_;
70   unsigned in_symbolizer_;
71   unsigned in_interceptor_scope_;
72
73   HwasanThreadLocalMallocStorage malloc_storage_;
74 };
75
76 HwasanThread *GetCurrentThread();
77 void SetCurrentThread(HwasanThread *t);
78
79 } // namespace __hwasan
80
81 #endif // HWASAN_THREAD_H