blob: 9abbfafe44ee1b596f9ed93732f5701a85def509 [file] [log] [blame]
Jonas Hahnfeld50fed042016-11-07 15:58:36 +00001/*! \file */
2/*
3 * tsan_annotations.h -- ThreadSanitizer annotations to support data
4 * race detection in OpenMP programs.
5 */
6
Jonas Hahnfeld50fed042016-11-07 15:58:36 +00007//===----------------------------------------------------------------------===//
8//
9// The LLVM Compiler Infrastructure
10//
11// This file is dual licensed under the MIT and the University of Illinois Open
12// Source Licenses. See LICENSE.txt for details.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef TSAN_ANNOTATIONS_H
17#define TSAN_ANNOTATIONS_H
18
19#include "kmp_config.h"
20
21/* types as used in tsan/rtl/tsan_interface_ann.cc */
22typedef unsigned long uptr;
Jonathan Peyton30419822017-05-12 18:01:32 +000023typedef signed long sptr;
Jonas Hahnfeld50fed042016-11-07 15:58:36 +000024
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29/* Declaration of all annotation functions in tsan/rtl/tsan_interface_ann.cc */
30void AnnotateHappensBefore(const char *f, int l, uptr addr);
31void AnnotateHappensAfter(const char *f, int l, uptr addr);
32void AnnotateCondVarSignal(const char *f, int l, uptr cv);
33void AnnotateCondVarSignalAll(const char *f, int l, uptr cv);
34void AnnotateMutexIsNotPHB(const char *f, int l, uptr mu);
35void AnnotateCondVarWait(const char *f, int l, uptr cv, uptr lock);
36void AnnotateRWLockCreate(const char *f, int l, uptr m);
37void AnnotateRWLockCreateStatic(const char *f, int l, uptr m);
38void AnnotateRWLockDestroy(const char *f, int l, uptr m);
39void AnnotateRWLockAcquired(const char *f, int l, uptr m, uptr is_w);
40void AnnotateRWLockReleased(const char *f, int l, uptr m, uptr is_w);
41void AnnotateTraceMemory(const char *f, int l, uptr mem);
42void AnnotateFlushState(const char *f, int l);
43void AnnotateNewMemory(const char *f, int l, uptr mem, uptr size);
44void AnnotateNoOp(const char *f, int l, uptr mem);
45void AnnotateFlushExpectedRaces(const char *f, int l);
Jonathan Peyton30419822017-05-12 18:01:32 +000046void AnnotateEnableRaceDetection(const char *f, int l, int enable);
47void AnnotateMutexIsUsedAsCondVar(const char *f, int l, uptr mu);
48void AnnotatePCQGet(const char *f, int l, uptr pcq);
49void AnnotatePCQPut(const char *f, int l, uptr pcq);
50void AnnotatePCQDestroy(const char *f, int l, uptr pcq);
51void AnnotatePCQCreate(const char *f, int l, uptr pcq);
52void AnnotateExpectRace(const char *f, int l, uptr mem, char *desc);
53void AnnotateBenignRaceSized(const char *f, int l, uptr mem, uptr size,
54 char *desc);
55void AnnotateBenignRace(const char *f, int l, uptr mem, char *desc);
Jonas Hahnfeld50fed042016-11-07 15:58:36 +000056void AnnotateIgnoreReadsBegin(const char *f, int l);
57void AnnotateIgnoreReadsEnd(const char *f, int l);
58void AnnotateIgnoreWritesBegin(const char *f, int l);
59void AnnotateIgnoreWritesEnd(const char *f, int l);
60void AnnotateIgnoreSyncBegin(const char *f, int l);
61void AnnotateIgnoreSyncEnd(const char *f, int l);
Jonathan Peyton30419822017-05-12 18:01:32 +000062void AnnotatePublishMemoryRange(const char *f, int l, uptr addr, uptr size);
63void AnnotateUnpublishMemoryRange(const char *f, int l, uptr addr, uptr size);
64void AnnotateThreadName(const char *f, int l, char *name);
Jonas Hahnfeld50fed042016-11-07 15:58:36 +000065void WTFAnnotateHappensBefore(const char *f, int l, uptr addr);
66void WTFAnnotateHappensAfter(const char *f, int l, uptr addr);
Jonathan Peyton30419822017-05-12 18:01:32 +000067void WTFAnnotateBenignRaceSized(const char *f, int l, uptr mem, uptr sz,
68 char *desc);
Jonas Hahnfeld50fed042016-11-07 15:58:36 +000069int RunningOnValgrind();
70double ValgrindSlowdown(void);
Jonathan Peyton30419822017-05-12 18:01:32 +000071const char *ThreadSanitizerQuery(const char *query);
Jonas Hahnfeld50fed042016-11-07 15:58:36 +000072void AnnotateMemoryIsInitialized(const char *f, int l, uptr mem, uptr sz);
73
74#ifdef __cplusplus
75}
76#endif
77
78#ifdef TSAN_SUPPORT
Jonathan Peyton30419822017-05-12 18:01:32 +000079#define ANNOTATE_HAPPENS_AFTER(addr) \
80 AnnotateHappensAfter(__FILE__, __LINE__, (uptr)addr)
81#define ANNOTATE_HAPPENS_BEFORE(addr) \
82 AnnotateHappensBefore(__FILE__, __LINE__, (uptr)addr)
83#define ANNOTATE_IGNORE_WRITES_BEGIN() \
84 AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
Jonas Hahnfeld50fed042016-11-07 15:58:36 +000085#define ANNOTATE_IGNORE_WRITES_END() AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
Jonathan Peyton30419822017-05-12 18:01:32 +000086#define ANNOTATE_RWLOCK_CREATE(lck) \
87 AnnotateRWLockCreate(__FILE__, __LINE__, (uptr)lck)
88#define ANNOTATE_RWLOCK_RELEASED(lck) \
89 AnnotateRWLockAcquired(__FILE__, __LINE__, (uptr)lck, 1)
90#define ANNOTATE_RWLOCK_ACQUIRED(lck) \
91 AnnotateRWLockReleased(__FILE__, __LINE__, (uptr)lck, 1)
92#define ANNOTATE_BARRIER_BEGIN(addr) \
93 AnnotateHappensBefore(__FILE__, __LINE__, (uptr)addr)
94#define ANNOTATE_BARRIER_END(addr) \
95 AnnotateHappensAfter(__FILE__, __LINE__, (uptr)addr)
96#define ANNOTATE_REDUCE_AFTER(addr) \
97 AnnotateHappensAfter(__FILE__, __LINE__, (uptr)addr)
98#define ANNOTATE_REDUCE_BEFORE(addr) \
99 AnnotateHappensBefore(__FILE__, __LINE__, (uptr)addr)
Jonas Hahnfeld50fed042016-11-07 15:58:36 +0000100#else
101#define ANNOTATE_HAPPENS_AFTER(addr)
102#define ANNOTATE_HAPPENS_BEFORE(addr)
103#define ANNOTATE_IGNORE_WRITES_BEGIN()
104#define ANNOTATE_IGNORE_WRITES_END()
105#define ANNOTATE_RWLOCK_CREATE(lck)
106#define ANNOTATE_RWLOCK_RELEASED(lck)
107#define ANNOTATE_RWLOCK_ACQUIRED(lck)
Jonas Hahnfeld35801a22017-02-15 08:14:22 +0000108#define ANNOTATE_BARRIER_BEGIN(addr)
109#define ANNOTATE_BARRIER_END(addr)
Jonas Hahnfeld50fed042016-11-07 15:58:36 +0000110#define ANNOTATE_REDUCE_AFTER(addr)
111#define ANNOTATE_REDUCE_BEFORE(addr)
112#endif
113
114#define ANNOTATE_QUEUING
115#define ANNOTATE_TICKET
116#define ANNOTATE_FUTEX
117#define ANNOTATE_TAS
118#define ANNOTATE_DRDPA
119
120#ifdef ANNOTATE_QUEUING
121#define ANNOTATE_QUEUING_CREATE(lck)
122#define ANNOTATE_QUEUING_RELEASED(lck) ANNOTATE_HAPPENS_BEFORE(lck)
123#define ANNOTATE_QUEUING_ACQUIRED(lck) ANNOTATE_HAPPENS_AFTER(lck)
124#else
125#define ANNOTATE_QUEUING_CREATE(lck)
126#define ANNOTATE_QUEUING_RELEASED(lck)
127#define ANNOTATE_QUEUING_ACQUIRED(lck)
128#endif
129
130#ifdef ANNOTATE_TICKET
131#define ANNOTATE_TICKET_CREATE(lck)
132#define ANNOTATE_TICKET_RELEASED(lck) ANNOTATE_HAPPENS_BEFORE(lck)
133#define ANNOTATE_TICKET_ACQUIRED(lck) ANNOTATE_HAPPENS_AFTER(lck)
134#else
135#define ANNOTATE_TICKET_CREATE(lck)
136#define ANNOTATE_TICKET_RELEASED(lck)
137#define ANNOTATE_TICKET_ACQUIRED(lck)
138#endif
139
140#ifdef ANNOTATE_FUTEX
141#define ANNOTATE_FUTEX_CREATE(lck)
142#define ANNOTATE_FUTEX_RELEASED(lck) ANNOTATE_HAPPENS_BEFORE(lck)
143#define ANNOTATE_FUTEX_ACQUIRED(lck) ANNOTATE_HAPPENS_AFTER(lck)
144#else
145#define ANNOTATE_FUTEX_CREATE(lck)
146#define ANNOTATE_FUTEX_RELEASED(lck)
147#define ANNOTATE_FUTEX_ACQUIRED(lck)
148#endif
149
150#ifdef ANNOTATE_TAS
151#define ANNOTATE_TAS_CREATE(lck)
152#define ANNOTATE_TAS_RELEASED(lck) ANNOTATE_HAPPENS_BEFORE(lck)
153#define ANNOTATE_TAS_ACQUIRED(lck) ANNOTATE_HAPPENS_AFTER(lck)
154#else
155#define ANNOTATE_TAS_CREATE(lck)
156#define ANNOTATE_TAS_RELEASED(lck)
157#define ANNOTATE_TAS_ACQUIRED(lck)
158#endif
159
160#ifdef ANNOTATE_DRDPA
161#define ANNOTATE_DRDPA_CREATE(lck)
162#define ANNOTATE_DRDPA_RELEASED(lck) ANNOTATE_HAPPENS_BEFORE(lck)
163#define ANNOTATE_DRDPA_ACQUIRED(lck) ANNOTATE_HAPPENS_AFTER(lck)
164#else
165#define ANNOTATE_DRDPA_CREATE(lck)
166#define ANNOTATE_DRDPA_RELEASED(lck)
167#define ANNOTATE_DRDPA_ACQUIRED(lck)
168#endif
169
170#endif