From 87bc568eca2748dcbaec8886d0b3e947c1075d06 Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Wed, 29 Aug 2018 22:47:53 +0000 Subject: [PATCH] [hwasan] remove more stale code llvm-svn: 340985 --- .../lib/hwasan/hwasan_dynamic_shadow.cc | 2 +- compiler-rt/lib/hwasan/hwasan_linux.cc | 73 ++++++------------- compiler-rt/lib/hwasan/hwasan_mapping.h | 9 +-- 3 files changed, 27 insertions(+), 57 deletions(-) diff --git a/compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cc b/compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cc index e95f48e4a631..06682e60a9eb 100644 --- a/compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cc +++ b/compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cc @@ -39,7 +39,7 @@ static void UnmapFromTo(uptr from, uptr to) { // shadow_size_bytes bytes on the right of it are mapped r/o. static uptr MapDynamicShadow(uptr shadow_size_bytes) { const uptr granularity = GetMmapGranularity(); - const uptr alignment = granularity * SHADOW_GRANULARITY; + const uptr alignment = granularity << kShadowScale; const uptr left_padding = granularity; const uptr shadow_size = RoundUpTo(shadow_size_bytes, granularity); diff --git a/compiler-rt/lib/hwasan/hwasan_linux.cc b/compiler-rt/lib/hwasan/hwasan_linux.cc index 9da3bbe8c429..ac952b35116d 100644 --- a/compiler-rt/lib/hwasan/hwasan_linux.cc +++ b/compiler-rt/lib/hwasan/hwasan_linux.cc @@ -101,51 +101,38 @@ static void PrintAddressSpaceLayout() { else CHECK_EQ(kHighShadowEnd + 1, kHighMemStart); PrintRange(kHighShadowStart, kHighShadowEnd, "HighShadow"); - if (SHADOW_OFFSET) { - if (kLowShadowEnd + 1 < kHighShadowStart) - PrintRange(kLowShadowEnd + 1, kHighShadowStart - 1, "ShadowGap"); - else - CHECK_EQ(kLowMemEnd + 1, kHighShadowStart); - PrintRange(kLowShadowStart, kLowShadowEnd, "LowShadow"); - if (kLowMemEnd + 1 < kLowShadowStart) - PrintRange(kLowMemEnd + 1, kLowShadowStart - 1, "ShadowGap"); - else - CHECK_EQ(kLowMemEnd + 1, kLowShadowStart); - PrintRange(kLowMemStart, kLowMemEnd, "LowMem"); - CHECK_EQ(0, kLowMemStart); - } else { - if (kLowMemEnd + 1 < kHighShadowStart) - PrintRange(kLowMemEnd + 1, kHighShadowStart - 1, "ShadowGap"); - else - CHECK_EQ(kLowMemEnd + 1, kHighShadowStart); - PrintRange(kLowMemStart, kLowMemEnd, "LowMem"); - CHECK_EQ(kLowShadowEnd + 1, kLowMemStart); - PrintRange(kLowShadowStart, kLowShadowEnd, "LowShadow"); - PrintRange(0, kLowShadowStart - 1, "ShadowGap"); - } + if (kLowShadowEnd + 1 < kHighShadowStart) + PrintRange(kLowShadowEnd + 1, kHighShadowStart - 1, "ShadowGap"); + else + CHECK_EQ(kLowMemEnd + 1, kHighShadowStart); + PrintRange(kLowShadowStart, kLowShadowEnd, "LowShadow"); + if (kLowMemEnd + 1 < kLowShadowStart) + PrintRange(kLowMemEnd + 1, kLowShadowStart - 1, "ShadowGap"); + else + CHECK_EQ(kLowMemEnd + 1, kLowShadowStart); + PrintRange(kLowMemStart, kLowMemEnd, "LowMem"); + CHECK_EQ(0, kLowMemStart); } static uptr GetHighMemEnd() { // HighMem covers the upper part of the address space. uptr max_address = GetMaxUserVirtualAddress(); - if (SHADOW_OFFSET) - // Adjust max address to make sure that kHighMemEnd and kHighMemStart are - // properly aligned: - max_address |= SHADOW_GRANULARITY * GetMmapGranularity() - 1; + // Adjust max address to make sure that kHighMemEnd and kHighMemStart are + // properly aligned: + max_address |= (GetMmapGranularity() << kShadowScale) - 1; return max_address; } static void InitializeShadowBaseAddress(uptr shadow_size_bytes) { // Set the shadow memory address to uninitialized. __hwasan_shadow_memory_dynamic_address = kDefaultShadowSentinel; - uptr shadow_start = SHADOW_OFFSET; + uptr shadow_start = __hwasan_shadow_memory_dynamic_address; // Detect if a dynamic shadow address must be used and find the available // location when necessary. When dynamic address is used, the macro // kLowShadowBeg expands to __hwasan_shadow_memory_dynamic_address which // was just set to kDefaultShadowSentinel. if (shadow_start == kDefaultShadowSentinel) { __hwasan_shadow_memory_dynamic_address = 0; - CHECK_EQ(0, SHADOW_OFFSET); shadow_start = FindDynamicShadowStart(shadow_size_bytes); } // Update the shadow memory address (potentially) used by instrumentation. @@ -160,18 +147,12 @@ bool InitShadow() { InitializeShadowBaseAddress(MemToShadowSize(kHighMemEnd)); // Place the low memory first. - if (SHADOW_OFFSET) { - kLowMemEnd = SHADOW_OFFSET - 1; - kLowMemStart = 0; - } else { - // LowMem covers as much of the first 4GB as possible. - kLowMemEnd = (1UL << 32) - 1; - kLowMemStart = MemToShadow(kLowMemEnd) + 1; - } + kLowMemEnd = __hwasan_shadow_memory_dynamic_address - 1; + kLowMemStart = 0; // Define the low shadow based on the already placed low memory. kLowShadowEnd = MemToShadow(kLowMemEnd); - kLowShadowStart = SHADOW_OFFSET ? SHADOW_OFFSET : MemToShadow(kLowMemStart); + kLowShadowStart = __hwasan_shadow_memory_dynamic_address; // High shadow takes whatever memory is left up there (making sure it is not // interfering with low memory in the fixed case). @@ -188,10 +169,7 @@ bool InitShadow() { CHECK_GT(kHighShadowStart, kLowMemEnd); CHECK_GT(kLowMemEnd, kLowMemStart); CHECK_GT(kLowShadowEnd, kLowShadowStart); - if (SHADOW_OFFSET) - CHECK_GT(kLowShadowStart, kLowMemEnd); - else - CHECK_GT(kLowMemEnd, kLowShadowStart); + CHECK_GT(kLowShadowStart, kLowMemEnd); if (Verbosity()) PrintAddressSpaceLayout(); @@ -202,15 +180,10 @@ bool InitShadow() { // Protect all the gaps. ProtectGap(0, Min(kLowMemStart, kLowShadowStart)); - if (SHADOW_OFFSET) { - if (kLowMemEnd + 1 < kLowShadowStart) - ProtectGap(kLowMemEnd + 1, kLowShadowStart - kLowMemEnd - 1); - if (kLowShadowEnd + 1 < kHighShadowStart) - ProtectGap(kLowShadowEnd + 1, kHighShadowStart - kLowShadowEnd - 1); - } else { - if (kLowMemEnd + 1 < kHighShadowStart) - ProtectGap(kLowMemEnd + 1, kHighShadowStart - kLowMemEnd - 1); - } + if (kLowMemEnd + 1 < kLowShadowStart) + ProtectGap(kLowMemEnd + 1, kLowShadowStart - kLowMemEnd - 1); + if (kLowShadowEnd + 1 < kHighShadowStart) + ProtectGap(kLowShadowEnd + 1, kHighShadowStart - kLowShadowEnd - 1); if (kHighShadowEnd + 1 < kHighMemStart) ProtectGap(kHighShadowEnd + 1, kHighMemStart - kHighShadowEnd - 1); diff --git a/compiler-rt/lib/hwasan/hwasan_mapping.h b/compiler-rt/lib/hwasan/hwasan_mapping.h index b12e98620d47..e204a5bdbe48 100644 --- a/compiler-rt/lib/hwasan/hwasan_mapping.h +++ b/compiler-rt/lib/hwasan/hwasan_mapping.h @@ -54,17 +54,14 @@ static constexpr u64 kDefaultShadowSentinel = ~(u64)0; constexpr uptr kShadowScale = 4; constexpr uptr kShadowAlignment = 1ULL << kShadowScale; -#define SHADOW_OFFSET (__hwasan_shadow_memory_dynamic_address) - -#define SHADOW_GRANULARITY (1ULL << kShadowScale) - namespace __hwasan { inline uptr MemToShadow(uptr untagged_addr) { - return (untagged_addr >> kShadowScale) + SHADOW_OFFSET; + return (untagged_addr >> kShadowScale) + + __hwasan_shadow_memory_dynamic_address; } inline uptr ShadowToMem(uptr shadow_addr) { - return (shadow_addr - SHADOW_OFFSET) << kShadowScale; + return (shadow_addr - __hwasan_shadow_memory_dynamic_address) << kShadowScale; } inline uptr MemToShadowSize(uptr size) { return size >> kShadowScale;