46 #ifndef ABSL_BASE_DYNAMIC_ANNOTATIONS_H_ 47 #define ABSL_BASE_DYNAMIC_ANNOTATIONS_H_ 49 #ifndef DYNAMIC_ANNOTATIONS_ENABLED 50 # define DYNAMIC_ANNOTATIONS_ENABLED 0 53 #if DYNAMIC_ANNOTATIONS_ENABLED != 0 64 #define ANNOTATE_BENIGN_RACE(pointer, description) \ 65 AnnotateBenignRaceSized(__FILE__, __LINE__, pointer, \ 66 sizeof(*(pointer)), description) 70 #define ANNOTATE_BENIGN_RACE_SIZED(address, size, description) \ 71 AnnotateBenignRaceSized(__FILE__, __LINE__, address, size, description) 76 #define ANNOTATE_ENABLE_RACE_DETECTION(enable) \ 77 AnnotateEnableRaceDetection(__FILE__, __LINE__, enable) 83 #define ANNOTATE_THREAD_NAME(name) \ 84 AnnotateThreadName(__FILE__, __LINE__, name) 92 #define ANNOTATE_RWLOCK_CREATE(lock) \ 93 AnnotateRWLockCreate(__FILE__, __LINE__, lock) 97 #ifdef THREAD_SANITIZER 98 #define ANNOTATE_RWLOCK_CREATE_STATIC(lock) \ 99 AnnotateRWLockCreateStatic(__FILE__, __LINE__, lock) 101 #define ANNOTATE_RWLOCK_CREATE_STATIC(lock) ANNOTATE_RWLOCK_CREATE(lock) 105 #define ANNOTATE_RWLOCK_DESTROY(lock) \ 106 AnnotateRWLockDestroy(__FILE__, __LINE__, lock) 110 #define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) \ 111 AnnotateRWLockAcquired(__FILE__, __LINE__, lock, is_w) 114 #define ANNOTATE_RWLOCK_RELEASED(lock, is_w) \ 115 AnnotateRWLockReleased(__FILE__, __LINE__, lock, is_w) 119 #define ANNOTATE_RWLOCK_CREATE(lock) 120 #define ANNOTATE_RWLOCK_CREATE_STATIC(lock) 121 #define ANNOTATE_RWLOCK_DESTROY(lock) 122 #define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) 123 #define ANNOTATE_RWLOCK_RELEASED(lock, is_w) 124 #define ANNOTATE_BENIGN_RACE(address, description) 125 #define ANNOTATE_BENIGN_RACE_SIZED(address, size, description) 126 #define ANNOTATE_THREAD_NAME(name) 127 #define ANNOTATE_ENABLE_RACE_DETECTION(enable) 132 #if DYNAMIC_ANNOTATIONS_ENABLED == 1 || defined(MEMORY_SANITIZER) 133 #define ANNOTATE_MEMORY_IS_INITIALIZED(address, size) \ 134 AnnotateMemoryIsInitialized(__FILE__, __LINE__, address, size) 136 #define ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size) \ 137 AnnotateMemoryIsUninitialized(__FILE__, __LINE__, address, size) 139 #define ANNOTATE_MEMORY_IS_INITIALIZED(address, size) 140 #define ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size) 145 #if defined(__clang__) && (!defined(SWIG)) \ 146 && defined(__CLANG_SUPPORT_DYN_ANNOTATION__) 148 #if DYNAMIC_ANNOTATIONS_ENABLED == 0 149 #define ANNOTALYSIS_ENABLED 154 #define ATTRIBUTE_IGNORE_READS_BEGIN \ 155 __attribute((exclusive_lock_function("*"))) 156 #define ATTRIBUTE_IGNORE_READS_END \ 157 __attribute((unlock_function("*"))) 159 #define ATTRIBUTE_IGNORE_READS_BEGIN 160 #define ATTRIBUTE_IGNORE_READS_END 163 #if (DYNAMIC_ANNOTATIONS_ENABLED != 0) || defined(ANNOTALYSIS_ENABLED) 164 #define ANNOTATIONS_ENABLED 167 #if (DYNAMIC_ANNOTATIONS_ENABLED != 0) 174 #define ANNOTATE_IGNORE_READS_BEGIN() \ 175 AnnotateIgnoreReadsBegin(__FILE__, __LINE__) 178 #define ANNOTATE_IGNORE_READS_END() \ 179 AnnotateIgnoreReadsEnd(__FILE__, __LINE__) 182 #define ANNOTATE_IGNORE_WRITES_BEGIN() \ 183 AnnotateIgnoreWritesBegin(__FILE__, __LINE__) 186 #define ANNOTATE_IGNORE_WRITES_END() \ 187 AnnotateIgnoreWritesEnd(__FILE__, __LINE__) 192 #elif defined(ANNOTALYSIS_ENABLED) 194 #define ANNOTATE_IGNORE_READS_BEGIN() \ 195 StaticAnnotateIgnoreReadsBegin(__FILE__, __LINE__) 197 #define ANNOTATE_IGNORE_READS_END() \ 198 StaticAnnotateIgnoreReadsEnd(__FILE__, __LINE__) 200 #define ANNOTATE_IGNORE_WRITES_BEGIN() \ 201 StaticAnnotateIgnoreWritesBegin(__FILE__, __LINE__) 203 #define ANNOTATE_IGNORE_WRITES_END() \ 204 StaticAnnotateIgnoreWritesEnd(__FILE__, __LINE__) 207 #define ANNOTATE_IGNORE_READS_BEGIN() 208 #define ANNOTATE_IGNORE_READS_END() 209 #define ANNOTATE_IGNORE_WRITES_BEGIN() 210 #define ANNOTATE_IGNORE_WRITES_END() 215 #if defined(ANNOTATIONS_ENABLED) 218 #define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() \ 220 ANNOTATE_IGNORE_READS_BEGIN(); \ 221 ANNOTATE_IGNORE_WRITES_BEGIN(); \ 225 #define ANNOTATE_IGNORE_READS_AND_WRITES_END() \ 227 ANNOTATE_IGNORE_WRITES_END(); \ 228 ANNOTATE_IGNORE_READS_END(); \ 232 #define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() 233 #define ANNOTATE_IGNORE_READS_AND_WRITES_END() 242 const volatile void *lock);
244 const volatile void *lock);
246 const volatile void *lock);
248 const volatile void *lock,
long is_w);
250 const volatile void *lock,
long is_w);
252 const volatile void *address,
253 const char *description);
255 const volatile void *address,
257 const char *description);
262 const volatile void *mem,
size_t size);
264 const volatile void *mem,
size_t size);
277 #if defined(ANNOTALYSIS_ENABLED) 284 #pragma GCC diagnostic push 285 #pragma GCC diagnostic ignored "-Wunused-function" 286 static inline void StaticAnnotateIgnoreReadsBegin(
const char *file,
int line)
287 ATTRIBUTE_IGNORE_READS_BEGIN { (void)file; (void)line; }
288 static inline void StaticAnnotateIgnoreReadsEnd(
const char *file,
int line)
289 ATTRIBUTE_IGNORE_READS_END { (void)file; (void)line; }
290 static inline void StaticAnnotateIgnoreWritesBegin(
291 const char *file,
int line) { (void)file; (void)line; }
292 static inline void StaticAnnotateIgnoreWritesEnd(
293 const char *file,
int line) { (void)file; (void)line; }
294 #pragma GCC diagnostic pop 339 #if defined(__cplusplus) && defined(ANNOTATIONS_ENABLED) 340 template <
typename T>
348 #define ANNOTATE_UNPROTECTED_READ(x) (x) 351 #if DYNAMIC_ANNOTATIONS_ENABLED != 0 && defined(__cplusplus) 353 #define ANNOTATE_BENIGN_RACE_STATIC(static_var, description) \ 355 class static_var ## _annotator { \ 357 static_var ## _annotator() { \ 358 ANNOTATE_BENIGN_RACE_SIZED(&static_var, \ 359 sizeof(static_var), \ 360 # static_var ": " description); \ 363 static static_var ## _annotator the ## static_var ## _annotator;\ 366 #define ANNOTATE_BENIGN_RACE_STATIC(static_var, description) 369 #ifdef ADDRESS_SANITIZER 373 #include <sanitizer/common_interface_defs.h> 374 #define ANNOTATE_CONTIGUOUS_CONTAINER(beg, end, old_mid, new_mid) \ 375 __sanitizer_annotate_contiguous_container(beg, end, old_mid, new_mid) 376 #define ADDRESS_SANITIZER_REDZONE(name) \ 377 struct { char x[8] __attribute__ ((aligned (8))); } name 379 #define ANNOTATE_CONTIGUOUS_CONTAINER(beg, end, old_mid, new_mid) 380 #define ADDRESS_SANITIZER_REDZONE(name) static_assert(true, "") 381 #endif // ADDRESS_SANITIZER 384 #undef ANNOTALYSIS_ENABLED 385 #undef ANNOTATIONS_ENABLED 386 #undef ATTRIBUTE_IGNORE_READS_BEGIN 387 #undef ATTRIBUTE_IGNORE_READS_END void AnnotateMemoryIsInitialized(const char *file, int line, const volatile void *mem, size_t size)
void AnnotateRWLockCreate(const char *file, int line, const volatile void *lock)
void AnnotateMemoryIsUninitialized(const char *file, int line, const volatile void *mem, size_t size)
void AnnotateBenignRace(const char *file, int line, const volatile void *address, const char *description)
void AnnotateIgnoreReadsBegin(const char *file, int line) ATTRIBUTE_IGNORE_READS_BEGIN
void AnnotateRWLockReleased(const char *file, int line, const volatile void *lock, long is_w)
#define ANNOTATE_UNPROTECTED_READ(x)
#define ANNOTATE_IGNORE_READS_END()
void AnnotateRWLockDestroy(const char *file, int line, const volatile void *lock)
void AnnotateThreadName(const char *file, int line, const char *name)
#define ATTRIBUTE_IGNORE_READS_END
double ValgrindSlowdown(void)
void AnnotateRWLockCreateStatic(const char *file, int line, const volatile void *lock)
void AnnotateIgnoreReadsEnd(const char *file, int line) ATTRIBUTE_IGNORE_READS_END
void AnnotateIgnoreWritesBegin(const char *file, int line)
int RunningOnValgrind(void)
#define ANNOTATE_IGNORE_READS_BEGIN()
void AnnotateBenignRaceSized(const char *file, int line, const volatile void *address, size_t size, const char *description)
#define ATTRIBUTE_IGNORE_READS_BEGIN
void AnnotateIgnoreWritesEnd(const char *file, int line)
void AnnotateRWLockAcquired(const char *file, int line, const volatile void *lock, long is_w)
void AnnotateEnableRaceDetection(const char *file, int line, int enable)