3 #include "hwasan_thread.h"
4 #include "hwasan_poisoning.h"
5 #include "hwasan_interface_internal.h"
7 #include "sanitizer_common/sanitizer_tls_get_addr.h"
11 HwasanThread *HwasanThread::Create(thread_callback_t start_routine,
13 uptr PageSize = GetPageSizeCached();
14 uptr size = RoundUpTo(sizeof(HwasanThread), PageSize);
15 HwasanThread *thread = (HwasanThread*)MmapOrDie(size, __func__);
16 thread->start_routine_ = start_routine;
18 thread->destructor_iterations_ = GetPthreadDestructorIterations();
23 void HwasanThread::SetThreadStackAndTls() {
26 GetThreadStackAndTls(IsMainThread(), &stack_bottom_, &stack_size,
27 &tls_begin_, &tls_size);
28 stack_top_ = stack_bottom_ + stack_size;
29 tls_end_ = tls_begin_ + tls_size;
32 CHECK(AddrIsInStack((uptr)&local));
35 void HwasanThread::Init() {
36 SetThreadStackAndTls();
37 CHECK(MEM_IS_APP(stack_bottom_));
38 CHECK(MEM_IS_APP(stack_top_ - 1));
41 void HwasanThread::TSDDtor(void *tsd) {
42 HwasanThread *t = (HwasanThread*)tsd;
46 void HwasanThread::ClearShadowForThreadStackAndTLS() {
47 TagMemory(stack_bottom_, stack_top_ - stack_bottom_, 0);
48 if (tls_begin_ != tls_end_)
49 TagMemory(tls_begin_, tls_end_ - tls_begin_, 0);
52 void HwasanThread::Destroy() {
53 malloc_storage().CommitBack();
54 ClearShadowForThreadStackAndTLS();
55 uptr size = RoundUpTo(sizeof(HwasanThread), GetPageSizeCached());
56 UnmapOrDie(this, size);
60 thread_return_t HwasanThread::ThreadStart() {
63 if (!start_routine_) {
64 // start_routine_ == 0 if we're on the main thread or on one of the
65 // OS X libdispatch worker threads. But nobody is supposed to call
66 // ThreadStart() for the worker threads.
70 thread_return_t res = start_routine_(arg_);
75 } // namespace __hwasan