forked from OSchip/llvm-project
[asan] Fix deadlock in stack unwinder on android/x86.
Fixes PR17116. Patch by 林作健 (manjian2006 at gmail.com). llvm-svn: 190590
This commit is contained in:
parent
e8f961e847
commit
58dbe06230
|
@ -29,21 +29,21 @@ void PrintStack(StackTrace *stack);
|
||||||
// The pc will be in the position 0 of the resulting stack trace.
|
// The pc will be in the position 0 of the resulting stack trace.
|
||||||
// The bp may refer to the current frame or to the caller's frame.
|
// The bp may refer to the current frame or to the caller's frame.
|
||||||
#if SANITIZER_WINDOWS
|
#if SANITIZER_WINDOWS
|
||||||
#define GET_STACK_TRACE_WITH_PC_AND_BP(max_s, pc, bp, fast) \
|
#define GET_STACK_TRACE_WITH_PC_AND_BP(max_s, pc, bp, fast) \
|
||||||
StackTrace stack; \
|
StackTrace stack; \
|
||||||
GetStackTrace(&stack, max_s, pc, bp, 0, 0, fast)
|
GetStackTrace(&stack, max_s, pc, bp, 0, 0, fast)
|
||||||
#else
|
#else
|
||||||
#define GET_STACK_TRACE_WITH_PC_AND_BP(max_s, pc, bp, fast) \
|
#define GET_STACK_TRACE_WITH_PC_AND_BP(max_s, pc, bp, fast) \
|
||||||
StackTrace stack; \
|
StackTrace stack; \
|
||||||
{ \
|
{ \
|
||||||
uptr stack_top = 0, stack_bottom = 0; \
|
AsanThread *t; \
|
||||||
AsanThread *t; \
|
stack.size = 0; \
|
||||||
if (asan_inited && (t = GetCurrentThread())) { \
|
if (asan_inited && (t = GetCurrentThread()) && !t->isUnwinding()) { \
|
||||||
stack_top = t->stack_top(); \
|
uptr stack_top = t->stack_top(); \
|
||||||
stack_bottom = t->stack_bottom(); \
|
uptr stack_bottom = t->stack_bottom(); \
|
||||||
} \
|
ScopedUnwinding unwind_scope(t); \
|
||||||
GetStackTrace(&stack, max_s, pc, bp, \
|
GetStackTrace(&stack, max_s, pc, bp, stack_top, stack_bottom, fast); \
|
||||||
stack_top, stack_bottom, fast); \
|
} \
|
||||||
}
|
}
|
||||||
#endif // SANITIZER_WINDOWS
|
#endif // SANITIZER_WINDOWS
|
||||||
|
|
||||||
|
|
|
@ -87,11 +87,17 @@ class AsanThread {
|
||||||
return fake_stack_;
|
return fake_stack_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// True is this thread is currently unwinding stack (i.e. collecting a stack
|
||||||
|
// trace). Used to prevent deadlocks on platforms where libc unwinder calls
|
||||||
|
// malloc internally. See PR17116 for more details.
|
||||||
|
bool isUnwinding() const { return unwinding; }
|
||||||
|
void setUnwinding(bool b) { unwinding = b; }
|
||||||
|
|
||||||
AsanThreadLocalMallocStorage &malloc_storage() { return malloc_storage_; }
|
AsanThreadLocalMallocStorage &malloc_storage() { return malloc_storage_; }
|
||||||
AsanStats &stats() { return stats_; }
|
AsanStats &stats() { return stats_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AsanThread() {}
|
AsanThread() : unwinding(false) {}
|
||||||
void SetThreadStackAndTls();
|
void SetThreadStackAndTls();
|
||||||
void ClearShadowForThreadStackAndTLS();
|
void ClearShadowForThreadStackAndTLS();
|
||||||
AsanThreadContext *context_;
|
AsanThreadContext *context_;
|
||||||
|
@ -105,6 +111,19 @@ class AsanThread {
|
||||||
FakeStack *fake_stack_;
|
FakeStack *fake_stack_;
|
||||||
AsanThreadLocalMallocStorage malloc_storage_;
|
AsanThreadLocalMallocStorage malloc_storage_;
|
||||||
AsanStats stats_;
|
AsanStats stats_;
|
||||||
|
bool unwinding;
|
||||||
|
};
|
||||||
|
|
||||||
|
// ScopedUnwinding is a scope for stacktracing member of a context
|
||||||
|
class ScopedUnwinding {
|
||||||
|
public:
|
||||||
|
explicit ScopedUnwinding(AsanThread *t) : thread(t) {
|
||||||
|
t->setUnwinding(true);
|
||||||
|
}
|
||||||
|
~ScopedUnwinding() { thread->setUnwinding(false); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
AsanThread *thread;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CreateThreadContextArgs {
|
struct CreateThreadContextArgs {
|
||||||
|
|
|
@ -114,8 +114,9 @@ static void ProcessPlatformSpecificAllocationsCb(uptr chunk, void *arg) {
|
||||||
chunk = GetUserBegin(chunk);
|
chunk = GetUserBegin(chunk);
|
||||||
LsanMetadata m(chunk);
|
LsanMetadata m(chunk);
|
||||||
if (m.allocated() && m.tag() != kReachable) {
|
if (m.allocated() && m.tag() != kReachable) {
|
||||||
if (linker->containsAddress(
|
u32 stack_id = m.stack_trace_id();
|
||||||
GetCallerPC(m.stack_trace_id(), param->stack_depot_reverse_map))) {
|
if (!stack_id || linker->containsAddress(GetCallerPC(
|
||||||
|
stack_id, param->stack_depot_reverse_map))) {
|
||||||
m.set_tag(kReachable);
|
m.set_tag(kReachable);
|
||||||
param->frontier->push_back(chunk);
|
param->frontier->push_back(chunk);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue