Files
clang-p2996/compiler-rt/lib/esan/esan_linux.cpp
Qin Zhao 0ab52b97e8 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

llvm-svn: 280954
2016-09-08 16:09:46 +00:00

84 lines
2.5 KiB
C++

//===-- esan.cpp ----------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file is a part of EfficiencySanitizer, a family of performance tuners.
//
// Linux-specific code for the Esan run-time.
//===----------------------------------------------------------------------===//
#include "sanitizer_common/sanitizer_platform.h"
#if SANITIZER_FREEBSD || SANITIZER_LINUX
#include "esan.h"
#include "esan_shadow.h"
#include "interception/interception.h"
#include "sanitizer_common/sanitizer_common.h"
#include <sys/mman.h>
#include <errno.h>
namespace __esan {
void verifyAddressSpace() {
#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'.
uptr StackLimit = GetStackSizeLimitInBytes();
if (StackSizeIsUnlimited() || StackLimit > MaxStackSize) {
VReport(1, "The stack size limit is beyond the maximum supported.\n"
"Re-execing with a stack size below 1TB.\n");
SetStackSizeLimitInBytes(MaxStackSize);
ReExec();
}
#endif
}
static bool liesWithinSingleAppRegion(uptr Start, SIZE_T Size) {
uptr AppStart, AppEnd;
for (int i = 0; getAppRegion(i, &AppStart, &AppEnd); ++i) {
if (Start >= AppStart && Start + Size - 1 <= AppEnd) {
return true;
}
}
return false;
}
bool fixMmapAddr(void **Addr, SIZE_T Size, int Flags) {
if (*Addr) {
if (!liesWithinSingleAppRegion((uptr)*Addr, Size)) {
VPrintf(1, "mmap conflict: [%p-%p) is not in an app region\n",
*Addr, (uptr)*Addr + Size);
if (Flags & MAP_FIXED) {
errno = EINVAL;
return false;
} else {
*Addr = 0;
}
}
}
return true;
}
uptr checkMmapResult(uptr Addr, SIZE_T Size) {
if ((void *)Addr == MAP_FAILED)
return Addr;
if (!liesWithinSingleAppRegion(Addr, Size)) {
// FIXME: attempt to dynamically add this as an app region if it
// fits our shadow criteria.
// We could also try to remap somewhere else.
Printf("ERROR: unsupported mapping at [%p-%p)\n", Addr, Addr+Size);
Die();
}
return Addr;
}
} // namespace __esan
#endif // SANITIZER_FREEBSD || SANITIZER_LINUX