[hwasan] remove more stale code

llvm-svn: 340985
This commit is contained in:
Kostya Serebryany 2018-08-29 22:47:53 +00:00
parent 4e864b8329
commit 87bc568eca
3 changed files with 27 additions and 57 deletions

View File

@ -39,7 +39,7 @@ static void UnmapFromTo(uptr from, uptr to) {
// shadow_size_bytes bytes on the right of it are mapped r/o. // shadow_size_bytes bytes on the right of it are mapped r/o.
static uptr MapDynamicShadow(uptr shadow_size_bytes) { static uptr MapDynamicShadow(uptr shadow_size_bytes) {
const uptr granularity = GetMmapGranularity(); const uptr granularity = GetMmapGranularity();
const uptr alignment = granularity * SHADOW_GRANULARITY; const uptr alignment = granularity << kShadowScale;
const uptr left_padding = granularity; const uptr left_padding = granularity;
const uptr shadow_size = const uptr shadow_size =
RoundUpTo(shadow_size_bytes, granularity); RoundUpTo(shadow_size_bytes, granularity);

View File

@ -101,51 +101,38 @@ static void PrintAddressSpaceLayout() {
else else
CHECK_EQ(kHighShadowEnd + 1, kHighMemStart); CHECK_EQ(kHighShadowEnd + 1, kHighMemStart);
PrintRange(kHighShadowStart, kHighShadowEnd, "HighShadow"); PrintRange(kHighShadowStart, kHighShadowEnd, "HighShadow");
if (SHADOW_OFFSET) { if (kLowShadowEnd + 1 < kHighShadowStart)
if (kLowShadowEnd + 1 < kHighShadowStart) PrintRange(kLowShadowEnd + 1, kHighShadowStart - 1, "ShadowGap");
PrintRange(kLowShadowEnd + 1, kHighShadowStart - 1, "ShadowGap"); else
else CHECK_EQ(kLowMemEnd + 1, kHighShadowStart);
CHECK_EQ(kLowMemEnd + 1, kHighShadowStart); PrintRange(kLowShadowStart, kLowShadowEnd, "LowShadow");
PrintRange(kLowShadowStart, kLowShadowEnd, "LowShadow"); if (kLowMemEnd + 1 < kLowShadowStart)
if (kLowMemEnd + 1 < kLowShadowStart) PrintRange(kLowMemEnd + 1, kLowShadowStart - 1, "ShadowGap");
PrintRange(kLowMemEnd + 1, kLowShadowStart - 1, "ShadowGap"); else
else CHECK_EQ(kLowMemEnd + 1, kLowShadowStart);
CHECK_EQ(kLowMemEnd + 1, kLowShadowStart); PrintRange(kLowMemStart, kLowMemEnd, "LowMem");
PrintRange(kLowMemStart, kLowMemEnd, "LowMem"); CHECK_EQ(0, kLowMemStart);
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");
}
} }
static uptr GetHighMemEnd() { static uptr GetHighMemEnd() {
// HighMem covers the upper part of the address space. // HighMem covers the upper part of the address space.
uptr max_address = GetMaxUserVirtualAddress(); uptr max_address = GetMaxUserVirtualAddress();
if (SHADOW_OFFSET) // Adjust max address to make sure that kHighMemEnd and kHighMemStart are
// Adjust max address to make sure that kHighMemEnd and kHighMemStart are // properly aligned:
// properly aligned: max_address |= (GetMmapGranularity() << kShadowScale) - 1;
max_address |= SHADOW_GRANULARITY * GetMmapGranularity() - 1;
return max_address; return max_address;
} }
static void InitializeShadowBaseAddress(uptr shadow_size_bytes) { static void InitializeShadowBaseAddress(uptr shadow_size_bytes) {
// Set the shadow memory address to uninitialized. // Set the shadow memory address to uninitialized.
__hwasan_shadow_memory_dynamic_address = kDefaultShadowSentinel; __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 // Detect if a dynamic shadow address must be used and find the available
// location when necessary. When dynamic address is used, the macro // location when necessary. When dynamic address is used, the macro
// kLowShadowBeg expands to __hwasan_shadow_memory_dynamic_address which // kLowShadowBeg expands to __hwasan_shadow_memory_dynamic_address which
// was just set to kDefaultShadowSentinel. // was just set to kDefaultShadowSentinel.
if (shadow_start == kDefaultShadowSentinel) { if (shadow_start == kDefaultShadowSentinel) {
__hwasan_shadow_memory_dynamic_address = 0; __hwasan_shadow_memory_dynamic_address = 0;
CHECK_EQ(0, SHADOW_OFFSET);
shadow_start = FindDynamicShadowStart(shadow_size_bytes); shadow_start = FindDynamicShadowStart(shadow_size_bytes);
} }
// Update the shadow memory address (potentially) used by instrumentation. // Update the shadow memory address (potentially) used by instrumentation.
@ -160,18 +147,12 @@ bool InitShadow() {
InitializeShadowBaseAddress(MemToShadowSize(kHighMemEnd)); InitializeShadowBaseAddress(MemToShadowSize(kHighMemEnd));
// Place the low memory first. // Place the low memory first.
if (SHADOW_OFFSET) { kLowMemEnd = __hwasan_shadow_memory_dynamic_address - 1;
kLowMemEnd = SHADOW_OFFSET - 1; kLowMemStart = 0;
kLowMemStart = 0;
} else {
// LowMem covers as much of the first 4GB as possible.
kLowMemEnd = (1UL << 32) - 1;
kLowMemStart = MemToShadow(kLowMemEnd) + 1;
}
// Define the low shadow based on the already placed low memory. // Define the low shadow based on the already placed low memory.
kLowShadowEnd = MemToShadow(kLowMemEnd); 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 // High shadow takes whatever memory is left up there (making sure it is not
// interfering with low memory in the fixed case). // interfering with low memory in the fixed case).
@ -188,10 +169,7 @@ bool InitShadow() {
CHECK_GT(kHighShadowStart, kLowMemEnd); CHECK_GT(kHighShadowStart, kLowMemEnd);
CHECK_GT(kLowMemEnd, kLowMemStart); CHECK_GT(kLowMemEnd, kLowMemStart);
CHECK_GT(kLowShadowEnd, kLowShadowStart); CHECK_GT(kLowShadowEnd, kLowShadowStart);
if (SHADOW_OFFSET) CHECK_GT(kLowShadowStart, kLowMemEnd);
CHECK_GT(kLowShadowStart, kLowMemEnd);
else
CHECK_GT(kLowMemEnd, kLowShadowStart);
if (Verbosity()) if (Verbosity())
PrintAddressSpaceLayout(); PrintAddressSpaceLayout();
@ -202,15 +180,10 @@ bool InitShadow() {
// Protect all the gaps. // Protect all the gaps.
ProtectGap(0, Min(kLowMemStart, kLowShadowStart)); ProtectGap(0, Min(kLowMemStart, kLowShadowStart));
if (SHADOW_OFFSET) { if (kLowMemEnd + 1 < kLowShadowStart)
if (kLowMemEnd + 1 < kLowShadowStart) ProtectGap(kLowMemEnd + 1, kLowShadowStart - kLowMemEnd - 1);
ProtectGap(kLowMemEnd + 1, kLowShadowStart - kLowMemEnd - 1); if (kLowShadowEnd + 1 < kHighShadowStart)
if (kLowShadowEnd + 1 < kHighShadowStart) ProtectGap(kLowShadowEnd + 1, kHighShadowStart - kLowShadowEnd - 1);
ProtectGap(kLowShadowEnd + 1, kHighShadowStart - kLowShadowEnd - 1);
} else {
if (kLowMemEnd + 1 < kHighShadowStart)
ProtectGap(kLowMemEnd + 1, kHighShadowStart - kLowMemEnd - 1);
}
if (kHighShadowEnd + 1 < kHighMemStart) if (kHighShadowEnd + 1 < kHighMemStart)
ProtectGap(kHighShadowEnd + 1, kHighMemStart - kHighShadowEnd - 1); ProtectGap(kHighShadowEnd + 1, kHighMemStart - kHighShadowEnd - 1);

View File

@ -54,17 +54,14 @@ static constexpr u64 kDefaultShadowSentinel = ~(u64)0;
constexpr uptr kShadowScale = 4; constexpr uptr kShadowScale = 4;
constexpr uptr kShadowAlignment = 1ULL << kShadowScale; constexpr uptr kShadowAlignment = 1ULL << kShadowScale;
#define SHADOW_OFFSET (__hwasan_shadow_memory_dynamic_address)
#define SHADOW_GRANULARITY (1ULL << kShadowScale)
namespace __hwasan { namespace __hwasan {
inline uptr MemToShadow(uptr untagged_addr) { 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) { 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) { inline uptr MemToShadowSize(uptr size) {
return size >> kShadowScale; return size >> kShadowScale;