[compiler-rt] r190663 - [asan] second attempt to use TLS with fake stack. This time it looks (more) async-signal safe.
Kostya Serebryany
kcc at google.com
Thu Sep 12 23:32:26 PDT 2013
Author: kcc
Date: Fri Sep 13 01:32:26 2013
New Revision: 190663
URL: http://llvm.org/viewvc/llvm-project?rev=190663&view=rev
Log:
[asan] second attempt to use TLS with fake stack. This time it looks (more) async-signal safe.
Modified:
compiler-rt/trunk/lib/asan/asan_fake_stack.cc
compiler-rt/trunk/lib/asan/asan_fake_stack.h
compiler-rt/trunk/lib/asan/asan_thread.cc
compiler-rt/trunk/lib/asan/asan_thread.h
Modified: compiler-rt/trunk/lib/asan/asan_fake_stack.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_fake_stack.cc?rev=190663&r1=190662&r2=190663&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_fake_stack.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_fake_stack.cc Fri Sep 13 01:32:26 2013
@@ -122,6 +122,20 @@ NOINLINE void FakeStack::GC(uptr real_st
needs_gc_ = false;
}
+#if SANITIZER_LINUX
+static THREADLOCAL FakeStack *fake_stack_tls;
+
+FakeStack *GetTLSFakeStack() {
+ return fake_stack_tls;
+}
+void SetTLSFakeStack(FakeStack *fs) {
+ fake_stack_tls = fs;
+}
+#else
+FakeStack *GetTLSFakeStack() { return 0; }
+void SetTLSFakeStack(FakeStack *fs) { }
+#endif // SANITIZER_LINUX
+
static FakeStack *GetFakeStack() {
AsanThread *t = GetCurrentThread();
if (!t) return 0;
@@ -129,14 +143,9 @@ static FakeStack *GetFakeStack() {
}
static FakeStack *GetFakeStackFast() {
-#if 0 && SANITIZER_LINUX // breaks with signals...
- static THREADLOCAL FakeStack *fake_stack;
- if (!fake_stack)
- fake_stack = GetFakeStack();
- return fake_stack;
-#else
+ if (FakeStack *fs = GetTLSFakeStack())
+ return fs;
return GetFakeStack();
-#endif
}
ALWAYS_INLINE uptr OnMalloc(uptr class_id, uptr size, uptr real_stack) {
Modified: compiler-rt/trunk/lib/asan/asan_fake_stack.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_fake_stack.h?rev=190663&r1=190662&r2=190663&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_fake_stack.h (original)
+++ compiler-rt/trunk/lib/asan/asan_fake_stack.h Fri Sep 13 01:32:26 2013
@@ -168,6 +168,9 @@ class FakeStack {
bool needs_gc_;
};
+FakeStack *GetTLSFakeStack();
+void SetTLSFakeStack(FakeStack *fs);
+
} // namespace __asan
#endif // ASAN_FAKE_STACK_H
Modified: compiler-rt/trunk/lib/asan/asan_thread.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_thread.cc?rev=190663&r1=190662&r2=190663&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_thread.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_thread.cc Fri Sep 13 01:32:26 2013
@@ -122,9 +122,11 @@ FakeStack *AsanThread::AsyncSignalSafeLa
// if that was successfull, it initilizes the pointer.
if (atomic_compare_exchange_strong(
reinterpret_cast<atomic_uintptr_t *>(&fake_stack_), &old_val, 1UL,
- memory_order_relaxed))
- return fake_stack_ =
- FakeStack::Create(Log2(RoundUpToPowerOfTwo(stack_size)));
+ memory_order_relaxed)) {
+ fake_stack_ = FakeStack::Create(Log2(RoundUpToPowerOfTwo(stack_size)));
+ SetTLSFakeStack(fake_stack_);
+ return fake_stack_;
+ }
return 0;
}
Modified: compiler-rt/trunk/lib/asan/asan_thread.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_thread.h?rev=190663&r1=190662&r2=190663&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_thread.h (original)
+++ compiler-rt/trunk/lib/asan/asan_thread.h Fri Sep 13 01:32:26 2013
@@ -78,7 +78,10 @@ class AsanThread {
void DeleteFakeStack() {
if (!fake_stack_) return;
fake_stack_->PoisonAll(0);
- fake_stack_->Destroy();
+ FakeStack *t = fake_stack_;
+ fake_stack_ = 0;
+ SetTLSFakeStack(0);
+ t->Destroy();
}
bool has_fake_stack() {
More information about the llvm-commits
mailing list