]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/msan/msan_thread.h
Merge llvm trunk r351319, resolve conflicts, and update FREEBSD-Xlist.
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / msan / msan_thread.h
1 //===-- msan_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 MemorySanitizer.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef MSAN_THREAD_H
15 #define MSAN_THREAD_H
16
17 #include "msan_allocator.h"
18 #include "sanitizer_common/sanitizer_common.h"
19
20 namespace __msan {
21
22 class MsanThread {
23  public:
24   static MsanThread *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   MsanThreadLocalMallocStorage &malloc_storage() { return malloc_storage_; }
46
47   int destructor_iterations_;
48
49  private:
50   // NOTE: There is no MsanThread constructor. It is allocated
51   // via mmap() and *must* be valid in zero-initialized state.
52   void SetThreadStackAndTls();
53   void ClearShadowForThreadStackAndTLS();
54   thread_callback_t start_routine_;
55   void *arg_;
56   uptr stack_top_;
57   uptr stack_bottom_;
58   uptr tls_begin_;
59   uptr tls_end_;
60
61   unsigned in_signal_handler_;
62
63   MsanThreadLocalMallocStorage malloc_storage_;
64 };
65
66 MsanThread *GetCurrentThread();
67 void SetCurrentThread(MsanThread *t);
68
69 } // namespace __msan
70
71 #endif // MSAN_THREAD_H