1 //===-- msan_thread.h -------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is a part of MemorySanitizer.
12 //===----------------------------------------------------------------------===//
17 #include "msan_allocator.h"
18 #include "sanitizer_common/sanitizer_common.h"
24 static MsanThread *Create(thread_callback_t start_routine, void *arg);
25 static void TSDDtor(void *tsd);
28 void Init(); // Should be called from the thread itself.
29 thread_return_t ThreadStart();
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; }
37 bool AddrIsInStack(uptr addr) {
38 return addr >= stack_bottom_ && addr < stack_top_;
41 bool InSignalHandler() { return in_signal_handler_; }
42 void EnterSignalHandler() { in_signal_handler_++; }
43 void LeaveSignalHandler() { in_signal_handler_--; }
45 MsanThreadLocalMallocStorage &malloc_storage() { return malloc_storage_; }
47 int destructor_iterations_;
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_;
61 unsigned in_signal_handler_;
63 MsanThreadLocalMallocStorage malloc_storage_;
66 MsanThread *GetCurrentThread();
67 void SetCurrentThread(MsanThread *t);
71 #endif // MSAN_THREAD_H