forked from OSchip/llvm-project
[NFC][asan] Split fake_stack() into two funcions
This commit is contained in:
parent
64b1cbca19
commit
5b0e50550c
|
@ -187,7 +187,7 @@ void SetTLSFakeStack(FakeStack *fs) { }
|
|||
static FakeStack *GetFakeStack() {
|
||||
AsanThread *t = GetCurrentThread();
|
||||
if (!t) return nullptr;
|
||||
return t->fake_stack();
|
||||
return t->get_or_create_fake_stack();
|
||||
}
|
||||
|
||||
static FakeStack *GetFakeStackFast() {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include "asan_activation.h"
|
||||
#include "asan_allocator.h"
|
||||
#include "asan_fake_stack.h"
|
||||
#include "asan_interceptors.h"
|
||||
#include "asan_interface_internal.h"
|
||||
#include "asan_internal.h"
|
||||
|
@ -586,8 +587,12 @@ static void UnpoisonDefaultStack() {
|
|||
|
||||
static void UnpoisonFakeStack() {
|
||||
AsanThread *curr_thread = GetCurrentThread();
|
||||
if (curr_thread && curr_thread->has_fake_stack())
|
||||
curr_thread->fake_stack()->HandleNoReturn();
|
||||
if (!curr_thread)
|
||||
return;
|
||||
FakeStack *stack = curr_thread->get_fake_stack();
|
||||
if (!stack)
|
||||
return;
|
||||
stack->HandleNoReturn();
|
||||
}
|
||||
|
||||
} // namespace __asan
|
||||
|
|
|
@ -339,8 +339,8 @@ bool AsanThread::GetStackFrameAccessByAddr(uptr addr,
|
|||
uptr bottom = 0;
|
||||
if (AddrIsInStack(addr)) {
|
||||
bottom = stack_bottom();
|
||||
} else if (has_fake_stack()) {
|
||||
bottom = fake_stack()->AddrIsInFakeStack(addr);
|
||||
} else if (FakeStack *fake_stack = get_fake_stack()) {
|
||||
bottom = fake_stack->AddrIsInFakeStack(addr);
|
||||
CHECK(bottom);
|
||||
access->offset = addr - bottom;
|
||||
access->frame_pc = ((uptr*)bottom)[2];
|
||||
|
@ -380,8 +380,8 @@ uptr AsanThread::GetStackVariableShadowStart(uptr addr) {
|
|||
uptr bottom = 0;
|
||||
if (AddrIsInStack(addr)) {
|
||||
bottom = stack_bottom();
|
||||
} else if (has_fake_stack()) {
|
||||
bottom = fake_stack()->AddrIsInFakeStack(addr);
|
||||
} else if (FakeStack *fake_stack = get_fake_stack()) {
|
||||
bottom = fake_stack->AddrIsInFakeStack(addr);
|
||||
if (bottom == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -415,9 +415,10 @@ static bool ThreadStackContainsAddress(ThreadContextBase *tctx_base,
|
|||
return false;
|
||||
if (t->AddrIsInStack((uptr)addr))
|
||||
return true;
|
||||
if (t->has_fake_stack() && t->fake_stack()->AddrIsInFakeStack((uptr)addr))
|
||||
return true;
|
||||
return false;
|
||||
FakeStack *fake_stack = t->get_fake_stack();
|
||||
if (!fake_stack)
|
||||
return false;
|
||||
return fake_stack->AddrIsInFakeStack((uptr)addr);
|
||||
}
|
||||
|
||||
AsanThread *GetCurrentThread() {
|
||||
|
@ -505,8 +506,12 @@ void GetAllThreadAllocatorCachesLocked(InternalMmapVector<uptr> *caches) {}
|
|||
void ForEachExtraStackRange(tid_t os_id, RangeIteratorCallback callback,
|
||||
void *arg) {
|
||||
__asan::AsanThread *t = __asan::GetAsanThreadByOsIDLocked(os_id);
|
||||
if (t && t->has_fake_stack())
|
||||
t->fake_stack()->ForEachFakeFrame(callback, arg);
|
||||
if (!t)
|
||||
return;
|
||||
__asan::FakeStack *fake_stack = t->get_fake_stack();
|
||||
if (!fake_stack)
|
||||
return;
|
||||
fake_stack->ForEachFakeFrame(callback, arg);
|
||||
}
|
||||
|
||||
void LockThreadRegistry() {
|
||||
|
|
|
@ -104,17 +104,18 @@ class AsanThread {
|
|||
void FinishSwitchFiber(FakeStack *fake_stack_save, uptr *bottom_old,
|
||||
uptr *size_old);
|
||||
|
||||
bool has_fake_stack() {
|
||||
return !atomic_load(&stack_switching_, memory_order_relaxed) &&
|
||||
(reinterpret_cast<uptr>(fake_stack_) > 1);
|
||||
}
|
||||
|
||||
FakeStack *fake_stack() {
|
||||
if (!__asan_option_detect_stack_use_after_return)
|
||||
return nullptr;
|
||||
FakeStack *get_fake_stack() {
|
||||
if (atomic_load(&stack_switching_, memory_order_relaxed))
|
||||
return nullptr;
|
||||
if (!has_fake_stack())
|
||||
if (reinterpret_cast<uptr>(fake_stack_) <= 1)
|
||||
return nullptr;
|
||||
return fake_stack_;
|
||||
}
|
||||
|
||||
FakeStack *get_or_create_fake_stack() {
|
||||
if (atomic_load(&stack_switching_, memory_order_relaxed))
|
||||
return nullptr;
|
||||
if (reinterpret_cast<uptr>(fake_stack_) <= 1)
|
||||
return AsyncSignalSafeLazyInitFakeStack();
|
||||
return fake_stack_;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue