1 //===-- esan.cpp ----------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is a part of EfficiencySanitizer, a family of performance tuners.
12 // Linux-specific code for the Esan run-time.
13 //===----------------------------------------------------------------------===//
15 #include "sanitizer_common/sanitizer_platform.h"
16 #if SANITIZER_FREEBSD || SANITIZER_LINUX
19 #include "esan_shadow.h"
20 #include "interception/interception.h"
21 #include "sanitizer_common/sanitizer_common.h"
27 void verifyAddressSpace() {
28 #if SANITIZER_LINUX && (defined(__x86_64__) || SANITIZER_MIPS64)
29 // The kernel determines its mmap base from the stack size limit.
30 // Our Linux 64-bit shadow mapping assumes the stack limit is less than a
31 // terabyte, which keeps the mmap region above 0x7e00'.
32 uptr StackLimit = GetStackSizeLimitInBytes();
33 if (StackSizeIsUnlimited() || StackLimit > MaxStackSize) {
34 VReport(1, "The stack size limit is beyond the maximum supported.\n"
35 "Re-execing with a stack size below 1TB.\n");
36 SetStackSizeLimitInBytes(MaxStackSize);
42 static bool liesWithinSingleAppRegion(uptr Start, SIZE_T Size) {
43 uptr AppStart, AppEnd;
44 for (int i = 0; getAppRegion(i, &AppStart, &AppEnd); ++i) {
45 if (Start >= AppStart && Start + Size - 1 <= AppEnd) {
52 bool fixMmapAddr(void **Addr, SIZE_T Size, int Flags) {
54 if (!liesWithinSingleAppRegion((uptr)*Addr, Size)) {
55 VPrintf(1, "mmap conflict: [%p-%p) is not in an app region\n",
56 *Addr, (uptr)*Addr + Size);
57 if (Flags & MAP_FIXED) {
68 uptr checkMmapResult(uptr Addr, SIZE_T Size) {
69 if ((void *)Addr == MAP_FAILED)
71 if (!liesWithinSingleAppRegion(Addr, Size)) {
72 // FIXME: attempt to dynamically add this as an app region if it
73 // fits our shadow criteria.
74 // We could also try to remap somewhere else.
75 Printf("ERROR: unsupported mapping at [%p-%p)\n", Addr, Addr+Size);
83 #endif // SANITIZER_FREEBSD || SANITIZER_LINUX