2012-06-04 21:55:19 +08:00
|
|
|
//===-- tsan_rtl.cc -------------------------------------------------------===//
|
2012-05-10 21:48:04 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of ThreadSanitizer (TSan), a race detector.
|
|
|
|
//
|
|
|
|
// Main file (entry points) for the TSan run-time.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-06-30 00:58:33 +08:00
|
|
|
#include "sanitizer_common/sanitizer_atomic.h"
|
2012-06-18 16:44:30 +08:00
|
|
|
#include "sanitizer_common/sanitizer_common.h"
|
2012-05-31 21:42:53 +08:00
|
|
|
#include "sanitizer_common/sanitizer_libc.h"
|
2012-09-01 01:27:49 +08:00
|
|
|
#include "sanitizer_common/sanitizer_stackdepot.h"
|
2012-06-07 17:50:16 +08:00
|
|
|
#include "sanitizer_common/sanitizer_placement_new.h"
|
2012-09-06 16:48:43 +08:00
|
|
|
#include "sanitizer_common/sanitizer_symbolizer.h"
|
2012-05-10 21:48:04 +08:00
|
|
|
#include "tsan_defs.h"
|
|
|
|
#include "tsan_platform.h"
|
|
|
|
#include "tsan_rtl.h"
|
|
|
|
#include "tsan_mman.h"
|
|
|
|
#include "tsan_suppressions.h"
|
2013-03-21 15:02:36 +08:00
|
|
|
#include "tsan_symbolize.h"
|
2015-04-28 08:56:48 +08:00
|
|
|
#include "ubsan/ubsan_init.h"
|
2012-05-10 21:48:04 +08:00
|
|
|
|
2014-05-30 21:36:29 +08:00
|
|
|
#ifdef __SSE3__
|
|
|
|
// <emmintrin.h> transitively includes <stdlib.h>,
|
|
|
|
// and it's prohibited to include std headers into tsan runtime.
|
|
|
|
// So we do this dirty trick.
|
|
|
|
#define _MM_MALLOC_H_INCLUDED
|
|
|
|
#define __MM_MALLOC_H
|
|
|
|
#include <emmintrin.h>
|
|
|
|
typedef __m128i m128;
|
|
|
|
#endif
|
|
|
|
|
2012-05-23 02:07:45 +08:00
|
|
|
volatile int __tsan_resumed = 0;
|
2012-05-10 21:48:04 +08:00
|
|
|
|
|
|
|
extern "C" void __tsan_resume() {
|
2012-05-23 02:07:45 +08:00
|
|
|
__tsan_resumed = 1;
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace __tsan {
|
|
|
|
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2012-06-05 21:50:57 +08:00
|
|
|
THREADLOCAL char cur_thread_placeholder[sizeof(ThreadState)] ALIGNED(64);
|
2012-07-06 00:18:28 +08:00
|
|
|
#endif
|
2012-06-05 21:50:57 +08:00
|
|
|
static char ctx_placeholder[sizeof(Context)] ALIGNED(64);
|
2014-03-20 18:36:20 +08:00
|
|
|
Context *ctx;
|
2012-05-10 21:48:04 +08:00
|
|
|
|
2013-01-30 17:24:00 +08:00
|
|
|
// Can be overriden by a front-end.
|
2013-10-14 14:31:03 +08:00
|
|
|
#ifdef TSAN_EXTERNAL_HOOKS
|
|
|
|
bool OnFinalize(bool failed);
|
2013-12-11 15:31:36 +08:00
|
|
|
void OnInitialize();
|
2013-10-14 14:31:03 +08:00
|
|
|
#else
|
2014-02-04 16:46:09 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
2013-10-14 14:31:03 +08:00
|
|
|
bool WEAK OnFinalize(bool failed) {
|
2013-01-30 17:24:00 +08:00
|
|
|
return failed;
|
|
|
|
}
|
2014-02-04 16:46:09 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
2013-12-11 15:31:36 +08:00
|
|
|
void WEAK OnInitialize() {}
|
2013-10-14 14:31:03 +08:00
|
|
|
#endif
|
2013-01-30 17:24:00 +08:00
|
|
|
|
2013-03-15 21:48:44 +08:00
|
|
|
static char thread_registry_placeholder[sizeof(ThreadRegistry)];
|
|
|
|
|
|
|
|
static ThreadContextBase *CreateThreadContext(u32 tid) {
|
|
|
|
// Map thread trace when context is created.
|
|
|
|
MapThreadTrace(GetThreadTrace(tid), TraceSize() * sizeof(Event));
|
2015-02-15 00:14:10 +08:00
|
|
|
const uptr hdr = GetThreadTraceHeader(tid);
|
|
|
|
MapThreadTrace(hdr, sizeof(Trace));
|
|
|
|
new((void*)hdr) Trace();
|
2015-02-14 01:39:03 +08:00
|
|
|
// We are going to use only a small part of the trace with the default
|
|
|
|
// value of history_size. However, the constructor writes to the whole trace.
|
2015-02-15 00:14:10 +08:00
|
|
|
// Unmap the unused part.
|
|
|
|
uptr hdr_end = hdr + sizeof(Trace);
|
|
|
|
hdr_end -= sizeof(TraceHeader) * (kTraceParts - TraceParts());
|
|
|
|
hdr_end = RoundUp(hdr_end, GetPageSizeCached());
|
|
|
|
if (hdr_end < hdr + sizeof(Trace))
|
|
|
|
UnmapOrDie((void*)hdr_end, hdr + sizeof(Trace) - hdr_end);
|
2013-03-20 18:31:53 +08:00
|
|
|
void *mem = internal_alloc(MBlockThreadContex, sizeof(ThreadContext));
|
2013-03-15 21:48:44 +08:00
|
|
|
return new(mem) ThreadContext(tid);
|
|
|
|
}
|
|
|
|
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2013-03-15 21:48:44 +08:00
|
|
|
static const u32 kThreadQuarantineSize = 16;
|
|
|
|
#else
|
|
|
|
static const u32 kThreadQuarantineSize = 64;
|
|
|
|
#endif
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
Context::Context()
|
|
|
|
: initialized()
|
|
|
|
, report_mtx(MutexTypeReport, StatMtxReport)
|
|
|
|
, nreported()
|
|
|
|
, nmissed_expected()
|
2013-03-15 21:48:44 +08:00
|
|
|
, thread_registry(new(thread_registry_placeholder) ThreadRegistry(
|
2014-04-11 23:38:03 +08:00
|
|
|
CreateThreadContext, kMaxTid, kThreadQuarantineSize, kMaxTidReuse))
|
2012-05-10 21:48:04 +08:00
|
|
|
, racy_stacks(MBlockRacyStacks)
|
2012-10-05 23:51:32 +08:00
|
|
|
, racy_addresses(MBlockRacyAddresses)
|
2014-02-28 18:48:13 +08:00
|
|
|
, fired_suppressions(8) {
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// The objects are allocated in TLS, so one may rely on zero-initialization.
|
2012-08-30 21:02:30 +08:00
|
|
|
ThreadState::ThreadState(Context *ctx, int tid, int unique_id, u64 epoch,
|
2014-04-11 23:38:03 +08:00
|
|
|
unsigned reuse_count,
|
2012-05-10 21:48:04 +08:00
|
|
|
uptr stk_addr, uptr stk_size,
|
|
|
|
uptr tls_addr, uptr tls_size)
|
|
|
|
: fast_state(tid, epoch)
|
|
|
|
// Do not touch these, rely on zero initialization,
|
|
|
|
// they may be accessed before the ctor.
|
2013-05-21 16:12:35 +08:00
|
|
|
// , ignore_reads_and_writes()
|
2013-12-24 20:55:56 +08:00
|
|
|
// , ignore_interceptors()
|
2014-04-11 23:38:03 +08:00
|
|
|
, clock(tid, reuse_count)
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2013-03-25 18:10:44 +08:00
|
|
|
, jmp_bufs(MBlockJmpBuf)
|
|
|
|
#endif
|
2012-05-10 21:48:04 +08:00
|
|
|
, tid(tid)
|
2012-08-30 21:02:30 +08:00
|
|
|
, unique_id(unique_id)
|
2012-05-10 21:48:04 +08:00
|
|
|
, stk_addr(stk_addr)
|
|
|
|
, stk_size(stk_size)
|
|
|
|
, tls_addr(tls_addr)
|
2014-03-25 02:54:20 +08:00
|
|
|
, tls_size(tls_size)
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2014-03-25 02:54:20 +08:00
|
|
|
, last_sleep_clock(tid)
|
|
|
|
#endif
|
|
|
|
{
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
|
|
|
|
2015-02-16 22:49:34 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2013-03-21 15:02:36 +08:00
|
|
|
static void MemoryProfiler(Context *ctx, fd_t fd, int i) {
|
2013-03-21 14:24:31 +08:00
|
|
|
uptr n_threads;
|
|
|
|
uptr n_running_threads;
|
|
|
|
ctx->thread_registry->GetNumberOfThreads(&n_threads, &n_running_threads);
|
2013-03-21 15:02:36 +08:00
|
|
|
InternalScopedBuffer<char> buf(4096);
|
2014-05-29 22:11:38 +08:00
|
|
|
WriteMemoryProfile(buf.data(), buf.size(), n_threads, n_running_threads);
|
2015-04-09 22:11:25 +08:00
|
|
|
WriteToFile(fd, buf.data(), internal_strlen(buf.data()));
|
2013-03-21 14:24:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void BackgroundThread(void *arg) {
|
2013-12-24 20:55:56 +08:00
|
|
|
// This is a non-initialized non-user thread, nothing to see here.
|
2014-04-24 21:09:17 +08:00
|
|
|
// We don't use ScopedIgnoreInterceptors, because we want ignores to be
|
|
|
|
// enabled even when the thread function exits (e.g. during pthread thread
|
|
|
|
// shutdown code).
|
|
|
|
cur_thread()->ignore_interceptors++;
|
2013-03-21 21:01:50 +08:00
|
|
|
const u64 kMs2Ns = 1000 * 1000;
|
2013-03-21 14:24:31 +08:00
|
|
|
|
|
|
|
fd_t mprof_fd = kInvalidFd;
|
|
|
|
if (flags()->profile_memory && flags()->profile_memory[0]) {
|
2014-05-29 22:02:06 +08:00
|
|
|
if (internal_strcmp(flags()->profile_memory, "stdout") == 0) {
|
|
|
|
mprof_fd = 1;
|
|
|
|
} else if (internal_strcmp(flags()->profile_memory, "stderr") == 0) {
|
|
|
|
mprof_fd = 2;
|
2013-05-08 22:43:49 +08:00
|
|
|
} else {
|
2014-12-03 06:20:11 +08:00
|
|
|
InternalScopedString filename(kMaxPathLength);
|
|
|
|
filename.append("%s.%d", flags()->profile_memory, (int)internal_getpid());
|
2015-04-09 00:03:22 +08:00
|
|
|
fd_t fd = OpenFile(filename.data(), WrOnly);
|
|
|
|
if (fd == kInvalidFd) {
|
2014-05-29 22:02:06 +08:00
|
|
|
Printf("ThreadSanitizer: failed to open memory profile file '%s'\n",
|
|
|
|
&filename[0]);
|
|
|
|
} else {
|
2015-04-09 00:03:22 +08:00
|
|
|
mprof_fd = fd;
|
2014-05-29 22:02:06 +08:00
|
|
|
}
|
2013-03-21 14:24:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 last_flush = NanoTime();
|
2013-10-04 01:14:35 +08:00
|
|
|
uptr last_rss = 0;
|
2014-04-24 21:09:17 +08:00
|
|
|
for (int i = 0;
|
|
|
|
atomic_load(&ctx->stop_background_thread, memory_order_relaxed) == 0;
|
|
|
|
i++) {
|
|
|
|
SleepForMillis(100);
|
2013-03-21 14:24:31 +08:00
|
|
|
u64 now = NanoTime();
|
2012-05-22 19:33:03 +08:00
|
|
|
|
2013-03-21 15:02:36 +08:00
|
|
|
// Flush memory if requested.
|
2013-10-04 01:14:35 +08:00
|
|
|
if (flags()->flush_memory_ms > 0) {
|
2013-03-21 21:01:50 +08:00
|
|
|
if (last_flush + flags()->flush_memory_ms * kMs2Ns < now) {
|
2014-09-11 07:08:06 +08:00
|
|
|
VPrintf(1, "ThreadSanitizer: periodic memory flush\n");
|
2013-03-21 14:24:31 +08:00
|
|
|
FlushShadowMemory();
|
|
|
|
last_flush = NanoTime();
|
|
|
|
}
|
|
|
|
}
|
2014-05-29 21:50:54 +08:00
|
|
|
// GetRSS can be expensive on huge programs, so don't do it every 100ms.
|
2014-07-25 21:48:25 +08:00
|
|
|
if (flags()->memory_limit_mb > 0) {
|
2013-10-04 01:14:35 +08:00
|
|
|
uptr rss = GetRSS();
|
|
|
|
uptr limit = uptr(flags()->memory_limit_mb) << 20;
|
2014-09-11 07:08:06 +08:00
|
|
|
VPrintf(1, "ThreadSanitizer: memory flush check"
|
|
|
|
" RSS=%llu LAST=%llu LIMIT=%llu\n",
|
|
|
|
(u64)rss >> 20, (u64)last_rss >> 20, (u64)limit >> 20);
|
2013-10-04 01:14:35 +08:00
|
|
|
if (2 * rss > limit + last_rss) {
|
2014-09-11 07:08:06 +08:00
|
|
|
VPrintf(1, "ThreadSanitizer: flushing memory due to RSS\n");
|
2013-10-04 01:14:35 +08:00
|
|
|
FlushShadowMemory();
|
|
|
|
rss = GetRSS();
|
2014-09-11 07:08:06 +08:00
|
|
|
VPrintf(1, "ThreadSanitizer: memory flushed RSS=%llu\n", (u64)rss>>20);
|
2013-10-04 01:14:35 +08:00
|
|
|
}
|
|
|
|
last_rss = rss;
|
|
|
|
}
|
2013-03-21 14:24:31 +08:00
|
|
|
|
2013-03-21 15:02:36 +08:00
|
|
|
// Write memory profile if requested.
|
2013-03-21 14:24:31 +08:00
|
|
|
if (mprof_fd != kInvalidFd)
|
2013-03-21 15:02:36 +08:00
|
|
|
MemoryProfiler(ctx, mprof_fd, i);
|
|
|
|
|
2013-03-21 21:01:50 +08:00
|
|
|
// Flush symbolizer cache if requested.
|
|
|
|
if (flags()->flush_symbolizer_ms > 0) {
|
|
|
|
u64 last = atomic_load(&ctx->last_symbolize_time_ns,
|
|
|
|
memory_order_relaxed);
|
|
|
|
if (last != 0 && last + flags()->flush_symbolizer_ms * kMs2Ns < now) {
|
|
|
|
Lock l(&ctx->report_mtx);
|
2013-04-05 15:30:29 +08:00
|
|
|
SpinMutexLock l2(&CommonSanitizerReportMutex);
|
2013-03-21 21:01:50 +08:00
|
|
|
SymbolizeFlush();
|
|
|
|
atomic_store(&ctx->last_symbolize_time_ns, 0, memory_order_relaxed);
|
|
|
|
}
|
2013-03-21 15:02:36 +08:00
|
|
|
}
|
2012-05-22 19:33:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-24 21:09:17 +08:00
|
|
|
static void StartBackgroundThread() {
|
|
|
|
ctx->background_thread = internal_start_thread(&BackgroundThread, 0);
|
|
|
|
}
|
|
|
|
|
2015-02-20 14:42:41 +08:00
|
|
|
#ifndef __mips__
|
2014-04-24 21:09:17 +08:00
|
|
|
static void StopBackgroundThread() {
|
|
|
|
atomic_store(&ctx->stop_background_thread, 1, memory_order_relaxed);
|
|
|
|
internal_join_thread(ctx->background_thread);
|
|
|
|
ctx->background_thread = 0;
|
|
|
|
}
|
2014-05-27 22:18:43 +08:00
|
|
|
#endif
|
2015-02-20 14:42:41 +08:00
|
|
|
#endif
|
2014-04-24 21:09:17 +08:00
|
|
|
|
2013-03-18 23:49:07 +08:00
|
|
|
void DontNeedShadowFor(uptr addr, uptr size) {
|
|
|
|
uptr shadow_beg = MemToShadow(addr);
|
|
|
|
uptr shadow_end = MemToShadow(addr + size);
|
|
|
|
FlushUnneededShadowMemory(shadow_beg, shadow_end - shadow_beg);
|
|
|
|
}
|
|
|
|
|
2012-11-07 00:00:16 +08:00
|
|
|
void MapShadow(uptr addr, uptr size) {
|
2014-02-05 21:41:09 +08:00
|
|
|
// Global data is not 64K aligned, but there are no adjacent mappings,
|
|
|
|
// so we can get away with unaligned mapping.
|
|
|
|
// CHECK_EQ(addr, addr & ~((64 << 10) - 1)); // windows wants 64K alignment
|
2012-11-07 00:48:46 +08:00
|
|
|
MmapFixedNoReserve(MemToShadow(addr), size * kShadowMultiplier);
|
2014-05-29 21:50:54 +08:00
|
|
|
|
|
|
|
// Meta shadow is 2:1, so tread carefully.
|
2014-06-06 23:54:49 +08:00
|
|
|
static bool data_mapped = false;
|
2014-05-29 21:50:54 +08:00
|
|
|
static uptr mapped_meta_end = 0;
|
|
|
|
uptr meta_begin = (uptr)MemToMeta(addr);
|
|
|
|
uptr meta_end = (uptr)MemToMeta(addr + size);
|
|
|
|
meta_begin = RoundDownTo(meta_begin, 64 << 10);
|
|
|
|
meta_end = RoundUpTo(meta_end, 64 << 10);
|
2014-06-06 23:54:49 +08:00
|
|
|
if (!data_mapped) {
|
|
|
|
// First call maps data+bss.
|
|
|
|
data_mapped = true;
|
|
|
|
MmapFixedNoReserve(meta_begin, meta_end - meta_begin);
|
|
|
|
} else {
|
|
|
|
// Mapping continous heap.
|
|
|
|
// Windows wants 64K alignment.
|
|
|
|
meta_begin = RoundDownTo(meta_begin, 64 << 10);
|
|
|
|
meta_end = RoundUpTo(meta_end, 64 << 10);
|
|
|
|
if (meta_end <= mapped_meta_end)
|
|
|
|
return;
|
|
|
|
if (meta_begin < mapped_meta_end)
|
|
|
|
meta_begin = mapped_meta_end;
|
|
|
|
MmapFixedNoReserve(meta_begin, meta_end - meta_begin);
|
|
|
|
mapped_meta_end = meta_end;
|
|
|
|
}
|
|
|
|
VPrintf(2, "mapped meta shadow for (%p-%p) at (%p-%p)\n",
|
2014-05-29 21:50:54 +08:00
|
|
|
addr, addr+size, meta_begin, meta_end);
|
2012-11-07 00:00:16 +08:00
|
|
|
}
|
|
|
|
|
2012-12-13 16:14:02 +08:00
|
|
|
void MapThreadTrace(uptr addr, uptr size) {
|
2012-12-21 20:30:52 +08:00
|
|
|
DPrintf("#0: Mapping trace at %p-%p(0x%zx)\n", addr, addr + size, size);
|
2014-10-25 01:07:29 +08:00
|
|
|
CHECK_GE(addr, kTraceMemBeg);
|
|
|
|
CHECK_LE(addr + size, kTraceMemEnd);
|
2014-02-05 19:37:20 +08:00
|
|
|
CHECK_EQ(addr, addr & ~((64 << 10) - 1)); // windows wants 64K alignment
|
2013-10-16 23:35:12 +08:00
|
|
|
uptr addr1 = (uptr)MmapFixedNoReserve(addr, size);
|
|
|
|
if (addr1 != addr) {
|
|
|
|
Printf("FATAL: ThreadSanitizer can not mmap thread trace (%p/%p->%p)\n",
|
|
|
|
addr, size, addr1);
|
2012-12-13 16:14:02 +08:00
|
|
|
Die();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-25 01:07:29 +08:00
|
|
|
static void CheckShadowMapping() {
|
|
|
|
for (uptr i = 0; i < ARRAY_SIZE(UserRegions); i += 2) {
|
|
|
|
const uptr beg = UserRegions[i];
|
|
|
|
const uptr end = UserRegions[i + 1];
|
|
|
|
VPrintf(3, "checking shadow region %p-%p\n", beg, end);
|
|
|
|
for (uptr p0 = beg; p0 <= end; p0 += (end - beg) / 4) {
|
|
|
|
for (int x = -1; x <= 1; x++) {
|
|
|
|
const uptr p = p0 + x;
|
|
|
|
if (p < beg || p >= end)
|
|
|
|
continue;
|
|
|
|
const uptr s = MemToShadow(p);
|
2015-02-16 21:52:04 +08:00
|
|
|
const uptr m = (uptr)MemToMeta(p);
|
|
|
|
VPrintf(3, " checking pointer %p: shadow=%p meta=%p\n", p, s, m);
|
2014-10-25 01:07:29 +08:00
|
|
|
CHECK(IsAppMem(p));
|
|
|
|
CHECK(IsShadowMem(s));
|
|
|
|
CHECK_EQ(p & ~(kShadowCell - 1), ShadowToMem(s));
|
|
|
|
CHECK(IsMetaMem(m));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
void Initialize(ThreadState *thr) {
|
|
|
|
// Thread safe because done before all threads exist.
|
|
|
|
static bool is_initialized = false;
|
|
|
|
if (is_initialized)
|
|
|
|
return;
|
|
|
|
is_initialized = true;
|
2013-12-24 20:55:56 +08:00
|
|
|
// We are not ready to handle interceptors yet.
|
|
|
|
ScopedIgnoreInterceptors ignore;
|
2013-01-31 22:11:21 +08:00
|
|
|
SanitizerToolName = "ThreadSanitizer";
|
2012-09-11 17:44:48 +08:00
|
|
|
// Install tool-specific callbacks in sanitizer_common.
|
|
|
|
SetCheckFailedCallback(TsanCheckFailed);
|
|
|
|
|
2014-08-16 03:53:51 +08:00
|
|
|
ctx = new(ctx_placeholder) Context;
|
|
|
|
const char *options = GetEnv(kTsanOptionsEnv);
|
|
|
|
InitializeFlags(&ctx->flags, options);
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2012-08-15 23:35:15 +08:00
|
|
|
InitializeAllocator();
|
2012-08-17 03:36:45 +08:00
|
|
|
#endif
|
2012-05-10 21:48:04 +08:00
|
|
|
InitializeInterceptors();
|
2014-10-25 01:07:29 +08:00
|
|
|
CheckShadowMapping();
|
2014-08-16 03:53:51 +08:00
|
|
|
InitializePlatform();
|
2012-05-10 21:48:04 +08:00
|
|
|
InitializeMutex();
|
|
|
|
InitializeDynamicAnnotations();
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2012-05-10 21:48:04 +08:00
|
|
|
InitializeShadowMemory();
|
2012-11-07 00:00:16 +08:00
|
|
|
#endif
|
2012-11-02 20:17:51 +08:00
|
|
|
// Setup correct file descriptor for error reports.
|
2014-09-11 07:08:06 +08:00
|
|
|
__sanitizer_set_report_path(common_flags()->log_path);
|
2012-05-10 21:48:04 +08:00
|
|
|
InitializeSuppressions();
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2013-10-03 21:37:17 +08:00
|
|
|
InitializeLibIgnore();
|
2014-07-26 09:37:23 +08:00
|
|
|
Symbolizer::GetOrInit()->AddHooks(EnterSymbolizer, ExitSymbolizer);
|
2015-02-20 14:42:41 +08:00
|
|
|
// On MIPS, TSan initialization is run before
|
|
|
|
// __pthread_initialize_minimal_internal() is finished, so we can not spawn
|
|
|
|
// new threads.
|
|
|
|
#ifndef __mips__
|
2014-04-24 21:09:17 +08:00
|
|
|
StartBackgroundThread();
|
|
|
|
SetSandboxingCallback(StopBackgroundThread);
|
2015-02-20 14:42:41 +08:00
|
|
|
#endif
|
2014-05-27 22:18:43 +08:00
|
|
|
#endif
|
2014-09-11 07:08:06 +08:00
|
|
|
if (common_flags()->detect_deadlocks)
|
2014-03-18 21:13:47 +08:00
|
|
|
ctx->dd = DDetector::Create(flags());
|
2012-09-06 16:48:43 +08:00
|
|
|
|
2014-09-11 07:08:06 +08:00
|
|
|
VPrintf(1, "***** Running under ThreadSanitizer v2 (pid %d) *****\n",
|
|
|
|
(int)internal_getpid());
|
2012-05-10 21:48:04 +08:00
|
|
|
|
|
|
|
// Initialize thread 0.
|
|
|
|
int tid = ThreadCreate(thr, 0, 0, true);
|
|
|
|
CHECK_EQ(tid, 0);
|
2013-05-18 00:56:53 +08:00
|
|
|
ThreadStart(thr, tid, internal_getpid());
|
2015-04-28 08:56:48 +08:00
|
|
|
#if TSAN_CONTAINS_UBSAN
|
|
|
|
__ubsan::InitAsPlugin();
|
|
|
|
#endif
|
2012-05-10 21:48:04 +08:00
|
|
|
ctx->initialized = true;
|
|
|
|
|
2012-05-23 02:07:45 +08:00
|
|
|
if (flags()->stop_on_start) {
|
2012-11-02 20:17:51 +08:00
|
|
|
Printf("ThreadSanitizer is suspended at startup (pid %d)."
|
2012-05-23 02:07:45 +08:00
|
|
|
" Call __tsan_resume().\n",
|
2013-05-18 00:56:53 +08:00
|
|
|
(int)internal_getpid());
|
2013-01-30 15:45:58 +08:00
|
|
|
while (__tsan_resumed == 0) {}
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
2014-02-07 17:28:57 +08:00
|
|
|
|
|
|
|
OnInitialize();
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int Finalize(ThreadState *thr) {
|
|
|
|
bool failed = false;
|
|
|
|
|
2012-11-08 00:41:57 +08:00
|
|
|
if (flags()->atexit_sleep_ms > 0 && ThreadCount(thr) > 1)
|
|
|
|
SleepForMillis(flags()->atexit_sleep_ms);
|
|
|
|
|
2012-10-02 20:07:16 +08:00
|
|
|
// Wait for pending reports.
|
|
|
|
ctx->report_mtx.Lock();
|
2013-04-05 15:30:29 +08:00
|
|
|
CommonSanitizerReportMutex.Lock();
|
|
|
|
CommonSanitizerReportMutex.Unlock();
|
2012-10-02 20:07:16 +08:00
|
|
|
ctx->report_mtx.Unlock();
|
|
|
|
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2015-01-20 21:21:20 +08:00
|
|
|
if (Verbosity()) AllocatorPrintStats();
|
2013-01-24 17:08:03 +08:00
|
|
|
#endif
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
ThreadFinalize(thr);
|
|
|
|
|
|
|
|
if (ctx->nreported) {
|
|
|
|
failed = true;
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2012-11-02 20:17:51 +08:00
|
|
|
Printf("ThreadSanitizer: reported %d warnings\n", ctx->nreported);
|
2012-10-07 22:21:24 +08:00
|
|
|
#else
|
2012-11-02 20:17:51 +08:00
|
|
|
Printf("Found %d data race(s)\n", ctx->nreported);
|
2012-10-07 22:21:24 +08:00
|
|
|
#endif
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx->nmissed_expected) {
|
|
|
|
failed = true;
|
2012-11-02 20:17:51 +08:00
|
|
|
Printf("ThreadSanitizer: missed %d expected races\n",
|
2012-05-10 21:48:04 +08:00
|
|
|
ctx->nmissed_expected);
|
|
|
|
}
|
|
|
|
|
2014-09-11 07:08:06 +08:00
|
|
|
if (common_flags()->print_suppressions)
|
2013-03-28 01:59:57 +08:00
|
|
|
PrintMatchedSuppressions();
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2013-03-29 00:21:19 +08:00
|
|
|
if (flags()->print_benign)
|
|
|
|
PrintMatchedBenignRaces();
|
|
|
|
#endif
|
2013-03-28 01:59:57 +08:00
|
|
|
|
2013-01-30 17:24:00 +08:00
|
|
|
failed = OnFinalize(failed);
|
|
|
|
|
2015-02-18 07:23:10 +08:00
|
|
|
#if TSAN_COLLECT_STATS
|
2012-11-13 21:53:43 +08:00
|
|
|
StatAggregate(ctx->stat, thr->stat);
|
2012-05-10 21:48:04 +08:00
|
|
|
StatOutput(ctx->stat);
|
2015-02-13 23:25:47 +08:00
|
|
|
#endif
|
|
|
|
|
2012-05-17 23:00:27 +08:00
|
|
|
return failed ? flags()->exitcode : 0;
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
|
|
|
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2014-01-24 20:33:35 +08:00
|
|
|
void ForkBefore(ThreadState *thr, uptr pc) {
|
|
|
|
ctx->thread_registry->Lock();
|
2014-03-26 22:13:31 +08:00
|
|
|
ctx->report_mtx.Lock();
|
2014-01-24 20:33:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ForkParentAfter(ThreadState *thr, uptr pc) {
|
|
|
|
ctx->report_mtx.Unlock();
|
2014-03-26 22:13:31 +08:00
|
|
|
ctx->thread_registry->Unlock();
|
2014-01-24 20:33:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ForkChildAfter(ThreadState *thr, uptr pc) {
|
|
|
|
ctx->report_mtx.Unlock();
|
2014-03-26 22:13:31 +08:00
|
|
|
ctx->thread_registry->Unlock();
|
2014-01-24 20:33:35 +08:00
|
|
|
|
|
|
|
uptr nthread = 0;
|
|
|
|
ctx->thread_registry->GetNumberOfThreads(0, 0, &nthread /* alive threads */);
|
|
|
|
VPrintf(1, "ThreadSanitizer: forked new process with pid %d,"
|
|
|
|
" parent had %d threads\n", (int)internal_getpid(), (int)nthread);
|
|
|
|
if (nthread == 1) {
|
2015-02-16 22:49:34 +08:00
|
|
|
StartBackgroundThread();
|
2014-01-24 20:33:35 +08:00
|
|
|
} else {
|
|
|
|
// We've just forked a multi-threaded process. We cannot reasonably function
|
|
|
|
// after that (some mutexes may be locked before fork). So just enable
|
|
|
|
// ignores for everything in the hope that we will exec soon.
|
|
|
|
ctx->after_multithreaded_fork = true;
|
|
|
|
thr->ignore_interceptors++;
|
|
|
|
ThreadIgnoreBegin(thr, pc);
|
|
|
|
ThreadIgnoreSyncBegin(thr, pc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifdef SANITIZER_GO
|
2014-06-07 02:05:12 +08:00
|
|
|
NOINLINE
|
|
|
|
void GrowShadowStack(ThreadState *thr) {
|
|
|
|
const int sz = thr->shadow_stack_end - thr->shadow_stack;
|
|
|
|
const int newsz = 2 * sz;
|
|
|
|
uptr *newstack = (uptr*)internal_alloc(MBlockShadowStack,
|
|
|
|
newsz * sizeof(uptr));
|
|
|
|
internal_memcpy(newstack, thr->shadow_stack, sz * sizeof(uptr));
|
|
|
|
internal_free(thr->shadow_stack);
|
|
|
|
thr->shadow_stack = newstack;
|
|
|
|
thr->shadow_stack_pos = newstack + sz;
|
|
|
|
thr->shadow_stack_end = newstack + newsz;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-09-01 01:27:49 +08:00
|
|
|
u32 CurrentStackId(ThreadState *thr, uptr pc) {
|
2015-03-16 22:42:21 +08:00
|
|
|
if (!thr->is_inited) // May happen during bootstrap.
|
2012-09-01 01:27:49 +08:00
|
|
|
return 0;
|
2014-06-07 02:05:12 +08:00
|
|
|
if (pc != 0) {
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2014-06-07 02:05:12 +08:00
|
|
|
DCHECK_LT(thr->shadow_stack_pos, thr->shadow_stack_end);
|
|
|
|
#else
|
|
|
|
if (thr->shadow_stack_pos == thr->shadow_stack_end)
|
|
|
|
GrowShadowStack(thr);
|
|
|
|
#endif
|
|
|
|
thr->shadow_stack_pos[0] = pc;
|
|
|
|
thr->shadow_stack_pos++;
|
|
|
|
}
|
2014-11-04 06:23:44 +08:00
|
|
|
u32 id = StackDepotPut(
|
|
|
|
StackTrace(thr->shadow_stack, thr->shadow_stack_pos - thr->shadow_stack));
|
2014-06-06 23:56:08 +08:00
|
|
|
if (pc != 0)
|
2012-09-01 01:27:49 +08:00
|
|
|
thr->shadow_stack_pos--;
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2012-07-06 00:18:28 +08:00
|
|
|
void TraceSwitch(ThreadState *thr) {
|
2012-06-22 19:08:55 +08:00
|
|
|
thr->nomalloc++;
|
2013-03-20 18:31:53 +08:00
|
|
|
Trace *thr_trace = ThreadTrace(thr->tid);
|
|
|
|
Lock l(&thr_trace->mtx);
|
2012-12-04 20:19:53 +08:00
|
|
|
unsigned trace = (thr->fast_state.epoch() / kTracePartSize) % TraceParts();
|
2013-03-20 18:31:53 +08:00
|
|
|
TraceHeader *hdr = &thr_trace->headers[trace];
|
2012-05-10 21:48:04 +08:00
|
|
|
hdr->epoch0 = thr->fast_state.epoch();
|
2014-11-04 06:23:44 +08:00
|
|
|
ObtainCurrentStack(thr, 0, &hdr->stack0);
|
2012-12-06 20:16:15 +08:00
|
|
|
hdr->mset0 = thr->mset;
|
2012-06-22 19:08:55 +08:00
|
|
|
thr->nomalloc--;
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
|
|
|
|
2013-03-20 18:31:53 +08:00
|
|
|
Trace *ThreadTrace(int tid) {
|
|
|
|
return (Trace*)GetThreadTraceHeader(tid);
|
|
|
|
}
|
|
|
|
|
2012-11-28 18:35:31 +08:00
|
|
|
uptr TraceTopPC(ThreadState *thr) {
|
|
|
|
Event *events = (Event*)GetThreadTrace(thr->tid);
|
2012-11-28 20:19:50 +08:00
|
|
|
uptr pc = events[thr->fast_state.GetTracePos()];
|
2012-11-28 18:35:31 +08:00
|
|
|
return pc;
|
|
|
|
}
|
|
|
|
|
2012-11-28 20:19:50 +08:00
|
|
|
uptr TraceSize() {
|
|
|
|
return (uptr)(1ull << (kTracePartSizeBits + flags()->history_size + 1));
|
|
|
|
}
|
|
|
|
|
2012-12-04 20:19:53 +08:00
|
|
|
uptr TraceParts() {
|
|
|
|
return TraceSize() / kTracePartSize;
|
|
|
|
}
|
|
|
|
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2012-05-10 21:48:04 +08:00
|
|
|
extern "C" void __tsan_trace_switch() {
|
|
|
|
TraceSwitch(cur_thread());
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void __tsan_report_race() {
|
|
|
|
ReportRace(cur_thread());
|
|
|
|
}
|
2012-07-06 00:18:28 +08:00
|
|
|
#endif
|
2012-05-10 21:48:04 +08:00
|
|
|
|
|
|
|
ALWAYS_INLINE
|
2013-03-29 06:23:03 +08:00
|
|
|
Shadow LoadShadow(u64 *p) {
|
2012-05-10 21:48:04 +08:00
|
|
|
u64 raw = atomic_load((atomic_uint64_t*)p, memory_order_relaxed);
|
|
|
|
return Shadow(raw);
|
|
|
|
}
|
|
|
|
|
|
|
|
ALWAYS_INLINE
|
2013-03-29 06:23:03 +08:00
|
|
|
void StoreShadow(u64 *sp, u64 s) {
|
2012-05-10 21:48:04 +08:00
|
|
|
atomic_store((atomic_uint64_t*)sp, s, memory_order_relaxed);
|
|
|
|
}
|
|
|
|
|
|
|
|
ALWAYS_INLINE
|
2013-03-29 06:23:03 +08:00
|
|
|
void StoreIfNotYetStored(u64 *sp, u64 *s) {
|
2012-05-10 21:48:04 +08:00
|
|
|
StoreShadow(sp, *s);
|
|
|
|
*s = 0;
|
|
|
|
}
|
|
|
|
|
2014-05-30 21:36:29 +08:00
|
|
|
ALWAYS_INLINE
|
|
|
|
void HandleRace(ThreadState *thr, u64 *shadow_mem,
|
2012-05-10 21:48:04 +08:00
|
|
|
Shadow cur, Shadow old) {
|
|
|
|
thr->racy_state[0] = cur.raw();
|
|
|
|
thr->racy_state[1] = old.raw();
|
|
|
|
thr->racy_shadow_addr = shadow_mem;
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2012-05-10 21:48:04 +08:00
|
|
|
HACKY_CALL(__tsan_report_race);
|
2012-07-06 00:18:28 +08:00
|
|
|
#else
|
|
|
|
ReportRace(thr);
|
|
|
|
#endif
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool HappensBefore(Shadow old, ThreadState *thr) {
|
2012-12-01 04:02:11 +08:00
|
|
|
return thr->clock.get(old.TidWithIgnore()) >= old.epoch();
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
|
|
|
|
2014-05-30 21:36:29 +08:00
|
|
|
ALWAYS_INLINE
|
|
|
|
void MemoryAccessImpl1(ThreadState *thr, uptr addr,
|
2013-02-01 17:42:06 +08:00
|
|
|
int kAccessSizeLog, bool kAccessIsWrite, bool kIsAtomic,
|
2012-05-10 21:48:04 +08:00
|
|
|
u64 *shadow_mem, Shadow cur) {
|
|
|
|
StatInc(thr, StatMop);
|
|
|
|
StatInc(thr, kAccessIsWrite ? StatMopWrite : StatMopRead);
|
|
|
|
StatInc(thr, (StatType)(StatMop1 + kAccessSizeLog));
|
|
|
|
|
|
|
|
// This potentially can live in an MMX/SSE scratch register.
|
|
|
|
// The required intrinsics are:
|
|
|
|
// __m128i _mm_move_epi64(__m128i*);
|
|
|
|
// _mm_storel_epi64(u64*, __m128i);
|
|
|
|
u64 store_word = cur.raw();
|
|
|
|
|
|
|
|
// scan all the shadow values and dispatch to 4 categories:
|
|
|
|
// same, replace, candidate and race (see comments below).
|
|
|
|
// we consider only 3 cases regarding access sizes:
|
|
|
|
// equal, intersect and not intersect. initially I considered
|
|
|
|
// larger and smaller as well, it allowed to replace some
|
|
|
|
// 'candidates' with 'same' or 'replace', but I think
|
|
|
|
// it's just not worth it (performance- and complexity-wise).
|
|
|
|
|
2013-03-20 19:22:03 +08:00
|
|
|
Shadow old(0);
|
2015-01-19 23:01:07 +08:00
|
|
|
|
2015-01-21 16:09:13 +08:00
|
|
|
// It release mode we manually unroll the loop,
|
|
|
|
// because empirically gcc generates better code this way.
|
|
|
|
// However, we can't afford unrolling in debug mode, because the function
|
|
|
|
// consumes almost 4K of stack. Gtest gives only 4K of stack to death test
|
|
|
|
// threads, which is not enough for the unrolled loop.
|
|
|
|
#if SANITIZER_DEBUG
|
|
|
|
for (int idx = 0; idx < 4; idx++) {
|
|
|
|
#include "tsan_update_shadow_word_inl.h"
|
|
|
|
}
|
|
|
|
#else
|
2015-01-19 23:01:07 +08:00
|
|
|
int idx = 0;
|
2012-05-10 21:48:04 +08:00
|
|
|
#include "tsan_update_shadow_word_inl.h"
|
2015-01-19 23:01:07 +08:00
|
|
|
idx = 1;
|
2012-05-10 21:48:04 +08:00
|
|
|
#include "tsan_update_shadow_word_inl.h"
|
2015-01-19 23:01:07 +08:00
|
|
|
idx = 2;
|
2012-05-10 21:48:04 +08:00
|
|
|
#include "tsan_update_shadow_word_inl.h"
|
2015-01-19 23:01:07 +08:00
|
|
|
idx = 3;
|
2012-05-10 21:48:04 +08:00
|
|
|
#include "tsan_update_shadow_word_inl.h"
|
2015-01-21 16:09:13 +08:00
|
|
|
#endif
|
2012-05-10 21:48:04 +08:00
|
|
|
|
|
|
|
// we did not find any races and had already stored
|
|
|
|
// the current access info, so we are done
|
|
|
|
if (LIKELY(store_word == 0))
|
|
|
|
return;
|
|
|
|
// choose a random candidate slot and replace it
|
|
|
|
StoreShadow(shadow_mem + (cur.epoch() % kShadowCnt), store_word);
|
|
|
|
StatInc(thr, StatShadowReplace);
|
|
|
|
return;
|
|
|
|
RACE:
|
|
|
|
HandleRace(thr, shadow_mem, cur, old);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-30 19:56:56 +08:00
|
|
|
void UnalignedMemoryAccess(ThreadState *thr, uptr pc, uptr addr,
|
|
|
|
int size, bool kAccessIsWrite, bool kIsAtomic) {
|
|
|
|
while (size) {
|
|
|
|
int size1 = 1;
|
|
|
|
int kAccessSizeLog = kSizeLog1;
|
2014-08-13 21:20:23 +08:00
|
|
|
if (size >= 8 && (addr & ~7) == ((addr + 7) & ~7)) {
|
2013-04-30 19:56:56 +08:00
|
|
|
size1 = 8;
|
|
|
|
kAccessSizeLog = kSizeLog8;
|
2014-08-13 21:20:23 +08:00
|
|
|
} else if (size >= 4 && (addr & ~7) == ((addr + 3) & ~7)) {
|
2013-04-30 19:56:56 +08:00
|
|
|
size1 = 4;
|
|
|
|
kAccessSizeLog = kSizeLog4;
|
2014-08-13 21:20:23 +08:00
|
|
|
} else if (size >= 2 && (addr & ~7) == ((addr + 1) & ~7)) {
|
2013-04-30 19:56:56 +08:00
|
|
|
size1 = 2;
|
|
|
|
kAccessSizeLog = kSizeLog2;
|
|
|
|
}
|
|
|
|
MemoryAccess(thr, pc, addr, kAccessSizeLog, kAccessIsWrite, kIsAtomic);
|
|
|
|
addr += size1;
|
|
|
|
size -= size1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-30 21:36:29 +08:00
|
|
|
ALWAYS_INLINE
|
|
|
|
bool ContainsSameAccessSlow(u64 *s, u64 a, u64 sync_epoch, bool is_write) {
|
|
|
|
Shadow cur(a);
|
|
|
|
for (uptr i = 0; i < kShadowCnt; i++) {
|
|
|
|
Shadow old(LoadShadow(&s[i]));
|
|
|
|
if (Shadow::Addr0AndSizeAreEqual(cur, old) &&
|
|
|
|
old.TidWithIgnore() == cur.TidWithIgnore() &&
|
|
|
|
old.epoch() > sync_epoch &&
|
|
|
|
old.IsAtomic() == cur.IsAtomic() &&
|
|
|
|
old.IsRead() <= cur.IsRead())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-19 23:01:07 +08:00
|
|
|
#if defined(__SSE3__)
|
2014-05-30 21:36:29 +08:00
|
|
|
#define SHUF(v0, v1, i0, i1, i2, i3) _mm_castps_si128(_mm_shuffle_ps( \
|
|
|
|
_mm_castsi128_ps(v0), _mm_castsi128_ps(v1), \
|
|
|
|
(i0)*1 + (i1)*4 + (i2)*16 + (i3)*64))
|
|
|
|
ALWAYS_INLINE
|
|
|
|
bool ContainsSameAccessFast(u64 *s, u64 a, u64 sync_epoch, bool is_write) {
|
|
|
|
// This is an optimized version of ContainsSameAccessSlow.
|
|
|
|
// load current access into access[0:63]
|
|
|
|
const m128 access = _mm_cvtsi64_si128(a);
|
|
|
|
// duplicate high part of access in addr0:
|
|
|
|
// addr0[0:31] = access[32:63]
|
|
|
|
// addr0[32:63] = access[32:63]
|
|
|
|
// addr0[64:95] = access[32:63]
|
|
|
|
// addr0[96:127] = access[32:63]
|
|
|
|
const m128 addr0 = SHUF(access, access, 1, 1, 1, 1);
|
|
|
|
// load 4 shadow slots
|
|
|
|
const m128 shadow0 = _mm_load_si128((__m128i*)s);
|
|
|
|
const m128 shadow1 = _mm_load_si128((__m128i*)s + 1);
|
|
|
|
// load high parts of 4 shadow slots into addr_vect:
|
|
|
|
// addr_vect[0:31] = shadow0[32:63]
|
|
|
|
// addr_vect[32:63] = shadow0[96:127]
|
|
|
|
// addr_vect[64:95] = shadow1[32:63]
|
|
|
|
// addr_vect[96:127] = shadow1[96:127]
|
|
|
|
m128 addr_vect = SHUF(shadow0, shadow1, 1, 3, 1, 3);
|
|
|
|
if (!is_write) {
|
|
|
|
// set IsRead bit in addr_vect
|
|
|
|
const m128 rw_mask1 = _mm_cvtsi64_si128(1<<15);
|
|
|
|
const m128 rw_mask = SHUF(rw_mask1, rw_mask1, 0, 0, 0, 0);
|
|
|
|
addr_vect = _mm_or_si128(addr_vect, rw_mask);
|
|
|
|
}
|
|
|
|
// addr0 == addr_vect?
|
|
|
|
const m128 addr_res = _mm_cmpeq_epi32(addr0, addr_vect);
|
|
|
|
// epoch1[0:63] = sync_epoch
|
|
|
|
const m128 epoch1 = _mm_cvtsi64_si128(sync_epoch);
|
|
|
|
// epoch[0:31] = sync_epoch[0:31]
|
|
|
|
// epoch[32:63] = sync_epoch[0:31]
|
|
|
|
// epoch[64:95] = sync_epoch[0:31]
|
|
|
|
// epoch[96:127] = sync_epoch[0:31]
|
|
|
|
const m128 epoch = SHUF(epoch1, epoch1, 0, 0, 0, 0);
|
|
|
|
// load low parts of shadow cell epochs into epoch_vect:
|
|
|
|
// epoch_vect[0:31] = shadow0[0:31]
|
|
|
|
// epoch_vect[32:63] = shadow0[64:95]
|
|
|
|
// epoch_vect[64:95] = shadow1[0:31]
|
|
|
|
// epoch_vect[96:127] = shadow1[64:95]
|
|
|
|
const m128 epoch_vect = SHUF(shadow0, shadow1, 0, 2, 0, 2);
|
|
|
|
// epoch_vect >= sync_epoch?
|
|
|
|
const m128 epoch_res = _mm_cmpgt_epi32(epoch_vect, epoch);
|
|
|
|
// addr_res & epoch_res
|
|
|
|
const m128 res = _mm_and_si128(addr_res, epoch_res);
|
|
|
|
// mask[0] = res[7]
|
|
|
|
// mask[1] = res[15]
|
|
|
|
// ...
|
|
|
|
// mask[15] = res[127]
|
|
|
|
const int mask = _mm_movemask_epi8(res);
|
|
|
|
return mask != 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ALWAYS_INLINE
|
|
|
|
bool ContainsSameAccess(u64 *s, u64 a, u64 sync_epoch, bool is_write) {
|
2015-01-19 23:01:07 +08:00
|
|
|
#if defined(__SSE3__)
|
2014-05-30 21:36:29 +08:00
|
|
|
bool res = ContainsSameAccessFast(s, a, sync_epoch, is_write);
|
2014-10-25 01:07:29 +08:00
|
|
|
// NOTE: this check can fail if the shadow is concurrently mutated
|
2014-12-18 18:17:01 +08:00
|
|
|
// by other threads. But it still can be useful if you modify
|
|
|
|
// ContainsSameAccessFast and want to ensure that it's not completely broken.
|
|
|
|
// DCHECK_EQ(res, ContainsSameAccessSlow(s, a, sync_epoch, is_write));
|
2014-05-30 21:36:29 +08:00
|
|
|
return res;
|
|
|
|
#else
|
|
|
|
return ContainsSameAccessSlow(s, a, sync_epoch, is_write);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-03-29 17:44:16 +08:00
|
|
|
ALWAYS_INLINE USED
|
2012-05-10 21:48:04 +08:00
|
|
|
void MemoryAccess(ThreadState *thr, uptr pc, uptr addr,
|
2013-02-01 17:42:06 +08:00
|
|
|
int kAccessSizeLog, bool kAccessIsWrite, bool kIsAtomic) {
|
2012-05-10 21:48:04 +08:00
|
|
|
u64 *shadow_mem = (u64*)MemToShadow(addr);
|
2012-12-08 03:23:59 +08:00
|
|
|
DPrintf2("#%d: MemoryAccess: @%p %p size=%d"
|
2012-06-06 21:11:29 +08:00
|
|
|
" is_write=%d shadow_mem=%p {%zx, %zx, %zx, %zx}\n",
|
2012-05-10 21:48:04 +08:00
|
|
|
(int)thr->fast_state.tid(), (void*)pc, (void*)addr,
|
|
|
|
(int)(1 << kAccessSizeLog), kAccessIsWrite, shadow_mem,
|
2012-06-06 21:11:29 +08:00
|
|
|
(uptr)shadow_mem[0], (uptr)shadow_mem[1],
|
|
|
|
(uptr)shadow_mem[2], (uptr)shadow_mem[3]);
|
2015-01-03 12:29:12 +08:00
|
|
|
#if SANITIZER_DEBUG
|
2012-05-10 21:48:04 +08:00
|
|
|
if (!IsAppMem(addr)) {
|
2012-11-02 20:17:51 +08:00
|
|
|
Printf("Access to non app mem %zx\n", addr);
|
2012-05-10 21:48:04 +08:00
|
|
|
DCHECK(IsAppMem(addr));
|
|
|
|
}
|
|
|
|
if (!IsShadowMem((uptr)shadow_mem)) {
|
2012-11-02 20:17:51 +08:00
|
|
|
Printf("Bad shadow addr %p (%zx)\n", shadow_mem, addr);
|
2012-05-10 21:48:04 +08:00
|
|
|
DCHECK(IsShadowMem((uptr)shadow_mem));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-06-07 00:06:19 +08:00
|
|
|
if (kCppMode && *shadow_mem == kShadowRodata) {
|
2013-03-20 21:21:50 +08:00
|
|
|
// Access to .rodata section, no races here.
|
|
|
|
// Measurements show that it can be 10-20% of all memory accesses.
|
|
|
|
StatInc(thr, StatMop);
|
|
|
|
StatInc(thr, kAccessIsWrite ? StatMopWrite : StatMopRead);
|
|
|
|
StatInc(thr, (StatType)(StatMop1 + kAccessSizeLog));
|
|
|
|
StatInc(thr, StatMopRodata);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
FastState fast_state = thr->fast_state;
|
2014-05-30 21:36:29 +08:00
|
|
|
if (fast_state.GetIgnoreBit()) {
|
|
|
|
StatInc(thr, StatMop);
|
|
|
|
StatInc(thr, kAccessIsWrite ? StatMopWrite : StatMopRead);
|
|
|
|
StatInc(thr, (StatType)(StatMop1 + kAccessSizeLog));
|
|
|
|
StatInc(thr, StatMopIgnored);
|
2012-05-10 21:48:04 +08:00
|
|
|
return;
|
2014-05-15 20:51:48 +08:00
|
|
|
}
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
Shadow cur(fast_state);
|
|
|
|
cur.SetAddr0AndSizeLog(addr & 7, kAccessSizeLog);
|
|
|
|
cur.SetWrite(kAccessIsWrite);
|
2013-02-01 17:42:06 +08:00
|
|
|
cur.SetAtomic(kIsAtomic);
|
2012-05-10 21:48:04 +08:00
|
|
|
|
2014-05-30 21:36:29 +08:00
|
|
|
if (LIKELY(ContainsSameAccess(shadow_mem, cur.raw(),
|
|
|
|
thr->fast_synch_epoch, kAccessIsWrite))) {
|
|
|
|
StatInc(thr, StatMop);
|
|
|
|
StatInc(thr, kAccessIsWrite ? StatMopWrite : StatMopRead);
|
|
|
|
StatInc(thr, (StatType)(StatMop1 + kAccessSizeLog));
|
|
|
|
StatInc(thr, StatMopSame);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kCollectHistory) {
|
|
|
|
fast_state.IncrementEpoch();
|
|
|
|
thr->fast_state = fast_state;
|
2014-06-07 02:05:12 +08:00
|
|
|
TraceAddEvent(thr, fast_state, EventTypeMop, pc);
|
2014-05-30 21:36:29 +08:00
|
|
|
cur.IncrementEpoch();
|
|
|
|
}
|
|
|
|
|
|
|
|
MemoryAccessImpl1(thr, addr, kAccessSizeLog, kAccessIsWrite, kIsAtomic,
|
|
|
|
shadow_mem, cur);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called by MemoryAccessRange in tsan_rtl_thread.cc
|
2014-06-07 00:06:19 +08:00
|
|
|
ALWAYS_INLINE USED
|
2014-05-30 21:36:29 +08:00
|
|
|
void MemoryAccessImpl(ThreadState *thr, uptr addr,
|
|
|
|
int kAccessSizeLog, bool kAccessIsWrite, bool kIsAtomic,
|
|
|
|
u64 *shadow_mem, Shadow cur) {
|
|
|
|
if (LIKELY(ContainsSameAccess(shadow_mem, cur.raw(),
|
|
|
|
thr->fast_synch_epoch, kAccessIsWrite))) {
|
|
|
|
StatInc(thr, StatMop);
|
|
|
|
StatInc(thr, kAccessIsWrite ? StatMopWrite : StatMopRead);
|
|
|
|
StatInc(thr, (StatType)(StatMop1 + kAccessSizeLog));
|
|
|
|
StatInc(thr, StatMopSame);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MemoryAccessImpl1(thr, addr, kAccessSizeLog, kAccessIsWrite, kIsAtomic,
|
2012-05-10 21:48:04 +08:00
|
|
|
shadow_mem, cur);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void MemoryRangeSet(ThreadState *thr, uptr pc, uptr addr, uptr size,
|
|
|
|
u64 val) {
|
2013-03-19 00:56:48 +08:00
|
|
|
(void)thr;
|
|
|
|
(void)pc;
|
2012-05-10 21:48:04 +08:00
|
|
|
if (size == 0)
|
|
|
|
return;
|
|
|
|
// FIXME: fix me.
|
|
|
|
uptr offset = addr % kShadowCell;
|
|
|
|
if (offset) {
|
|
|
|
offset = kShadowCell - offset;
|
|
|
|
if (size <= offset)
|
|
|
|
return;
|
|
|
|
addr += offset;
|
|
|
|
size -= offset;
|
|
|
|
}
|
2012-09-02 20:04:51 +08:00
|
|
|
DCHECK_EQ(addr % 8, 0);
|
|
|
|
// If a user passes some insane arguments (memset(0)),
|
|
|
|
// let it just crash as usual.
|
|
|
|
if (!IsAppMem(addr) || !IsAppMem(addr + size - 1))
|
|
|
|
return;
|
2013-03-19 00:56:48 +08:00
|
|
|
// Don't want to touch lots of shadow memory.
|
|
|
|
// If a program maps 10MB stack, there is no need reset the whole range.
|
2012-08-16 00:52:19 +08:00
|
|
|
size = (size + (kShadowCell - 1)) & ~(kShadowCell - 1);
|
2013-06-13 18:15:44 +08:00
|
|
|
// UnmapOrDie/MmapFixedNoReserve does not work on Windows,
|
|
|
|
// so we do it only for C/C++.
|
2014-02-14 19:41:26 +08:00
|
|
|
if (kGoMode || size < common_flags()->clear_shadow_mmap_threshold) {
|
2013-03-19 00:56:48 +08:00
|
|
|
u64 *p = (u64*)MemToShadow(addr);
|
|
|
|
CHECK(IsShadowMem((uptr)p));
|
|
|
|
CHECK(IsShadowMem((uptr)(p + size * kShadowCnt / kShadowCell - 1)));
|
|
|
|
// FIXME: may overwrite a part outside the region
|
|
|
|
for (uptr i = 0; i < size / kShadowCell * kShadowCnt;) {
|
|
|
|
p[i++] = val;
|
|
|
|
for (uptr j = 1; j < kShadowCnt; j++)
|
|
|
|
p[i++] = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// The region is big, reset only beginning and end.
|
2015-02-20 14:42:41 +08:00
|
|
|
const uptr kPageSize = GetPageSizeCached();
|
2013-03-19 00:56:48 +08:00
|
|
|
u64 *begin = (u64*)MemToShadow(addr);
|
|
|
|
u64 *end = begin + size / kShadowCell * kShadowCnt;
|
|
|
|
u64 *p = begin;
|
|
|
|
// Set at least first kPageSize/2 to page boundary.
|
|
|
|
while ((p < begin + kPageSize / kShadowSize / 2) || ((uptr)p % kPageSize)) {
|
|
|
|
*p++ = val;
|
|
|
|
for (uptr j = 1; j < kShadowCnt; j++)
|
|
|
|
*p++ = 0;
|
|
|
|
}
|
|
|
|
// Reset middle part.
|
|
|
|
u64 *p1 = p;
|
|
|
|
p = RoundDown(end, kPageSize);
|
|
|
|
UnmapOrDie((void*)p1, (uptr)p - (uptr)p1);
|
|
|
|
MmapFixedNoReserve((uptr)p1, (uptr)p - (uptr)p1);
|
|
|
|
// Set the ending.
|
|
|
|
while (p < end) {
|
|
|
|
*p++ = val;
|
|
|
|
for (uptr j = 1; j < kShadowCnt; j++)
|
|
|
|
*p++ = 0;
|
|
|
|
}
|
2012-08-16 00:52:19 +08:00
|
|
|
}
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryResetRange(ThreadState *thr, uptr pc, uptr addr, uptr size) {
|
|
|
|
MemoryRangeSet(thr, pc, addr, size, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryRangeFreed(ThreadState *thr, uptr pc, uptr addr, uptr size) {
|
2013-03-19 00:56:48 +08:00
|
|
|
// Processing more than 1k (4k of shadow) is expensive,
|
|
|
|
// can cause excessive memory consumption (user does not necessary touch
|
|
|
|
// the whole range) and most likely unnecessary.
|
|
|
|
if (size > 1024)
|
|
|
|
size = 1024;
|
2013-02-01 22:41:58 +08:00
|
|
|
CHECK_EQ(thr->is_freeing, false);
|
|
|
|
thr->is_freeing = true;
|
2012-05-10 21:48:04 +08:00
|
|
|
MemoryAccessRange(thr, pc, addr, size, true);
|
2013-02-01 22:41:58 +08:00
|
|
|
thr->is_freeing = false;
|
2014-05-15 20:51:48 +08:00
|
|
|
if (kCollectHistory) {
|
|
|
|
thr->fast_state.IncrementEpoch();
|
|
|
|
TraceAddEvent(thr, thr->fast_state, EventTypeMop, pc);
|
|
|
|
}
|
2012-05-17 22:17:51 +08:00
|
|
|
Shadow s(thr->fast_state);
|
2012-11-30 14:39:01 +08:00
|
|
|
s.ClearIgnoreBit();
|
2012-05-17 22:17:51 +08:00
|
|
|
s.MarkAsFreed();
|
|
|
|
s.SetWrite(true);
|
|
|
|
s.SetAddr0AndSizeLog(0, 3);
|
|
|
|
MemoryRangeSet(thr, pc, addr, size, s.raw());
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
|
|
|
|
2012-08-16 00:52:19 +08:00
|
|
|
void MemoryRangeImitateWrite(ThreadState *thr, uptr pc, uptr addr, uptr size) {
|
2014-05-15 20:51:48 +08:00
|
|
|
if (kCollectHistory) {
|
|
|
|
thr->fast_state.IncrementEpoch();
|
|
|
|
TraceAddEvent(thr, thr->fast_state, EventTypeMop, pc);
|
|
|
|
}
|
2012-08-16 00:52:19 +08:00
|
|
|
Shadow s(thr->fast_state);
|
2012-11-30 14:39:01 +08:00
|
|
|
s.ClearIgnoreBit();
|
2012-08-16 00:52:19 +08:00
|
|
|
s.SetWrite(true);
|
|
|
|
s.SetAddr0AndSizeLog(0, 3);
|
|
|
|
MemoryRangeSet(thr, pc, addr, size, s.raw());
|
|
|
|
}
|
|
|
|
|
2013-03-29 17:44:16 +08:00
|
|
|
ALWAYS_INLINE USED
|
2012-05-10 21:48:04 +08:00
|
|
|
void FuncEntry(ThreadState *thr, uptr pc) {
|
|
|
|
StatInc(thr, StatFuncEnter);
|
2012-07-17 00:44:47 +08:00
|
|
|
DPrintf2("#%d: FuncEntry %p\n", (int)thr->fast_state.tid(), (void*)pc);
|
2014-05-15 20:51:48 +08:00
|
|
|
if (kCollectHistory) {
|
|
|
|
thr->fast_state.IncrementEpoch();
|
|
|
|
TraceAddEvent(thr, thr->fast_state, EventTypeFuncEnter, pc);
|
|
|
|
}
|
2012-05-10 21:48:04 +08:00
|
|
|
|
|
|
|
// Shadow stack maintenance can be replaced with
|
|
|
|
// stack unwinding during trace switch (which presumably must be faster).
|
2013-10-16 23:35:12 +08:00
|
|
|
DCHECK_GE(thr->shadow_stack_pos, thr->shadow_stack);
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2013-10-16 23:35:12 +08:00
|
|
|
DCHECK_LT(thr->shadow_stack_pos, thr->shadow_stack_end);
|
2012-07-17 00:44:47 +08:00
|
|
|
#else
|
2014-06-07 02:05:12 +08:00
|
|
|
if (thr->shadow_stack_pos == thr->shadow_stack_end)
|
|
|
|
GrowShadowStack(thr);
|
2012-07-17 00:44:47 +08:00
|
|
|
#endif
|
2012-05-10 21:48:04 +08:00
|
|
|
thr->shadow_stack_pos[0] = pc;
|
|
|
|
thr->shadow_stack_pos++;
|
|
|
|
}
|
|
|
|
|
2013-03-29 17:44:16 +08:00
|
|
|
ALWAYS_INLINE USED
|
2012-05-10 21:48:04 +08:00
|
|
|
void FuncExit(ThreadState *thr) {
|
|
|
|
StatInc(thr, StatFuncExit);
|
2012-07-17 00:44:47 +08:00
|
|
|
DPrintf2("#%d: FuncExit\n", (int)thr->fast_state.tid());
|
2014-05-15 20:51:48 +08:00
|
|
|
if (kCollectHistory) {
|
|
|
|
thr->fast_state.IncrementEpoch();
|
|
|
|
TraceAddEvent(thr, thr->fast_state, EventTypeFuncExit, 0);
|
|
|
|
}
|
2012-05-10 21:48:04 +08:00
|
|
|
|
2013-10-16 23:35:12 +08:00
|
|
|
DCHECK_GT(thr->shadow_stack_pos, thr->shadow_stack);
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2013-10-16 23:35:12 +08:00
|
|
|
DCHECK_LT(thr->shadow_stack_pos, thr->shadow_stack_end);
|
2012-07-17 00:44:47 +08:00
|
|
|
#endif
|
2012-05-10 21:48:04 +08:00
|
|
|
thr->shadow_stack_pos--;
|
|
|
|
}
|
|
|
|
|
2013-11-27 19:30:28 +08:00
|
|
|
void ThreadIgnoreBegin(ThreadState *thr, uptr pc) {
|
2013-09-19 12:39:04 +08:00
|
|
|
DPrintf("#%d: ThreadIgnoreBegin\n", thr->tid);
|
|
|
|
thr->ignore_reads_and_writes++;
|
2013-10-10 23:58:12 +08:00
|
|
|
CHECK_GT(thr->ignore_reads_and_writes, 0);
|
2013-09-19 12:39:04 +08:00
|
|
|
thr->fast_state.SetIgnoreBit();
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2014-04-03 20:51:26 +08:00
|
|
|
if (!ctx->after_multithreaded_fork)
|
|
|
|
thr->mop_ignore_set.Add(CurrentStackId(thr, pc));
|
2013-11-27 19:30:28 +08:00
|
|
|
#endif
|
2013-09-19 12:39:04 +08:00
|
|
|
}
|
|
|
|
|
2013-11-27 19:30:28 +08:00
|
|
|
void ThreadIgnoreEnd(ThreadState *thr, uptr pc) {
|
2013-09-19 12:39:04 +08:00
|
|
|
DPrintf("#%d: ThreadIgnoreEnd\n", thr->tid);
|
|
|
|
thr->ignore_reads_and_writes--;
|
|
|
|
CHECK_GE(thr->ignore_reads_and_writes, 0);
|
2013-11-27 19:30:28 +08:00
|
|
|
if (thr->ignore_reads_and_writes == 0) {
|
2012-05-10 21:48:04 +08:00
|
|
|
thr->fast_state.ClearIgnoreBit();
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2013-11-27 19:30:28 +08:00
|
|
|
thr->mop_ignore_set.Reset();
|
|
|
|
#endif
|
|
|
|
}
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
|
|
|
|
2013-11-27 19:30:28 +08:00
|
|
|
void ThreadIgnoreSyncBegin(ThreadState *thr, uptr pc) {
|
2013-10-10 23:58:12 +08:00
|
|
|
DPrintf("#%d: ThreadIgnoreSyncBegin\n", thr->tid);
|
|
|
|
thr->ignore_sync++;
|
|
|
|
CHECK_GT(thr->ignore_sync, 0);
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2014-04-03 20:51:26 +08:00
|
|
|
if (!ctx->after_multithreaded_fork)
|
|
|
|
thr->sync_ignore_set.Add(CurrentStackId(thr, pc));
|
2013-11-27 19:30:28 +08:00
|
|
|
#endif
|
2013-10-10 23:58:12 +08:00
|
|
|
}
|
|
|
|
|
2013-11-27 19:30:28 +08:00
|
|
|
void ThreadIgnoreSyncEnd(ThreadState *thr, uptr pc) {
|
2013-10-10 23:58:12 +08:00
|
|
|
DPrintf("#%d: ThreadIgnoreSyncEnd\n", thr->tid);
|
|
|
|
thr->ignore_sync--;
|
|
|
|
CHECK_GE(thr->ignore_sync, 0);
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2013-11-27 19:30:28 +08:00
|
|
|
if (thr->ignore_sync == 0)
|
2014-04-03 20:28:16 +08:00
|
|
|
thr->sync_ignore_set.Reset();
|
2013-11-27 19:30:28 +08:00
|
|
|
#endif
|
2013-10-10 23:58:12 +08:00
|
|
|
}
|
|
|
|
|
2012-07-06 00:18:28 +08:00
|
|
|
bool MD5Hash::operator==(const MD5Hash &other) const {
|
|
|
|
return hash[0] == other.hash[0] && hash[1] == other.hash[1];
|
|
|
|
}
|
|
|
|
|
2015-01-03 12:29:12 +08:00
|
|
|
#if SANITIZER_DEBUG
|
2012-05-10 21:48:04 +08:00
|
|
|
void build_consistency_debug() {}
|
|
|
|
#else
|
|
|
|
void build_consistency_release() {}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if TSAN_COLLECT_STATS
|
|
|
|
void build_consistency_stats() {}
|
|
|
|
#else
|
|
|
|
void build_consistency_nostats() {}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} // namespace __tsan
|
|
|
|
|
2014-12-09 09:31:14 +08:00
|
|
|
#ifndef SANITIZER_GO
|
2012-05-10 21:48:04 +08:00
|
|
|
// Must be included in this file to make sure everything is inlined.
|
|
|
|
#include "tsan_interface_inl.h"
|
2012-07-06 00:18:28 +08:00
|
|
|
#endif
|