leonardchan created this revision. leonardchan added reviewers: phosek, mcgrathr, vitalybuka, eugenis. leonardchan added a project: Sanitizers. Herald added a subscriber: dberris. leonardchan requested review of this revision. Herald added a subscriber: Sanitizers.
Similar to `InitOptions` in asan, we can use this optional struct for initializing some members thread objects before they are created. On linux, this is unused and can remain undefined. On fuchsia, this will just be the stack bounds. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D104553 Files: compiler-rt/lib/hwasan/hwasan_linux.cpp compiler-rt/lib/hwasan/hwasan_thread.cpp compiler-rt/lib/hwasan/hwasan_thread.h compiler-rt/lib/hwasan/hwasan_thread_list.h Index: compiler-rt/lib/hwasan/hwasan_thread_list.h =================================================================== --- compiler-rt/lib/hwasan/hwasan_thread_list.h +++ compiler-rt/lib/hwasan/hwasan_thread_list.h @@ -85,7 +85,7 @@ RoundUpTo(ring_buffer_size_ + sizeof(Thread), ring_buffer_size_ * 2); } - Thread *CreateCurrentThread() { + Thread *CreateCurrentThread(const Thread::InitState *state = nullptr) { Thread *t = nullptr; { SpinMutexLock l(&free_list_mutex_); @@ -104,7 +104,7 @@ SpinMutexLock l(&live_list_mutex_); live_list_.push_back(t); } - t->Init((uptr)t - ring_buffer_size_, ring_buffer_size_); + t->Init((uptr)t - ring_buffer_size_, ring_buffer_size_, state); AddThreadStats(t); return t; } Index: compiler-rt/lib/hwasan/hwasan_thread.h =================================================================== --- compiler-rt/lib/hwasan/hwasan_thread.h +++ compiler-rt/lib/hwasan/hwasan_thread.h @@ -23,9 +23,13 @@ class Thread { public: - void Init(uptr stack_buffer_start, uptr stack_buffer_size); + // These are optional parameters that can be passed to Init. + struct InitState; + + void Init(uptr stack_buffer_start, uptr stack_buffer_size, + const InitState *state = nullptr); void InitRandomState(); - void InitStackAndTls(); + void InitStackAndTls(const InitState *state = nullptr); // Must be called from the thread itself. void InitStackRingBuffer(uptr stack_buffer_start, uptr stack_buffer_size); Index: compiler-rt/lib/hwasan/hwasan_thread.cpp =================================================================== --- compiler-rt/lib/hwasan/hwasan_thread.cpp +++ compiler-rt/lib/hwasan/hwasan_thread.cpp @@ -34,7 +34,8 @@ stack_allocations_->push(0); } -void Thread::Init(uptr stack_buffer_start, uptr stack_buffer_size) { +void Thread::Init(uptr stack_buffer_start, uptr stack_buffer_size, + const InitState *state) { CHECK_EQ(0, unique_id_); // try to catch bad stack reuse CHECK_EQ(0, stack_top_); CHECK_EQ(0, stack_bottom_); @@ -44,7 +45,7 @@ if (auto sz = flags()->heap_history_size) heap_allocations_ = HeapAllocationsRingBuffer::New(sz); - InitStackAndTls(); + InitStackAndTls(state); InitStackRingBuffer(stack_buffer_start, stack_buffer_size); } Index: compiler-rt/lib/hwasan/hwasan_linux.cpp =================================================================== --- compiler-rt/lib/hwasan/hwasan_linux.cpp +++ compiler-rt/lib/hwasan/hwasan_linux.cpp @@ -427,7 +427,7 @@ HandleDeadlySignal(info, context, GetTid(), &OnStackUnwind, nullptr); } -void Thread::InitStackAndTls() { +void Thread::InitStackAndTls(const InitState *state) { uptr tls_size; uptr stack_size; GetThreadStackAndTls(IsMainThread(), &stack_bottom_, &stack_size, &tls_begin_,
Index: compiler-rt/lib/hwasan/hwasan_thread_list.h =================================================================== --- compiler-rt/lib/hwasan/hwasan_thread_list.h +++ compiler-rt/lib/hwasan/hwasan_thread_list.h @@ -85,7 +85,7 @@ RoundUpTo(ring_buffer_size_ + sizeof(Thread), ring_buffer_size_ * 2); } - Thread *CreateCurrentThread() { + Thread *CreateCurrentThread(const Thread::InitState *state = nullptr) { Thread *t = nullptr; { SpinMutexLock l(&free_list_mutex_); @@ -104,7 +104,7 @@ SpinMutexLock l(&live_list_mutex_); live_list_.push_back(t); } - t->Init((uptr)t - ring_buffer_size_, ring_buffer_size_); + t->Init((uptr)t - ring_buffer_size_, ring_buffer_size_, state); AddThreadStats(t); return t; } Index: compiler-rt/lib/hwasan/hwasan_thread.h =================================================================== --- compiler-rt/lib/hwasan/hwasan_thread.h +++ compiler-rt/lib/hwasan/hwasan_thread.h @@ -23,9 +23,13 @@ class Thread { public: - void Init(uptr stack_buffer_start, uptr stack_buffer_size); + // These are optional parameters that can be passed to Init. + struct InitState; + + void Init(uptr stack_buffer_start, uptr stack_buffer_size, + const InitState *state = nullptr); void InitRandomState(); - void InitStackAndTls(); + void InitStackAndTls(const InitState *state = nullptr); // Must be called from the thread itself. void InitStackRingBuffer(uptr stack_buffer_start, uptr stack_buffer_size); Index: compiler-rt/lib/hwasan/hwasan_thread.cpp =================================================================== --- compiler-rt/lib/hwasan/hwasan_thread.cpp +++ compiler-rt/lib/hwasan/hwasan_thread.cpp @@ -34,7 +34,8 @@ stack_allocations_->push(0); } -void Thread::Init(uptr stack_buffer_start, uptr stack_buffer_size) { +void Thread::Init(uptr stack_buffer_start, uptr stack_buffer_size, + const InitState *state) { CHECK_EQ(0, unique_id_); // try to catch bad stack reuse CHECK_EQ(0, stack_top_); CHECK_EQ(0, stack_bottom_); @@ -44,7 +45,7 @@ if (auto sz = flags()->heap_history_size) heap_allocations_ = HeapAllocationsRingBuffer::New(sz); - InitStackAndTls(); + InitStackAndTls(state); InitStackRingBuffer(stack_buffer_start, stack_buffer_size); } Index: compiler-rt/lib/hwasan/hwasan_linux.cpp =================================================================== --- compiler-rt/lib/hwasan/hwasan_linux.cpp +++ compiler-rt/lib/hwasan/hwasan_linux.cpp @@ -427,7 +427,7 @@ HandleDeadlySignal(info, context, GetTid(), &OnStackUnwind, nullptr); } -void Thread::InitStackAndTls() { +void Thread::InitStackAndTls(const InitState *state) { uptr tls_size; uptr stack_size; GetThreadStackAndTls(IsMainThread(), &stack_bottom_, &stack_size, &tls_begin_,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits