blob: ed22e67edd5018a122f41c914c04843e9699ff0a [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001//===-- 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
20namespace __msan {
21
22class 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_; }
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080035 bool IsMainThread() { return start_routine_ == nullptr; }
Stephen Hines2d1fdb22014-05-28 23:58:16 -070036
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
66MsanThread *GetCurrentThread();
67void SetCurrentThread(MsanThread *t);
68
69} // namespace __msan
70
71#endif // MSAN_THREAD_H