diff options
author | Dmitry Vyukov <dvyukov@google.com> | 2014-12-25 10:32:25 +0000 |
---|---|---|
committer | Dmitry Vyukov <dvyukov@google.com> | 2014-12-25 10:32:25 +0000 |
commit | bda655004e93bce7c8d60a62f754e0ec6494cf1e (patch) | |
tree | 8f68ab5bd0d98c6c3c899708e9178732c4d1d5fb | |
parent | 25b383ac663e0406164cd951958a22e8ddfc13c1 (diff) | |
download | bcm5719-llvm-bda655004e93bce7c8d60a62f754e0ec6494cf1e.tar.gz bcm5719-llvm-bda655004e93bce7c8d60a62f754e0ec6494cf1e.zip |
tsan: fix trace initialization during thread id reuse
The current code leaves the first event in the trace part uninitialized
(from the previous thread). It can cause unpredictable behavior
during stack/mutexset restoration.
Initialize the first event to a fake harmless memory access.
llvm-svn: 224834
-rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc index d84cd44b554..065ba88439c 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc @@ -111,15 +111,13 @@ void ThreadContext::OnStarted(void *arg) { thr->dd_pt = ctx->dd->CreatePhysicalThread(); thr->dd_lt = ctx->dd->CreateLogicalThread(unique_id); } + thr->fast_state.SetHistorySize(flags()->history_size); + // Commit switch to the new part of the trace. + // TraceAddEvent will reset stack0/mset0 in the new part for us. + TraceAddEvent(thr, thr->fast_state, EventTypeMop, 0); + thr->fast_synch_epoch = epoch0; AcquireImpl(thr, 0, &sync); - thr->fast_state.SetHistorySize(flags()->history_size); - const uptr trace = (epoch0 / kTracePartSize) % TraceParts(); - Trace *thr_trace = ThreadTrace(thr->tid); - TraceHeader *hdr = &thr_trace->headers[trace]; - hdr->epoch0 = epoch0; - ObtainCurrentStack(thr, 0, &hdr->stack0); - hdr->mset0 = thr->mset; StatInc(thr, StatSyncAcquire); sync.Reset(&thr->clock_cache); DPrintf("#%d: ThreadStart epoch=%zu stk_addr=%zx stk_size=%zx " |