1 //===-- hwasan_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 HWAddressSanitizer.
12 //===----------------------------------------------------------------------===//
14 #ifndef HWASAN_THREAD_H
15 #define HWASAN_THREAD_H
17 #include "hwasan_allocator.h"
18 #include "sanitizer_common/sanitizer_common.h"
24 static HwasanThread *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 bool InSymbolizer() { return in_symbolizer_; }
46 void EnterSymbolizer() { in_symbolizer_++; }
47 void LeaveSymbolizer() { in_symbolizer_--; }
49 bool InInterceptorScope() { return in_interceptor_scope_; }
50 void EnterInterceptorScope() { in_interceptor_scope_++; }
51 void LeaveInterceptorScope() { in_interceptor_scope_--; }
53 HwasanThreadLocalMallocStorage &malloc_storage() { return malloc_storage_; }
55 tag_t GenerateRandomTag();
57 int destructor_iterations_;
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_;
71 unsigned in_signal_handler_;
72 unsigned in_symbolizer_;
73 unsigned in_interceptor_scope_;
78 HwasanThreadLocalMallocStorage malloc_storage_;
81 HwasanThread *GetCurrentThread();
82 void SetCurrentThread(HwasanThread *t);
84 } // namespace __hwasan
86 #endif // HWASAN_THREAD_H