aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2023-04-26 16:20:04 -0700
committerVitaly Buka <vitalybuka@google.com>2023-04-26 19:52:21 -0700
commitfd85a6df1d9336601207a80ea65502d86c78f750 (patch)
treec6eefdd58204fabf53169e16c2e5c445bebaabf6
parent9a1e60c586dc12fc6aaf592478ed036f219e508e (diff)
downloadllvm-fd85a6df1d9336601207a80ea65502d86c78f750.zip
llvm-fd85a6df1d9336601207a80ea65502d86c78f750.tar.gz
llvm-fd85a6df1d9336601207a80ea65502d86c78f750.tar.bz2
[NFC][HWASAN] Move InTaggableRegion
Prepare to use it in all tag related functions. Reviewed By: thurston Differential Revision: https://reviews.llvm.org/D149304
-rw-r--r--compiler-rt/lib/hwasan/hwasan.h11
-rw-r--r--compiler-rt/lib/hwasan/hwasan_allocator.cpp14
-rw-r--r--compiler-rt/lib/hwasan/hwasan_allocator.h10
3 files changed, 18 insertions, 17 deletions
diff --git a/compiler-rt/lib/hwasan/hwasan.h b/compiler-rt/lib/hwasan/hwasan.h
index c3d71a2..0e85b1b 100644
--- 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 kRecordFPShift = 48;
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.cpp b/compiler-rt/lib/hwasan/hwasan_allocator.cpp
index 585d907..e7650c0 100644
--- a/compiler-rt/lib/hwasan/hwasan_allocator.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_allocator.cpp
@@ -417,7 +417,7 @@ HwasanChunkView FindHeapChunkByAddress(uptr address) {
static const void *AllocationBegin(const void *p) {
const void *untagged_ptr =
- __hwasan::InTaggableRegion(reinterpret_cast<uptr>(p)) ? UntagPtr(p) : p;
+ InTaggableRegion(reinterpret_cast<uptr>(p)) ? UntagPtr(p) : p;
if (!untagged_ptr)
return nullptr;
@@ -435,7 +435,7 @@ static const void *AllocationBegin(const void *p) {
static uptr AllocationSize(const void *p) {
const void *untagged_ptr =
- __hwasan::InTaggableRegion(reinterpret_cast<uptr>(p)) ? UntagPtr(p) : p;
+ InTaggableRegion(reinterpret_cast<uptr>(p)) ? UntagPtr(p) : p;
if (!untagged_ptr) return 0;
const void *beg = allocator.GetBlockBegin(untagged_ptr);
if (!beg)
@@ -549,7 +549,7 @@ void GetAllocatorGlobalRange(uptr *begin, uptr *end) {
}
uptr PointsIntoChunk(void *p) {
- p = __hwasan::InTaggableRegion(reinterpret_cast<uptr>(p)) ? UntagPtr(p) : p;
+ p = InTaggableRegion(reinterpret_cast<uptr>(p)) ? UntagPtr(p) : p;
uptr addr = reinterpret_cast<uptr>(p);
uptr chunk =
reinterpret_cast<uptr>(__hwasan::allocator.GetBlockBeginFastLocked(p));
@@ -567,7 +567,7 @@ uptr PointsIntoChunk(void *p) {
}
uptr GetUserBegin(uptr chunk) {
- if (__hwasan::InTaggableRegion(chunk))
+ if (InTaggableRegion(chunk))
CHECK_EQ(UntagAddr(chunk), chunk);
void *block = __hwasan::allocator.GetBlockBeginFastLocked(
reinterpret_cast<void *>(chunk));
@@ -583,13 +583,13 @@ uptr GetUserBegin(uptr chunk) {
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<void *>(chunk))
@@ -628,7 +628,7 @@ void ForEachChunk(ForEachChunkCallback callback, void *arg) {
}
IgnoreObjectResult IgnoreObject(const void *p) {
- p = __hwasan::InTaggableRegion(reinterpret_cast<uptr>(p)) ? UntagPtr(p) : p;
+ p = InTaggableRegion(reinterpret_cast<uptr>(p)) ? UntagPtr(p) : p;
uptr addr = reinterpret_cast<uptr>(p);
uptr chunk = reinterpret_cast<uptr>(__hwasan::allocator.GetBlockBegin(p));
if (!chunk)
diff --git a/compiler-rt/lib/hwasan/hwasan_allocator.h b/compiler-rt/lib/hwasan/hwasan_allocator.h
index b7a06da..ecf3f68 100644
--- a/compiler-rt/lib/hwasan/hwasan_allocator.h
+++ b/compiler-rt/lib/hwasan/hwasan_allocator.h
@@ -127,16 +127,6 @@ typedef RingBuffer<HeapAllocationRecord> HeapAllocationsRingBuffer;
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