diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2012-05-22 18:07:45 +0000 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2012-05-22 18:07:45 +0000 |
| commit | 302cebb8f1a193052f0739b4da90b013f3638e94 (patch) | |
| tree | 7cf26d110f098c9c66d6a8e1c6fc589be3886c6e /compiler-rt/lib/tsan/rtl/tsan_rtl.cc | |
| parent | 8b3304da56822ae35fd223eafd2d0c558aafabc4 (diff) | |
| download | bcm5719-llvm-302cebb8f1a193052f0739b4da90b013f3638e94.tar.gz bcm5719-llvm-302cebb8f1a193052f0739b4da90b013f3638e94.zip | |
tsan: add shadow memory flush + fix few bugs
llvm-svn: 157270
Diffstat (limited to 'compiler-rt/lib/tsan/rtl/tsan_rtl.cc')
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_rtl.cc | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc index 05be9581806..c93bdcf87e1 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc @@ -21,10 +21,10 @@ #include "tsan_placement_new.h" #include "tsan_suppressions.h" -volatile int __tsan_stop = 0; +volatile int __tsan_resumed = 0; extern "C" void __tsan_resume() { - __tsan_stop = 0; + __tsan_resumed = 1; } namespace __tsan { @@ -59,7 +59,6 @@ ThreadState::ThreadState(Context *ctx, int tid, u64 epoch, // , in_rtl() , shadow_stack_pos(&shadow_stack[0]) , tid(tid) - , func_call_count() , stk_addr(stk_addr) , stk_size(stk_size) , tls_addr(tls_addr) @@ -138,6 +137,22 @@ static void InitializeMemoryProfile() { internal_start_thread(&MemoryProfileThread, (void*)(uptr)fd); } +static void MemoryFlushThread(void *arg) { + ScopedInRtl in_rtl; + for (int i = 0; ; i++) { + internal_sleep_ms(flags()->flush_memory_ms); + FlushShadowMemory(); + } +} + +static void InitializeMemoryFlush() { + if (flags()->flush_memory_ms == 0) + return; + if (flags()->flush_memory_ms < 100) + flags()->flush_memory_ms = 100; + internal_start_thread(&MemoryFlushThread, 0); +} + void Initialize(ThreadState *thr) { // Thread safe because done before all threads exist. static bool is_initialized = false; @@ -157,9 +172,10 @@ void Initialize(ThreadState *thr) { InitializeFlags(&ctx->flags, env); InitializeSuppressions(); InitializeMemoryProfile(); + InitializeMemoryFlush(); if (ctx->flags.verbosity) - Printf("***** Running under ThreadSanitizer v2 (pid=%d) *****\n", GetPid()); + Printf("***** Running under ThreadSanitizer v2 (pid %d) *****\n", GetPid()); // Initialize thread 0. ctx->thread_seq = 0; @@ -169,9 +185,11 @@ void Initialize(ThreadState *thr) { CHECK_EQ(thr->in_rtl, 1); ctx->initialized = true; - if (__tsan_stop) { - Printf("ThreadSanitizer is suspended at startup.\n"); - while (__tsan_stop); + if (flags()->stop_on_start) { + Printf("ThreadSanitizer is suspended at startup (pid %d)." + " Call __tsan_resume().\n", + GetPid()); + while (__tsan_resumed == 0); } } |

