]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/hwasan/hwasan_thread.h
Merge ^/head r338690 through r338730.
[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   tag_t GenerateRandomTag();
56
57   int destructor_iterations_;
58
59  private:
60   // NOTE: There is no HwasanThread constructor. It is allocated
61   // via mmap() and *must* be valid in zero-initialized state.
62   void SetThreadStackAndTls();
63   void ClearShadowForThreadStackAndTLS();
64   thread_callback_t start_routine_;
65   void *arg_;
66   uptr stack_top_;
67   uptr stack_bottom_;
68   uptr tls_begin_;
69   uptr tls_end_;
70
71   unsigned in_signal_handler_;
72   unsigned in_symbolizer_;
73   unsigned in_interceptor_scope_;
74
75   u32 random_state_;
76   u32 random_buffer_;
77
78   HwasanThreadLocalMallocStorage malloc_storage_;
79 };
80
81 HwasanThread *GetCurrentThread();
82 void SetCurrentThread(HwasanThread *t);
83
84 } // namespace __hwasan
85
86 #endif // HWASAN_THREAD_H