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

It's NOOP without HWASAN.

PiperOrigin-RevId: 543045322
Change-Id: Ibb5f28d316bfc5e8aa51861fd55e50ecb517a9a3
This commit is contained in:
Abseil Team
2023-06-23 23:10:38 -07:00
committed by Copybara-Service
parent 34eb767645
commit 474d21b580

View File

@@ -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.
// -------------------------------------------------------------
@@ -456,6 +461,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.