[PATCH] [asan] Make ASan report the correct thread address ranges to LSan.
Sergey Matveev
earthdok at google.com
Fri May 24 11:50:47 PDT 2013
Hi kcc, glider, samsonov,
This CL enables thread support in LSan when used on top of ASan.
Depends on D861.
http://llvm-reviews.chandlerc.com/D862
Files:
lib/asan/asan_rtl.cc
lib/asan/asan_thread.cc
lib/asan/asan_thread.h
Index: lib/asan/asan_rtl.cc
===================================================================
--- lib/asan/asan_rtl.cc
+++ lib/asan/asan_rtl.cc
@@ -547,6 +547,8 @@
asan_inited = 1;
asan_init_is_running = false;
+ InitTlsSize();
+
// Create main thread.
AsanTSDInit(AsanThread::TSDDtor);
AsanThread *main_thread = AsanThread::Create(0, 0);
Index: lib/asan/asan_thread.cc
===================================================================
--- lib/asan/asan_thread.cc
+++ lib/asan/asan_thread.cc
@@ -107,7 +107,7 @@
}
void AsanThread::Init() {
- SetThreadStackTopAndBottom();
+ SetThreadStackAndTls();
CHECK(AddrIsInMem(stack_bottom_));
CHECK(AddrIsInMem(stack_top_ - 1));
ClearShadowForThreadStack();
@@ -143,8 +143,13 @@
return res;
}
-void AsanThread::SetThreadStackTopAndBottom() {
- GetThreadStackTopAndBottom(tid() == 0, &stack_top_, &stack_bottom_);
+void AsanThread::SetThreadStackAndTls() {
+ uptr stack_size = 0, tls_size = 0;
+ GetThreadStackAndTls(tid() == 0, &stack_bottom_, &stack_size, &tls_begin_,
+ &tls_size);
+ stack_top_ = stack_bottom_ + stack_size;
+ tls_end_ = tls_begin_ + tls_size;
+
int local;
CHECK(AddrIsInStack((uptr)&local));
}
@@ -251,8 +256,19 @@
bool GetThreadRangesLocked(uptr os_id, uptr *stack_begin, uptr *stack_end,
uptr *tls_begin, uptr *tls_end,
uptr *cache_begin, uptr *cache_end) {
- // FIXME: Stub.
- return false;
+ __asan::AsanThreadContext *context = static_cast<__asan::AsanThreadContext *>(
+ __asan::asanThreadRegistry().FindThreadContextByOsIDLocked(os_id));
+ if (!context) return false;
+ __asan::AsanThread *t = context->thread;
+ if (!t) return false;
+ *stack_begin = t->stack_bottom();
+ *stack_end = t->stack_top();
+ *tls_begin = t->tls_begin();
+ *tls_end = t->tls_end();
+ // ASan doesn't keep allocator caches in TLS, so these are unused.
+ *cache_begin = 0;
+ *cache_end = 0;
+ return true;
}
void LockThreadRegistry() {
Index: lib/asan/asan_thread.h
===================================================================
--- lib/asan/asan_thread.h
+++ lib/asan/asan_thread.h
@@ -63,6 +63,8 @@
uptr stack_top() { return stack_top_; }
uptr stack_bottom() { return stack_bottom_; }
uptr stack_size() { return stack_top_ - stack_bottom_; }
+ uptr tls_begin() { return tls_begin_; }
+ uptr tls_end() { return tls_end_; }
u32 tid() { return context_->tid; }
AsanThreadContext *context() { return context_; }
void set_context(AsanThreadContext *context) { context_ = context; }
@@ -79,13 +81,15 @@
private:
AsanThread() {}
- void SetThreadStackTopAndBottom();
+ void SetThreadStackAndTls();
void ClearShadowForThreadStack();
AsanThreadContext *context_;
thread_callback_t start_routine_;
void *arg_;
uptr stack_top_;
uptr stack_bottom_;
+ uptr tls_begin_;
+ uptr tls_end_;
FakeStack fake_stack_;
AsanThreadLocalMallocStorage malloc_storage_;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D862.1.patch
Type: text/x-patch
Size: 3007 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130524/611d6943/attachment.bin>
More information about the llvm-commits
mailing list