[PATCH] [asan] Move lsan_disabled out of thread context.
Sergey Matveev
earthdok at google.com
Fri Jun 21 05:32:36 PDT 2013
Hi kcc,
http://llvm-reviews.chandlerc.com/D1017
Files:
lib/asan/asan_allocator2.cc
lib/asan/asan_thread.cc
lib/asan/asan_thread.h
Index: lib/asan/asan_allocator2.cc
===================================================================
--- lib/asan/asan_allocator2.cc
+++ lib/asan/asan_allocator2.cc
@@ -257,6 +257,12 @@
static AllocatorCache fallback_allocator_cache;
static SpinMutex fallback_mutex;
+#if CAN_SANITIZE_LEAKS
+// This can't be stored in the thread context, because people call
+// __lsan_disable() from very strange places.
+THREADLOCAL int lsan_disabled;
+#endif
+
QuarantineCache *GetQuarantineCache(AsanThreadLocalMallocStorage *ms) {
CHECK(ms);
CHECK_LE(sizeof(QuarantineCache), sizeof(ms->quarantine_cache));
@@ -423,10 +429,9 @@
uptr fill_size = Min(size, (uptr)fl.max_malloc_fill_size);
REAL(memset)(res, fl.malloc_fill_byte, fill_size);
}
- if (t && t->lsan_disabled())
- m->lsan_tag = __lsan::kIgnored;
- else
- m->lsan_tag = __lsan::kDirectlyLeaked;
+#if CAN_SANITIZE_LEAKS
+ if (lsan_disabled) m->lsan_tag = __lsan::kIgnored;
+#endif
// Must be the last mutation of metadata in this function.
atomic_store((atomic_uint8_t *)m, CHUNK_ALLOCATED, memory_order_release);
ASAN_MALLOC_HOOK(res, size);
@@ -798,20 +803,18 @@
SANITIZER_INTERFACE_ATTRIBUTE
void __lsan_disable() {
#if CAN_SANITIZE_LEAKS
- __asan_init();
- __asan::AsanThread *t = __asan::GetCurrentThread();
- CHECK(t);
- t->disable_lsan();
+ __asan::lsan_disabled++;
#endif // CAN_SANITIZE_LEAKS
}
SANITIZER_INTERFACE_ATTRIBUTE
void __lsan_enable() {
#if CAN_SANITIZE_LEAKS
- __asan_init();
- __asan::AsanThread *t = __asan::GetCurrentThread();
- CHECK(t);
- t->enable_lsan();
+ if (!__asan::lsan_disabled) {
+ Report("Unmatched call to __lsan_enable().\n");
+ Die();
+ }
+ __asan::lsan_disabled--;
#endif // CAN_SANITIZE_LEAKS
}
} // extern "C"
Index: lib/asan/asan_thread.cc
===================================================================
--- lib/asan/asan_thread.cc
+++ lib/asan/asan_thread.cc
@@ -109,7 +109,6 @@
void AsanThread::Init() {
SetThreadStackAndTls();
- lsan_disabled_ = 0;
CHECK(AddrIsInMem(stack_bottom_));
CHECK(AddrIsInMem(stack_top_ - 1));
ClearShadowForThreadStackAndTLS();
Index: lib/asan/asan_thread.h
===================================================================
--- lib/asan/asan_thread.h
+++ lib/asan/asan_thread.h
@@ -65,15 +65,6 @@
uptr stack_size() { return stack_top_ - stack_bottom_; }
uptr tls_begin() { return tls_begin_; }
uptr tls_end() { return tls_end_; }
- uptr lsan_disabled() { return lsan_disabled_; }
- void disable_lsan() { lsan_disabled_++; }
- void enable_lsan() {
- if (!lsan_disabled_) {
- Report("Unmatched call to __lsan_enable().\n");
- Die();
- }
- lsan_disabled_--;
- }
u32 tid() { return context_->tid; }
AsanThreadContext *context() { return context_; }
void set_context(AsanThreadContext *context) { context_ = context; }
@@ -99,7 +90,6 @@
uptr stack_bottom_;
uptr tls_begin_;
uptr tls_end_;
- uptr lsan_disabled_;
FakeStack fake_stack_;
AsanThreadLocalMallocStorage malloc_storage_;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1017.1.patch
Type: text/x-patch
Size: 3055 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130621/9681916c/attachment.bin>
More information about the llvm-commits
mailing list