diff --git a/compiler-rt/include/sanitizer/hwasan_interface.h b/compiler-rt/include/sanitizer/hwasan_interface.h --- a/compiler-rt/include/sanitizer/hwasan_interface.h +++ b/compiler-rt/include/sanitizer/hwasan_interface.h @@ -40,6 +40,12 @@ void __hwasan_tag_memory(const volatile void *p, unsigned char tag, size_t size); + // Return an untagged version of the provided pointer. Provided to enable + // architecture- and runtime-independent untagging. Note that a tagged and an + // untagged pointer may be pointers to different memory, as is the case on x64 + // with page aliasing. + void *__hwasan_untag_pointer(const volatile void *p); + /// Set pointer tag. Previous tag is lost. void *__hwasan_tag_pointer(const volatile void *p, unsigned char tag); diff --git a/compiler-rt/lib/hwasan/hwasan.cpp b/compiler-rt/lib/hwasan/hwasan.cpp --- a/compiler-rt/lib/hwasan/hwasan.cpp +++ b/compiler-rt/lib/hwasan/hwasan.cpp @@ -448,6 +448,8 @@ TagMemoryAligned(p, sz, tag); } +uptr __hwasan_untag_pointer(uptr p) { return UntagAddr(p); } + uptr __hwasan_tag_pointer(uptr p, u8 tag) { return AddTagToPointer(p, tag); } diff --git a/compiler-rt/lib/hwasan/hwasan_interface_internal.h b/compiler-rt/lib/hwasan/hwasan_interface_internal.h --- a/compiler-rt/lib/hwasan/hwasan_interface_internal.h +++ b/compiler-rt/lib/hwasan/hwasan_interface_internal.h @@ -105,6 +105,9 @@ SANITIZER_INTERFACE_ATTRIBUTE void __hwasan_tag_memory(uptr p, u8 tag, uptr sz); +SANITIZER_INTERFACE_ATTRIBUTE +uptr __hwasan_untag_pointer(uptr p); + SANITIZER_INTERFACE_ATTRIBUTE uptr __hwasan_tag_pointer(uptr p, u8 tag);