// ---------------------- TSD ---------------- {{{1
extern "C" void __hwasan_thread_enter() {
- Thread *t = Thread::Create();
- SetCurrentThread(t);
- t->Init();
+ Thread::Create();
}
extern "C" void __hwasan_thread_exit() {
CHECK(0 && "RemoveFromThreadList: thread not found");
}
-Thread *Thread::Create() {
+void Thread::Create() {
static u64 unique_id;
uptr PageSize = GetPageSizeCached();
uptr size = RoundUpTo(sizeof(Thread), PageSize);
thread->heap_allocations_ = RingBuffer<HeapAllocationRecord>::New(sz);
thread->unique_id_ = unique_id++;
InsertIntoThreadList(thread);
- return thread;
+ SetCurrentThread(thread);
+ thread->Init();
}
-void Thread::SetThreadStackAndTls() {
+void Thread::Init() {
// GetPthreadDestructorIterations may call malloc, so disable the tagging.
ScopedTaggingDisabler disabler;
CHECK(AddrIsInStack((uptr)&local));
CHECK(MemIsApp(stack_bottom_));
CHECK(MemIsApp(stack_top_ - 1));
-}
-void Thread::Init() {
- SetThreadStackAndTls();
if (stack_bottom_) {
CHECK(MemIsApp(stack_bottom_));
CHECK(MemIsApp(stack_top_ - 1));
class Thread {
public:
- static Thread *Create();
+ static void Create(); // Must be called from the thread itself.
void Destroy();
- void Init();
-
uptr stack_top() { return stack_top_; }
uptr stack_bottom() { return stack_bottom_; }
uptr tls_begin() { return tls_begin_; }
private:
// NOTE: There is no Thread constructor. It is allocated
// via mmap() and *must* be valid in zero-initialized state.
- void SetThreadStackAndTls();
+ void Init();
void ClearShadowForThreadStackAndTLS();
void Print(const char *prefix);
uptr stack_top_;