blob: f0931df16344740863ef9b1099311f7cd51c13b8 [file] [log] [blame]
Alexey Samsonov3b2f9f42012-06-04 13:55:19 +00001//===-- tsan_interface_ann.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//===----------------------------------------------------------------------===//
Alexey Samsonov90f96302012-06-04 13:27:49 +000013#include "sanitizer_common/sanitizer_libc.h"
Dmitry Vyukov01ea6532012-12-04 14:01:21 +000014#include "sanitizer_common/sanitizer_internal_defs.h"
Alexey Samsonov8bd90982012-06-07 09:50:16 +000015#include "sanitizer_common/sanitizer_placement_new.h"
Dmitry Vyukov5cf581a2013-06-17 19:57:03 +000016#include "sanitizer_common/sanitizer_stacktrace.h"
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000017#include "tsan_interface_ann.h"
18#include "tsan_mutex.h"
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000019#include "tsan_report.h"
20#include "tsan_rtl.h"
21#include "tsan_mman.h"
22#include "tsan_flags.h"
Dmitry Vyukovea03fc22012-06-14 21:40:35 +000023#include "tsan_platform.h"
Dmitry Vyukovf2cbda42013-03-28 16:21:19 +000024#include "tsan_vector.h"
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000025
26#define CALLERPC ((uptr)__builtin_return_address(0))
27
28using namespace __tsan; // NOLINT
29
30namespace __tsan {
31
32class ScopedAnnotation {
33 public:
34 ScopedAnnotation(ThreadState *thr, const char *aname, const char *f, int l,
35 uptr pc)
Dmitry Vyukovce372102013-12-24 12:55:56 +000036 : thr_(thr) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000037 FuncEntry(thr_, pc);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000038 DPrintf("#%d: annotation %s() %s:%d\n", thr_->tid, aname, f, l);
39 }
40
41 ~ScopedAnnotation() {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000042 FuncExit(thr_);
43 }
44 private:
45 ThreadState *const thr_;
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000046};
47
48#define SCOPED_ANNOTATION(typ) \
49 if (!flags()->enable_annotations) \
50 return; \
51 ThreadState *thr = cur_thread(); \
Dmitry Vyukov3238e1c2013-11-27 11:30:28 +000052 const uptr caller_pc = (uptr)__builtin_return_address(0); \
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000053 StatInc(thr, StatAnnotation); \
54 StatInc(thr, Stat##typ); \
Dmitry Vyukov3238e1c2013-11-27 11:30:28 +000055 ScopedAnnotation sa(thr, __FUNCTION__, f, l, caller_pc); \
56 const uptr pc = __sanitizer::StackTrace::GetCurrentPc(); \
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000057 (void)pc; \
58/**/
59
60static const int kMaxDescLen = 128;
61
62struct ExpectRace {
63 ExpectRace *next;
64 ExpectRace *prev;
65 int hitcount;
Dmitry Vyukovf2cbda42013-03-28 16:21:19 +000066 int addcount;
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000067 uptr addr;
68 uptr size;
69 char *file;
70 int line;
71 char desc[kMaxDescLen];
72};
73
74struct DynamicAnnContext {
75 Mutex mtx;
76 ExpectRace expect;
77 ExpectRace benign;
78
79 DynamicAnnContext()
80 : mtx(MutexTypeAnnotations, StatMtxAnnotations) {
81 }
82};
83
84static DynamicAnnContext *dyn_ann_ctx;
Alexey Samsonovef2e2cf2012-06-05 13:50:57 +000085static char dyn_ann_ctx_placeholder[sizeof(DynamicAnnContext)] ALIGNED(64);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000086
87static void AddExpectRace(ExpectRace *list,
88 char *f, int l, uptr addr, uptr size, char *desc) {
89 ExpectRace *race = list->next;
90 for (; race != list; race = race->next) {
Dmitry Vyukovf2cbda42013-03-28 16:21:19 +000091 if (race->addr == addr && race->size == size) {
92 race->addcount++;
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000093 return;
Dmitry Vyukovf2cbda42013-03-28 16:21:19 +000094 }
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000095 }
96 race = (ExpectRace*)internal_alloc(MBlockExpectRace, sizeof(ExpectRace));
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000097 race->addr = addr;
98 race->size = size;
99 race->file = f;
100 race->line = l;
101 race->desc[0] = 0;
Dmitry Vyukovf2cbda42013-03-28 16:21:19 +0000102 race->hitcount = 0;
103 race->addcount = 1;
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000104 if (desc) {
105 int i = 0;
106 for (; i < kMaxDescLen - 1 && desc[i]; i++)
107 race->desc[i] = desc[i];
108 race->desc[i] = 0;
109 }
110 race->prev = list;
111 race->next = list->next;
112 race->next->prev = race;
113 list->next = race;
114}
115
116static ExpectRace *FindRace(ExpectRace *list, uptr addr, uptr size) {
117 for (ExpectRace *race = list->next; race != list; race = race->next) {
118 uptr maxbegin = max(race->addr, addr);
119 uptr minend = min(race->addr + race->size, addr + size);
120 if (maxbegin < minend)
121 return race;
122 }
123 return 0;
124}
125
126static bool CheckContains(ExpectRace *list, uptr addr, uptr size) {
127 ExpectRace *race = FindRace(list, addr, size);
Dmitry Vyukovea03fc22012-06-14 21:40:35 +0000128 if (race == 0 && AlternativeAddress(addr))
129 race = FindRace(list, AlternativeAddress(addr), size);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000130 if (race == 0)
131 return false;
Alexey Samsonov51ae9832012-06-06 13:11:29 +0000132 DPrintf("Hit expected/benign race: %s addr=%zx:%d %s:%d\n",
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000133 race->desc, race->addr, (int)race->size, race->file, race->line);
134 race->hitcount++;
135 return true;
136}
137
138static void InitList(ExpectRace *list) {
139 list->next = list;
140 list->prev = list;
141}
142
143void InitializeDynamicAnnotations() {
144 dyn_ann_ctx = new(dyn_ann_ctx_placeholder) DynamicAnnContext;
145 InitList(&dyn_ann_ctx->expect);
146 InitList(&dyn_ann_ctx->benign);
147}
148
149bool IsExpectedReport(uptr addr, uptr size) {
150 Lock lock(&dyn_ann_ctx->mtx);
151 if (CheckContains(&dyn_ann_ctx->expect, addr, size))
152 return true;
153 if (CheckContains(&dyn_ann_ctx->benign, addr, size))
154 return true;
155 return false;
156}
157
Dmitry Vyukovf2cbda42013-03-28 16:21:19 +0000158static void CollectMatchedBenignRaces(Vector<ExpectRace> *matched,
159 int *unique_count, int *hit_count, int ExpectRace::*counter) {
160 ExpectRace *list = &dyn_ann_ctx->benign;
161 for (ExpectRace *race = list->next; race != list; race = race->next) {
162 (*unique_count)++;
163 if (race->*counter == 0)
164 continue;
165 (*hit_count) += race->*counter;
166 uptr i = 0;
167 for (; i < matched->Size(); i++) {
168 ExpectRace *race0 = &(*matched)[i];
169 if (race->line == race0->line
170 && internal_strcmp(race->file, race0->file) == 0
171 && internal_strcmp(race->desc, race0->desc) == 0) {
172 race0->*counter += race->*counter;
173 break;
174 }
175 }
176 if (i == matched->Size())
177 matched->PushBack(*race);
178 }
179}
180
181void PrintMatchedBenignRaces() {
182 Lock lock(&dyn_ann_ctx->mtx);
183 int unique_count = 0;
184 int hit_count = 0;
185 int add_count = 0;
186 Vector<ExpectRace> hit_matched(MBlockScopedBuf);
187 CollectMatchedBenignRaces(&hit_matched, &unique_count, &hit_count,
188 &ExpectRace::hitcount);
189 Vector<ExpectRace> add_matched(MBlockScopedBuf);
190 CollectMatchedBenignRaces(&add_matched, &unique_count, &add_count,
191 &ExpectRace::addcount);
192 if (hit_matched.Size()) {
193 Printf("ThreadSanitizer: Matched %d \"benign\" races (pid=%d):\n",
Peter Collingbourneffaf2ea2013-05-17 16:56:53 +0000194 hit_count, (int)internal_getpid());
Dmitry Vyukovf2cbda42013-03-28 16:21:19 +0000195 for (uptr i = 0; i < hit_matched.Size(); i++) {
196 Printf("%d %s:%d %s\n",
197 hit_matched[i].hitcount, hit_matched[i].file,
198 hit_matched[i].line, hit_matched[i].desc);
199 }
200 }
201 if (hit_matched.Size()) {
202 Printf("ThreadSanitizer: Annotated %d \"benign\" races, %d unique"
203 " (pid=%d):\n",
Peter Collingbourneffaf2ea2013-05-17 16:56:53 +0000204 add_count, unique_count, (int)internal_getpid());
Dmitry Vyukovf2cbda42013-03-28 16:21:19 +0000205 for (uptr i = 0; i < add_matched.Size(); i++) {
206 Printf("%d %s:%d %s\n",
207 add_matched[i].addcount, add_matched[i].file,
208 add_matched[i].line, add_matched[i].desc);
209 }
210 }
211}
212
213static void ReportMissedExpectedRace(ExpectRace *race) {
214 Printf("==================\n");
215 Printf("WARNING: ThreadSanitizer: missed expected data race\n");
216 Printf(" %s addr=%zx %s:%d\n",
217 race->desc, race->addr, race->file, race->line);
218 Printf("==================\n");
219}
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000220} // namespace __tsan
221
222using namespace __tsan; // NOLINT
223
224extern "C" {
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000225void INTERFACE_ATTRIBUTE AnnotateHappensBefore(char *f, int l, uptr addr) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000226 SCOPED_ANNOTATION(AnnotateHappensBefore);
Dmitry Vyukovc2437ff2013-09-19 04:42:25 +0000227 Release(thr, pc, addr);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000228}
229
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000230void INTERFACE_ATTRIBUTE AnnotateHappensAfter(char *f, int l, uptr addr) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000231 SCOPED_ANNOTATION(AnnotateHappensAfter);
Dmitry Vyukovc2437ff2013-09-19 04:42:25 +0000232 Acquire(thr, pc, addr);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000233}
234
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000235void INTERFACE_ATTRIBUTE AnnotateCondVarSignal(char *f, int l, uptr cv) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000236 SCOPED_ANNOTATION(AnnotateCondVarSignal);
237}
238
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000239void INTERFACE_ATTRIBUTE AnnotateCondVarSignalAll(char *f, int l, uptr cv) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000240 SCOPED_ANNOTATION(AnnotateCondVarSignalAll);
241}
242
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000243void INTERFACE_ATTRIBUTE AnnotateMutexIsNotPHB(char *f, int l, uptr mu) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000244 SCOPED_ANNOTATION(AnnotateMutexIsNotPHB);
245}
246
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000247void INTERFACE_ATTRIBUTE AnnotateCondVarWait(char *f, int l, uptr cv,
248 uptr lock) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000249 SCOPED_ANNOTATION(AnnotateCondVarWait);
250}
251
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000252void INTERFACE_ATTRIBUTE AnnotateRWLockCreate(char *f, int l, uptr m) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000253 SCOPED_ANNOTATION(AnnotateRWLockCreate);
Dmitry Vyukov4723e6b2012-08-16 13:29:41 +0000254 MutexCreate(thr, pc, m, true, true, false);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000255}
256
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000257void INTERFACE_ATTRIBUTE AnnotateRWLockCreateStatic(char *f, int l, uptr m) {
Dmitry Vyukov4723e6b2012-08-16 13:29:41 +0000258 SCOPED_ANNOTATION(AnnotateRWLockCreateStatic);
259 MutexCreate(thr, pc, m, true, true, true);
260}
261
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000262void INTERFACE_ATTRIBUTE AnnotateRWLockDestroy(char *f, int l, uptr m) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000263 SCOPED_ANNOTATION(AnnotateRWLockDestroy);
Dmitry Vyukov4723e6b2012-08-16 13:29:41 +0000264 MutexDestroy(thr, pc, m);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000265}
266
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000267void INTERFACE_ATTRIBUTE AnnotateRWLockAcquired(char *f, int l, uptr m,
268 uptr is_w) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000269 SCOPED_ANNOTATION(AnnotateRWLockAcquired);
Dmitry Vyukov4723e6b2012-08-16 13:29:41 +0000270 if (is_w)
271 MutexLock(thr, pc, m);
272 else
273 MutexReadLock(thr, pc, m);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000274}
275
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000276void INTERFACE_ATTRIBUTE AnnotateRWLockReleased(char *f, int l, uptr m,
277 uptr is_w) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000278 SCOPED_ANNOTATION(AnnotateRWLockReleased);
Dmitry Vyukov4723e6b2012-08-16 13:29:41 +0000279 if (is_w)
280 MutexUnlock(thr, pc, m);
281 else
282 MutexReadUnlock(thr, pc, m);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000283}
284
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000285void INTERFACE_ATTRIBUTE AnnotateTraceMemory(char *f, int l, uptr mem) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000286 SCOPED_ANNOTATION(AnnotateTraceMemory);
287}
288
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000289void INTERFACE_ATTRIBUTE AnnotateFlushState(char *f, int l) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000290 SCOPED_ANNOTATION(AnnotateFlushState);
291}
292
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000293void INTERFACE_ATTRIBUTE AnnotateNewMemory(char *f, int l, uptr mem,
294 uptr size) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000295 SCOPED_ANNOTATION(AnnotateNewMemory);
296}
297
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000298void INTERFACE_ATTRIBUTE AnnotateNoOp(char *f, int l, uptr mem) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000299 SCOPED_ANNOTATION(AnnotateNoOp);
300}
301
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000302void INTERFACE_ATTRIBUTE AnnotateFlushExpectedRaces(char *f, int l) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000303 SCOPED_ANNOTATION(AnnotateFlushExpectedRaces);
304 Lock lock(&dyn_ann_ctx->mtx);
305 while (dyn_ann_ctx->expect.next != &dyn_ann_ctx->expect) {
306 ExpectRace *race = dyn_ann_ctx->expect.next;
307 if (race->hitcount == 0) {
308 CTX()->nmissed_expected++;
309 ReportMissedExpectedRace(race);
310 }
311 race->prev->next = race->next;
312 race->next->prev = race->prev;
313 internal_free(race);
314 }
315}
316
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000317void INTERFACE_ATTRIBUTE AnnotateEnableRaceDetection(
318 char *f, int l, int enable) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000319 SCOPED_ANNOTATION(AnnotateEnableRaceDetection);
320 // FIXME: Reconsider this functionality later. It may be irrelevant.
321}
322
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000323void INTERFACE_ATTRIBUTE AnnotateMutexIsUsedAsCondVar(
324 char *f, int l, uptr mu) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000325 SCOPED_ANNOTATION(AnnotateMutexIsUsedAsCondVar);
326}
327
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000328void INTERFACE_ATTRIBUTE AnnotatePCQGet(
329 char *f, int l, uptr pcq) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000330 SCOPED_ANNOTATION(AnnotatePCQGet);
331}
332
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000333void INTERFACE_ATTRIBUTE AnnotatePCQPut(
334 char *f, int l, uptr pcq) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000335 SCOPED_ANNOTATION(AnnotatePCQPut);
336}
337
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000338void INTERFACE_ATTRIBUTE AnnotatePCQDestroy(
339 char *f, int l, uptr pcq) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000340 SCOPED_ANNOTATION(AnnotatePCQDestroy);
341}
342
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000343void INTERFACE_ATTRIBUTE AnnotatePCQCreate(
344 char *f, int l, uptr pcq) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000345 SCOPED_ANNOTATION(AnnotatePCQCreate);
346}
347
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000348void INTERFACE_ATTRIBUTE AnnotateExpectRace(
349 char *f, int l, uptr mem, char *desc) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000350 SCOPED_ANNOTATION(AnnotateExpectRace);
351 Lock lock(&dyn_ann_ctx->mtx);
352 AddExpectRace(&dyn_ann_ctx->expect,
353 f, l, mem, 1, desc);
Alexey Samsonov51ae9832012-06-06 13:11:29 +0000354 DPrintf("Add expected race: %s addr=%zx %s:%d\n", desc, mem, f, l);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000355}
356
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000357static void BenignRaceImpl(
358 char *f, int l, uptr mem, uptr size, char *desc) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000359 Lock lock(&dyn_ann_ctx->mtx);
360 AddExpectRace(&dyn_ann_ctx->benign,
361 f, l, mem, size, desc);
Alexey Samsonov51ae9832012-06-06 13:11:29 +0000362 DPrintf("Add benign race: %s addr=%zx %s:%d\n", desc, mem, f, l);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000363}
364
365// FIXME: Turn it off later. WTF is benign race?1?? Go talk to Hans Boehm.
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000366void INTERFACE_ATTRIBUTE AnnotateBenignRaceSized(
367 char *f, int l, uptr mem, uptr size, char *desc) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000368 SCOPED_ANNOTATION(AnnotateBenignRaceSized);
369 BenignRaceImpl(f, l, mem, size, desc);
370}
371
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000372void INTERFACE_ATTRIBUTE AnnotateBenignRace(
373 char *f, int l, uptr mem, char *desc) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000374 SCOPED_ANNOTATION(AnnotateBenignRace);
375 BenignRaceImpl(f, l, mem, 1, desc);
376}
377
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000378void INTERFACE_ATTRIBUTE AnnotateIgnoreReadsBegin(char *f, int l) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000379 SCOPED_ANNOTATION(AnnotateIgnoreReadsBegin);
Dmitry Vyukov3238e1c2013-11-27 11:30:28 +0000380 ThreadIgnoreBegin(thr, pc);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000381}
382
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000383void INTERFACE_ATTRIBUTE AnnotateIgnoreReadsEnd(char *f, int l) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000384 SCOPED_ANNOTATION(AnnotateIgnoreReadsEnd);
Dmitry Vyukov3238e1c2013-11-27 11:30:28 +0000385 ThreadIgnoreEnd(thr, pc);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000386}
387
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000388void INTERFACE_ATTRIBUTE AnnotateIgnoreWritesBegin(char *f, int l) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000389 SCOPED_ANNOTATION(AnnotateIgnoreWritesBegin);
Dmitry Vyukov3238e1c2013-11-27 11:30:28 +0000390 ThreadIgnoreBegin(thr, pc);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000391}
392
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000393void INTERFACE_ATTRIBUTE AnnotateIgnoreWritesEnd(char *f, int l) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000394 SCOPED_ANNOTATION(AnnotateIgnoreWritesEnd);
Dmitry Vyukov3238e1c2013-11-27 11:30:28 +0000395 ThreadIgnoreEnd(thr, pc);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000396}
397
Dmitry Vyukovfbb194f2013-10-10 15:58:12 +0000398void INTERFACE_ATTRIBUTE AnnotateIgnoreSyncBegin(char *f, int l) {
399 SCOPED_ANNOTATION(AnnotateIgnoreSyncBegin);
Dmitry Vyukov3238e1c2013-11-27 11:30:28 +0000400 ThreadIgnoreSyncBegin(thr, pc);
Dmitry Vyukovfbb194f2013-10-10 15:58:12 +0000401}
402
403void INTERFACE_ATTRIBUTE AnnotateIgnoreSyncEnd(char *f, int l) {
404 SCOPED_ANNOTATION(AnnotateIgnoreSyncEnd);
Dmitry Vyukov3238e1c2013-11-27 11:30:28 +0000405 ThreadIgnoreSyncEnd(thr, pc);
Dmitry Vyukovfbb194f2013-10-10 15:58:12 +0000406}
407
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000408void INTERFACE_ATTRIBUTE AnnotatePublishMemoryRange(
409 char *f, int l, uptr addr, uptr size) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000410 SCOPED_ANNOTATION(AnnotatePublishMemoryRange);
411}
412
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000413void INTERFACE_ATTRIBUTE AnnotateUnpublishMemoryRange(
414 char *f, int l, uptr addr, uptr size) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000415 SCOPED_ANNOTATION(AnnotateUnpublishMemoryRange);
416}
417
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000418void INTERFACE_ATTRIBUTE AnnotateThreadName(
419 char *f, int l, char *name) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000420 SCOPED_ANNOTATION(AnnotateThreadName);
Dmitry Vyukov1b469932012-12-04 15:46:05 +0000421 ThreadSetName(thr, name);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000422}
423
Alexander Potapenkobbfc7222013-04-02 11:21:53 +0000424// We deliberately omit the implementation of WTFAnnotateHappensBefore() and
425// WTFAnnotateHappensAfter(). Those are being used by Webkit to annotate
426// atomic operations, which should be handled by ThreadSanitizer correctly.
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000427void INTERFACE_ATTRIBUTE WTFAnnotateHappensBefore(char *f, int l, uptr addr) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000428 SCOPED_ANNOTATION(AnnotateHappensBefore);
429}
430
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000431void INTERFACE_ATTRIBUTE WTFAnnotateHappensAfter(char *f, int l, uptr addr) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000432 SCOPED_ANNOTATION(AnnotateHappensAfter);
433}
434
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000435void INTERFACE_ATTRIBUTE WTFAnnotateBenignRaceSized(
436 char *f, int l, uptr mem, uptr sz, char *desc) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000437 SCOPED_ANNOTATION(AnnotateBenignRaceSized);
Dmitry Vyukov2918b672013-11-19 16:03:15 +0000438 BenignRaceImpl(f, l, mem, sz, desc);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000439}
440
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000441int INTERFACE_ATTRIBUTE RunningOnValgrind() {
Dmitry Vyukov65c21a52012-05-24 09:24:45 +0000442 return flags()->running_on_valgrind;
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000443}
444
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000445double __attribute__((weak)) INTERFACE_ATTRIBUTE ValgrindSlowdown(void) {
Dmitry Vyukov166b8e52012-05-17 08:04:41 +0000446 return 10.0;
447}
448
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000449const char INTERFACE_ATTRIBUTE* ThreadSanitizerQuery(const char *query) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000450 if (internal_strcmp(query, "pure_happens_before") == 0)
451 return "1";
452 else
453 return "0";
454}
Evgeniy Stepanov91375fd2013-09-18 11:20:31 +0000455
456void INTERFACE_ATTRIBUTE
457AnnotateMemoryIsInitialized(char *f, int l, uptr mem, uptr sz) {}
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000458} // extern "C"