[llvm-commits] [compiler-rt] r158499 - in /compiler-rt/trunk/lib: asan/asan_internal.h asan/asan_posix.cc asan/asan_rtl.cc asan/asan_win.cc sanitizer_common/sanitizer_common.h sanitizer_common/sanitizer_internal_defs.h sanitizer_common/sanitizer_posix.cc sanitizer_common/sanitizer_win.cc

Alexey Samsonov samsonov at google.com
Fri Jun 15 00:29:14 PDT 2012


Author: samsonov
Date: Fri Jun 15 02:29:14 2012
New Revision: 158499

URL: http://llvm.org/viewvc/llvm-project?rev=158499&view=rev
Log:
[Sanitizer] move ShadowRangeIsAvailable and several defines to common runtime

Modified:
    compiler-rt/trunk/lib/asan/asan_internal.h
    compiler-rt/trunk/lib/asan/asan_posix.cc
    compiler-rt/trunk/lib/asan/asan_rtl.cc
    compiler-rt/trunk/lib/asan/asan_win.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc

Modified: compiler-rt/trunk/lib/asan/asan_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_internal.h?rev=158499&r1=158498&r2=158499&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_internal.h (original)
+++ compiler-rt/trunk/lib/asan/asan_internal.h Fri Jun 15 02:29:14 2012
@@ -121,7 +121,6 @@
 
 // asan_linux.cc / asan_mac.cc / asan_win.cc
 void *AsanDoesNotSupportStaticLinkage();
-bool AsanShadowRangeIsAvailable();
 
 void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp);
 
@@ -203,22 +202,12 @@
 # define GET_CURRENT_FRAME() (uptr)0xDEADBEEF
 #endif
 
-#ifndef _WIN32
-const uptr kMmapGranularity = kPageSize;
-# define THREAD_CALLING_CONV
-typedef void* thread_return_t;
-#else
-const uptr kMmapGranularity = 1UL << 16;
-# define THREAD_CALLING_CONV __stdcall
-typedef DWORD thread_return_t;
-
+#ifdef _WIN32
 # ifndef ASAN_USE_EXTERNAL_SYMBOLIZER
 #  define ASAN_USE_EXTERNAL_SYMBOLIZER __asan_WinSymbolize
 bool __asan_WinSymbolize(const void *addr, char *out_buffer, int buffer_size);
 # endif
-#endif
-
-typedef thread_return_t (THREAD_CALLING_CONV *thread_callback_t)(void* arg);
+#endif  // _WIN32
 
 // These magic values are written to shadow for better error reporting.
 const int kAsanHeapLeftRedzoneMagic = 0xfa;

Modified: compiler-rt/trunk/lib/asan/asan_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_posix.cc?rev=158499&r1=158498&r2=158499&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_posix.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_posix.cc Fri Jun 15 02:29:14 2012
@@ -32,31 +32,6 @@
 
 namespace __asan {
 
-static inline bool IntervalsAreSeparate(uptr start1, uptr end1,
-                                        uptr start2, uptr end2) {
-  CHECK(start1 <= end1);
-  CHECK(start2 <= end2);
-  return (end1 < start2) || (end2 < start1);
-}
-
-// 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() {
-  ProcessMaps procmaps;
-  uptr start, end;
-  uptr shadow_start = kLowShadowBeg;
-  if (kLowShadowBeg > 0) shadow_start -= kMmapGranularity;
-  uptr shadow_end = kHighShadowEnd;
-  while (procmaps.Next(&start, &end,
-                       /*offset*/0, /*filename*/0, /*filename_size*/0)) {
-    if (!IntervalsAreSeparate(start, end, shadow_start, shadow_end))
-      return false;
-  }
-  return true;
-}
-
 static void MaybeInstallSigaction(int signum,
                                   void (*handler)(int, siginfo_t *, void *)) {
   if (!AsanInterceptsSignal(signum))

Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=158499&r1=158498&r2=158499&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Fri Jun 15 02:29:14 2012
@@ -539,7 +539,10 @@
     DisableCoreDumper();
   }
 
