[compiler-rt] r255996 - [tsan] Add a DCHECK to verify __tsan_read* and __tsan_write function aren't called from ScopedInterceptor
Kuba Brecka via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 18 05:08:17 PST 2015
Author: kuba.brecka
Date: Fri Dec 18 07:08:15 2015
New Revision: 255996
URL: http://llvm.org/viewvc/llvm-project?rev=255996&view=rev
Log:
[tsan] Add a DCHECK to verify __tsan_read* and __tsan_write function aren't called from ScopedInterceptor
Interceptors using ScopedInteceptor should never call into user's code before the ScopedInterceptor is out of scope (and its destructor is called). Let's add a DCHECK to enforce that.
Differential Revision: http://reviews.llvm.org/D15381
Modified:
compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_interface_inl.h
compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=255996&r1=255995&r2=255996&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Fri Dec 18 07:08:15 2015
@@ -281,9 +281,15 @@ ScopedInterceptor::ScopedInterceptor(Thr
thr_->in_ignored_lib = true;
ThreadIgnoreBegin(thr_, pc_);
}
+#if SANITIZER_DEBUG
+ thr_->in_interceptor_count++;
+#endif
}
ScopedInterceptor::~ScopedInterceptor() {
+#if SANITIZER_DEBUG
+ thr_->in_interceptor_count--;
+#endif
if (in_ignored_lib_) {
thr_->in_ignored_lib = false;
ThreadIgnoreEnd(thr_, pc_);
@@ -296,6 +302,9 @@ ScopedInterceptor::~ScopedInterceptor()
}
void ScopedInterceptor::UserCallbackStart() {
+#if SANITIZER_DEBUG
+ thr_->in_interceptor_count--;
+#endif
if (in_ignored_lib_) {
thr_->in_ignored_lib = false;
ThreadIgnoreEnd(thr_, pc_);
@@ -307,6 +316,9 @@ void ScopedInterceptor::UserCallbackEnd(
thr_->in_ignored_lib = true;
ThreadIgnoreBegin(thr_, pc_);
}
+#if SANITIZER_DEBUG
+ thr_->in_interceptor_count++;
+#endif
}
#define TSAN_INTERCEPT(func) INTERCEPT_FUNCTION(func)
@@ -2108,7 +2120,9 @@ TSAN_INTERCEPTOR(sighandler_t, signal, i
}
TSAN_INTERCEPTOR(int, sigsuspend, const __sanitizer_sigset_t *mask) {
- SCOPED_TSAN_INTERCEPTOR(sigsuspend, mask);
+ {
+ SCOPED_TSAN_INTERCEPTOR(sigsuspend, mask);
+ }
return REAL(sigsuspend)(mask);
}
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interface_inl.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interface_inl.h?rev=255996&r1=255995&r2=255996&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interface_inl.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interface_inl.h Fri Dec 18 07:08:15 2015
@@ -18,69 +18,36 @@
using namespace __tsan; // NOLINT
-void __tsan_read1(void *addr) {
- MemoryRead(cur_thread(), CALLERPC, (uptr)addr, kSizeLog1);
-}
-
-void __tsan_read2(void *addr) {
- MemoryRead(cur_thread(), CALLERPC, (uptr)addr, kSizeLog2);
-}
-
-void __tsan_read4(void *addr) {
- MemoryRead(cur_thread(), CALLERPC, (uptr)addr, kSizeLog4);
-}
-
-void __tsan_read8(void *addr) {
- MemoryRead(cur_thread(), CALLERPC, (uptr)addr, kSizeLog8);
-}
-
-void __tsan_write1(void *addr) {
- MemoryWrite(cur_thread(), CALLERPC, (uptr)addr, kSizeLog1);
-}
-
-void __tsan_write2(void *addr) {
- MemoryWrite(cur_thread(), CALLERPC, (uptr)addr, kSizeLog2);
-}
-
-void __tsan_write4(void *addr) {
- MemoryWrite(cur_thread(), CALLERPC, (uptr)addr, kSizeLog4);
-}
-
-void __tsan_write8(void *addr) {
- MemoryWrite(cur_thread(), CALLERPC, (uptr)addr, kSizeLog8);
-}
-
-void __tsan_read1_pc(void *addr, void *pc) {
- MemoryRead(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog1);
-}
-
-void __tsan_read2_pc(void *addr, void *pc) {
- MemoryRead(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog2);
-}
-
-void __tsan_read4_pc(void *addr, void *pc) {
- MemoryRead(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog4);
-}
-
-void __tsan_read8_pc(void *addr, void *pc) {
- MemoryRead(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog8);
-}
-
-void __tsan_write1_pc(void *addr, void *pc) {
- MemoryWrite(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog1);
-}
-
-void __tsan_write2_pc(void *addr, void *pc) {
- MemoryWrite(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog2);
-}
-
-void __tsan_write4_pc(void *addr, void *pc) {
- MemoryWrite(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog4);
-}
-
-void __tsan_write8_pc(void *addr, void *pc) {
- MemoryWrite(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog8);
-}
+#define TSAN_MEM_ACCESS_FUNC(type, func, size) \
+ void __tsan_##type(void *addr) { \
+ ThreadState *thr = cur_thread(); \
+ DCHECK_EQ(thr->in_interceptor_count, 0); \
+ func(thr, CALLERPC, (uptr)addr, size); \
+ }
+
+#define TSAN_MEM_ACCESS_FUNC_PC(type, func, size) \
+ void __tsan_##type(void *addr, void *pc) { \
+ ThreadState *thr = cur_thread(); \
+ DCHECK_EQ(thr->in_interceptor_count, 0); \
+ func(thr, (uptr)pc, (uptr)addr, size); \
+ }
+
+TSAN_MEM_ACCESS_FUNC(read1, MemoryRead, kSizeLog1)
+TSAN_MEM_ACCESS_FUNC(read2, MemoryRead, kSizeLog2)
+TSAN_MEM_ACCESS_FUNC(read4, MemoryRead, kSizeLog4)
+TSAN_MEM_ACCESS_FUNC(read8, MemoryRead, kSizeLog8)
+TSAN_MEM_ACCESS_FUNC(write1, MemoryWrite, kSizeLog1)
+TSAN_MEM_ACCESS_FUNC(write2, MemoryWrite, kSizeLog2)
+TSAN_MEM_ACCESS_FUNC(write4, MemoryWrite, kSizeLog4)
+TSAN_MEM_ACCESS_FUNC(write8, MemoryWrite, kSizeLog8)
+TSAN_MEM_ACCESS_FUNC_PC(read1_pc, MemoryRead, kSizeLog1)
+TSAN_MEM_ACCESS_FUNC_PC(read2_pc, MemoryRead, kSizeLog2)
+TSAN_MEM_ACCESS_FUNC_PC(read4_pc, MemoryRead, kSizeLog4)
+TSAN_MEM_ACCESS_FUNC_PC(read8_pc, MemoryRead, kSizeLog8)
+TSAN_MEM_ACCESS_FUNC_PC(write1_pc, MemoryWrite, kSizeLog1)
+TSAN_MEM_ACCESS_FUNC_PC(write2_pc, MemoryWrite, kSizeLog2)
+TSAN_MEM_ACCESS_FUNC_PC(write4_pc, MemoryWrite, kSizeLog4)
+TSAN_MEM_ACCESS_FUNC_PC(write8_pc, MemoryWrite, kSizeLog8)
void __tsan_vptr_update(void **vptr_p, void *new_val) {
CHECK_EQ(sizeof(vptr_p), 8);
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h?rev=255996&r1=255995&r2=255996&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h Fri Dec 18 07:08:15 2015
@@ -372,6 +372,9 @@ struct ThreadState {
const int unique_id;
bool in_symbolizer;
bool in_ignored_lib;
+#if SANITIZER_DEBUG
+ int in_interceptor_count;
+#endif
bool is_inited;
bool is_dead;
bool is_freeing;
More information about the llvm-commits
mailing list