Commit 474d21b5 by Abseil Team Committed by Copybara-Service

Add absl::HwasanTagPointer() to allow users to change HWASAN tags

It's NOOP without HWASAN.

PiperOrigin-RevId: 543045322
Change-Id: Ibb5f28d316bfc5e8aa51861fd55e50ecb517a9a3
parent 34eb7676
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#define ABSL_BASE_DYNAMIC_ANNOTATIONS_H_ #define ABSL_BASE_DYNAMIC_ANNOTATIONS_H_
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
#include "absl/base/attributes.h" #include "absl/base/attributes.h"
#include "absl/base/config.h" #include "absl/base/config.h"
...@@ -53,6 +54,10 @@ ...@@ -53,6 +54,10 @@
#include "absl/base/macros.h" #include "absl/base/macros.h"
#endif #endif
#ifdef ABSL_HAVE_HWADDRESS_SANITIZER
#include <sanitizer/hwasan_interface.h>
#endif
// TODO(rogeeff): Remove after the backward compatibility period. // TODO(rogeeff): Remove after the backward compatibility period.
#include "absl/base/internal/dynamic_annotations.h" // IWYU pragma: export #include "absl/base/internal/dynamic_annotations.h" // IWYU pragma: export
...@@ -111,7 +116,7 @@ ...@@ -111,7 +116,7 @@
#if ABSL_INTERNAL_RACE_ANNOTATIONS_ENABLED == 1 #if ABSL_INTERNAL_RACE_ANNOTATIONS_ENABLED == 1
// Some of the symbols used in this section (e.g. AnnotateBenignRaceSized) are // 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. // library. Therefore they do not use ABSL_INTERNAL_C_SYMBOL.
// ------------------------------------------------------------- // -------------------------------------------------------------
...@@ -457,6 +462,26 @@ ABSL_NAMESPACE_END ...@@ -457,6 +462,26 @@ ABSL_NAMESPACE_END
#endif // ABSL_HAVE_ADDRESS_SANITIZER #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. // Undefine the macros intended only for this file.
#undef ABSL_INTERNAL_RACE_ANNOTATIONS_ENABLED #undef ABSL_INTERNAL_RACE_ANNOTATIONS_ENABLED
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment