00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #ifndef ABSL_BASE_DYNAMIC_ANNOTATIONS_H_
00047 #define ABSL_BASE_DYNAMIC_ANNOTATIONS_H_
00048
00049 #ifndef DYNAMIC_ANNOTATIONS_ENABLED
00050 # define DYNAMIC_ANNOTATIONS_ENABLED 0
00051 #endif
00052
00053 #if DYNAMIC_ANNOTATIONS_ENABLED != 0
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 #define ANNOTATE_BENIGN_RACE(pointer, description) \
00065 AnnotateBenignRaceSized(__FILE__, __LINE__, pointer, \
00066 sizeof(*(pointer)), description)
00067
00068
00069
00070 #define ANNOTATE_BENIGN_RACE_SIZED(address, size, description) \
00071 AnnotateBenignRaceSized(__FILE__, __LINE__, address, size, description)
00072
00073
00074
00075
00076 #define ANNOTATE_ENABLE_RACE_DETECTION(enable) \
00077 AnnotateEnableRaceDetection(__FILE__, __LINE__, enable)
00078
00079
00080
00081
00082
00083 #define ANNOTATE_THREAD_NAME(name) \
00084 AnnotateThreadName(__FILE__, __LINE__, name)
00085
00086
00087
00088
00089
00090
00091
00092 #define ANNOTATE_RWLOCK_CREATE(lock) \
00093 AnnotateRWLockCreate(__FILE__, __LINE__, lock)
00094
00095
00096
00097 #ifdef THREAD_SANITIZER
00098 #define ANNOTATE_RWLOCK_CREATE_STATIC(lock) \
00099 AnnotateRWLockCreateStatic(__FILE__, __LINE__, lock)
00100 #else
00101 #define ANNOTATE_RWLOCK_CREATE_STATIC(lock) ANNOTATE_RWLOCK_CREATE(lock)
00102 #endif
00103
00104
00105 #define ANNOTATE_RWLOCK_DESTROY(lock) \
00106 AnnotateRWLockDestroy(__FILE__, __LINE__, lock)
00107
00108
00109
00110 #define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) \
00111 AnnotateRWLockAcquired(__FILE__, __LINE__, lock, is_w)
00112
00113
00114 #define ANNOTATE_RWLOCK_RELEASED(lock, is_w) \
00115 AnnotateRWLockReleased(__FILE__, __LINE__, lock, is_w)
00116
00117 #else
00118
00119 #define ANNOTATE_RWLOCK_CREATE(lock)
00120 #define ANNOTATE_RWLOCK_CREATE_STATIC(lock)
00121 #define ANNOTATE_RWLOCK_DESTROY(lock)
00122 #define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w)
00123 #define ANNOTATE_RWLOCK_RELEASED(lock, is_w)
00124 #define ANNOTATE_BENIGN_RACE(address, description)
00125 #define ANNOTATE_BENIGN_RACE_SIZED(address, size, description)
00126 #define ANNOTATE_THREAD_NAME(name)
00127 #define ANNOTATE_ENABLE_RACE_DETECTION(enable)
00128
00129 #endif
00130
00131
00132 #if DYNAMIC_ANNOTATIONS_ENABLED == 1 || defined(MEMORY_SANITIZER)
00133 #define ANNOTATE_MEMORY_IS_INITIALIZED(address, size) \
00134 AnnotateMemoryIsInitialized(__FILE__, __LINE__, address, size)
00135
00136 #define ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size) \
00137 AnnotateMemoryIsUninitialized(__FILE__, __LINE__, address, size)
00138 #else
00139 #define ANNOTATE_MEMORY_IS_INITIALIZED(address, size)
00140 #define ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size)
00141 #endif
00142
00143
00144
00145 #if defined(__clang__) && (!defined(SWIG)) \
00146 && defined(__CLANG_SUPPORT_DYN_ANNOTATION__)
00147
00148 #if DYNAMIC_ANNOTATIONS_ENABLED == 0
00149 #define ANNOTALYSIS_ENABLED
00150 #endif
00151
00152
00153
00154 #define ATTRIBUTE_IGNORE_READS_BEGIN \
00155 __attribute((exclusive_lock_function("*")))
00156 #define ATTRIBUTE_IGNORE_READS_END \
00157 __attribute((unlock_function("*")))
00158 #else
00159 #define ATTRIBUTE_IGNORE_READS_BEGIN
00160 #define ATTRIBUTE_IGNORE_READS_END
00161 #endif
00162
00163 #if (DYNAMIC_ANNOTATIONS_ENABLED != 0) || defined(ANNOTALYSIS_ENABLED)
00164 #define ANNOTATIONS_ENABLED
00165 #endif
00166
00167 #if (DYNAMIC_ANNOTATIONS_ENABLED != 0)
00168
00169
00170
00171
00172
00173
00174 #define ANNOTATE_IGNORE_READS_BEGIN() \
00175 AnnotateIgnoreReadsBegin(__FILE__, __LINE__)
00176
00177
00178 #define ANNOTATE_IGNORE_READS_END() \
00179 AnnotateIgnoreReadsEnd(__FILE__, __LINE__)
00180
00181
00182 #define ANNOTATE_IGNORE_WRITES_BEGIN() \
00183 AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
00184
00185
00186 #define ANNOTATE_IGNORE_WRITES_END() \
00187 AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
00188
00189
00190
00191
00192 #elif defined(ANNOTALYSIS_ENABLED)
00193
00194 #define ANNOTATE_IGNORE_READS_BEGIN() \
00195 StaticAnnotateIgnoreReadsBegin(__FILE__, __LINE__)
00196
00197 #define ANNOTATE_IGNORE_READS_END() \
00198 StaticAnnotateIgnoreReadsEnd(__FILE__, __LINE__)
00199
00200 #define ANNOTATE_IGNORE_WRITES_BEGIN() \
00201 StaticAnnotateIgnoreWritesBegin(__FILE__, __LINE__)
00202
00203 #define ANNOTATE_IGNORE_WRITES_END() \
00204 StaticAnnotateIgnoreWritesEnd(__FILE__, __LINE__)
00205
00206 #else
00207 #define ANNOTATE_IGNORE_READS_BEGIN()
00208 #define ANNOTATE_IGNORE_READS_END()
00209 #define ANNOTATE_IGNORE_WRITES_BEGIN()
00210 #define ANNOTATE_IGNORE_WRITES_END()
00211 #endif
00212
00213
00214
00215 #if defined(ANNOTATIONS_ENABLED)
00216
00217
00218 #define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() \
00219 do { \
00220 ANNOTATE_IGNORE_READS_BEGIN(); \
00221 ANNOTATE_IGNORE_WRITES_BEGIN(); \
00222 }while (0)
00223
00224
00225 #define ANNOTATE_IGNORE_READS_AND_WRITES_END() \
00226 do { \
00227 ANNOTATE_IGNORE_WRITES_END(); \
00228 ANNOTATE_IGNORE_READS_END(); \
00229 }while (0)
00230
00231 #else
00232 #define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN()
00233 #define ANNOTATE_IGNORE_READS_AND_WRITES_END()
00234 #endif
00235
00236
00237 #include <stddef.h>
00238 #ifdef __cplusplus
00239 extern "C" {
00240 #endif
00241 void AnnotateRWLockCreate(const char *file, int line,
00242 const volatile void *lock);
00243 void AnnotateRWLockCreateStatic(const char *file, int line,
00244 const volatile void *lock);
00245 void AnnotateRWLockDestroy(const char *file, int line,
00246 const volatile void *lock);
00247 void AnnotateRWLockAcquired(const char *file, int line,
00248 const volatile void *lock, long is_w);
00249 void AnnotateRWLockReleased(const char *file, int line,
00250 const volatile void *lock, long is_w);
00251 void AnnotateBenignRace(const char *file, int line,
00252 const volatile void *address,
00253 const char *description);
00254 void AnnotateBenignRaceSized(const char *file, int line,
00255 const volatile void *address,
00256 size_t size,
00257 const char *description);
00258 void AnnotateThreadName(const char *file, int line,
00259 const char *name);
00260 void AnnotateEnableRaceDetection(const char *file, int line, int enable);
00261 void AnnotateMemoryIsInitialized(const char *file, int line,
00262 const volatile void *mem, size_t size);
00263 void AnnotateMemoryIsUninitialized(const char *file, int line,
00264 const volatile void *mem, size_t size);
00265
00266
00267
00268
00269
00270 void AnnotateIgnoreReadsBegin(const char *file, int line)
00271 ATTRIBUTE_IGNORE_READS_BEGIN;
00272 void AnnotateIgnoreReadsEnd(const char *file, int line)
00273 ATTRIBUTE_IGNORE_READS_END;
00274 void AnnotateIgnoreWritesBegin(const char *file, int line);
00275 void AnnotateIgnoreWritesEnd(const char *file, int line);
00276
00277 #if defined(ANNOTALYSIS_ENABLED)
00278
00279
00280
00281
00282
00283
00284 #pragma GCC diagnostic push
00285 #pragma GCC diagnostic ignored "-Wunused-function"
00286 static inline void StaticAnnotateIgnoreReadsBegin(const char *file, int line)
00287 ATTRIBUTE_IGNORE_READS_BEGIN { (void)file; (void)line; }
00288 static inline void StaticAnnotateIgnoreReadsEnd(const char *file, int line)
00289 ATTRIBUTE_IGNORE_READS_END { (void)file; (void)line; }
00290 static inline void StaticAnnotateIgnoreWritesBegin(
00291 const char *file, int line) { (void)file; (void)line; }
00292 static inline void StaticAnnotateIgnoreWritesEnd(
00293 const char *file, int line) { (void)file; (void)line; }
00294 #pragma GCC diagnostic pop
00295 #endif
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312 int RunningOnValgrind(void);
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325 double ValgrindSlowdown(void);
00326
00327 #ifdef __cplusplus
00328 }
00329 #endif
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339 #if defined(__cplusplus) && defined(ANNOTATIONS_ENABLED)
00340 template <typename T>
00341 inline T ANNOTATE_UNPROTECTED_READ(const volatile T &x) {
00342 ANNOTATE_IGNORE_READS_BEGIN();
00343 T res = x;
00344 ANNOTATE_IGNORE_READS_END();
00345 return res;
00346 }
00347 #else
00348 #define ANNOTATE_UNPROTECTED_READ(x) (x)
00349 #endif
00350
00351 #if DYNAMIC_ANNOTATIONS_ENABLED != 0 && defined(__cplusplus)
00352
00353 #define ANNOTATE_BENIGN_RACE_STATIC(static_var, description) \
00354 namespace { \
00355 class static_var ## _annotator { \
00356 public: \
00357 static_var ## _annotator() { \
00358 ANNOTATE_BENIGN_RACE_SIZED(&static_var, \
00359 sizeof(static_var), \
00360 # static_var ": " description); \
00361 } \
00362 }; \
00363 static static_var ## _annotator the ## static_var ## _annotator;\
00364 } // namespace
00365 #else
00366 #define ANNOTATE_BENIGN_RACE_STATIC(static_var, description)
00367 #endif
00368
00369 #ifdef ADDRESS_SANITIZER
00370
00371
00372
00373 #include <sanitizer/common_interface_defs.h>
00374 #define ANNOTATE_CONTIGUOUS_CONTAINER(beg, end, old_mid, new_mid) \
00375 __sanitizer_annotate_contiguous_container(beg, end, old_mid, new_mid)
00376 #define ADDRESS_SANITIZER_REDZONE(name) \
00377 struct { char x[8] __attribute__ ((aligned (8))); } name
00378 #else
00379 #define ANNOTATE_CONTIGUOUS_CONTAINER(beg, end, old_mid, new_mid)
00380 #define ADDRESS_SANITIZER_REDZONE(name) static_assert(true, "")
00381 #endif // ADDRESS_SANITIZER
00382
00383
00384 #undef ANNOTALYSIS_ENABLED
00385 #undef ANNOTATIONS_ENABLED
00386 #undef ATTRIBUTE_IGNORE_READS_BEGIN
00387 #undef ATTRIBUTE_IGNORE_READS_END
00388
00389 #endif