1 /*! \file */ 2 /* 3 * tsan_annotations.h -- ThreadSanitizer annotations to support data 4 * race detection in OpenMP programs. 5 */ 6 7 //===----------------------------------------------------------------------===// 8 // 9 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 10 // See https://llvm.org/LICENSE.txt for license information. 11 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef TSAN_ANNOTATIONS_H 16 #define TSAN_ANNOTATIONS_H 17 18 #include "kmp_config.h" 19 20 /* types as used in tsan/rtl/tsan_interface_ann.cc */ 21 typedef unsigned long uptr; 22 typedef signed long sptr; 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /* Declaration of all annotation functions in tsan/rtl/tsan_interface_ann.cc */ 29 void AnnotateHappensBefore(const char *f, int l, uptr addr); 30 void AnnotateHappensAfter(const char *f, int l, uptr addr); 31 void AnnotateCondVarSignal(const char *f, int l, uptr cv); 32 void AnnotateCondVarSignalAll(const char *f, int l, uptr cv); 33 void AnnotateMutexIsNotPHB(const char *f, int l, uptr mu); 34 void AnnotateCondVarWait(const char *f, int l, uptr cv, uptr lock); 35 void AnnotateRWLockCreate(const char *f, int l, uptr m); 36 void AnnotateRWLockCreateStatic(const char *f, int l, uptr m); 37 void AnnotateRWLockDestroy(const char *f, int l, uptr m); 38 void AnnotateRWLockAcquired(const char *f, int l, uptr m, uptr is_w); 39 void AnnotateRWLockReleased(const char *f, int l, uptr m, uptr is_w); 40 void AnnotateTraceMemory(const char *f, int l, uptr mem); 41 void AnnotateFlushState(const char *f, int l); 42 void AnnotateNewMemory(const char *f, int l, uptr mem, uptr size); 43 void AnnotateNoOp(const char *f, int l, uptr mem); 44 void AnnotateFlushExpectedRaces(const char *f, int l); 45 void AnnotateEnableRaceDetection(const char *f, int l, int enable); 46 void AnnotateMutexIsUsedAsCondVar(const char *f, int l, uptr mu); 47 void AnnotatePCQGet(const char *f, int l, uptr pcq); 48 void AnnotatePCQPut(const char *f, int l, uptr pcq); 49 void AnnotatePCQDestroy(const char *f, int l, uptr pcq); 50 void AnnotatePCQCreate(const char *f, int l, uptr pcq); 51 void AnnotateExpectRace(const char *f, int l, uptr mem, char *desc); 52 void AnnotateBenignRaceSized(const char *f, int l, uptr mem, uptr size, 53 char *desc); 54 void AnnotateBenignRace(const char *f, int l, uptr mem, char *desc); 55 void AnnotateIgnoreReadsBegin(const char *f, int l); 56 void AnnotateIgnoreReadsEnd(const char *f, int l); 57 void AnnotateIgnoreWritesBegin(const char *f, int l); 58 void AnnotateIgnoreWritesEnd(const char *f, int l); 59 void AnnotateIgnoreSyncBegin(const char *f, int l); 60 void AnnotateIgnoreSyncEnd(const char *f, int l); 61 void AnnotatePublishMemoryRange(const char *f, int l, uptr addr, uptr size); 62 void AnnotateUnpublishMemoryRange(const char *f, int l, uptr addr, uptr size); 63 void AnnotateThreadName(const char *f, int l, char *name); 64 void WTFAnnotateHappensBefore(const char *f, int l, uptr addr); 65 void WTFAnnotateHappensAfter(const char *f, int l, uptr addr); 66 void WTFAnnotateBenignRaceSized(const char *f, int l, uptr mem, uptr sz, 67 char *desc); 68 int RunningOnValgrind(); 69 double ValgrindSlowdown(void); 70 const char *ThreadSanitizerQuery(const char *query); 71 void AnnotateMemoryIsInitialized(const char *f, int l, uptr mem, uptr sz); 72 73 #ifdef __cplusplus 74 } 75 #endif 76 77 #ifdef TSAN_SUPPORT 78 #define ANNOTATE_HAPPENS_AFTER(addr) \ 79 AnnotateHappensAfter(__FILE__, __LINE__, (uptr)addr) 80 #define ANNOTATE_HAPPENS_BEFORE(addr) \ 81 AnnotateHappensBefore(__FILE__, __LINE__, (uptr)addr) 82 #define ANNOTATE_IGNORE_WRITES_BEGIN() \ 83 AnnotateIgnoreWritesBegin(__FILE__, __LINE__) 84 #define ANNOTATE_IGNORE_WRITES_END() AnnotateIgnoreWritesEnd(__FILE__, __LINE__) 85 #define ANNOTATE_RWLOCK_CREATE(lck) \ 86 AnnotateRWLockCreate(__FILE__, __LINE__, (uptr)lck) 87 #define ANNOTATE_RWLOCK_RELEASED(lck) \ 88 AnnotateRWLockAcquired(__FILE__, __LINE__, (uptr)lck, 1) 89 #define ANNOTATE_RWLOCK_ACQUIRED(lck) \ 90 AnnotateRWLockReleased(__FILE__, __LINE__, (uptr)lck, 1) 91 #define ANNOTATE_BARRIER_BEGIN(addr) \ 92 AnnotateHappensBefore(__FILE__, __LINE__, (uptr)addr) 93 #define ANNOTATE_BARRIER_END(addr) \ 94 AnnotateHappensAfter(__FILE__, __LINE__, (uptr)addr) 95 #define ANNOTATE_REDUCE_AFTER(addr) \ 96 AnnotateHappensAfter(__FILE__, __LINE__, (uptr)addr) 97 #define ANNOTATE_REDUCE_BEFORE(addr) \ 98 AnnotateHappensBefore(__FILE__, __LINE__, (uptr)addr) 99 #else 100 #define ANNOTATE_HAPPENS_AFTER(addr) 101 #define ANNOTATE_HAPPENS_BEFORE(addr) 102 #define ANNOTATE_IGNORE_WRITES_BEGIN() 103 #define ANNOTATE_IGNORE_WRITES_END() 104 #define ANNOTATE_RWLOCK_CREATE(lck) 105 #define ANNOTATE_RWLOCK_RELEASED(lck) 106 #define ANNOTATE_RWLOCK_ACQUIRED(lck) 107 #define ANNOTATE_BARRIER_BEGIN(addr) 108 #define ANNOTATE_BARRIER_END(addr) 109 #define ANNOTATE_REDUCE_AFTER(addr) 110 #define ANNOTATE_REDUCE_BEFORE(addr) 111 #endif 112 113 #define ANNOTATE_QUEUING 114 #define ANNOTATE_TICKET 115 #define ANNOTATE_FUTEX 116 #define ANNOTATE_TAS 117 #define ANNOTATE_DRDPA 118 119 #ifdef ANNOTATE_QUEUING 120 #define ANNOTATE_QUEUING_CREATE(lck) 121 #define ANNOTATE_QUEUING_RELEASED(lck) ANNOTATE_HAPPENS_BEFORE(lck) 122 #define ANNOTATE_QUEUING_ACQUIRED(lck) ANNOTATE_HAPPENS_AFTER(lck) 123 #else 124 #define ANNOTATE_QUEUING_CREATE(lck) 125 #define ANNOTATE_QUEUING_RELEASED(lck) 126 #define ANNOTATE_QUEUING_ACQUIRED(lck) 127 #endif 128 129 #ifdef ANNOTATE_TICKET 130 #define ANNOTATE_TICKET_CREATE(lck) 131 #define ANNOTATE_TICKET_RELEASED(lck) ANNOTATE_HAPPENS_BEFORE(lck) 132 #define ANNOTATE_TICKET_ACQUIRED(lck) ANNOTATE_HAPPENS_AFTER(lck) 133 #else 134 #define ANNOTATE_TICKET_CREATE(lck) 135 #define ANNOTATE_TICKET_RELEASED(lck) 136 #define ANNOTATE_TICKET_ACQUIRED(lck) 137 #endif 138 139 #ifdef ANNOTATE_FUTEX 140 #define ANNOTATE_FUTEX_CREATE(lck) 141 #define ANNOTATE_FUTEX_RELEASED(lck) ANNOTATE_HAPPENS_BEFORE(lck) 142 #define ANNOTATE_FUTEX_ACQUIRED(lck) ANNOTATE_HAPPENS_AFTER(lck) 143 #else 144 #define ANNOTATE_FUTEX_CREATE(lck) 145 #define ANNOTATE_FUTEX_RELEASED(lck) 146 #define ANNOTATE_FUTEX_ACQUIRED(lck) 147 #endif 148 149 #ifdef ANNOTATE_TAS 150 #define ANNOTATE_TAS_CREATE(lck) 151 #define ANNOTATE_TAS_RELEASED(lck) ANNOTATE_HAPPENS_BEFORE(lck) 152 #define ANNOTATE_TAS_ACQUIRED(lck) ANNOTATE_HAPPENS_AFTER(lck) 153 #else 154 #define ANNOTATE_TAS_CREATE(lck) 155 #define ANNOTATE_TAS_RELEASED(lck) 156 #define ANNOTATE_TAS_ACQUIRED(lck) 157 #endif 158 159 #ifdef ANNOTATE_DRDPA 160 #define ANNOTATE_DRDPA_CREATE(lck) 161 #define ANNOTATE_DRDPA_RELEASED(lck) ANNOTATE_HAPPENS_BEFORE(lck) 162 #define ANNOTATE_DRDPA_ACQUIRED(lck) ANNOTATE_HAPPENS_AFTER(lck) 163 #else 164 #define ANNOTATE_DRDPA_CREATE(lck) 165 #define ANNOTATE_DRDPA_RELEASED(lck) 166 #define ANNOTATE_DRDPA_ACQUIRED(lck) 167 #endif 168 169 #endif 170