diff options
author | 2023-06-23 23:10:38 -0700 | |
---|---|---|
committer | 2023-06-23 23:11:25 -0700 | |
commit | 474d21b580e2765aec2e85d2995bf45820be258e (patch) | |
tree | 1a1918ac0daa0866d718824ac39d26ce57b41352 /absl/base/dynamic_annotations.h | |
parent | 34eb767645347f100bdd66fc1e35eee96e357961 (diff) |
Add absl::HwasanTagPointer() to allow users to change HWASAN tags
It's NOOP without HWASAN.
PiperOrigin-RevId: 543045322
Change-Id: Ibb5f28d316bfc5e8aa51861fd55e50ecb517a9a3
Diffstat (limited to 'absl/base/dynamic_annotations.h')
-rw-r--r-- | absl/base/dynamic_annotations.h | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/absl/base/dynamic_annotations.h b/absl/base/dynamic_annotations.h index 3ea7c156..7ba8912e 100644 --- a/absl/base/dynamic_annotations.h +++ b/absl/base/dynamic_annotations.h @@ -46,6 +46,7 @@ #define ABSL_BASE_DYNAMIC_ANNOTATIONS_H_ #include <stddef.h> +#include <stdint.h> #include "absl/base/attributes.h" #include "absl/base/config.h" @@ -53,6 +54,10 @@ #include "absl/base/macros.h" #endif +#ifdef ABSL_HAVE_HWADDRESS_SANITIZER +#include <sanitizer/hwasan_interface.h> +#endif + // TODO(rogeeff): Remove after the backward compatibility period. #include "absl/base/internal/dynamic_annotations.h" // IWYU pragma: export @@ -111,7 +116,7 @@ #if ABSL_INTERNAL_RACE_ANNOTATIONS_ENABLED == 1 // Some of the symbols used in this section (e.g. AnnotateBenignRaceSized) are -// defined by the compiler-based santizer implementation, not by the Abseil +// defined by the compiler-based sanitizer implementation, not by the Abseil // library. Therefore they do not use ABSL_INTERNAL_C_SYMBOL. // ------------------------------------------------------------- @@ -457,6 +462,26 @@ ABSL_NAMESPACE_END #endif // ABSL_HAVE_ADDRESS_SANITIZER // ------------------------------------------------------------------------- +// HWAddress sanitizer annotations + +#ifdef __cplusplus +namespace absl { +#ifdef ABSL_HAVE_HWADDRESS_SANITIZER +// Under HWASAN changes the tag of the pointer. +template <typename T> +T* HwasanTagPointer(T* ptr, uintptr_t tag) { + return reinterpret_cast<T*>(__hwasan_tag_pointer(ptr, tag)); +} +#else +template <typename T> +T* HwasanTagPointer(T* ptr, uintptr_t) { + return ptr; +} +#endif +} // namespace absl +#endif + +// ------------------------------------------------------------------------- // Undefine the macros intended only for this file. #undef ABSL_INTERNAL_RACE_ANNOTATIONS_ENABLED |