-  if (AsanShadowRangeIsAvailable()) {
+  uptr shadow_start = kLowShadowBeg;
+  if (kLowShadowBeg > 0) shadow_start -= kMmapGranularity;
+  uptr shadow_end = kHighShadowEnd;
+  if (MemoryRangeIsAvailable(shadow_start, shadow_end)) {
     if (kLowShadowBeg != kLowShadowEnd) {
       // mmap the low shadow plus at least one page.
       ReserveShadowMemoryRange(kLowShadowBeg - kMmapGranularity, kLowShadowEnd);

Modified: compiler-rt/trunk/lib/asan/asan_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_win.cc?rev=158499&r1=158498&r2=158499&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_win.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_win.cc Fri Jun 15 02:29:14 2012
@@ -159,11 +159,6 @@
   return 0;
 }
 
-bool AsanShadowRangeIsAvailable() {
-  // FIXME: shall we do anything here on Windows?
-  return true;
-}
-
 void SetAlternateSignalStack() {
   // FIXME: Decide what to do on Windows.
 }

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=158499&r1=158498&r2=158499&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Fri Jun 15 02:29:14 2012
@@ -25,6 +25,11 @@
 const uptr kWordSizeInBits = 8 * kWordSize;
 const uptr kPageSizeBits = 12;
 const uptr kPageSize = 1UL << kPageSizeBits;
+#ifndef _WIN32
+const uptr kMmapGranularity = kPageSize;
+#else
+const uptr kMmapGranularity = 1UL << 16;
+#endif
 
 // Threads
 int GetPid();
@@ -37,6 +42,8 @@
 void UnmapOrDie(void *addr, uptr size);
 void *MmapFixedNoReserve(uptr fixed_addr, uptr size);
 void *Mprotect(uptr fixed_addr, uptr size);
+// Used to check if we can map shadow memory to a fixed location.
+bool MemoryRangeIsAvailable(uptr range_start, uptr range_end);
 
 // Internal allocator
 void *InternalAlloc(uptr size);

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h?rev=158499&r1=158498&r2=158499&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h Fri Jun 15 02:29:14 2012
@@ -51,6 +51,15 @@
 # define USED __attribute__((used))
 #endif
 
+#if defined(_WIN32)
+typedef DWORD thread_return_t;
+# define THREAD_CALLING_CONV __stdcall
+#else  // _WIN32
+typedef void* thread_return_t;
+# define THREAD_CALLING_CONV
+#endif  // _WIN32
+typedef thread_return_t (THREAD_CALLING_CONV *thread_callback_t)(void* arg);
+
 // If __WORDSIZE was undefined by the platform, define it in terms of the
 // compiler built-ins __LP64__ and _WIN64.
 #ifndef __WORDSIZE

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc?rev=158499&r1=158498&r2=158499&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc Fri Jun 15 02:29:14 2012
@@ -80,6 +80,28 @@
                        0, 0);
 }
 
+static inline bool IntervalsAreSeparate(uptr start1, uptr end1,
+                                        uptr start2, uptr end2) {
+  CHECK(start1 <= end1);
+  CHECK(start2 <= end2);
+  return (end1 < start2) || (end2 < start1);
+}
+
+// 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 MemoryRangeIsAvailable(uptr range_start, uptr range_end) {
+  ProcessMaps procmaps;
+  uptr start, end;
+  while (procmaps.Next(&start, &end,
+                       /*offset*/0, /*filename*/0, /*filename_size*/0)) {
+    if (!IntervalsAreSeparate(start, end, range_start, range_end))
+      return false;
+  }
+  return true;
+}
+
 void DumpProcessMap() {
   ProcessMaps proc_maps;
   uptr start, end;

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc?rev=158499&r1=158498&r2=158499&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc Fri Jun 15 02:29:14 2012
@@ -70,6 +70,11 @@
                       MEM_RESERVE | MEM_COMMIT, PAGE_NOACCESS);
 }
 
+bool MemoryRangeIsAvailable(uptr range_start, uptr range_end) {
+  // FIXME: shall we do anything here on Windows?
+  return true;
+}
+
 const char *GetEnv(const char *name) {
   static char env_buffer[32767] = {};
 





More information about the llvm-commits mailing list