diff --git a/compiler-rt/lib/hwasan/hwasan.h b/compiler-rt/lib/hwasan/hwasan.h --- a/compiler-rt/lib/hwasan/hwasan.h +++ b/compiler-rt/lib/hwasan/hwasan.h @@ -16,6 +16,7 @@ #include "hwasan_flags.h" #include "hwasan_interface_internal.h" +#include "hwasan_mapping.h" #include "sanitizer_common/sanitizer_common.h" #include "sanitizer_common/sanitizer_flags.h" #include "sanitizer_common/sanitizer_internal_defs.h" @@ -78,6 +79,16 @@ const unsigned kRecordFPLShift = 4; const unsigned kRecordFPModulus = 1 << (64 - kRecordFPShift + kRecordFPLShift); +static inline bool InTaggableRegion(uptr addr) { +#if defined(HWASAN_ALIASING_MODE) + // Aliases are mapped next to shadow so that the upper bits match the shadow + // base. + return (addr >> kTaggableRegionCheckShift) == + (__hwasan::GetShadowOffset() >> kTaggableRegionCheckShift); +#endif + return true; +} + static inline tag_t GetTagFromPointer(uptr p) { return (p >> kAddressTagShift) & kTagMask; } diff --git a/compiler-rt/lib/hwasan/hwasan_allocator.h b/compiler-rt/lib/hwasan/hwasan_allocator.h --- a/compiler-rt/lib/hwasan/hwasan_allocator.h +++ b/compiler-rt/lib/hwasan/hwasan_allocator.h @@ -127,16 +127,6 @@ void GetAllocatorStats(AllocatorStatCounters s); -inline bool InTaggableRegion(uptr addr) { -#if defined(HWASAN_ALIASING_MODE) - // Aliases are mapped next to shadow so that the upper bits match the shadow - // base. - return (addr >> kTaggableRegionCheckShift) == - (GetShadowOffset() >> kTaggableRegionCheckShift); -#endif - return true; -} - } // namespace __hwasan #endif // HWASAN_ALLOCATOR_H diff --git a/compiler-rt/lib/hwasan/hwasan_allocator.cpp b/compiler-rt/lib/hwasan/hwasan_allocator.cpp --- a/compiler-rt/lib/hwasan/hwasan_allocator.cpp +++ b/compiler-rt/lib/hwasan/hwasan_allocator.cpp @@ -417,7 +417,7 @@ static const void *AllocationBegin(const void *p) { const void *untagged_ptr = - __hwasan::InTaggableRegion(reinterpret_cast(p)) ? UntagPtr(p) : p; + InTaggableRegion(reinterpret_cast(p)) ? UntagPtr(p) : p; if (!untagged_ptr) return nullptr; @@ -435,7 +435,7 @@ static uptr AllocationSize(const void *p) { const void *untagged_ptr = - __hwasan::InTaggableRegion(reinterpret_cast(p)) ? UntagPtr(p) : p; + InTaggableRegion(reinterpret_cast(p)) ? UntagPtr(p) : p; if (!untagged_ptr) return 0; const void *beg = allocator.GetBlockBegin(untagged_ptr); if (!beg) @@ -549,7 +549,7 @@ } uptr PointsIntoChunk(void *p) { - p = __hwasan::InTaggableRegion(reinterpret_cast(p)) ? UntagPtr(p) : p; + p = InTaggableRegion(reinterpret_cast(p)) ? UntagPtr(p) : p; uptr addr = reinterpret_cast(p); uptr chunk = reinterpret_cast(__hwasan::allocator.GetBlockBeginFastLocked(p)); @@ -567,7 +567,7 @@ } uptr GetUserBegin(uptr chunk) { - if (__hwasan::InTaggableRegion(chunk)) + if (InTaggableRegion(chunk)) CHECK_EQ(UntagAddr(chunk), chunk); void *block = __hwasan::allocator.GetBlockBeginFastLocked( reinterpret_cast(chunk)); @@ -583,13 +583,13 @@ uptr GetUserAddr(uptr chunk) { tag_t mem_tag = *(tag_t *)__hwasan::MemToShadow(chunk); - if (!__hwasan::InTaggableRegion(chunk)) + if (!InTaggableRegion(chunk)) return chunk; return AddTagToPointer(chunk, mem_tag); } LsanMetadata::LsanMetadata(uptr chunk) { - if (__hwasan::InTaggableRegion(chunk)) + if (InTaggableRegion(chunk)) CHECK_EQ(UntagAddr(chunk), chunk); metadata_ = chunk ? __hwasan::allocator.GetMetaData(reinterpret_cast(chunk)) @@ -628,7 +628,7 @@ } IgnoreObjectResult IgnoreObject(const void *p) { - p = __hwasan::InTaggableRegion(reinterpret_cast(p)) ? UntagPtr(p) : p; + p = InTaggableRegion(reinterpret_cast(p)) ? UntagPtr(p) : p; uptr addr = reinterpret_cast(p); uptr chunk = reinterpret_cast(__hwasan::allocator.GetBlockBegin(p)); if (!chunk)