[compiler-rt] 189c552 - [compiler-rt][hwasan] Refactor kAliasRegionStart usage
Leonard Chan via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 12 16:35:17 PDT 2021
Author: Leonard Chan
Date: 2021-07-12T16:33:05-07:00
New Revision: 189c55251849076e17ddab590c1302f4af0e60f8
URL: https://github.com/llvm/llvm-project/commit/189c55251849076e17ddab590c1302f4af0e60f8
DIFF: https://github.com/llvm/llvm-project/commit/189c55251849076e17ddab590c1302f4af0e60f8.diff
LOG: [compiler-rt][hwasan] Refactor kAliasRegionStart usage
This moves logic for setting kAliasRegionStart into hwasan_allocator.cpp
so other platforms that do not support aliasing mode will not need to define
kAliasRegionStart.
Differential Revision: https://reviews.llvm.org/D105725
Added:
Modified:
compiler-rt/lib/hwasan/hwasan_allocator.cpp
compiler-rt/lib/hwasan/hwasan_linux.cpp
compiler-rt/lib/hwasan/hwasan_mapping.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/hwasan/hwasan_allocator.cpp b/compiler-rt/lib/hwasan/hwasan_allocator.cpp
index e53de53e46d5c..ef6d4d6c7678e 100644
--- a/compiler-rt/lib/hwasan/hwasan_allocator.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_allocator.cpp
@@ -80,12 +80,29 @@ void GetAllocatorStats(AllocatorStatCounters s) {
allocator.GetStats(s);
}
+uptr GetAliasRegionStart() {
+#if defined(HWASAN_ALIASING_MODE)
+ constexpr uptr kAliasRegionOffset = 1ULL << (kTaggableRegionCheckShift - 1);
+ uptr AliasRegionStart =
+ __hwasan_shadow_memory_dynamic_address + kAliasRegionOffset;
+
+ CHECK_EQ(AliasRegionStart >> kTaggableRegionCheckShift,
+ __hwasan_shadow_memory_dynamic_address >> kTaggableRegionCheckShift);
+ CHECK_EQ(
+ (AliasRegionStart + kAliasRegionOffset - 1) >> kTaggableRegionCheckShift,
+ __hwasan_shadow_memory_dynamic_address >> kTaggableRegionCheckShift);
+ return AliasRegionStart;
+#else
+ return 0;
+#endif
+}
+
void HwasanAllocatorInit() {
atomic_store_relaxed(&hwasan_allocator_tagging_enabled,
!flags()->disable_allocator_tagging);
SetAllocatorMayReturnNull(common_flags()->allocator_may_return_null);
allocator.Init(common_flags()->allocator_release_to_os_interval_ms,
- kAliasRegionStart);
+ GetAliasRegionStart());
for (uptr i = 0; i < sizeof(tail_magic); i++)
tail_magic[i] = GetCurrentThread()->GenerateRandomTag();
}
diff --git a/compiler-rt/lib/hwasan/hwasan_linux.cpp b/compiler-rt/lib/hwasan/hwasan_linux.cpp
index c1569b90a9e4b..e22723529f449 100644
--- a/compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_linux.cpp
@@ -72,8 +72,6 @@ uptr kLowMemEnd;
uptr kHighMemStart;
uptr kHighMemEnd;
-uptr kAliasRegionStart; // Always 0 when aliases aren't used.
-
static void PrintRange(uptr start, uptr end, const char *name) {
Printf("|| [%p, %p] || %.*s ||\n", (void *)start, (void *)end, 10, name);
}
@@ -194,18 +192,6 @@ bool InitShadow() {
// High memory starts where allocated shadow allows.
kHighMemStart = ShadowToMem(kHighShadowStart);
-# if defined(HWASAN_ALIASING_MODE)
- constexpr uptr kAliasRegionOffset = 1ULL << (kTaggableRegionCheckShift - 1);
- kAliasRegionStart =
- __hwasan_shadow_memory_dynamic_address + kAliasRegionOffset;
-
- CHECK_EQ(kAliasRegionStart >> kTaggableRegionCheckShift,
- __hwasan_shadow_memory_dynamic_address >> kTaggableRegionCheckShift);
- CHECK_EQ(
- (kAliasRegionStart + kAliasRegionOffset - 1) >> kTaggableRegionCheckShift,
- __hwasan_shadow_memory_dynamic_address >> kTaggableRegionCheckShift);
-# endif
-
// Check the sanity of the defined memory ranges (there might be gaps).
CHECK_EQ(kHighMemStart % GetMmapGranularity(), 0);
CHECK_GT(kHighMemStart, kHighShadowEnd);
diff --git a/compiler-rt/lib/hwasan/hwasan_mapping.h b/compiler-rt/lib/hwasan/hwasan_mapping.h
index fae66d5719e51..79a143632f6ab 100644
--- a/compiler-rt/lib/hwasan/hwasan_mapping.h
+++ b/compiler-rt/lib/hwasan/hwasan_mapping.h
@@ -48,8 +48,6 @@ extern uptr kHighShadowEnd;
extern uptr kHighMemStart;
extern uptr kHighMemEnd;
-extern uptr kAliasRegionStart;
-
inline uptr GetShadowOffset() {
return SANITIZER_FUCHSIA ? 0 : __hwasan_shadow_memory_dynamic_address;
}
@@ -70,6 +68,8 @@ inline bool MemIsShadow(uptr p) {
(kHighShadowStart <= p && p <= kHighShadowEnd);
}
+uptr GetAliasRegionStart();
+
} // namespace __hwasan
#endif // HWASAN_MAPPING_H
More information about the llvm-commits
mailing list