dynamic_annotations.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. // Copyright 2017 The Abseil Authors.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // This file defines dynamic annotations for use with dynamic analysis tool
  15. // such as valgrind, PIN, etc.
  16. //
  17. // Dynamic annotation is a source code annotation that affects the generated
  18. // code (that is, the annotation is not a comment). Each such annotation is
  19. // attached to a particular instruction and/or to a particular object (address)
  20. // in the program.
  21. //
  22. // The annotations that should be used by users are macros in all upper-case
  23. // (e.g., ABSL_ANNOTATE_THREAD_NAME).
  24. //
  25. // Actual implementation of these macros may differ depending on the dynamic
  26. // analysis tool being used.
  27. //
  28. // This file supports the following configurations:
  29. // - Dynamic Annotations enabled (with static thread-safety warnings disabled).
  30. // In this case, macros expand to functions implemented by Thread Sanitizer,
  31. // when building with TSan. When not provided an external implementation,
  32. // dynamic_annotations.cc provides no-op implementations.
  33. //
  34. // - Static Clang thread-safety warnings enabled.
  35. // When building with a Clang compiler that supports thread-safety warnings,
  36. // a subset of annotations can be statically-checked at compile-time. We
  37. // expand these macros to static-inline functions that can be analyzed for
  38. // thread-safety, but afterwards elided when building the final binary.
  39. //
  40. // - All annotations are disabled.
  41. // If neither Dynamic Annotations nor Clang thread-safety warnings are
  42. // enabled, then all annotation-macros expand to empty.
  43. #ifndef ABSL_BASE_DYNAMIC_ANNOTATIONS_H_
  44. #define ABSL_BASE_DYNAMIC_ANNOTATIONS_H_
  45. #include <stddef.h>
  46. #include <stdint.h>
  47. #include "absl/base/attributes.h"
  48. #include "absl/base/config.h"
  49. #ifdef __cplusplus
  50. #include "absl/base/macros.h"
  51. #endif
  52. #ifdef ABSL_HAVE_HWADDRESS_SANITIZER
  53. #include <sanitizer/hwasan_interface.h>
  54. #endif
  55. // TODO(rogeeff): Remove after the backward compatibility period.
  56. #include "absl/base/internal/dynamic_annotations.h" // IWYU pragma: export
  57. // -------------------------------------------------------------------------
  58. // Decide which features are enabled.
  59. #ifdef ABSL_HAVE_THREAD_SANITIZER
  60. #define ABSL_INTERNAL_RACE_ANNOTATIONS_ENABLED 1
  61. #define ABSL_INTERNAL_READS_ANNOTATIONS_ENABLED 1
  62. #define ABSL_INTERNAL_WRITES_ANNOTATIONS_ENABLED 1
  63. #define ABSL_INTERNAL_ANNOTALYSIS_ENABLED 0
  64. #define ABSL_INTERNAL_READS_WRITES_ANNOTATIONS_ENABLED 1
  65. #else
  66. #define ABSL_INTERNAL_RACE_ANNOTATIONS_ENABLED 0
  67. #define ABSL_INTERNAL_READS_ANNOTATIONS_ENABLED 0
  68. #define ABSL_INTERNAL_WRITES_ANNOTATIONS_ENABLED 0
  69. // Clang provides limited support for static thread-safety analysis through a
  70. // feature called Annotalysis. We configure macro-definitions according to
  71. // whether Annotalysis support is available. When running in opt-mode, GCC
  72. // will issue a warning, if these attributes are compiled. Only include them
  73. // when compiling using Clang.
  74. #if defined(__clang__)
  75. #define ABSL_INTERNAL_ANNOTALYSIS_ENABLED 1
  76. #if !defined(SWIG)
  77. #define ABSL_INTERNAL_IGNORE_READS_ATTRIBUTE_ENABLED 1
  78. #endif
  79. #else
  80. #define ABSL_INTERNAL_ANNOTALYSIS_ENABLED 0
  81. #endif
  82. // Read/write annotations are enabled in Annotalysis mode; disabled otherwise.
  83. #define ABSL_INTERNAL_READS_WRITES_ANNOTATIONS_ENABLED \
  84. ABSL_INTERNAL_ANNOTALYSIS_ENABLED
  85. #endif // ABSL_HAVE_THREAD_SANITIZER
  86. #ifdef __cplusplus
  87. #define ABSL_INTERNAL_BEGIN_EXTERN_C extern "C" {
  88. #define ABSL_INTERNAL_END_EXTERN_C } // extern "C"
  89. #define ABSL_INTERNAL_GLOBAL_SCOPED(F) ::F
  90. #define ABSL_INTERNAL_STATIC_INLINE inline
  91. #else
  92. #define ABSL_INTERNAL_BEGIN_EXTERN_C // empty
  93. #define ABSL_INTERNAL_END_EXTERN_C // empty
  94. #define ABSL_INTERNAL_GLOBAL_SCOPED(F) F
  95. #define ABSL_INTERNAL_STATIC_INLINE static inline
  96. #endif
  97. // -------------------------------------------------------------------------
  98. // Define race annotations.
  99. #if ABSL_INTERNAL_RACE_ANNOTATIONS_ENABLED == 1
  100. // Some of the symbols used in this section (e.g. AnnotateBenignRaceSized) are
  101. // defined by the compiler-based sanitizer implementation, not by the Abseil
  102. // library. Therefore they do not use ABSL_INTERNAL_C_SYMBOL.
  103. // -------------------------------------------------------------
  104. // Annotations that suppress errors. It is usually better to express the
  105. // program's synchronization using the other annotations, but these can be used
  106. // when all else fails.
  107. // Report that we may have a benign race at `pointer`, with size
  108. // "sizeof(*(pointer))". `pointer` must be a non-void* pointer. Insert at the
  109. // point where `pointer` has been allocated, preferably close to the point
  110. // where the race happens. See also ABSL_ANNOTATE_BENIGN_RACE_STATIC.
  111. #define ABSL_ANNOTATE_BENIGN_RACE(pointer, description) \
  112. ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateBenignRaceSized) \
  113. (__FILE__, __LINE__, pointer, sizeof(*(pointer)), description)
  114. // Same as ABSL_ANNOTATE_BENIGN_RACE(`address`, `description`), but applies to
  115. // the memory range [`address`, `address`+`size`).
  116. #define ABSL_ANNOTATE_BENIGN_RACE_SIZED(address, size, description) \
  117. ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateBenignRaceSized) \
  118. (__FILE__, __LINE__, address, size, description)
  119. // Enable (`enable`!=0) or disable (`enable`==0) race detection for all threads.
  120. // This annotation could be useful if you want to skip expensive race analysis
  121. // during some period of program execution, e.g. during initialization.
  122. #define ABSL_ANNOTATE_ENABLE_RACE_DETECTION(enable) \
  123. ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateEnableRaceDetection) \
  124. (__FILE__, __LINE__, enable)
  125. // -------------------------------------------------------------
  126. // Annotations useful for debugging.
  127. // Report the current thread `name` to a race detector.
  128. #define ABSL_ANNOTATE_THREAD_NAME(name) \
  129. ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateThreadName)(__FILE__, __LINE__, name)
  130. // -------------------------------------------------------------
  131. // Annotations useful when implementing locks. They are not normally needed by
  132. // modules that merely use locks. The `lock` argument is a pointer to the lock
  133. // object.
  134. // Report that a lock has been created at address `lock`.
  135. #define ABSL_ANNOTATE_RWLOCK_CREATE(lock) \
  136. ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateRWLockCreate)(__FILE__, __LINE__, lock)
  137. // Report that a linker initialized lock has been created at address `lock`.
  138. #ifdef ABSL_HAVE_THREAD_SANITIZER
  139. #define ABSL_ANNOTATE_RWLOCK_CREATE_STATIC(lock) \
  140. ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateRWLockCreateStatic) \
  141. (__FILE__, __LINE__, lock)
  142. #else
  143. #define ABSL_ANNOTATE_RWLOCK_CREATE_STATIC(lock) \
  144. ABSL_ANNOTATE_RWLOCK_CREATE(lock)
  145. #endif
  146. // Report that the lock at address `lock` is about to be destroyed.
  147. #define ABSL_ANNOTATE_RWLOCK_DESTROY(lock) \
  148. ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateRWLockDestroy)(__FILE__, __LINE__, lock)
  149. // Report that the lock at address `lock` has been acquired.
  150. // `is_w`=1 for writer lock, `is_w`=0 for reader lock.
  151. #define ABSL_ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) \
  152. ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateRWLockAcquired) \
  153. (__FILE__, __LINE__, lock, is_w)
  154. // Report that the lock at address `lock` is about to be released.
  155. // `is_w`=1 for writer lock, `is_w`=0 for reader lock.
  156. #define ABSL_ANNOTATE_RWLOCK_RELEASED(lock, is_w) \
  157. ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateRWLockReleased) \
  158. (__FILE__, __LINE__, lock, is_w)
  159. // Apply ABSL_ANNOTATE_BENIGN_RACE_SIZED to a static variable `static_var`.
  160. #define ABSL_ANNOTATE_BENIGN_RACE_STATIC(static_var, description) \
  161. namespace { \
  162. class static_var##_annotator { \
  163. public: \
  164. static_var##_annotator() { \
  165. ABSL_ANNOTATE_BENIGN_RACE_SIZED(&static_var, sizeof(static_var), \
  166. #static_var ": " description); \
  167. } \
  168. }; \
  169. static static_var##_annotator the##static_var##_annotator; \
  170. } // namespace
  171. // Function prototypes of annotations provided by the compiler-based sanitizer
  172. // implementation.
  173. ABSL_INTERNAL_BEGIN_EXTERN_C
  174. void AnnotateRWLockCreate(const char* file, int line,
  175. const volatile void* lock);
  176. void AnnotateRWLockCreateStatic(const char* file, int line,
  177. const volatile void* lock);
  178. void AnnotateRWLockDestroy(const char* file, int line,
  179. const volatile void* lock);
  180. void AnnotateRWLockAcquired(const char* file, int line,
  181. const volatile void* lock, long is_w); // NOLINT
  182. void AnnotateRWLockReleased(const char* file, int line,
  183. const volatile void* lock, long is_w); // NOLINT
  184. void AnnotateBenignRace(const char* file, int line,
  185. const volatile void* address, const char* description);
  186. void AnnotateBenignRaceSized(const char* file, int line,
  187. const volatile void* address, size_t size,
  188. const char* description);
  189. void AnnotateThreadName(const char* file, int line, const char* name);
  190. void AnnotateEnableRaceDetection(const char* file, int line, int enable);
  191. ABSL_INTERNAL_END_EXTERN_C
  192. #else // ABSL_INTERNAL_RACE_ANNOTATIONS_ENABLED == 0
  193. #define ABSL_ANNOTATE_RWLOCK_CREATE(lock) // empty
  194. #define ABSL_ANNOTATE_RWLOCK_CREATE_STATIC(lock) // empty
  195. #define ABSL_ANNOTATE_RWLOCK_DESTROY(lock) // empty
  196. #define ABSL_ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) // empty
  197. #define ABSL_ANNOTATE_RWLOCK_RELEASED(lock, is_w) // empty
  198. #define ABSL_ANNOTATE_BENIGN_RACE(address, description) // empty
  199. #define ABSL_ANNOTATE_BENIGN_RACE_SIZED(address, size, description) // empty
  200. #define ABSL_ANNOTATE_THREAD_NAME(name) // empty
  201. #define ABSL_ANNOTATE_ENABLE_RACE_DETECTION(enable) // empty
  202. #define ABSL_ANNOTATE_BENIGN_RACE_STATIC(static_var, description) // empty
  203. #endif // ABSL_INTERNAL_RACE_ANNOTATIONS_ENABLED
  204. // -------------------------------------------------------------------------
  205. // Define memory annotations.
  206. #ifdef ABSL_HAVE_MEMORY_SANITIZER
  207. #include <sanitizer/msan_interface.h>
  208. #define ABSL_ANNOTATE_MEMORY_IS_INITIALIZED(address, size) \
  209. __msan_unpoison(address, size)
  210. #define ABSL_ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size) \
  211. __msan_allocated_memory(address, size)
  212. #else // !defined(ABSL_HAVE_MEMORY_SANITIZER)
  213. // TODO(rogeeff): remove this branch
  214. #ifdef ABSL_HAVE_THREAD_SANITIZER
  215. #define ABSL_ANNOTATE_MEMORY_IS_INITIALIZED(address, size) \
  216. do { \
  217. (void)(address); \
  218. (void)(size); \
  219. } while (0)
  220. #define ABSL_ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size) \
  221. do { \
  222. (void)(address); \
  223. (void)(size); \
  224. } while (0)
  225. #else
  226. #define ABSL_ANNOTATE_MEMORY_IS_INITIALIZED(address, size) // empty
  227. #define ABSL_ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size) // empty
  228. #endif
  229. #endif // ABSL_HAVE_MEMORY_SANITIZER
  230. // -------------------------------------------------------------------------
  231. // Define IGNORE_READS_BEGIN/_END attributes.
  232. #if defined(ABSL_INTERNAL_IGNORE_READS_ATTRIBUTE_ENABLED)
  233. #define ABSL_INTERNAL_IGNORE_READS_BEGIN_ATTRIBUTE \
  234. __attribute((exclusive_lock_function("*")))
  235. #define ABSL_INTERNAL_IGNORE_READS_END_ATTRIBUTE \
  236. __attribute((unlock_function("*")))
  237. #else // !defined(ABSL_INTERNAL_IGNORE_READS_ATTRIBUTE_ENABLED)
  238. #define ABSL_INTERNAL_IGNORE_READS_BEGIN_ATTRIBUTE // empty
  239. #define ABSL_INTERNAL_IGNORE_READS_END_ATTRIBUTE // empty
  240. #endif // defined(ABSL_INTERNAL_IGNORE_READS_ATTRIBUTE_ENABLED)
  241. // -------------------------------------------------------------------------
  242. // Define IGNORE_READS_BEGIN/_END annotations.
  243. #if ABSL_INTERNAL_READS_ANNOTATIONS_ENABLED == 1
  244. // Some of the symbols used in this section (e.g. AnnotateIgnoreReadsBegin) are
  245. // defined by the compiler-based implementation, not by the Abseil
  246. // library. Therefore they do not use ABSL_INTERNAL_C_SYMBOL.
  247. // Request the analysis tool to ignore all reads in the current thread until
  248. // ABSL_ANNOTATE_IGNORE_READS_END is called. Useful to ignore intentional racey
  249. // reads, while still checking other reads and all writes.
  250. // See also ABSL_ANNOTATE_UNPROTECTED_READ.
  251. #define ABSL_ANNOTATE_IGNORE_READS_BEGIN() \
  252. ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateIgnoreReadsBegin) \
  253. (__FILE__, __LINE__)
  254. // Stop ignoring reads.
  255. #define ABSL_ANNOTATE_IGNORE_READS_END() \
  256. ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateIgnoreReadsEnd) \
  257. (__FILE__, __LINE__)
  258. // Function prototypes of annotations provided by the compiler-based sanitizer
  259. // implementation.
  260. ABSL_INTERNAL_BEGIN_EXTERN_C
  261. void AnnotateIgnoreReadsBegin(const char* file, int line)
  262. ABSL_INTERNAL_IGNORE_READS_BEGIN_ATTRIBUTE;
  263. void AnnotateIgnoreReadsEnd(const char* file,
  264. int line) ABSL_INTERNAL_IGNORE_READS_END_ATTRIBUTE;
  265. ABSL_INTERNAL_END_EXTERN_C
  266. #elif defined(ABSL_INTERNAL_ANNOTALYSIS_ENABLED)
  267. // When Annotalysis is enabled without Dynamic Annotations, the use of
  268. // static-inline functions allows the annotations to be read at compile-time,
  269. // while still letting the compiler elide the functions from the final build.
  270. //
  271. // TODO(delesley) -- The exclusive lock here ignores writes as well, but
  272. // allows IGNORE_READS_AND_WRITES to work properly.
  273. #define ABSL_ANNOTATE_IGNORE_READS_BEGIN() \
  274. ABSL_INTERNAL_GLOBAL_SCOPED( \
  275. ABSL_INTERNAL_C_SYMBOL(AbslInternalAnnotateIgnoreReadsBegin)) \
  276. ()
  277. #define ABSL_ANNOTATE_IGNORE_READS_END() \
  278. ABSL_INTERNAL_GLOBAL_SCOPED( \
  279. ABSL_INTERNAL_C_SYMBOL(AbslInternalAnnotateIgnoreReadsEnd)) \
  280. ()
  281. ABSL_INTERNAL_STATIC_INLINE void ABSL_INTERNAL_C_SYMBOL(
  282. AbslInternalAnnotateIgnoreReadsBegin)()
  283. ABSL_INTERNAL_IGNORE_READS_BEGIN_ATTRIBUTE {}
  284. ABSL_INTERNAL_STATIC_INLINE void ABSL_INTERNAL_C_SYMBOL(
  285. AbslInternalAnnotateIgnoreReadsEnd)()
  286. ABSL_INTERNAL_IGNORE_READS_END_ATTRIBUTE {}
  287. #else
  288. #define ABSL_ANNOTATE_IGNORE_READS_BEGIN() // empty
  289. #define ABSL_ANNOTATE_IGNORE_READS_END() // empty
  290. #endif
  291. // -------------------------------------------------------------------------
  292. // Define IGNORE_WRITES_BEGIN/_END annotations.
  293. #if ABSL_INTERNAL_WRITES_ANNOTATIONS_ENABLED == 1
  294. // Similar to ABSL_ANNOTATE_IGNORE_READS_BEGIN, but ignore writes instead.
  295. #define ABSL_ANNOTATE_IGNORE_WRITES_BEGIN() \
  296. ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateIgnoreWritesBegin)(__FILE__, __LINE__)
  297. // Stop ignoring writes.
  298. #define ABSL_ANNOTATE_IGNORE_WRITES_END() \
  299. ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateIgnoreWritesEnd)(__FILE__, __LINE__)
  300. // Function prototypes of annotations provided by the compiler-based sanitizer
  301. // implementation.
  302. ABSL_INTERNAL_BEGIN_EXTERN_C
  303. void AnnotateIgnoreWritesBegin(const char* file, int line);
  304. void AnnotateIgnoreWritesEnd(const char* file, int line);
  305. ABSL_INTERNAL_END_EXTERN_C
  306. #else
  307. #define ABSL_ANNOTATE_IGNORE_WRITES_BEGIN() // empty
  308. #define ABSL_ANNOTATE_IGNORE_WRITES_END() // empty
  309. #endif
  310. // -------------------------------------------------------------------------
  311. // Define the ABSL_ANNOTATE_IGNORE_READS_AND_WRITES_* annotations using the more
  312. // primitive annotations defined above.
  313. //
  314. // Instead of doing
  315. // ABSL_ANNOTATE_IGNORE_READS_BEGIN();
  316. // ... = x;
  317. // ABSL_ANNOTATE_IGNORE_READS_END();
  318. // one can use
  319. // ... = ABSL_ANNOTATE_UNPROTECTED_READ(x);
  320. #if defined(ABSL_INTERNAL_READS_WRITES_ANNOTATIONS_ENABLED)
  321. // Start ignoring all memory accesses (both reads and writes).
  322. #define ABSL_ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() \
  323. do { \
  324. ABSL_ANNOTATE_IGNORE_READS_BEGIN(); \
  325. ABSL_ANNOTATE_IGNORE_WRITES_BEGIN(); \
  326. } while (0)
  327. // Stop ignoring both reads and writes.
  328. #define ABSL_ANNOTATE_IGNORE_READS_AND_WRITES_END() \
  329. do { \
  330. ABSL_ANNOTATE_IGNORE_WRITES_END(); \
  331. ABSL_ANNOTATE_IGNORE_READS_END(); \
  332. } while (0)
  333. #ifdef __cplusplus
  334. // ABSL_ANNOTATE_UNPROTECTED_READ is the preferred way to annotate racey reads.
  335. #define ABSL_ANNOTATE_UNPROTECTED_READ(x) \
  336. absl::base_internal::AnnotateUnprotectedRead(x)
  337. namespace absl {
  338. ABSL_NAMESPACE_BEGIN
  339. namespace base_internal {
  340. template <typename T>
  341. inline T AnnotateUnprotectedRead(const volatile T& x) { // NOLINT
  342. ABSL_ANNOTATE_IGNORE_READS_BEGIN();
  343. T res = x;
  344. ABSL_ANNOTATE_IGNORE_READS_END();
  345. return res;
  346. }
  347. } // namespace base_internal
  348. ABSL_NAMESPACE_END
  349. } // namespace absl
  350. #endif
  351. #else
  352. #define ABSL_ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() // empty
  353. #define ABSL_ANNOTATE_IGNORE_READS_AND_WRITES_END() // empty
  354. #define ABSL_ANNOTATE_UNPROTECTED_READ(x) (x)
  355. #endif
  356. // -------------------------------------------------------------------------
  357. // Address sanitizer annotations
  358. #ifdef ABSL_HAVE_ADDRESS_SANITIZER
  359. // Describe the current state of a contiguous container such as e.g.
  360. // std::vector or std::string. For more details see
  361. // sanitizer/common_interface_defs.h, which is provided by the compiler.
  362. #include <sanitizer/common_interface_defs.h>
  363. #define ABSL_ANNOTATE_CONTIGUOUS_CONTAINER(beg, end, old_mid, new_mid) \
  364. __sanitizer_annotate_contiguous_container(beg, end, old_mid, new_mid)
  365. #define ABSL_ADDRESS_SANITIZER_REDZONE(name) \
  366. struct { \
  367. alignas(8) char x[8]; \
  368. } name
  369. #else
  370. #define ABSL_ANNOTATE_CONTIGUOUS_CONTAINER(beg, end, old_mid, new_mid) // empty
  371. #define ABSL_ADDRESS_SANITIZER_REDZONE(name) static_assert(true, "")
  372. #endif // ABSL_HAVE_ADDRESS_SANITIZER
  373. // -------------------------------------------------------------------------
  374. // HWAddress sanitizer annotations
  375. #ifdef __cplusplus
  376. namespace absl {
  377. #ifdef ABSL_HAVE_HWADDRESS_SANITIZER
  378. // Under HWASAN changes the tag of the pointer.
  379. template <typename T>
  380. T* HwasanTagPointer(T* ptr, uintptr_t tag) {
  381. return reinterpret_cast<T*>(__hwasan_tag_pointer(ptr, tag));
  382. }
  383. #else
  384. template <typename T>
  385. T* HwasanTagPointer(T* ptr, uintptr_t) {
  386. return ptr;
  387. }
  388. #endif
  389. } // namespace absl
  390. #endif
  391. // -------------------------------------------------------------------------
  392. // Undefine the macros intended only for this file.
  393. #undef ABSL_INTERNAL_RACE_ANNOTATIONS_ENABLED
  394. #undef ABSL_INTERNAL_READS_ANNOTATIONS_ENABLED
  395. #undef ABSL_INTERNAL_WRITES_ANNOTATIONS_ENABLED
  396. #undef ABSL_INTERNAL_ANNOTALYSIS_ENABLED
  397. #undef ABSL_INTERNAL_READS_WRITES_ANNOTATIONS_ENABLED
  398. #undef ABSL_INTERNAL_BEGIN_EXTERN_C
  399. #undef ABSL_INTERNAL_END_EXTERN_C
  400. #undef ABSL_INTERNAL_STATIC_INLINE
  401. #endif // ABSL_BASE_DYNAMIC_ANNOTATIONS_H_