Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions compiler-rt/lib/asan/asan_fake_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,35 +214,42 @@ void FakeStack::ForEachFakeFrame(RangeIteratorCallback callback, void *arg) {
#if (SANITIZER_LINUX && !SANITIZER_ANDROID) || SANITIZER_FUCHSIA
static THREADLOCAL FakeStack *fake_stack_tls;

FakeStack *GetTLSFakeStack() {
return fake_stack_tls;
}
void SetTLSFakeStack(FakeStack *fs) {
fake_stack_tls = fs;
}
static FakeStack* GetTLSFakeStack() { return fake_stack_tls; }
static void SetTLSFakeStack(FakeStack* fs) { fake_stack_tls = fs; }
void ResetTLSFakeStack() { fake_stack_tls = nullptr; }
#else
FakeStack *GetTLSFakeStack() { return 0; }
void SetTLSFakeStack(FakeStack *fs) { }
static FakeStack* GetTLSFakeStack() { return nullptr; }
static void SetTLSFakeStack(FakeStack*) {}
void ResetTLSFakeStack() {}
#endif // (SANITIZER_LINUX && !SANITIZER_ANDROID) || SANITIZER_FUCHSIA

static FakeStack *GetFakeStack() {
AsanThread *t = GetCurrentThread();
if (!t) return nullptr;
static FakeStack* GetFakeStack() {
AsanThread* t = GetCurrentThread();
if (!t)
return nullptr;
return t->get_or_create_fake_stack();
}

static FakeStack *GetFakeStackFast() {
if (FakeStack *fs = GetTLSFakeStack())
static FakeStack* GetFakeStackFast() {
FakeStack* fs = GetTLSFakeStack();
if (LIKELY(fs))
return fs;
if (!__asan_option_detect_stack_use_after_return)
return nullptr;
return GetFakeStack();
fs = GetFakeStack();
if (LIKELY(fs))
SetTLSFakeStack(fs);
return fs;
}

static FakeStack *GetFakeStackFastAlways() {
if (FakeStack *fs = GetTLSFakeStack())
static FakeStack* GetFakeStackFastAlways() {
FakeStack* fs = GetTLSFakeStack();
if (LIKELY(fs))
return fs;
return GetFakeStack();
fs = GetFakeStack();
if (LIKELY(fs))
SetTLSFakeStack(fs);
return fs;
}

static ALWAYS_INLINE uptr OnMalloc(uptr class_id, uptr size) {
Expand Down
3 changes: 1 addition & 2 deletions compiler-rt/lib/asan/asan_fake_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ class FakeStack {
void *true_start;
};

FakeStack *GetTLSFakeStack();
void SetTLSFakeStack(FakeStack *fs);
void ResetTLSFakeStack();

} // namespace __asan

Expand Down
6 changes: 3 additions & 3 deletions compiler-rt/lib/asan/asan_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void AsanThread::StartSwitchFiber(FakeStack **fake_stack_save, uptr bottom,
if (fake_stack_save)
*fake_stack_save = fake_stack_;
fake_stack_ = nullptr;
SetTLSFakeStack(nullptr);
ResetTLSFakeStack();
// if fake_stack_save is null, the fiber will die, delete the fakestack
if (!fake_stack_save && current_fake_stack)
current_fake_stack->Destroy(this->tid());
Expand All @@ -177,8 +177,8 @@ void AsanThread::FinishSwitchFiber(FakeStack *fake_stack_save, uptr *bottom_old,
}

if (fake_stack_save) {
SetTLSFakeStack(fake_stack_save);
fake_stack_ = fake_stack_save;
ResetTLSFakeStack();
}

if (bottom_old)
Expand Down Expand Up @@ -242,7 +242,7 @@ FakeStack *AsanThread::AsyncSignalSafeLazyInitFakeStack() {
Max(stack_size_log, static_cast<uptr>(flags()->min_uar_stack_size_log));
fake_stack_ = FakeStack::Create(stack_size_log);
DCHECK_EQ(GetCurrentThread(), this);
SetTLSFakeStack(fake_stack_);
ResetTLSFakeStack();
return fake_stack_;
}
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/asan/asan_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class AsanThread {
if (!fake_stack_) return;
FakeStack *t = fake_stack_;
fake_stack_ = nullptr;
SetTLSFakeStack(nullptr);
ResetTLSFakeStack();
t->Destroy(tid);
}

Expand Down