1 //===-- msan_thread.h -------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file is a part of MemorySanitizer.
11 //===----------------------------------------------------------------------===//
16 #include "msan_allocator.h"
17 #include "sanitizer_common/sanitizer_common.h"
23 static MsanThread *Create(thread_callback_t start_routine, void *arg);
24 static void TSDDtor(void *tsd);
27 void Init(); // Should be called from the thread itself.
28 thread_return_t ThreadStart();
30 uptr stack_top() { return stack_top_; }
31 uptr stack_bottom() { return stack_bottom_; }
32 uptr tls_begin() { return tls_begin_; }
33 uptr tls_end() { return tls_end_; }
34 bool IsMainThread() { return start_routine_ == nullptr; }
36 bool AddrIsInStack(uptr addr) {
37 return addr >= stack_bottom_ && addr < stack_top_;
40 bool InSignalHandler() { return in_signal_handler_; }
41 void EnterSignalHandler() { in_signal_handler_++; }
42 void LeaveSignalHandler() { in_signal_handler_--; }
44 MsanThreadLocalMallocStorage &malloc_storage() { return malloc_storage_; }
46 int destructor_iterations_;
49 // NOTE: There is no MsanThread constructor. It is allocated
50 // via mmap() and *must* be valid in zero-initialized state.
51 void SetThreadStackAndTls();
52 void ClearShadowForThreadStackAndTLS();
53 thread_callback_t start_routine_;
60 unsigned in_signal_handler_;
62 MsanThreadLocalMallocStorage malloc_storage_;
65 MsanThread *GetCurrentThread();
66 void SetCurrentThread(MsanThread *t);
70 #endif // MSAN_THREAD_H