diff options
author | Alexander Potapenko <glider@google.com> | 2012-02-13 17:09:40 +0000 |
---|---|---|
committer | Alexander Potapenko <glider@google.com> | 2012-02-13 17:09:40 +0000 |
commit | 720aaefb8d547c3a43d2097db5554d08699c393a (patch) | |
tree | ffb8b56491de7ac8bbed386bff434cd67772fea3 /compiler-rt | |
parent | 31ae8b62ea484bf891648a56e65f385a480c37e7 (diff) | |
download | bcm5719-llvm-720aaefb8d547c3a43d2097db5554d08699c393a.tar.gz bcm5719-llvm-720aaefb8d547c3a43d2097db5554d08699c393a.zip |
Move the non-trivial implementation of AsanShadowRangeIsAvailable to asan_mac.cc
to avoid crashes on Linux and Win.
llvm-svn: 150398
Diffstat (limited to 'compiler-rt')
-rw-r--r-- | compiler-rt/lib/asan/asan_internal.h | 3 | ||||
-rw-r--r-- | compiler-rt/lib/asan/asan_linux.cc | 5 | ||||
-rw-r--r-- | compiler-rt/lib/asan/asan_mac.cc | 36 | ||||
-rw-r--r-- | compiler-rt/lib/asan/asan_rtl.cc | 36 | ||||
-rw-r--r-- | compiler-rt/lib/asan/asan_win.cc | 5 |
5 files changed, 48 insertions, 37 deletions
diff --git a/compiler-rt/lib/asan/asan_internal.h b/compiler-rt/lib/asan/asan_internal.h index 0223885c4f0..67ed869d633 100644 --- a/compiler-rt/lib/asan/asan_internal.h +++ b/compiler-rt/lib/asan/asan_internal.h @@ -125,8 +125,9 @@ void ReplaceSystemMalloc(); void OutOfMemoryMessageAndDie(const char *mem_type, size_t size); -// asan_linux.cc / asan_mac.cc +// asan_linux.cc / asan_mac.cc / asan_win.cc void *AsanDoesNotSupportStaticLinkage(); +bool AsanShadowRangeIsAvailable(); int AsanOpenReadonly(const char* filename); const char *AsanGetEnv(const char *name); diff --git a/compiler-rt/lib/asan/asan_linux.cc b/compiler-rt/lib/asan/asan_linux.cc index b2339e41c38..14fc3e5fdcd 100644 --- a/compiler-rt/lib/asan/asan_linux.cc +++ b/compiler-rt/lib/asan/asan_linux.cc @@ -43,6 +43,11 @@ void *AsanDoesNotSupportStaticLinkage() { return &_DYNAMIC; // defined in link.h } +bool AsanShadowRangeIsAvailable() { + // FIXME: shall we need anything here on Linux? + return true; +} + void GetPcSpBp(void *context, uintptr_t *pc, uintptr_t *sp, uintptr_t *bp) { #ifdef ANDROID *pc = *sp = *bp = 0; diff --git a/compiler-rt/lib/asan/asan_mac.cc b/compiler-rt/lib/asan/asan_mac.cc index 8943a4ac232..2d91c43fd4a 100644 --- a/compiler-rt/lib/asan/asan_mac.cc +++ b/compiler-rt/lib/asan/asan_mac.cc @@ -76,6 +76,42 @@ void *AsanDoesNotSupportStaticLinkage() { return NULL; } +inline bool IntervalsAreSeparate(uintptr_t start1, uintptr_t end1, + uintptr_t start2, uintptr_t end2) { + CHECK(start1 <= end1); + CHECK(start2 <= end2); + if (start1 == start2) { + return false; + } else { + if (start1 < start2) { + return (end1 < start2); + } else { + return (end2 < start1); + } + } + return false; +} + +// FIXME: this is thread-unsafe, but should not cause problems most of the time. +// When the shadow is mapped only a single thread usually exists (plus maybe +// several worker threads on Mac, which aren't expected to map big chunks of +// memory). +bool AsanShadowRangeIsAvailable() { + AsanProcMaps procmaps; + uintptr_t start, end; + bool available = true; + while (procmaps.Next(&start, &end, + /*offset*/NULL, /*filename*/NULL, /*size*/NULL)) { + if (!IntervalsAreSeparate(start, end, + kLowShadowBeg - kMmapGranularity, + kHighShadowEnd)) { + available = false; + break; + } + } + return available; +} + bool AsanInterceptsSignal(int signum) { return (signum == SIGSEGV || signum == SIGBUS) && FLAG_handle_segv; } diff --git a/compiler-rt/lib/asan/asan_rtl.cc b/compiler-rt/lib/asan/asan_rtl.cc index 568a79f5d6e..715edb086c9 100644 --- a/compiler-rt/lib/asan/asan_rtl.cc +++ b/compiler-rt/lib/asan/asan_rtl.cc @@ -118,42 +118,6 @@ static void ReserveShadowMemoryRange(uintptr_t beg, uintptr_t end) { CHECK(res == (void*)beg && "ReserveShadowMemoryRange failed"); } -inline bool IntervalsAreSeparate(uintptr_t start1, uintptr_t end1, - uintptr_t start2, uintptr_t end2) { - CHECK(start1 <= end1); - CHECK(start2 <= end2); - if (start1 == start2) { - return false; - } else { - if (start1 < start2) { - return (end1 < start2); - } else { - return (end2 < start1); - } - } - return false; -} - -// FIXME: this is thread-unsafe, but should not cause problems most of the time. -// When the shadow is mapped only a single thread usually exists (plus maybe -// several worker threads on Mac, which aren't expected to map big chunks of -// memory. -bool AsanShadowRangeIsAvailable() { - AsanProcMaps procmaps; - uintptr_t start, end; - bool available = true; - while (procmaps.Next(&start, &end, - /*offset*/NULL, /*filename*/NULL, /*size*/NULL)) { - if (!IntervalsAreSeparate(start, end, - kLowShadowBeg - kMmapGranularity, - kHighShadowEnd)) { - available = false; - break; - } - } - return available; -} - // ---------------------- LowLevelAllocator ------------- {{{1 void *LowLevelAllocator::Allocate(size_t size) { CHECK((size & (size - 1)) == 0 && "size must be a power of two"); diff --git a/compiler-rt/lib/asan/asan_win.cc b/compiler-rt/lib/asan/asan_win.cc index b3aa93d9815..7de5d589799 100644 --- a/compiler-rt/lib/asan/asan_win.cc +++ b/compiler-rt/lib/asan/asan_win.cc @@ -223,6 +223,11 @@ void *AsanDoesNotSupportStaticLinkage() { return NULL; } +bool AsanShadowRangeIsAvailable() { + // FIXME: shall we do anything here on Windows? + return true; +} + int AtomicInc(int *a) { return InterlockedExchangeAdd((LONG*)a, 1) + 1; } |