blob: fd3c846678f5f59909606a5ee3413ed24dba485d [file] [log] [blame]
Alexey Samsonov603c4be2012-06-04 13:55:19 +00001//===-- tsan_interface_ann.cc ---------------------------------------------===//
Kostya Serebryany7ac41482012-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 Samsonovc0d78c12012-06-04 13:27:49 +000013#include "sanitizer_common/sanitizer_libc.h"
Dmitry Vyukov258c24b2012-12-04 14:01:21 +000014#include "sanitizer_common/sanitizer_internal_defs.h"
Alexey Samsonov47b16342012-06-07 09:50:16 +000015#include "sanitizer_common/sanitizer_placement_new.h"
Dmitry Vyukove7718bc2013-06-17 19:57:03 +000016#include "sanitizer_common/sanitizer_stacktrace.h"
Kostya Serebryany7ac41482012-05-10 13:48:04 +000017#include "tsan_interface_ann.h"
18#include "tsan_mutex.h"
Kostya Serebryany7ac41482012-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 Vyukov3fb44412012-06-14 21:40:35 +000023#include "tsan_platform.h"
Dmitry Vyukov0fd908c2013-03-28 16:21:19 +000024#include "tsan_vector.h"
Kostya Serebryany7ac41482012-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)
Stephen Hines2d1fdb22014-05-28 23:58:16 -070036 : thr_(thr) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +000037 FuncEntry(thr_, pc);
Kostya Serebryany7ac41482012-05-10 13:48:04 +000038 DPrintf("#%d: annotation %s() %s:%d\n", thr_->tid, aname, f, l);
39 }
40
41 ~ScopedAnnotation() {
Kostya Serebryany7ac41482012-05-10 13:48:04 +000042 FuncExit(thr_);
Stephen Hines6a211c52014-07-21 00:49:56 -070043 CheckNoLocks(thr_);
Kostya Serebryany7ac41482012-05-10 13:48:04 +000044 }
45 private:
46 ThreadState *const thr_;
Kostya Serebryany7ac41482012-05-10 13:48:04 +000047};
48
49#define SCOPED_ANNOTATION(typ) \
50 if (!flags()->enable_annotations) \
51 return; \
52 ThreadState *thr = cur_thread(); \
Stephen Hines2d1fdb22014-05-28 23:58:16 -070053 const uptr caller_pc = (uptr)__builtin_return_address(0); \
Kostya Serebryany7ac41482012-05-10 13:48:04 +000054 StatInc(thr, StatAnnotation); \
55 StatInc(thr, Stat##typ); \
Stephen Hines2d1fdb22014-05-28 23:58:16 -070056 ScopedAnnotation sa(thr, __func__, f, l, caller_pc); \
Stephen Hines6d186232014-11-26 17:56:19 -080057 const uptr pc = StackTrace::GetCurrentPc(); \
Kostya Serebryany7ac41482012-05-10 13:48:04 +000058 (void)pc; \
59/**/
60
61static const int kMaxDescLen = 128;
62
63struct ExpectRace {
64 ExpectRace *next;
65 ExpectRace *prev;
66 int hitcount;
Dmitry Vyukov0fd908c2013-03-28 16:21:19 +000067 int addcount;
Kostya Serebryany7ac41482012-05-10 13:48:04 +000068 uptr addr;
69 uptr size;
70 char *file;
71 int line;
72 char desc[kMaxDescLen];
73};
74
75struct DynamicAnnContext {
76 Mutex mtx;
77 ExpectRace expect;
78 ExpectRace benign;
79
80 DynamicAnnContext()
81 : mtx(MutexTypeAnnotations, StatMtxAnnotations) {
82 }
83};
84
85static DynamicAnnContext *dyn_ann_ctx;
Alexey Samsonov0a4c9062012-06-05 13:50:57 +000086static char dyn_ann_ctx_placeholder[sizeof(DynamicAnnContext)] ALIGNED(64);
Kostya Serebryany7ac41482012-05-10 13:48:04 +000087
88static void AddExpectRace(ExpectRace *list,
89 char *f, int l, uptr addr, uptr size, char *desc) {
90 ExpectRace *race = list->next;
91 for (; race != list; race = race->next) {
Dmitry Vyukov0fd908c2013-03-28 16:21:19 +000092 if (race->addr == addr && race->size == size) {
93 race->addcount++;
Kostya Serebryany7ac41482012-05-10 13:48:04 +000094 return;
Dmitry Vyukov0fd908c2013-03-28 16:21:19 +000095 }
Kostya Serebryany7ac41482012-05-10 13:48:04 +000096 }
97 race = (ExpectRace*)internal_alloc(MBlockExpectRace, sizeof(ExpectRace));
Kostya Serebryany7ac41482012-05-10 13:48:04 +000098 race->addr = addr;
99 race->size = size;
100 race->file = f;
101 race->line = l;
102 race->desc[0] = 0;
Dmitry Vyukov0fd908c2013-03-28 16:21:19 +0000103 race->hitcount = 0;
104 race->addcount = 1;
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000105 if (desc) {
106 int i = 0;
107 for (; i < kMaxDescLen - 1 && desc[i]; i++)
108 race->desc[i] = desc[i];
109 race->desc[i] = 0;
110 }
111 race->prev = list;
112 race->next = list->next;
113 race->next->prev = race;
114 list->next = race;
115}
116
117static ExpectRace *FindRace(ExpectRace *list, uptr addr, uptr size) {
118 for (ExpectRace *race = list->next; race != list; race = race->next) {
119 uptr maxbegin = max(race->addr, addr);
120 uptr minend = min(race->addr + race->size, addr + size);
121 if (maxbegin < minend)
122 return race;
123 }
124 return 0;
125}
126
127static bool CheckContains(ExpectRace *list, uptr addr, uptr size) {
128 ExpectRace *race = FindRace(list, addr, size);
129 if (race == 0)
130 return false;
Alexey Samsonove9541012012-06-06 13:11:29 +0000131 DPrintf("Hit expected/benign race: %s addr=%zx:%d %s:%d\n",
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000132 race->desc, race->addr, (int)race->size, race->file, race->line);
133 race->hitcount++;
134 return true;
135}
136
137static void InitList(ExpectRace *list) {
138 list->next = list;
139 list->prev = list;
140}
141
142void InitializeDynamicAnnotations() {
143 dyn_ann_ctx = new(dyn_ann_ctx_placeholder) DynamicAnnContext;
144 InitList(&dyn_ann_ctx->expect);
145 InitList(&dyn_ann_ctx->benign);
146}
147
148bool IsExpectedReport(uptr addr, uptr size) {
149 Lock lock(&dyn_ann_ctx->mtx);
150 if (CheckContains(&dyn_ann_ctx->expect, addr, size))
151 return true;
152 if (CheckContains(&dyn_ann_ctx->benign, addr, size))
153 return true;
154 return false;
155}
156
Dmitry Vyukov0fd908c2013-03-28 16:21:19 +0000157static void CollectMatchedBenignRaces(Vector<ExpectRace> *matched,
158 int *unique_count, int *hit_count, int ExpectRace::*counter) {
159 ExpectRace *list = &dyn_ann_ctx->benign;
160 for (ExpectRace *race = list->next; race != list; race = race->next) {
161 (*unique_count)++;
162 if (race->*counter == 0)
163 continue;
164 (*hit_count) += race->*counter;
165 uptr i = 0;
166 for (; i < matched->Size(); i++) {
167 ExpectRace *race0 = &(*matched)[i];
168 if (race->line == race0->line
169 && internal_strcmp(race->file, race0->file) == 0
170 && internal_strcmp(race->desc, race0->desc) == 0) {
171 race0->*counter += race->*counter;
172 break;
173 }
174 }
175 if (i == matched->Size())
176 matched->PushBack(*race);
177 }
178}
179
180void PrintMatchedBenignRaces() {
181 Lock lock(&dyn_ann_ctx->mtx);
182 int unique_count = 0;
183 int hit_count = 0;
184 int add_count = 0;
185 Vector<ExpectRace> hit_matched(MBlockScopedBuf);
186 CollectMatchedBenignRaces(&hit_matched, &unique_count, &hit_count,
187 &ExpectRace::hitcount);
188 Vector<ExpectRace> add_matched(MBlockScopedBuf);
189 CollectMatchedBenignRaces(&add_matched, &unique_count, &add_count,
190 &ExpectRace::addcount);
191 if (hit_matched.Size()) {
192 Printf("ThreadSanitizer: Matched %d \"benign\" races (pid=%d):\n",
Peter Collingbourne0b694fc2013-05-17 16:56:53 +0000193 hit_count, (int)internal_getpid());
Dmitry Vyukov0fd908c2013-03-28 16:21:19 +0000194 for (uptr i = 0; i < hit_matched.Size(); i++) {
195 Printf("%d %s:%d %s\n",
196 hit_matched[i].hitcount, hit_matched[i].file,
197 hit_matched[i].line, hit_matched[i].desc);
198 }
199 }
200 if (hit_matched.Size()) {
201 Printf("ThreadSanitizer: Annotated %d \"benign\" races, %d unique"
202 " (pid=%d):\n",
Peter Collingbourne0b694fc2013-05-17 16:56:53 +0000203 add_count, unique_count, (int)internal_getpid());
Dmitry Vyukov0fd908c2013-03-28 16:21:19 +0000204 for (uptr i = 0; i < add_matched.Size(); i++) {
205 Printf("%d %s:%d %s\n",
206 add_matched[i].addcount, add_matched[i].file,
207 add_matched[i].line, add_matched[i].desc);
208 }
209 }
210}
211
212static void ReportMissedExpectedRace(ExpectRace *race) {
213 Printf("==================\n");
214 Printf("WARNING: ThreadSanitizer: missed expected data race\n");
215 Printf(" %s addr=%zx %s:%d\n",
216 race->desc, race->addr, race->file, race->line);
217 Printf("==================\n");
218}
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000219} // namespace __tsan
220
221using namespace __tsan; // NOLINT
222
223extern "C" {
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000224void INTERFACE_ATTRIBUTE AnnotateHappensBefore(char *f, int l, uptr addr) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000225 SCOPED_ANNOTATION(AnnotateHappensBefore);
Dmitry Vyukov9c1e4f42013-09-19 04:42:25 +0000226 Release(thr, pc, addr);
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000227}
228
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000229void INTERFACE_ATTRIBUTE AnnotateHappensAfter(char *f, int l, uptr addr) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000230 SCOPED_ANNOTATION(AnnotateHappensAfter);
Dmitry Vyukov9c1e4f42013-09-19 04:42:25 +0000231 Acquire(thr, pc, addr);
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000232}
233
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000234void INTERFACE_ATTRIBUTE AnnotateCondVarSignal(char *f, int l, uptr cv) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000235 SCOPED_ANNOTATION(AnnotateCondVarSignal);
236}
237
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000238void INTERFACE_ATTRIBUTE AnnotateCondVarSignalAll(char *f, int l, uptr cv) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000239 SCOPED_ANNOTATION(AnnotateCondVarSignalAll);
240}
241
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000242void INTERFACE_ATTRIBUTE AnnotateMutexIsNotPHB(char *f, int l, uptr mu) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000243 SCOPED_ANNOTATION(AnnotateMutexIsNotPHB);
244}
245
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000246void INTERFACE_ATTRIBUTE AnnotateCondVarWait(char *f, int l, uptr cv,
247 uptr lock) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000248 SCOPED_ANNOTATION(AnnotateCondVarWait);
249}
250
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000251void INTERFACE_ATTRIBUTE AnnotateRWLockCreate(char *f, int l, uptr m) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000252 SCOPED_ANNOTATION(AnnotateRWLockCreate);
Dmitry Vyukovc20e9ba2012-08-16 13:29:41 +0000253 MutexCreate(thr, pc, m, true, true, false);
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000254}
255
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000256void INTERFACE_ATTRIBUTE AnnotateRWLockCreateStatic(char *f, int l, uptr m) {
Dmitry Vyukovc20e9ba2012-08-16 13:29:41 +0000257 SCOPED_ANNOTATION(AnnotateRWLockCreateStatic);
258 MutexCreate(thr, pc, m, true, true, true);
259}
260
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000261void INTERFACE_ATTRIBUTE AnnotateRWLockDestroy(char *f, int l, uptr m) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000262 SCOPED_ANNOTATION(AnnotateRWLockDestroy);
Dmitry Vyukovc20e9ba2012-08-16 13:29:41 +0000263 MutexDestroy(thr, pc, m);
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000264}
265
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000266void INTERFACE_ATTRIBUTE AnnotateRWLockAcquired(char *f, int l, uptr m,
267 uptr is_w) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000268 SCOPED_ANNOTATION(AnnotateRWLockAcquired);
Dmitry Vyukovc20e9ba2012-08-16 13:29:41 +0000269 if (is_w)
270 MutexLock(thr, pc, m);
271 else
272 MutexReadLock(thr, pc, m);
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000273}
274
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000275void INTERFACE_ATTRIBUTE AnnotateRWLockReleased(char *f, int l, uptr m,
276 uptr is_w) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000277 SCOPED_ANNOTATION(AnnotateRWLockReleased);
Dmitry Vyukovc20e9ba2012-08-16 13:29:41 +0000278 if (is_w)
279 MutexUnlock(thr, pc, m);
280 else
281 MutexReadUnlock(thr, pc, m);
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000282}
283
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000284void INTERFACE_ATTRIBUTE AnnotateTraceMemory(char *f, int l, uptr mem) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000285 SCOPED_ANNOTATION(AnnotateTraceMemory);
286}
287
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000288void INTERFACE_ATTRIBUTE AnnotateFlushState(char *f, int l) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000289 SCOPED_ANNOTATION(AnnotateFlushState);
290}
291
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000292void INTERFACE_ATTRIBUTE AnnotateNewMemory(char *f, int l, uptr mem,
293 uptr size) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000294 SCOPED_ANNOTATION(AnnotateNewMemory);
295}
296
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000297void INTERFACE_ATTRIBUTE AnnotateNoOp(char *f, int l, uptr mem) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000298 SCOPED_ANNOTATION(AnnotateNoOp);
299}
300
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000301void INTERFACE_ATTRIBUTE AnnotateFlushExpectedRaces(char *f, int l) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000302 SCOPED_ANNOTATION(AnnotateFlushExpectedRaces);
303 Lock lock(&dyn_ann_ctx->mtx);
304 while (dyn_ann_ctx->expect.next != &dyn_ann_ctx->expect) {
305 ExpectRace *race = dyn_ann_ctx->expect.next;
306 if (race->hitcount == 0) {
Stephen Hines2d1fdb22014-05-28 23:58:16 -0700307 ctx->nmissed_expected++;
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000308 ReportMissedExpectedRace(race);
309 }
310 race->prev->next = race->next;
311 race->next->prev = race->prev;
312 internal_free(race);
313 }
314}
315
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000316void INTERFACE_ATTRIBUTE AnnotateEnableRaceDetection(
317 char *f, int l, int enable) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000318 SCOPED_ANNOTATION(AnnotateEnableRaceDetection);
319 // FIXME: Reconsider this functionality later. It may be irrelevant.
320}
321
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000322void INTERFACE_ATTRIBUTE AnnotateMutexIsUsedAsCondVar(
323 char *f, int l, uptr mu) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000324 SCOPED_ANNOTATION(AnnotateMutexIsUsedAsCondVar);
325}
326
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000327void INTERFACE_ATTRIBUTE AnnotatePCQGet(
328 char *f, int l, uptr pcq) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000329 SCOPED_ANNOTATION(AnnotatePCQGet);
330}
331
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000332void INTERFACE_ATTRIBUTE AnnotatePCQPut(
333 char *f, int l, uptr pcq) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000334 SCOPED_ANNOTATION(AnnotatePCQPut);
335}
336
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000337void INTERFACE_ATTRIBUTE AnnotatePCQDestroy(
338 char *f, int l, uptr pcq) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000339 SCOPED_ANNOTATION(AnnotatePCQDestroy);
340}
341
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000342void INTERFACE_ATTRIBUTE AnnotatePCQCreate(
343 char *f, int l, uptr pcq) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000344 SCOPED_ANNOTATION(AnnotatePCQCreate);
345}
346
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000347void INTERFACE_ATTRIBUTE AnnotateExpectRace(
348 char *f, int l, uptr mem, char *desc) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000349 SCOPED_ANNOTATION(AnnotateExpectRace);
350 Lock lock(&dyn_ann_ctx->mtx);
351 AddExpectRace(&dyn_ann_ctx->expect,
352 f, l, mem, 1, desc);
Alexey Samsonove9541012012-06-06 13:11:29 +0000353 DPrintf("Add expected race: %s addr=%zx %s:%d\n", desc, mem, f, l);
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000354}
355
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000356static void BenignRaceImpl(
357 char *f, int l, uptr mem, uptr size, char *desc) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000358 Lock lock(&dyn_ann_ctx->mtx);
359 AddExpectRace(&dyn_ann_ctx->benign,
360 f, l, mem, size, desc);
Alexey Samsonove9541012012-06-06 13:11:29 +0000361 DPrintf("Add benign race: %s addr=%zx %s:%d\n", desc, mem, f, l);
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000362}
363
364// FIXME: Turn it off later. WTF is benign race?1?? Go talk to Hans Boehm.
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000365void INTERFACE_ATTRIBUTE AnnotateBenignRaceSized(
366 char *f, int l, uptr mem, uptr size, char *desc) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000367 SCOPED_ANNOTATION(AnnotateBenignRaceSized);
368 BenignRaceImpl(f, l, mem, size, desc);
369}
370
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000371void INTERFACE_ATTRIBUTE AnnotateBenignRace(
372 char *f, int l, uptr mem, char *desc) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000373 SCOPED_ANNOTATION(AnnotateBenignRace);
374 BenignRaceImpl(f, l, mem, 1, desc);
375}
376
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000377void INTERFACE_ATTRIBUTE AnnotateIgnoreReadsBegin(char *f, int l) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000378 SCOPED_ANNOTATION(AnnotateIgnoreReadsBegin);
Stephen Hines2d1fdb22014-05-28 23:58:16 -0700379 ThreadIgnoreBegin(thr, pc);
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000380}
381
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000382void INTERFACE_ATTRIBUTE AnnotateIgnoreReadsEnd(char *f, int l) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000383 SCOPED_ANNOTATION(AnnotateIgnoreReadsEnd);
Stephen Hines2d1fdb22014-05-28 23:58:16 -0700384 ThreadIgnoreEnd(thr, pc);
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000385}
386
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000387void INTERFACE_ATTRIBUTE AnnotateIgnoreWritesBegin(char *f, int l) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000388 SCOPED_ANNOTATION(AnnotateIgnoreWritesBegin);
Stephen Hines2d1fdb22014-05-28 23:58:16 -0700389 ThreadIgnoreBegin(thr, pc);
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000390}
391
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000392void INTERFACE_ATTRIBUTE AnnotateIgnoreWritesEnd(char *f, int l) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000393 SCOPED_ANNOTATION(AnnotateIgnoreWritesEnd);
Stephen Hines2d1fdb22014-05-28 23:58:16 -0700394 ThreadIgnoreEnd(thr, pc);
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000395}
396
Dmitry Vyukove1ddbf92013-10-10 15:58:12 +0000397void INTERFACE_ATTRIBUTE AnnotateIgnoreSyncBegin(char *f, int l) {
398 SCOPED_ANNOTATION(AnnotateIgnoreSyncBegin);
Stephen Hines2d1fdb22014-05-28 23:58:16 -0700399 ThreadIgnoreSyncBegin(thr, pc);
Dmitry Vyukove1ddbf92013-10-10 15:58:12 +0000400}
401
402void INTERFACE_ATTRIBUTE AnnotateIgnoreSyncEnd(char *f, int l) {
403 SCOPED_ANNOTATION(AnnotateIgnoreSyncEnd);
Stephen Hines2d1fdb22014-05-28 23:58:16 -0700404 ThreadIgnoreSyncEnd(thr, pc);
Dmitry Vyukove1ddbf92013-10-10 15:58:12 +0000405}
406
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000407void INTERFACE_ATTRIBUTE AnnotatePublishMemoryRange(
408 char *f, int l, uptr addr, uptr size) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000409 SCOPED_ANNOTATION(AnnotatePublishMemoryRange);
410}
411
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000412void INTERFACE_ATTRIBUTE AnnotateUnpublishMemoryRange(
413 char *f, int l, uptr addr, uptr size) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000414 SCOPED_ANNOTATION(AnnotateUnpublishMemoryRange);
415}
416
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000417void INTERFACE_ATTRIBUTE AnnotateThreadName(
418 char *f, int l, char *name) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000419 SCOPED_ANNOTATION(AnnotateThreadName);
Dmitry Vyukovaecf2e52012-12-04 15:46:05 +0000420 ThreadSetName(thr, name);
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000421}
422
Alexander Potapenko743d89d2013-04-02 11:21:53 +0000423// We deliberately omit the implementation of WTFAnnotateHappensBefore() and
424// WTFAnnotateHappensAfter(). Those are being used by Webkit to annotate
425// atomic operations, which should be handled by ThreadSanitizer correctly.
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000426void INTERFACE_ATTRIBUTE WTFAnnotateHappensBefore(char *f, int l, uptr addr) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000427 SCOPED_ANNOTATION(AnnotateHappensBefore);
428}
429
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000430void INTERFACE_ATTRIBUTE WTFAnnotateHappensAfter(char *f, int l, uptr addr) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000431 SCOPED_ANNOTATION(AnnotateHappensAfter);
432}
433
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000434void INTERFACE_ATTRIBUTE WTFAnnotateBenignRaceSized(
435 char *f, int l, uptr mem, uptr sz, char *desc) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000436 SCOPED_ANNOTATION(AnnotateBenignRaceSized);
Stephen Hines2d1fdb22014-05-28 23:58:16 -0700437 BenignRaceImpl(f, l, mem, sz, desc);
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000438}
439
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000440int INTERFACE_ATTRIBUTE RunningOnValgrind() {
Dmitry Vyukov24567d42012-05-24 09:24:45 +0000441 return flags()->running_on_valgrind;
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000442}
443
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000444double __attribute__((weak)) INTERFACE_ATTRIBUTE ValgrindSlowdown(void) {
Dmitry Vyukovdc2f0322012-05-17 08:04:41 +0000445 return 10.0;
446}
447
Dmitry Vyukov258c24b2012-12-04 14:01:21 +0000448const char INTERFACE_ATTRIBUTE* ThreadSanitizerQuery(const char *query) {
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000449 if (internal_strcmp(query, "pure_happens_before") == 0)
450 return "1";
451 else
452 return "0";
453}
Evgeniy Stepanov2ec73182013-09-18 11:20:31 +0000454
455void INTERFACE_ATTRIBUTE
456AnnotateMemoryIsInitialized(char *f, int l, uptr mem, uptr sz) {}
Stephen Hines6d186232014-11-26 17:56:19 -0800457void INTERFACE_ATTRIBUTE
458AnnotateMemoryIsUninitialized(char *f, int l, uptr mem, uptr sz) {}
Kostya Serebryany7ac41482012-05-10 13:48:04 +0000459} // extern "C"