blob: 0323f8b0649d09c9c2266b38dd08dab76126bac8 [file] [log] [blame]
Alexey Samsonov3b2f9f42012-06-04 13:55:19 +00001//===-- tsan_rtl.cc -------------------------------------------------------===//
Kostya Serebryany4ad375f2012-05-10 13:48:04 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file is a part of ThreadSanitizer (TSan), a race detector.
11//
12// Main file (entry points) for the TSan run-time.
13//===----------------------------------------------------------------------===//
14
Dmitry Vyukov6fa46f72012-06-29 16:58:33 +000015#include "sanitizer_common/sanitizer_atomic.h"
Alexey Samsonov58a3c582012-06-18 08:44:30 +000016#include "sanitizer_common/sanitizer_common.h"
Kostya Serebryanyc5bea202012-05-31 13:42:53 +000017#include "sanitizer_common/sanitizer_libc.h"
Alexey Samsonov8bd90982012-06-07 09:50:16 +000018#include "sanitizer_common/sanitizer_placement_new.h"
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000019#include "tsan_defs.h"
20#include "tsan_platform.h"
21#include "tsan_rtl.h"
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000022#include "tsan_mman.h"
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000023#include "tsan_suppressions.h"
24
Dmitry Vyukov302cebb2012-05-22 18:07:45 +000025volatile int __tsan_resumed = 0;
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000026
27extern "C" void __tsan_resume() {
Dmitry Vyukov302cebb2012-05-22 18:07:45 +000028 __tsan_resumed = 1;
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000029}
30
31namespace __tsan {
32
Dmitry Vyukov03d32ec2012-07-05 16:18:28 +000033#ifndef TSAN_GO
Alexey Samsonovef2e2cf2012-06-05 13:50:57 +000034THREADLOCAL char cur_thread_placeholder[sizeof(ThreadState)] ALIGNED(64);
Dmitry Vyukov954fc8c2012-08-15 15:35:15 +000035char allocator_placeholder[sizeof(Allocator)] ALIGNED(64);
Dmitry Vyukov03d32ec2012-07-05 16:18:28 +000036#endif
Alexey Samsonovef2e2cf2012-06-05 13:50:57 +000037static char ctx_placeholder[sizeof(Context)] ALIGNED(64);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000038
39static Context *ctx;
40Context *CTX() {
41 return ctx;
42}
43
44Context::Context()
45 : initialized()
46 , report_mtx(MutexTypeReport, StatMtxReport)
47 , nreported()
48 , nmissed_expected()
49 , thread_mtx(MutexTypeThreads, StatMtxThreads)
50 , racy_stacks(MBlockRacyStacks)
51 , racy_addresses(MBlockRacyAddresses) {
52}
53
54// The objects are allocated in TLS, so one may rely on zero-initialization.
55ThreadState::ThreadState(Context *ctx, int tid, u64 epoch,
56 uptr stk_addr, uptr stk_size,
57 uptr tls_addr, uptr tls_size)
58 : fast_state(tid, epoch)
59 // Do not touch these, rely on zero initialization,
60 // they may be accessed before the ctor.
61 // , fast_ignore_reads()
62 // , fast_ignore_writes()
63 // , in_rtl()
64 , shadow_stack_pos(&shadow_stack[0])
65 , tid(tid)
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000066 , stk_addr(stk_addr)
67 , stk_size(stk_size)
68 , tls_addr(tls_addr)
69 , tls_size(tls_size) {
70}
71
72ThreadContext::ThreadContext(int tid)
73 : tid(tid)
74 , unique_id()
75 , user_id()
76 , thr()
77 , status(ThreadStatusInvalid)
78 , detached()
79 , reuse_count()
80 , epoch0()
81 , epoch1()
Dmitry Vyukovf6985e32012-05-22 14:34:43 +000082 , dead_info()
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000083 , dead_next() {
84}
85
Dmitry Vyukov15710c92012-05-22 11:33:03 +000086static void WriteMemoryProfile(char *buf, uptr buf_size, int num) {
87 uptr shadow = GetShadowMemoryConsumption();
88
89 int nthread = 0;
90 int nlivethread = 0;
91 uptr threadmem = 0;
92 {
93 Lock l(&ctx->thread_mtx);
94 for (unsigned i = 0; i < kMaxTid; i++) {
95 ThreadContext *tctx = ctx->threads[i];
96 if (tctx == 0)
97 continue;
98 nthread += 1;
99 threadmem += sizeof(ThreadContext);
100 if (tctx->status != ThreadStatusRunning)
101 continue;
102 nlivethread += 1;
103 threadmem += sizeof(ThreadState);
104 }
105 }
106
107 uptr nsync = 0;
108 uptr syncmem = CTX()->synctab.GetMemoryConsumption(&nsync);
109
Alexey Samsonove1cb5242012-06-19 09:21:57 +0000110 internal_snprintf(buf, buf_size, "%d: shadow=%zuMB"
111 " thread=%zuMB(total=%d/live=%d)"
112 " sync=%zuMB(cnt=%zu)\n",
Dmitry Vyukov15710c92012-05-22 11:33:03 +0000113 num,
114 shadow >> 20,
115 threadmem >> 20, nthread, nlivethread,
116 syncmem >> 20, nsync);
117}
118
119static void MemoryProfileThread(void *arg) {
120 ScopedInRtl in_rtl;
121 fd_t fd = (fd_t)(uptr)arg;
122 for (int i = 0; ; i++) {
123 InternalScopedBuf<char> buf(4096);
124 WriteMemoryProfile(buf.Ptr(), buf.Size(), i);
125 internal_write(fd, buf.Ptr(), internal_strlen(buf.Ptr()));
Alexey Samsonov58a3c582012-06-18 08:44:30 +0000126 SleepForSeconds(1);
Dmitry Vyukov15710c92012-05-22 11:33:03 +0000127 }
128}
129
130static void InitializeMemoryProfile() {
131 if (flags()->profile_memory == 0 || flags()->profile_memory[0] == 0)
132 return;
133 InternalScopedBuf<char> filename(4096);
Alexey Samsonove1cb5242012-06-19 09:21:57 +0000134 internal_snprintf(filename.Ptr(), filename.Size(), "%s.%d",
Dmitry Vyukov15710c92012-05-22 11:33:03 +0000135 flags()->profile_memory, GetPid());
136 fd_t fd = internal_open(filename.Ptr(), true);
137 if (fd == kInvalidFd) {
Alexey Samsonovac4c2902012-06-06 10:13:27 +0000138 TsanPrintf("Failed to open memory profile file '%s'\n", &filename[0]);
Dmitry Vyukov15710c92012-05-22 11:33:03 +0000139 Die();
140 }
141 internal_start_thread(&MemoryProfileThread, (void*)(uptr)fd);
142}
143
Dmitry Vyukov302cebb2012-05-22 18:07:45 +0000144static void MemoryFlushThread(void *arg) {
145 ScopedInRtl in_rtl;
146 for (int i = 0; ; i++) {
Alexey Samsonov58a3c582012-06-18 08:44:30 +0000147 SleepForMillis(flags()->flush_memory_ms);
Dmitry Vyukov302cebb2012-05-22 18:07:45 +0000148 FlushShadowMemory();
149 }
150}
151
152static void InitializeMemoryFlush() {
153 if (flags()->flush_memory_ms == 0)
154 return;
155 if (flags()->flush_memory_ms < 100)
156 flags()->flush_memory_ms = 100;
157 internal_start_thread(&MemoryFlushThread, 0);
158}
159
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000160void Initialize(ThreadState *thr) {
161 // Thread safe because done before all threads exist.
162 static bool is_initialized = false;
163 if (is_initialized)
164 return;
165 is_initialized = true;
166 ScopedInRtl in_rtl;
Dmitry Vyukov954fc8c2012-08-15 15:35:15 +0000167 InitializeAllocator();
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000168 InitializeInterceptors();
169 const char *env = InitializePlatform();
170 InitializeMutex();
171 InitializeDynamicAnnotations();
172 ctx = new(ctx_placeholder) Context;
173 InitializeShadowMemory();
174 ctx->dead_list_size = 0;
175 ctx->dead_list_head = 0;
176 ctx->dead_list_tail = 0;
177 InitializeFlags(&ctx->flags, env);
178 InitializeSuppressions();
Dmitry Vyukov15710c92012-05-22 11:33:03 +0000179 InitializeMemoryProfile();
Dmitry Vyukov302cebb2012-05-22 18:07:45 +0000180 InitializeMemoryFlush();
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000181
182 if (ctx->flags.verbosity)
Alexey Samsonovac4c2902012-06-06 10:13:27 +0000183 TsanPrintf("***** Running under ThreadSanitizer v2 (pid %d) *****\n",
184 GetPid());
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000185
186 // Initialize thread 0.
187 ctx->thread_seq = 0;
188 int tid = ThreadCreate(thr, 0, 0, true);
189 CHECK_EQ(tid, 0);
190 ThreadStart(thr, tid);
191 CHECK_EQ(thr->in_rtl, 1);
192 ctx->initialized = true;
193
Dmitry Vyukov302cebb2012-05-22 18:07:45 +0000194 if (flags()->stop_on_start) {
Alexey Samsonovac4c2902012-06-06 10:13:27 +0000195 TsanPrintf("ThreadSanitizer is suspended at startup (pid %d)."
Dmitry Vyukov302cebb2012-05-22 18:07:45 +0000196 " Call __tsan_resume().\n",
197 GetPid());
198 while (__tsan_resumed == 0);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000199 }
200}
201
202int Finalize(ThreadState *thr) {
203 ScopedInRtl in_rtl;
204 Context *ctx = __tsan::ctx;
205 bool failed = false;
206
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000207 ThreadFinalize(thr);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000208
209 if (ctx->nreported) {
210 failed = true;
Alexey Samsonovac4c2902012-06-06 10:13:27 +0000211 TsanPrintf("ThreadSanitizer: reported %d warnings\n", ctx->nreported);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000212 }
213
214 if (ctx->nmissed_expected) {
215 failed = true;
Alexey Samsonovac4c2902012-06-06 10:13:27 +0000216 TsanPrintf("ThreadSanitizer: missed %d expected races\n",
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000217 ctx->nmissed_expected);
218 }
219
220 StatOutput(ctx->stat);
Dmitry Vyukov19b855f2012-05-17 15:00:27 +0000221 return failed ? flags()->exitcode : 0;
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000222}
223
Dmitry Vyukov03d32ec2012-07-05 16:18:28 +0000224void TraceSwitch(ThreadState *thr) {
Dmitry Vyukovde1fd1c2012-06-22 11:08:55 +0000225 thr->nomalloc++;
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000226 ScopedInRtl in_rtl;
227 Lock l(&thr->trace.mtx);
228 unsigned trace = (thr->fast_state.epoch() / kTracePartSize) % kTraceParts;
229 TraceHeader *hdr = &thr->trace.headers[trace];
230 hdr->epoch0 = thr->fast_state.epoch();
231 hdr->stack0.ObtainCurrent(thr, 0);
Dmitry Vyukovde1fd1c2012-06-22 11:08:55 +0000232 thr->nomalloc--;
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000233}
234
Dmitry Vyukov03d32ec2012-07-05 16:18:28 +0000235#ifndef TSAN_GO
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000236extern "C" void __tsan_trace_switch() {
237 TraceSwitch(cur_thread());
238}
239
240extern "C" void __tsan_report_race() {
241 ReportRace(cur_thread());
242}
Dmitry Vyukov03d32ec2012-07-05 16:18:28 +0000243#endif
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000244
245ALWAYS_INLINE
246static Shadow LoadShadow(u64 *p) {
247 u64 raw = atomic_load((atomic_uint64_t*)p, memory_order_relaxed);
248 return Shadow(raw);
249}
250
251ALWAYS_INLINE
252static void StoreShadow(u64 *sp, u64 s) {
253 atomic_store((atomic_uint64_t*)sp, s, memory_order_relaxed);
254}
255
256ALWAYS_INLINE
257static void StoreIfNotYetStored(u64 *sp, u64 *s) {
258 StoreShadow(sp, *s);
259 *s = 0;
260}
261
262static inline void HandleRace(ThreadState *thr, u64 *shadow_mem,
263 Shadow cur, Shadow old) {
264 thr->racy_state[0] = cur.raw();
265 thr->racy_state[1] = old.raw();
266 thr->racy_shadow_addr = shadow_mem;
Dmitry Vyukov03d32ec2012-07-05 16:18:28 +0000267#ifndef TSAN_GO
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000268 HACKY_CALL(__tsan_report_race);
Dmitry Vyukov03d32ec2012-07-05 16:18:28 +0000269#else
270 ReportRace(thr);
271#endif
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000272}
273
274static inline bool BothReads(Shadow s, int kAccessIsWrite) {
275 return !kAccessIsWrite && !s.is_write();
276}
277
278static inline bool OldIsRWStronger(Shadow old, int kAccessIsWrite) {
279 return old.is_write() || !kAccessIsWrite;
280}
281
282static inline bool OldIsRWWeaker(Shadow old, int kAccessIsWrite) {
283 return !old.is_write() || kAccessIsWrite;
284}
285
286static inline bool OldIsInSameSynchEpoch(Shadow old, ThreadState *thr) {
287 return old.epoch() >= thr->fast_synch_epoch;
288}
289
290static inline bool HappensBefore(Shadow old, ThreadState *thr) {
291 return thr->clock.get(old.tid()) >= old.epoch();
292}
293
294ALWAYS_INLINE
295void MemoryAccessImpl(ThreadState *thr, uptr addr,
296 int kAccessSizeLog, bool kAccessIsWrite, FastState fast_state,
297 u64 *shadow_mem, Shadow cur) {
298 StatInc(thr, StatMop);
299 StatInc(thr, kAccessIsWrite ? StatMopWrite : StatMopRead);
300 StatInc(thr, (StatType)(StatMop1 + kAccessSizeLog));
301
302 // This potentially can live in an MMX/SSE scratch register.
303 // The required intrinsics are:
304 // __m128i _mm_move_epi64(__m128i*);
305 // _mm_storel_epi64(u64*, __m128i);
306 u64 store_word = cur.raw();
307
308 // scan all the shadow values and dispatch to 4 categories:
309 // same, replace, candidate and race (see comments below).
310 // we consider only 3 cases regarding access sizes:
311 // equal, intersect and not intersect. initially I considered
312 // larger and smaller as well, it allowed to replace some
313 // 'candidates' with 'same' or 'replace', but I think
314 // it's just not worth it (performance- and complexity-wise).
315
316 Shadow old(0);
317 if (kShadowCnt == 1) {
318 int idx = 0;
319#include "tsan_update_shadow_word_inl.h"
320 } else if (kShadowCnt == 2) {
321 int idx = 0;
322#include "tsan_update_shadow_word_inl.h"
323 idx = 1;
324#include "tsan_update_shadow_word_inl.h"
325 } else if (kShadowCnt == 4) {
326 int idx = 0;
327#include "tsan_update_shadow_word_inl.h"
328 idx = 1;
329#include "tsan_update_shadow_word_inl.h"
330 idx = 2;
331#include "tsan_update_shadow_word_inl.h"
332 idx = 3;
333#include "tsan_update_shadow_word_inl.h"
334 } else if (kShadowCnt == 8) {
335 int idx = 0;
336#include "tsan_update_shadow_word_inl.h"
337 idx = 1;
338#include "tsan_update_shadow_word_inl.h"
339 idx = 2;
340#include "tsan_update_shadow_word_inl.h"
341 idx = 3;
342#include "tsan_update_shadow_word_inl.h"
343 idx = 4;
344#include "tsan_update_shadow_word_inl.h"
345 idx = 5;
346#include "tsan_update_shadow_word_inl.h"
347 idx = 6;
348#include "tsan_update_shadow_word_inl.h"
349 idx = 7;
350#include "tsan_update_shadow_word_inl.h"
351 } else {
352 CHECK(false);
353 }
354
355 // we did not find any races and had already stored
356 // the current access info, so we are done
357 if (LIKELY(store_word == 0))
358 return;
359 // choose a random candidate slot and replace it
360 StoreShadow(shadow_mem + (cur.epoch() % kShadowCnt), store_word);
361 StatInc(thr, StatShadowReplace);
362 return;
363 RACE:
364 HandleRace(thr, shadow_mem, cur, old);
365 return;
366}
367
368ALWAYS_INLINE
369void MemoryAccess(ThreadState *thr, uptr pc, uptr addr,
370 int kAccessSizeLog, bool kAccessIsWrite) {
371 u64 *shadow_mem = (u64*)MemToShadow(addr);
372 DPrintf2("#%d: tsan::OnMemoryAccess: @%p %p size=%d"
Alexey Samsonov51ae9832012-06-06 13:11:29 +0000373 " is_write=%d shadow_mem=%p {%zx, %zx, %zx, %zx}\n",
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000374 (int)thr->fast_state.tid(), (void*)pc, (void*)addr,
375 (int)(1 << kAccessSizeLog), kAccessIsWrite, shadow_mem,
Alexey Samsonov51ae9832012-06-06 13:11:29 +0000376 (uptr)shadow_mem[0], (uptr)shadow_mem[1],
377 (uptr)shadow_mem[2], (uptr)shadow_mem[3]);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000378#if TSAN_DEBUG
379 if (!IsAppMem(addr)) {
Alexey Samsonov51ae9832012-06-06 13:11:29 +0000380 TsanPrintf("Access to non app mem %zx\n", addr);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000381 DCHECK(IsAppMem(addr));
382 }
383 if (!IsShadowMem((uptr)shadow_mem)) {
Alexey Samsonov51ae9832012-06-06 13:11:29 +0000384 TsanPrintf("Bad shadow addr %p (%zx)\n", shadow_mem, addr);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000385 DCHECK(IsShadowMem((uptr)shadow_mem));
386 }
387#endif
388
389 FastState fast_state = thr->fast_state;
390 if (fast_state.GetIgnoreBit())
391 return;
392 fast_state.IncrementEpoch();
393 thr->fast_state = fast_state;
394 Shadow cur(fast_state);
395 cur.SetAddr0AndSizeLog(addr & 7, kAccessSizeLog);
396 cur.SetWrite(kAccessIsWrite);
397
398 // We must not store to the trace if we do not store to the shadow.
399 // That is, this call must be moved somewhere below.
400 TraceAddEvent(thr, fast_state.epoch(), EventTypeMop, pc);
401
402 MemoryAccessImpl(thr, addr, kAccessSizeLog, kAccessIsWrite, fast_state,
403 shadow_mem, cur);
404}
405
406static void MemoryRangeSet(ThreadState *thr, uptr pc, uptr addr, uptr size,
407 u64 val) {
408 if (size == 0)
409 return;
410 // FIXME: fix me.
411 uptr offset = addr % kShadowCell;
412 if (offset) {
413 offset = kShadowCell - offset;
414 if (size <= offset)
415 return;
416 addr += offset;
417 size -= offset;
418 }
419 CHECK_EQ(addr % 8, 0);
420 CHECK(IsAppMem(addr));
421 CHECK(IsAppMem(addr + size - 1));
422 (void)thr;
423 (void)pc;
424 // Some programs mmap like hundreds of GBs but actually used a small part.
425 // So, it's better to report a false positive on the memory
426 // then to hang here senselessly.
427 const uptr kMaxResetSize = 1024*1024*1024;
428 if (size > kMaxResetSize)
429 size = kMaxResetSize;
430 size = (size + 7) & ~7;
431 u64 *p = (u64*)MemToShadow(addr);
432 CHECK(IsShadowMem((uptr)p));
433 CHECK(IsShadowMem((uptr)(p + size * kShadowCnt / kShadowCell - 1)));
434 // FIXME: may overwrite a part outside the region
435 for (uptr i = 0; i < size * kShadowCnt / kShadowCell; i++)
436 p[i] = val;
437}
438
439void MemoryResetRange(ThreadState *thr, uptr pc, uptr addr, uptr size) {
440 MemoryRangeSet(thr, pc, addr, size, 0);
441}
442
443void MemoryRangeFreed(ThreadState *thr, uptr pc, uptr addr, uptr size) {
444 MemoryAccessRange(thr, pc, addr, size, true);
Dmitry Vyukovfee5b7d2012-05-17 14:17:51 +0000445 Shadow s(thr->fast_state);
446 s.MarkAsFreed();
447 s.SetWrite(true);
448 s.SetAddr0AndSizeLog(0, 3);
449 MemoryRangeSet(thr, pc, addr, size, s.raw());
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000450}
451
452void FuncEntry(ThreadState *thr, uptr pc) {
453 DCHECK_EQ(thr->in_rtl, 0);
454 StatInc(thr, StatFuncEnter);
Dmitry Vyukov5bfac972012-07-16 16:44:47 +0000455 DPrintf2("#%d: FuncEntry %p\n", (int)thr->fast_state.tid(), (void*)pc);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000456 thr->fast_state.IncrementEpoch();
457 TraceAddEvent(thr, thr->fast_state.epoch(), EventTypeFuncEnter, pc);
458
459 // Shadow stack maintenance can be replaced with
460 // stack unwinding during trace switch (which presumably must be faster).
Dmitry Vyukov3de9ca02012-05-28 07:45:35 +0000461 DCHECK_GE(thr->shadow_stack_pos, &thr->shadow_stack[0]);
Dmitry Vyukov5bfac972012-07-16 16:44:47 +0000462#ifndef TSAN_GO
Dmitry Vyukov3de9ca02012-05-28 07:45:35 +0000463 DCHECK_LT(thr->shadow_stack_pos, &thr->shadow_stack[kShadowStackSize]);
Dmitry Vyukov5bfac972012-07-16 16:44:47 +0000464#else
465 if (thr->shadow_stack_pos == thr->shadow_stack_end) {
466 const int sz = thr->shadow_stack_end - thr->shadow_stack;
467 const int newsz = 2 * sz;
468 uptr *newstack = (uptr*)internal_alloc(MBlockShadowStack,
469 newsz * sizeof(uptr));
470 internal_memcpy(newstack, thr->shadow_stack, sz * sizeof(uptr));
471 internal_free(thr->shadow_stack);
472 thr->shadow_stack = newstack;
473 thr->shadow_stack_pos = newstack + sz;
474 thr->shadow_stack_end = newstack + newsz;
475 }
476#endif
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000477 thr->shadow_stack_pos[0] = pc;
478 thr->shadow_stack_pos++;
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000479}
480
481void FuncExit(ThreadState *thr) {
482 DCHECK_EQ(thr->in_rtl, 0);
483 StatInc(thr, StatFuncExit);
Dmitry Vyukov5bfac972012-07-16 16:44:47 +0000484 DPrintf2("#%d: FuncExit\n", (int)thr->fast_state.tid());
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000485 thr->fast_state.IncrementEpoch();
486 TraceAddEvent(thr, thr->fast_state.epoch(), EventTypeFuncExit, 0);
487
Dmitry Vyukov3de9ca02012-05-28 07:45:35 +0000488 DCHECK_GT(thr->shadow_stack_pos, &thr->shadow_stack[0]);
Dmitry Vyukov5bfac972012-07-16 16:44:47 +0000489#ifndef TSAN_GO
Dmitry Vyukov3de9ca02012-05-28 07:45:35 +0000490 DCHECK_LT(thr->shadow_stack_pos, &thr->shadow_stack[kShadowStackSize]);
Dmitry Vyukov5bfac972012-07-16 16:44:47 +0000491#endif
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000492 thr->shadow_stack_pos--;
493}
494
495void IgnoreCtl(ThreadState *thr, bool write, bool begin) {
496 DPrintf("#%d: IgnoreCtl(%d, %d)\n", thr->tid, write, begin);
497 thr->ignore_reads_and_writes += begin ? 1 : -1;
498 CHECK_GE(thr->ignore_reads_and_writes, 0);
499 if (thr->ignore_reads_and_writes)
500 thr->fast_state.SetIgnoreBit();
501 else
502 thr->fast_state.ClearIgnoreBit();
503}
504
Dmitry Vyukov03d32ec2012-07-05 16:18:28 +0000505bool MD5Hash::operator==(const MD5Hash &other) const {
506 return hash[0] == other.hash[0] && hash[1] == other.hash[1];
507}
508
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000509#if TSAN_DEBUG
510void build_consistency_debug() {}
511#else
512void build_consistency_release() {}
513#endif
514
515#if TSAN_COLLECT_STATS
516void build_consistency_stats() {}
517#else
518void build_consistency_nostats() {}
519#endif
520
521#if TSAN_SHADOW_COUNT == 1
522void build_consistency_shadow1() {}
523#elif TSAN_SHADOW_COUNT == 2
524void build_consistency_shadow2() {}
525#elif TSAN_SHADOW_COUNT == 4
526void build_consistency_shadow4() {}
527#else
528void build_consistency_shadow8() {}
529#endif
530
531} // namespace __tsan
532
Dmitry Vyukov03d32ec2012-07-05 16:18:28 +0000533#ifndef TSAN_GO
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000534// Must be included in this file to make sure everything is inlined.
535#include "tsan_interface_inl.h"
Dmitry Vyukov03d32ec2012-07-05 16:18:28 +0000536#endif