blob: c6a57b339918af51bf56c1200dc9b29f4a471340 [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)
36 : thr_(thr)
37 , in_rtl_(thr->in_rtl) {
38 CHECK_EQ(thr_->in_rtl, 0);
39 FuncEntry(thr_, pc);
40 thr_->in_rtl++;
41 DPrintf("#%d: annotation %s() %s:%d\n", thr_->tid, aname, f, l);
42 }
43
44 ~ScopedAnnotation() {
45 thr_->in_rtl--;
46 CHECK_EQ(in_rtl_, thr_->in_rtl);
47 FuncExit(thr_);
48 }
49 private:
50 ThreadState *const thr_;
51 const int in_rtl_;
52};
53
54#define SCOPED_ANNOTATION(typ) \
55 if (!flags()->enable_annotations) \
56 return; \
57 ThreadState *thr = cur_thread(); \
Dmitry Vyukov3238e1c2013-11-27 11:30:28 +000058 const uptr caller_pc = (uptr)__builtin_return_address(0); \
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000059 StatInc(thr, StatAnnotation); \
60 StatInc(thr, Stat##typ); \
Dmitry Vyukov3238e1c2013-11-27 11:30:28 +000061 ScopedAnnotation sa(thr, __FUNCTION__, f, l, caller_pc); \
62 const uptr pc = __sanitizer::StackTrace::GetCurrentPc(); \
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000063 (void)pc; \
64/**/
65
66static const int kMaxDescLen = 128;
67
68struct ExpectRace {
69 ExpectRace *next;
70 ExpectRace *prev;
71 int hitcount;
Dmitry Vyukovf2cbda42013-03-28 16:21:19 +000072 int addcount;
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000073 uptr addr;
74 uptr size;
75 char *file;
76 int line;
77 char desc[kMaxDescLen];
78};
79
80struct DynamicAnnContext {
81 Mutex mtx;
82 ExpectRace expect;
83 ExpectRace benign;
84
85 DynamicAnnContext()
86 : mtx(MutexTypeAnnotations, StatMtxAnnotations) {
87 }
88};
89
90static DynamicAnnContext *dyn_ann_ctx;
Alexey Samsonovef2e2cf2012-06-05 13:50:57 +000091static char dyn_ann_ctx_placeholder[sizeof(DynamicAnnContext)] ALIGNED(64);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000092
93static void AddExpectRace(ExpectRace *list,
94 char *f, int l, uptr addr, uptr size, char *desc) {
95 ExpectRace *race = list->next;
96 for (; race != list; race = race->next) {
Dmitry Vyukovf2cbda42013-03-28 16:21:19 +000097 if (race->addr == addr && race->size == size) {
98 race->addcount++;
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000099 return;
Dmitry Vyukovf2cbda42013-03-28 16:21:19 +0000100 }
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000101 }
102 race = (ExpectRace*)internal_alloc(MBlockExpectRace, sizeof(ExpectRace));
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000103 race->addr = addr;
104 race->size = size;
105 race->file = f;
106 race->line = l;
107 race->desc[0] = 0;
Dmitry Vyukovf2cbda42013-03-28 16:21:19 +0000108 race->hitcount = 0;
109 race->addcount = 1;
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000110 if (desc) {
111 int i = 0;
112 for (; i < kMaxDescLen - 1 && desc[i]; i++)
113 race->desc[i] = desc[i];
114 race->desc[i] = 0;
115 }
116 race->prev = list;
117 race->next = list->next;
118 race->next->prev = race;
119 list->next = race;
120}
121
122static ExpectRace *FindRace(ExpectRace *list, uptr addr, uptr size) {
123 for (ExpectRace *race = list->next; race != list; race = race->next) {
124 uptr maxbegin = max(race->addr, addr);
125 uptr minend = min(race->addr + race->size, addr + size);
126 if (maxbegin < minend)
127 return race;
128 }
129 return 0;
130}
131
132static bool CheckContains(ExpectRace *list, uptr addr, uptr size) {
133 ExpectRace *race = FindRace(list, addr, size);
Dmitry Vyukovea03fc22012-06-14 21:40:35 +0000134 if (race == 0 && AlternativeAddress(addr))
135 race = FindRace(list, AlternativeAddress(addr), size);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000136 if (race == 0)
137 return false;
Alexey Samsonov51ae9832012-06-06 13:11:29 +0000138 DPrintf("Hit expected/benign race: %s addr=%zx:%d %s:%d\n",
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000139 race->desc, race->addr, (int)race->size, race->file, race->line);
140 race->hitcount++;
141 return true;
142}
143
144static void InitList(ExpectRace *list) {
145 list->next = list;
146 list->prev = list;
147}
148
149void InitializeDynamicAnnotations() {
150 dyn_ann_ctx = new(dyn_ann_ctx_placeholder) DynamicAnnContext;
151 InitList(&dyn_ann_ctx->expect);
152 InitList(&dyn_ann_ctx->benign);
153}
154
155bool IsExpectedReport(uptr addr, uptr size) {
156 Lock lock(&dyn_ann_ctx->mtx);
157 if (CheckContains(&dyn_ann_ctx->expect, addr, size))
158 return true;
159 if (CheckContains(&dyn_ann_ctx->benign, addr, size))
160 return true;
161 return false;
162}
163
Dmitry Vyukovf2cbda42013-03-28 16:21:19 +0000164static void CollectMatchedBenignRaces(Vector<ExpectRace> *matched,
165 int *unique_count, int *hit_count, int ExpectRace::*counter) {
166 ExpectRace *list = &dyn_ann_ctx->benign;
167 for (ExpectRace *race = list->next; race != list; race = race->next) {
168 (*unique_count)++;
169 if (race->*counter == 0)
170 continue;
171 (*hit_count) += race->*counter;
172 uptr i = 0;
173 for (; i < matched->Size(); i++) {
174 ExpectRace *race0 = &(*matched)[i];
175 if (race->line == race0->line
176 && internal_strcmp(race->file, race0->file) == 0
177 && internal_strcmp(race->desc, race0->desc) == 0) {
178 race0->*counter += race->*counter;
179 break;
180 }
181 }
182 if (i == matched->Size())
183 matched->PushBack(*race);
184 }
185}
186
187void PrintMatchedBenignRaces() {
188 Lock lock(&dyn_ann_ctx->mtx);
189 int unique_count = 0;
190 int hit_count = 0;
191 int add_count = 0;
192 Vector<ExpectRace> hit_matched(MBlockScopedBuf);
193 CollectMatchedBenignRaces(&hit_matched, &unique_count, &hit_count,
194 &ExpectRace::hitcount);
195 Vector<ExpectRace> add_matched(MBlockScopedBuf);
196 CollectMatchedBenignRaces(&add_matched, &unique_count, &add_count,
197 &ExpectRace::addcount);
198 if (hit_matched.Size()) {
199 Printf("ThreadSanitizer: Matched %d \"benign\" races (pid=%d):\n",
Peter Collingbourneffaf2ea2013-05-17 16:56:53 +0000200 hit_count, (int)internal_getpid());
Dmitry Vyukovf2cbda42013-03-28 16:21:19 +0000201 for (uptr i = 0; i < hit_matched.Size(); i++) {
202 Printf("%d %s:%d %s\n",
203 hit_matched[i].hitcount, hit_matched[i].file,
204 hit_matched[i].line, hit_matched[i].desc);
205 }
206 }
207 if (hit_matched.Size()) {
208 Printf("ThreadSanitizer: Annotated %d \"benign\" races, %d unique"
209 " (pid=%d):\n",
Peter Collingbourneffaf2ea2013-05-17 16:56:53 +0000210 add_count, unique_count, (int)internal_getpid());
Dmitry Vyukovf2cbda42013-03-28 16:21:19 +0000211 for (uptr i = 0; i < add_matched.Size(); i++) {
212 Printf("%d %s:%d %s\n",
213 add_matched[i].addcount, add_matched[i].file,
214 add_matched[i].line, add_matched[i].desc);
215 }
216 }
217}
218
219static void ReportMissedExpectedRace(ExpectRace *race) {
220 Printf("==================\n");
221 Printf("WARNING: ThreadSanitizer: missed expected data race\n");
222 Printf(" %s addr=%zx %s:%d\n",
223 race->desc, race->addr, race->file, race->line);
224 Printf("==================\n");
225}
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000226} // namespace __tsan
227
228using namespace __tsan; // NOLINT
229
230extern "C" {
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000231void INTERFACE_ATTRIBUTE AnnotateHappensBefore(char *f, int l, uptr addr) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000232 SCOPED_ANNOTATION(AnnotateHappensBefore);
Dmitry Vyukovc2437ff2013-09-19 04:42:25 +0000233 Release(thr, pc, addr);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000234}
235
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000236void INTERFACE_ATTRIBUTE AnnotateHappensAfter(char *f, int l, uptr addr) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000237 SCOPED_ANNOTATION(AnnotateHappensAfter);
Dmitry Vyukovc2437ff2013-09-19 04:42:25 +0000238 Acquire(thr, pc, addr);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000239}
240
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000241void INTERFACE_ATTRIBUTE AnnotateCondVarSignal(char *f, int l, uptr cv) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000242 SCOPED_ANNOTATION(AnnotateCondVarSignal);
243}
244
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000245void INTERFACE_ATTRIBUTE AnnotateCondVarSignalAll(char *f, int l, uptr cv) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000246 SCOPED_ANNOTATION(AnnotateCondVarSignalAll);
247}
248
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000249void INTERFACE_ATTRIBUTE AnnotateMutexIsNotPHB(char *f, int l, uptr mu) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000250 SCOPED_ANNOTATION(AnnotateMutexIsNotPHB);
251}
252
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000253void INTERFACE_ATTRIBUTE AnnotateCondVarWait(char *f, int l, uptr cv,
254 uptr lock) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000255 SCOPED_ANNOTATION(AnnotateCondVarWait);
256}
257
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000258void INTERFACE_ATTRIBUTE AnnotateRWLockCreate(char *f, int l, uptr m) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000259 SCOPED_ANNOTATION(AnnotateRWLockCreate);
Dmitry Vyukov4723e6b2012-08-16 13:29:41 +0000260 MutexCreate(thr, pc, m, true, true, false);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000261}
262
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000263void INTERFACE_ATTRIBUTE AnnotateRWLockCreateStatic(char *f, int l, uptr m) {
Dmitry Vyukov4723e6b2012-08-16 13:29:41 +0000264 SCOPED_ANNOTATION(AnnotateRWLockCreateStatic);
265 MutexCreate(thr, pc, m, true, true, true);
266}
267
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000268void INTERFACE_ATTRIBUTE AnnotateRWLockDestroy(char *f, int l, uptr m) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000269 SCOPED_ANNOTATION(AnnotateRWLockDestroy);
Dmitry Vyukov4723e6b2012-08-16 13:29:41 +0000270 MutexDestroy(thr, pc, m);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000271}
272
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000273void INTERFACE_ATTRIBUTE AnnotateRWLockAcquired(char *f, int l, uptr m,
274 uptr is_w) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000275 SCOPED_ANNOTATION(AnnotateRWLockAcquired);
Dmitry Vyukov4723e6b2012-08-16 13:29:41 +0000276 if (is_w)
277 MutexLock(thr, pc, m);
278 else
279 MutexReadLock(thr, pc, m);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000280}
281
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000282void INTERFACE_ATTRIBUTE AnnotateRWLockReleased(char *f, int l, uptr m,
283 uptr is_w) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000284 SCOPED_ANNOTATION(AnnotateRWLockReleased);
Dmitry Vyukov4723e6b2012-08-16 13:29:41 +0000285 if (is_w)
286 MutexUnlock(thr, pc, m);
287 else
288 MutexReadUnlock(thr, pc, m);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000289}
290
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000291void INTERFACE_ATTRIBUTE AnnotateTraceMemory(char *f, int l, uptr mem) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000292 SCOPED_ANNOTATION(AnnotateTraceMemory);
293}
294
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000295void INTERFACE_ATTRIBUTE AnnotateFlushState(char *f, int l) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000296 SCOPED_ANNOTATION(AnnotateFlushState);
297}
298
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000299void INTERFACE_ATTRIBUTE AnnotateNewMemory(char *f, int l, uptr mem,
300 uptr size) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000301 SCOPED_ANNOTATION(AnnotateNewMemory);
302}
303
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000304void INTERFACE_ATTRIBUTE AnnotateNoOp(char *f, int l, uptr mem) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000305 SCOPED_ANNOTATION(AnnotateNoOp);
306}
307
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000308void INTERFACE_ATTRIBUTE AnnotateFlushExpectedRaces(char *f, int l) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000309 SCOPED_ANNOTATION(AnnotateFlushExpectedRaces);
310 Lock lock(&dyn_ann_ctx->mtx);
311 while (dyn_ann_ctx->expect.next != &dyn_ann_ctx->expect) {
312 ExpectRace *race = dyn_ann_ctx->expect.next;
313 if (race->hitcount == 0) {
314 CTX()->nmissed_expected++;
315 ReportMissedExpectedRace(race);
316 }
317 race->prev->next = race->next;
318 race->next->prev = race->prev;
319 internal_free(race);
320 }
321}
322
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000323void INTERFACE_ATTRIBUTE AnnotateEnableRaceDetection(
324 char *f, int l, int enable) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000325 SCOPED_ANNOTATION(AnnotateEnableRaceDetection);
326 // FIXME: Reconsider this functionality later. It may be irrelevant.
327}
328
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000329void INTERFACE_ATTRIBUTE AnnotateMutexIsUsedAsCondVar(
330 char *f, int l, uptr mu) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000331 SCOPED_ANNOTATION(AnnotateMutexIsUsedAsCondVar);
332}
333
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000334void INTERFACE_ATTRIBUTE AnnotatePCQGet(
335 char *f, int l, uptr pcq) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000336 SCOPED_ANNOTATION(AnnotatePCQGet);
337}
338
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000339void INTERFACE_ATTRIBUTE AnnotatePCQPut(
340 char *f, int l, uptr pcq) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000341 SCOPED_ANNOTATION(AnnotatePCQPut);
342}
343
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000344void INTERFACE_ATTRIBUTE AnnotatePCQDestroy(
345 char *f, int l, uptr pcq) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000346 SCOPED_ANNOTATION(AnnotatePCQDestroy);
347}
348
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000349void INTERFACE_ATTRIBUTE AnnotatePCQCreate(
350 char *f, int l, uptr pcq) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000351 SCOPED_ANNOTATION(AnnotatePCQCreate);
352}
353
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000354void INTERFACE_ATTRIBUTE AnnotateExpectRace(
355 char *f, int l, uptr mem, char *desc) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000356 SCOPED_ANNOTATION(AnnotateExpectRace);
357 Lock lock(&dyn_ann_ctx->mtx);
358 AddExpectRace(&dyn_ann_ctx->expect,
359 f, l, mem, 1, desc);
Alexey Samsonov51ae9832012-06-06 13:11:29 +0000360 DPrintf("Add expected race: %s addr=%zx %s:%d\n", desc, mem, f, l);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000361}
362
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000363static void BenignRaceImpl(
364 char *f, int l, uptr mem, uptr size, char *desc) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000365 Lock lock(&dyn_ann_ctx->mtx);
366 AddExpectRace(&dyn_ann_ctx->benign,
367 f, l, mem, size, desc);
Alexey Samsonov51ae9832012-06-06 13:11:29 +0000368 DPrintf("Add benign race: %s addr=%zx %s:%d\n", desc, mem, f, l);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000369}
370
371// FIXME: Turn it off later. WTF is benign race?1?? Go talk to Hans Boehm.
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000372void INTERFACE_ATTRIBUTE AnnotateBenignRaceSized(
373 char *f, int l, uptr mem, uptr size, char *desc) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000374 SCOPED_ANNOTATION(AnnotateBenignRaceSized);
375 BenignRaceImpl(f, l, mem, size, desc);
376}
377
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000378void INTERFACE_ATTRIBUTE AnnotateBenignRace(
379 char *f, int l, uptr mem, char *desc) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000380 SCOPED_ANNOTATION(AnnotateBenignRace);
381 BenignRaceImpl(f, l, mem, 1, desc);
382}
383
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000384void INTERFACE_ATTRIBUTE AnnotateIgnoreReadsBegin(char *f, int l) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000385 SCOPED_ANNOTATION(AnnotateIgnoreReadsBegin);
Dmitry Vyukov3238e1c2013-11-27 11:30:28 +0000386 ThreadIgnoreBegin(thr, pc);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000387}
388
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000389void INTERFACE_ATTRIBUTE AnnotateIgnoreReadsEnd(char *f, int l) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000390 SCOPED_ANNOTATION(AnnotateIgnoreReadsEnd);
Dmitry Vyukov3238e1c2013-11-27 11:30:28 +0000391 ThreadIgnoreEnd(thr, pc);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000392}
393
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000394void INTERFACE_ATTRIBUTE AnnotateIgnoreWritesBegin(char *f, int l) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000395 SCOPED_ANNOTATION(AnnotateIgnoreWritesBegin);
Dmitry Vyukov3238e1c2013-11-27 11:30:28 +0000396 ThreadIgnoreBegin(thr, pc);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000397}
398
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000399void INTERFACE_ATTRIBUTE AnnotateIgnoreWritesEnd(char *f, int l) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000400 SCOPED_ANNOTATION(AnnotateIgnoreWritesEnd);
Dmitry Vyukov3238e1c2013-11-27 11:30:28 +0000401 ThreadIgnoreEnd(thr, pc);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000402}
403
Dmitry Vyukovfbb194f2013-10-10 15:58:12 +0000404void INTERFACE_ATTRIBUTE AnnotateIgnoreSyncBegin(char *f, int l) {
405 SCOPED_ANNOTATION(AnnotateIgnoreSyncBegin);
Dmitry Vyukov3238e1c2013-11-27 11:30:28 +0000406 ThreadIgnoreSyncBegin(thr, pc);
Dmitry Vyukovfbb194f2013-10-10 15:58:12 +0000407}
408
409void INTERFACE_ATTRIBUTE AnnotateIgnoreSyncEnd(char *f, int l) {
410 SCOPED_ANNOTATION(AnnotateIgnoreSyncEnd);
Dmitry Vyukov3238e1c2013-11-27 11:30:28 +0000411 ThreadIgnoreSyncEnd(thr, pc);
Dmitry Vyukovfbb194f2013-10-10 15:58:12 +0000412}
413
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000414void INTERFACE_ATTRIBUTE AnnotatePublishMemoryRange(
415 char *f, int l, uptr addr, uptr size) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000416 SCOPED_ANNOTATION(AnnotatePublishMemoryRange);
417}
418
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000419void INTERFACE_ATTRIBUTE AnnotateUnpublishMemoryRange(
420 char *f, int l, uptr addr, uptr size) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000421 SCOPED_ANNOTATION(AnnotateUnpublishMemoryRange);
422}
423
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000424void INTERFACE_ATTRIBUTE AnnotateThreadName(
425 char *f, int l, char *name) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000426 SCOPED_ANNOTATION(AnnotateThreadName);
Dmitry Vyukov1b469932012-12-04 15:46:05 +0000427 ThreadSetName(thr, name);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000428}
429
Alexander Potapenkobbfc7222013-04-02 11:21:53 +0000430// We deliberately omit the implementation of WTFAnnotateHappensBefore() and
431// WTFAnnotateHappensAfter(). Those are being used by Webkit to annotate
432// atomic operations, which should be handled by ThreadSanitizer correctly.
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000433void INTERFACE_ATTRIBUTE WTFAnnotateHappensBefore(char *f, int l, uptr addr) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000434 SCOPED_ANNOTATION(AnnotateHappensBefore);
435}
436
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000437void INTERFACE_ATTRIBUTE WTFAnnotateHappensAfter(char *f, int l, uptr addr) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000438 SCOPED_ANNOTATION(AnnotateHappensAfter);
439}
440
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000441void INTERFACE_ATTRIBUTE WTFAnnotateBenignRaceSized(
442 char *f, int l, uptr mem, uptr sz, char *desc) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000443 SCOPED_ANNOTATION(AnnotateBenignRaceSized);
Dmitry Vyukov2918b672013-11-19 16:03:15 +0000444 BenignRaceImpl(f, l, mem, sz, desc);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000445}
446
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000447int INTERFACE_ATTRIBUTE RunningOnValgrind() {
Dmitry Vyukov65c21a52012-05-24 09:24:45 +0000448 return flags()->running_on_valgrind;
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000449}
450
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000451double __attribute__((weak)) INTERFACE_ATTRIBUTE ValgrindSlowdown(void) {
Dmitry Vyukov166b8e52012-05-17 08:04:41 +0000452 return 10.0;
453}
454
Dmitry Vyukov01ea6532012-12-04 14:01:21 +0000455const char INTERFACE_ATTRIBUTE* ThreadSanitizerQuery(const char *query) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000456 if (internal_strcmp(query, "pure_happens_before") == 0)
457 return "1";
458 else
459 return "0";
460}
Evgeniy Stepanov91375fd2013-09-18 11:20:31 +0000461
462void INTERFACE_ATTRIBUTE
463AnnotateMemoryIsInitialized(char *f, int l, uptr mem, uptr sz) {}
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000464} // extern "C"