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