summaryrefslogtreecommitdiff
path: root/lib/esan
diff options
context:
space:
mode:
authorQin Zhao <zhaoqin@google.com>2016-09-08 16:09:46 +0000
committerQin Zhao <zhaoqin@google.com>2016-09-08 16:09:46 +0000
commit913a7aacf44cce8624785279414d4cb5c60e731c (patch)
tree8396576a9ea63bd30c10100c309e0e9d7df9cf7d /lib/esan
parent92655f0385f87c6fde76d19a84a9314e9f0b637c (diff)
Revert "[ESan][MIPS] Adds support for MIPS64"
Summary: This reverts commit 62b3eecdbe72af0255f0639b0446087a47efbf48. (D23799) The CL cause 13 ESan test failure on x86_64: Failing Tests (13): EfficiencySanitizer-x86_64 :: TestCases/large-stack-linux.c EfficiencySanitizer-x86_64 :: TestCases/libc-intercept.c EfficiencySanitizer-x86_64 :: TestCases/mmap-shadow-conflict.c EfficiencySanitizer-x86_64 :: TestCases/struct-simple.cpp EfficiencySanitizer-x86_64 :: TestCases/verbose-simple.c EfficiencySanitizer-x86_64 :: TestCases/workingset-early-fault.c EfficiencySanitizer-x86_64 :: TestCases/workingset-memset.cpp EfficiencySanitizer-x86_64 :: TestCases/workingset-midreport.cpp EfficiencySanitizer-x86_64 :: TestCases/workingset-samples.cpp EfficiencySanitizer-x86_64 :: TestCases/workingset-signal-posix.cpp EfficiencySanitizer-x86_64 :: TestCases/workingset-simple.cpp EfficiencySanitizer-x86_64 :: Unit/circular_buffer.cpp EfficiencySanitizer-x86_64 :: Unit/hashtable.cpp Unexpected Failures: 13 Reviewers: bruening, slthakur Subscribers: sdardis, kubabrecka, beanz Differential Revision: https://reviews.llvm.org/D24350 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@280954 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/esan')
-rw-r--r--lib/esan/esan.cpp8
-rw-r--r--lib/esan/esan.h1
-rw-r--r--lib/esan/esan_linux.cpp2
-rw-r--r--lib/esan/esan_shadow.h134
4 files changed, 24 insertions, 121 deletions
diff --git a/lib/esan/esan.cpp b/lib/esan/esan.cpp
index 09b530b66..2fb77894d 100644
--- a/lib/esan/esan.cpp
+++ b/lib/esan/esan.cpp
@@ -141,17 +141,9 @@ static bool verifyShadowScheme() {
}
#endif
-uptr VmaSize;
-
static void initializeShadow() {
verifyAddressSpace();
- // This is based on the assumption that the intial stack is always allocated
- // in the topmost segment of the user address space and the assumption
- // holds true on all the platforms currently supported.
- VmaSize =
- (MostSignificantSetBitIndex(GET_CURRENT_FRAME()) + 1);
-
DCHECK(verifyShadowScheme());
Mapping.initialize(ShadowScale[__esan_which_tool]);
diff --git a/lib/esan/esan.h b/lib/esan/esan.h
index e73b21e56..5a0dde627 100644
--- a/lib/esan/esan.h
+++ b/lib/esan/esan.h
@@ -34,7 +34,6 @@ namespace __esan {
extern bool EsanIsInitialized;
extern bool EsanDuringInit;
-extern uptr VmaSize;
void initializeLibrary(ToolType Tool);
int finalizeLibrary();
diff --git a/lib/esan/esan_linux.cpp b/lib/esan/esan_linux.cpp
index 014205ce0..aa961b661 100644
--- a/lib/esan/esan_linux.cpp
+++ b/lib/esan/esan_linux.cpp
@@ -25,7 +25,7 @@
namespace __esan {
void verifyAddressSpace() {
-#if SANITIZER_LINUX && (defined(__x86_64__) || SANITIZER_MIPS64)
+#if SANITIZER_LINUX && defined(__x86_64__)
// The kernel determines its mmap base from the stack size limit.
// Our Linux 64-bit shadow mapping assumes the stack limit is less than a
// terabyte, which keeps the mmap region above 0x7e00'.
diff --git a/lib/esan/esan_shadow.h b/lib/esan/esan_shadow.h
index 9007619be..f8f154ef7 100644
--- a/lib/esan/esan_shadow.h
+++ b/lib/esan/esan_shadow.h
@@ -15,7 +15,6 @@
#ifndef ESAN_SHADOW_H
#define ESAN_SHADOW_H
-#include "esan.h"
#include <sanitizer_common/sanitizer_platform.h>
#if SANITIZER_WORDSIZE != 64
@@ -24,13 +23,7 @@
namespace __esan {
-struct ApplicationRegion {
- uptr Start;
- uptr End;
- bool ShadowMergedWithPrev;
-};
-
-#if SANITIZER_LINUX && defined(__x86_64__)
+#if SANITIZER_LINUX && defined(__x86_64__)
// Linux x86_64
//
// Application memory falls into these 5 regions (ignoring the corner case
@@ -96,6 +89,12 @@ struct ApplicationRegion {
// [0x000015ff'ff601000, 0x00001600'00000000]
// [0x000015ff'ff600000, 0x000015ff'ff601000]
+struct ApplicationRegion {
+ uptr Start;
+ uptr End;
+ bool ShadowMergedWithPrev;
+};
+
static const struct ApplicationRegion AppRegions[] = {
{0x0000000000000000ull, 0x0000010000000000u, false},
{0x0000550000000000u, 0x0000570000000000u, false},
@@ -106,52 +105,6 @@ static const struct ApplicationRegion AppRegions[] = {
{0x00007fffff601000u, 0x0000800000000000u, true},
{0xffffffffff600000u, 0xffffffffff601000u, true},
};
-
-#elif SANITIZER_LINUX && SANITIZER_MIPS64
-
-// Application memory falls into these 3 regions
-//
-// [0x00000001'00000000, 0x00000002'00000000) non-PIE + heap
-// [0x000000aa'00000000, 0x000000ab'00000000) PIE
-// [0x000000ff'00000000, 0x000000ff'ffffffff) libraries + stack
-//
-// This formula translates from application memory to shadow memory:
-//
-// shadow(app) = ((app & 0x00000f'ffffffff) + offset) >> scale
-//
-// Where the offset for 1:1 is 0x000013'00000000. For other scales, the
-// offset is shifted left by the scale, except for scales of 1 and 2 where
-// it must be tweaked in order to pass the double-shadow test
-// (see the "shadow(shadow)" comments below):
-// scale == 0: 0x000013'00000000
-// scale == 1: 0x000022'00000000
-// scale == 2: 0x000044'00000000
-// scale >= 3: (0x000013'00000000 << scale)
-//
-// The resulting shadow memory regions for a 0 scaling are:
-//
-// [0x00000014'00000000, 0x00000015'00000000)
-// [0x0000001d'00000000, 0x0000001e'00000000)
-// [0x00000022'00000000, 0x00000022'ffffffff)
-//
-// We also want to ensure that a wild access by the application into the shadow
-// regions will not corrupt our own shadow memory. shadow(shadow) ends up
-// disjoint from shadow(app):
-//
-// [0x00000017'00000000, 0x00000018'00000000)
-// [0x00000020'00000000, 0x00000021'00000000)
-// [0x00000015'00000000, 0x00000015'ffffffff]
-
-static const struct ApplicationRegion AppRegions[] = {
- {0x0100000000u, 0x0200000000u, false},
- {0xaa00000000u, 0xab00000000u, false},
- {0xff00000000u, 0xffffffffffu, false},
-};
-
-#else
-#error Platform not supported
-#endif
-
static const u32 NumAppRegions = sizeof(AppRegions)/sizeof(AppRegions[0]);
// See the comment above: we do not currently support a stack size rlimit
@@ -160,58 +113,29 @@ static const uptr MaxStackSize = (1ULL << 40) - 4096;
class ShadowMapping {
public:
-
+ static const uptr Mask = 0x00000fffffffffffu;
// The scale and offset vary by tool.
uptr Scale;
uptr Offset;
-
- // TODO(sagar.thakur): Try to hardcode the mask as done in the compiler
- // instrumentation to reduce the runtime cost of appToShadow.
- struct ShadowMemoryMask40 {
- static const uptr Mask = 0x0000000fffffffffu;
- };
-
- struct ShadowMemoryMask47 {
- static const uptr Mask = 0x00000fffffffffffu;
- };
-
- const uptr OffsetArray40[3] = {
- 0x0000001300000000u,
- 0x0000002200000000u,
- 0x0000004400000000u,
- };
-
- const uptr OffsetArray47[3] = {
- 0x0000130000000000u,
- 0x0000220000000000u,
- 0x0000440000000000u,
- };
-
void initialize(uptr ShadowScale) {
+ static const uptr OffsetArray[3] = {
+ 0x0000130000000000u,
+ 0x0000220000000000u,
+ 0x0000440000000000u,
+ };
Scale = ShadowScale;
- switch (VmaSize) {
- case 40: {
- if (Scale <= 2)
- Offset = OffsetArray40[Scale];
- else
- Offset = OffsetArray40[0] << Scale;
- }
- break;
- case 47: {
- if (Scale <= 2)
- Offset = OffsetArray47[Scale];
- else
- Offset = OffsetArray47[0] << Scale;
- }
- break;
- default: {
- Printf("ERROR: %d-bit virtual memory address size not supported\n", VmaSize);
- Die();
- }
- }
+ if (Scale <= 2)
+ Offset = OffsetArray[Scale];
+ else
+ Offset = OffsetArray[0] << Scale;
}
};
extern ShadowMapping Mapping;
+#else
+// We'll want to use templatized functions over the ShadowMapping once
+// we support more platforms.
+#error Platform not supported
+#endif
static inline bool getAppRegion(u32 i, uptr *Start, uptr *End) {
if (i >= NumAppRegions)
@@ -230,21 +154,9 @@ bool isAppMem(uptr Mem) {
return false;
}
-template<typename Params>
-uptr appToShadowImpl(uptr App) {
- return (((App & Params::Mask) + Mapping.Offset) >> Mapping.Scale);
-}
-
ALWAYS_INLINE
uptr appToShadow(uptr App) {
- switch (VmaSize) {
- case 40: return appToShadowImpl<ShadowMapping::ShadowMemoryMask40>(App);
- case 47: return appToShadowImpl<ShadowMapping::ShadowMemoryMask47>(App);
- default: {
- Printf("ERROR: %d-bit virtual memory address size not supported\n", VmaSize);
- Die();
- }
- }
+ return (((App & ShadowMapping::Mask) + Mapping.Offset) >> Mapping.Scale);
}
static inline bool getShadowRegion(u32 i, uptr *Start, uptr *End) {