/src/LPM/external.protobuf/include/absl/base/dynamic_annotations.h
Line | Count | Source (jump to first uncovered line) |
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 | | #if !defined(SWIG) |
90 | | #define ABSL_INTERNAL_IGNORE_READS_ATTRIBUTE_ENABLED 1 |
91 | | #endif |
92 | | #else |
93 | | #define ABSL_INTERNAL_ANNOTALYSIS_ENABLED 0 |
94 | | #endif |
95 | | |
96 | | // Read/write annotations are enabled in Annotalysis mode; disabled otherwise. |
97 | | #define ABSL_INTERNAL_READS_WRITES_ANNOTATIONS_ENABLED \ |
98 | | ABSL_INTERNAL_ANNOTALYSIS_ENABLED |
99 | | |
100 | | #endif // ABSL_HAVE_THREAD_SANITIZER |
101 | | |
102 | | #ifdef __cplusplus |
103 | | #define ABSL_INTERNAL_BEGIN_EXTERN_C extern "C" { |
104 | | #define ABSL_INTERNAL_END_EXTERN_C } // extern "C" |
105 | | #define ABSL_INTERNAL_GLOBAL_SCOPED(F) ::F |
106 | | #define ABSL_INTERNAL_STATIC_INLINE inline |
107 | | #else |
108 | | #define ABSL_INTERNAL_BEGIN_EXTERN_C // empty |
109 | | #define ABSL_INTERNAL_END_EXTERN_C // empty |
110 | | #define ABSL_INTERNAL_GLOBAL_SCOPED(F) F |
111 | | #define ABSL_INTERNAL_STATIC_INLINE static inline |
112 | | #endif |
113 | | |
114 | | // ------------------------------------------------------------------------- |
115 | | // Define race annotations. |
116 | | |
117 | | #if ABSL_INTERNAL_RACE_ANNOTATIONS_ENABLED == 1 |
118 | | // Some of the symbols used in this section (e.g. AnnotateBenignRaceSized) are |
119 | | // defined by the compiler-based sanitizer implementation, not by the Abseil |
120 | | // library. Therefore they do not use ABSL_INTERNAL_C_SYMBOL. |
121 | | |
122 | | // ------------------------------------------------------------- |
123 | | // Annotations that suppress errors. It is usually better to express the |
124 | | // program's synchronization using the other annotations, but these can be used |
125 | | // when all else fails. |
126 | | |
127 | | // Report that we may have a benign race at `pointer`, with size |
128 | | // "sizeof(*(pointer))". `pointer` must be a non-void* pointer. Insert at the |
129 | | // point where `pointer` has been allocated, preferably close to the point |
130 | | // where the race happens. See also ABSL_ANNOTATE_BENIGN_RACE_STATIC. |
131 | | #define ABSL_ANNOTATE_BENIGN_RACE(pointer, description) \ |
132 | | ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateBenignRaceSized) \ |
133 | | (__FILE__, __LINE__, pointer, sizeof(*(pointer)), description) |
134 | | |
135 | | // Same as ABSL_ANNOTATE_BENIGN_RACE(`address`, `description`), but applies to |
136 | | // the memory range [`address`, `address`+`size`). |
137 | | #define ABSL_ANNOTATE_BENIGN_RACE_SIZED(address, size, description) \ |
138 | | ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateBenignRaceSized) \ |
139 | | (__FILE__, __LINE__, address, size, description) |
140 | | |
141 | | // Enable (`enable`!=0) or disable (`enable`==0) race detection for all threads. |
142 | | // This annotation could be useful if you want to skip expensive race analysis |
143 | | // during some period of program execution, e.g. during initialization. |
144 | | #define ABSL_ANNOTATE_ENABLE_RACE_DETECTION(enable) \ |
145 | | ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateEnableRaceDetection) \ |
146 | | (__FILE__, __LINE__, enable) |
147 | | |
148 | | // ------------------------------------------------------------- |
149 | | // Annotations useful for debugging. |
150 | | |
151 | | // Report the current thread `name` to a race detector. |
152 | | #define ABSL_ANNOTATE_THREAD_NAME(name) \ |
153 | | ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateThreadName)(__FILE__, __LINE__, name) |
154 | | |
155 | | // ------------------------------------------------------------- |
156 | | // Annotations useful when implementing locks. They are not normally needed by |
157 | | // modules that merely use locks. The `lock` argument is a pointer to the lock |
158 | | // object. |
159 | | |
160 | | // Report that a lock has been created at address `lock`. |
161 | | #define ABSL_ANNOTATE_RWLOCK_CREATE(lock) \ |
162 | | ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateRWLockCreate)(__FILE__, __LINE__, lock) |
163 | | |
164 | | // Report that a linker initialized lock has been created at address `lock`. |
165 | | #ifdef ABSL_HAVE_THREAD_SANITIZER |
166 | | #define ABSL_ANNOTATE_RWLOCK_CREATE_STATIC(lock) \ |
167 | | ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateRWLockCreateStatic) \ |
168 | | (__FILE__, __LINE__, lock) |
169 | | #else |
170 | | #define ABSL_ANNOTATE_RWLOCK_CREATE_STATIC(lock) \ |
171 | | ABSL_ANNOTATE_RWLOCK_CREATE(lock) |
172 | | #endif |
173 | | |
174 | | // Report that the lock at address `lock` is about to be destroyed. |
175 | | #define ABSL_ANNOTATE_RWLOCK_DESTROY(lock) \ |
176 | | ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateRWLockDestroy)(__FILE__, __LINE__, lock) |
177 | | |
178 | | // Report that the lock at address `lock` has been acquired. |
179 | | // `is_w`=1 for writer lock, `is_w`=0 for reader lock. |
180 | | #define ABSL_ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) \ |
181 | | ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateRWLockAcquired) \ |
182 | | (__FILE__, __LINE__, lock, is_w) |
183 | | |
184 | | // Report that the lock at address `lock` is about to be released. |
185 | | // `is_w`=1 for writer lock, `is_w`=0 for reader lock. |
186 | | #define ABSL_ANNOTATE_RWLOCK_RELEASED(lock, is_w) \ |
187 | | ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateRWLockReleased) \ |
188 | | (__FILE__, __LINE__, lock, is_w) |
189 | | |
190 | | // Apply ABSL_ANNOTATE_BENIGN_RACE_SIZED to a static variable `static_var`. |
191 | | #define ABSL_ANNOTATE_BENIGN_RACE_STATIC(static_var, description) \ |
192 | | namespace { \ |
193 | | class static_var##_annotator { \ |
194 | | public: \ |
195 | | static_var##_annotator() { \ |
196 | | ABSL_ANNOTATE_BENIGN_RACE_SIZED(&static_var, sizeof(static_var), \ |
197 | | #static_var ": " description); \ |
198 | | } \ |
199 | | }; \ |
200 | | static static_var##_annotator the##static_var##_annotator; \ |
201 | | } // namespace |
202 | | |
203 | | // Function prototypes of annotations provided by the compiler-based sanitizer |
204 | | // implementation. |
205 | | ABSL_INTERNAL_BEGIN_EXTERN_C |
206 | | void AnnotateRWLockCreate(const char* file, int line, |
207 | | const volatile void* lock); |
208 | | void AnnotateRWLockCreateStatic(const char* file, int line, |
209 | | const volatile void* lock); |
210 | | void AnnotateRWLockDestroy(const char* file, int line, |
211 | | const volatile void* lock); |
212 | | void AnnotateRWLockAcquired(const char* file, int line, |
213 | | const volatile void* lock, long is_w); // NOLINT |
214 | | void AnnotateRWLockReleased(const char* file, int line, |
215 | | const volatile void* lock, long is_w); // NOLINT |
216 | | void AnnotateBenignRace(const char* file, int line, |
217 | | const volatile void* address, const char* description); |
218 | | void AnnotateBenignRaceSized(const char* file, int line, |
219 | | const volatile void* address, size_t size, |
220 | | const char* description); |
221 | | void AnnotateThreadName(const char* file, int line, const char* name); |
222 | | void AnnotateEnableRaceDetection(const char* file, int line, int enable); |
223 | | ABSL_INTERNAL_END_EXTERN_C |
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 | | // TODO(rogeeff): remove this branch |
256 | | #ifdef ABSL_HAVE_THREAD_SANITIZER |
257 | | #define ABSL_ANNOTATE_MEMORY_IS_INITIALIZED(address, size) \ |
258 | | do { \ |
259 | | (void)(address); \ |
260 | | (void)(size); \ |
261 | | } while (0) |
262 | | #define ABSL_ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size) \ |
263 | | do { \ |
264 | | (void)(address); \ |
265 | | (void)(size); \ |
266 | | } while (0) |
267 | | #else |
268 | | |
269 | | #define ABSL_ANNOTATE_MEMORY_IS_INITIALIZED(address, size) // empty |
270 | | #define ABSL_ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size) // empty |
271 | | |
272 | | #endif |
273 | | |
274 | | #endif // ABSL_HAVE_MEMORY_SANITIZER |
275 | | |
276 | | // ------------------------------------------------------------------------- |
277 | | // Define IGNORE_READS_BEGIN/_END attributes. |
278 | | |
279 | | #if defined(ABSL_INTERNAL_IGNORE_READS_ATTRIBUTE_ENABLED) |
280 | | |
281 | | #define ABSL_INTERNAL_IGNORE_READS_BEGIN_ATTRIBUTE \ |
282 | | __attribute((exclusive_lock_function("*"))) |
283 | | #define ABSL_INTERNAL_IGNORE_READS_END_ATTRIBUTE \ |
284 | | __attribute((unlock_function("*"))) |
285 | | |
286 | | #else // !defined(ABSL_INTERNAL_IGNORE_READS_ATTRIBUTE_ENABLED) |
287 | | |
288 | | #define ABSL_INTERNAL_IGNORE_READS_BEGIN_ATTRIBUTE // empty |
289 | | #define ABSL_INTERNAL_IGNORE_READS_END_ATTRIBUTE // empty |
290 | | |
291 | | #endif // defined(ABSL_INTERNAL_IGNORE_READS_ATTRIBUTE_ENABLED) |
292 | | |
293 | | // ------------------------------------------------------------------------- |
294 | | // Define IGNORE_READS_BEGIN/_END annotations. |
295 | | |
296 | | #if ABSL_INTERNAL_READS_ANNOTATIONS_ENABLED == 1 |
297 | | // Some of the symbols used in this section (e.g. AnnotateIgnoreReadsBegin) are |
298 | | // defined by the compiler-based implementation, not by the Abseil |
299 | | // library. Therefore they do not use ABSL_INTERNAL_C_SYMBOL. |
300 | | |
301 | | // Request the analysis tool to ignore all reads in the current thread until |
302 | | // ABSL_ANNOTATE_IGNORE_READS_END is called. Useful to ignore intentional racey |
303 | | // reads, while still checking other reads and all writes. |
304 | | // See also ABSL_ANNOTATE_UNPROTECTED_READ. |
305 | | #define ABSL_ANNOTATE_IGNORE_READS_BEGIN() \ |
306 | | ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateIgnoreReadsBegin) \ |
307 | | (__FILE__, __LINE__) |
308 | | |
309 | | // Stop ignoring reads. |
310 | | #define ABSL_ANNOTATE_IGNORE_READS_END() \ |
311 | | ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateIgnoreReadsEnd) \ |
312 | | (__FILE__, __LINE__) |
313 | | |
314 | | // Function prototypes of annotations provided by the compiler-based sanitizer |
315 | | // implementation. |
316 | | ABSL_INTERNAL_BEGIN_EXTERN_C |
317 | | void AnnotateIgnoreReadsBegin(const char* file, int line) |
318 | | ABSL_INTERNAL_IGNORE_READS_BEGIN_ATTRIBUTE; |
319 | | void AnnotateIgnoreReadsEnd(const char* file, |
320 | | int line) ABSL_INTERNAL_IGNORE_READS_END_ATTRIBUTE; |
321 | | ABSL_INTERNAL_END_EXTERN_C |
322 | | |
323 | | #elif defined(ABSL_INTERNAL_ANNOTALYSIS_ENABLED) |
324 | | |
325 | | // When Annotalysis is enabled without Dynamic Annotations, the use of |
326 | | // static-inline functions allows the annotations to be read at compile-time, |
327 | | // while still letting the compiler elide the functions from the final build. |
328 | | // |
329 | | // TODO(delesley) -- The exclusive lock here ignores writes as well, but |
330 | | // allows IGNORE_READS_AND_WRITES to work properly. |
331 | | |
332 | | #define ABSL_ANNOTATE_IGNORE_READS_BEGIN() \ |
333 | | ABSL_INTERNAL_GLOBAL_SCOPED( \ |
334 | | ABSL_INTERNAL_C_SYMBOL(AbslInternalAnnotateIgnoreReadsBegin)) \ |
335 | | () |
336 | | |
337 | | #define ABSL_ANNOTATE_IGNORE_READS_END() \ |
338 | | ABSL_INTERNAL_GLOBAL_SCOPED( \ |
339 | | ABSL_INTERNAL_C_SYMBOL(AbslInternalAnnotateIgnoreReadsEnd)) \ |
340 | | () |
341 | | |
342 | | ABSL_INTERNAL_STATIC_INLINE void ABSL_INTERNAL_C_SYMBOL( |
343 | | AbslInternalAnnotateIgnoreReadsBegin)() |
344 | 0 | ABSL_INTERNAL_IGNORE_READS_BEGIN_ATTRIBUTE {} |
345 | | |
346 | | ABSL_INTERNAL_STATIC_INLINE void ABSL_INTERNAL_C_SYMBOL( |
347 | | AbslInternalAnnotateIgnoreReadsEnd)() |
348 | 0 | ABSL_INTERNAL_IGNORE_READS_END_ATTRIBUTE {} |
349 | | |
350 | | #else |
351 | | |
352 | | #define ABSL_ANNOTATE_IGNORE_READS_BEGIN() // empty |
353 | | #define ABSL_ANNOTATE_IGNORE_READS_END() // empty |
354 | | |
355 | | #endif |
356 | | |
357 | | // ------------------------------------------------------------------------- |
358 | | // Define IGNORE_WRITES_BEGIN/_END annotations. |
359 | | |
360 | | #if ABSL_INTERNAL_WRITES_ANNOTATIONS_ENABLED == 1 |
361 | | |
362 | | // Similar to ABSL_ANNOTATE_IGNORE_READS_BEGIN, but ignore writes instead. |
363 | | #define ABSL_ANNOTATE_IGNORE_WRITES_BEGIN() \ |
364 | | ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateIgnoreWritesBegin)(__FILE__, __LINE__) |
365 | | |
366 | | // Stop ignoring writes. |
367 | | #define ABSL_ANNOTATE_IGNORE_WRITES_END() \ |
368 | | ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateIgnoreWritesEnd)(__FILE__, __LINE__) |
369 | | |
370 | | // Function prototypes of annotations provided by the compiler-based sanitizer |
371 | | // implementation. |
372 | | ABSL_INTERNAL_BEGIN_EXTERN_C |
373 | | void AnnotateIgnoreWritesBegin(const char* file, int line); |
374 | | void AnnotateIgnoreWritesEnd(const char* file, int line); |
375 | | ABSL_INTERNAL_END_EXTERN_C |
376 | | |
377 | | #else |
378 | | |
379 | | #define ABSL_ANNOTATE_IGNORE_WRITES_BEGIN() // empty |
380 | | #define ABSL_ANNOTATE_IGNORE_WRITES_END() // empty |
381 | | |
382 | | #endif |
383 | | |
384 | | // ------------------------------------------------------------------------- |
385 | | // Define the ABSL_ANNOTATE_IGNORE_READS_AND_WRITES_* annotations using the more |
386 | | // primitive annotations defined above. |
387 | | // |
388 | | // Instead of doing |
389 | | // ABSL_ANNOTATE_IGNORE_READS_BEGIN(); |
390 | | // ... = x; |
391 | | // ABSL_ANNOTATE_IGNORE_READS_END(); |
392 | | // one can use |
393 | | // ... = ABSL_ANNOTATE_UNPROTECTED_READ(x); |
394 | | |
395 | | #if defined(ABSL_INTERNAL_READS_WRITES_ANNOTATIONS_ENABLED) |
396 | | |
397 | | // Start ignoring all memory accesses (both reads and writes). |
398 | | #define ABSL_ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() \ |
399 | | do { \ |
400 | | ABSL_ANNOTATE_IGNORE_READS_BEGIN(); \ |
401 | | ABSL_ANNOTATE_IGNORE_WRITES_BEGIN(); \ |
402 | | } while (0) |
403 | | |
404 | | // Stop ignoring both reads and writes. |
405 | | #define ABSL_ANNOTATE_IGNORE_READS_AND_WRITES_END() \ |
406 | | do { \ |
407 | | ABSL_ANNOTATE_IGNORE_WRITES_END(); \ |
408 | | ABSL_ANNOTATE_IGNORE_READS_END(); \ |
409 | | } while (0) |
410 | | |
411 | | #ifdef __cplusplus |
412 | | // ABSL_ANNOTATE_UNPROTECTED_READ is the preferred way to annotate racey reads. |
413 | | #define ABSL_ANNOTATE_UNPROTECTED_READ(x) \ |
414 | | absl::base_internal::AnnotateUnprotectedRead(x) |
415 | | |
416 | | namespace absl { |
417 | | ABSL_NAMESPACE_BEGIN |
418 | | namespace base_internal { |
419 | | |
420 | | template <typename T> |
421 | | inline T AnnotateUnprotectedRead(const volatile T& x) { // NOLINT |
422 | | ABSL_ANNOTATE_IGNORE_READS_BEGIN(); |
423 | | T res = x; |
424 | | ABSL_ANNOTATE_IGNORE_READS_END(); |
425 | | return res; |
426 | | } |
427 | | |
428 | | } // namespace base_internal |
429 | | ABSL_NAMESPACE_END |
430 | | } // namespace absl |
431 | | #endif |
432 | | |
433 | | #else |
434 | | |
435 | | #define ABSL_ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() // empty |
436 | | #define ABSL_ANNOTATE_IGNORE_READS_AND_WRITES_END() // empty |
437 | | #define ABSL_ANNOTATE_UNPROTECTED_READ(x) (x) |
438 | | |
439 | | #endif |
440 | | |
441 | | // ------------------------------------------------------------------------- |
442 | | // Address sanitizer annotations |
443 | | |
444 | | #ifdef ABSL_HAVE_ADDRESS_SANITIZER |
445 | | // Describe the current state of a contiguous container such as e.g. |
446 | | // std::vector or std::string. For more details see |
447 | | // sanitizer/common_interface_defs.h, which is provided by the compiler. |
448 | | #include <sanitizer/common_interface_defs.h> |
449 | | |
450 | | #define ABSL_ANNOTATE_CONTIGUOUS_CONTAINER(beg, end, old_mid, new_mid) \ |
451 | | __sanitizer_annotate_contiguous_container(beg, end, old_mid, new_mid) |
452 | | #define ABSL_ADDRESS_SANITIZER_REDZONE(name) \ |
453 | | struct { \ |
454 | | alignas(8) char x[8]; \ |
455 | | } name |
456 | | |
457 | | #else |
458 | | |
459 | | #define ABSL_ANNOTATE_CONTIGUOUS_CONTAINER(beg, end, old_mid, new_mid) // empty |
460 | | #define ABSL_ADDRESS_SANITIZER_REDZONE(name) static_assert(true, "") |
461 | | |
462 | | #endif // ABSL_HAVE_ADDRESS_SANITIZER |
463 | | |
464 | | // ------------------------------------------------------------------------- |
465 | | // HWAddress sanitizer annotations |
466 | | |
467 | | #ifdef __cplusplus |
468 | | namespace absl { |
469 | | #ifdef ABSL_HAVE_HWADDRESS_SANITIZER |
470 | | // Under HWASAN changes the tag of the pointer. |
471 | | template <typename T> |
472 | | T* HwasanTagPointer(T* ptr, uintptr_t tag) { |
473 | | return reinterpret_cast<T*>(__hwasan_tag_pointer(ptr, tag)); |
474 | | } |
475 | | #else |
476 | | template <typename T> |
477 | | T* HwasanTagPointer(T* ptr, uintptr_t) { |
478 | | return ptr; |
479 | | } |
480 | | #endif |
481 | | } // namespace absl |
482 | | #endif |
483 | | |
484 | | // ------------------------------------------------------------------------- |
485 | | // Undefine the macros intended only for this file. |
486 | | |
487 | | #undef ABSL_INTERNAL_RACE_ANNOTATIONS_ENABLED |
488 | | #undef ABSL_INTERNAL_READS_ANNOTATIONS_ENABLED |
489 | | #undef ABSL_INTERNAL_WRITES_ANNOTATIONS_ENABLED |
490 | | #undef ABSL_INTERNAL_ANNOTALYSIS_ENABLED |
491 | | #undef ABSL_INTERNAL_READS_WRITES_ANNOTATIONS_ENABLED |
492 | | #undef ABSL_INTERNAL_BEGIN_EXTERN_C |
493 | | #undef ABSL_INTERNAL_END_EXTERN_C |
494 | | #undef ABSL_INTERNAL_STATIC_INLINE |
495 | | |
496 | | #endif // ABSL_BASE_DYNAMIC_ANNOTATIONS_H_ |