[PATCH] D21900: [compiler-rt] Fix sanitizer memory allocator on win64.

Etienne Bergeron via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 6 12:25:44 PDT 2016


etienneb updated this revision to Diff 62932.
etienneb marked 4 inline comments as done.
etienneb added a comment.

fix


http://reviews.llvm.org/D21900

Files:
  lib/sanitizer_common/sanitizer_allocator.h
  lib/sanitizer_common/sanitizer_win.cc
  lib/sanitizer_common/tests/CMakeLists.txt
  lib/sanitizer_common/tests/sanitizer_allocator_test.cc

Index: lib/sanitizer_common/tests/sanitizer_allocator_test.cc
===================================================================
--- lib/sanitizer_common/tests/sanitizer_allocator_test.cc
+++ lib/sanitizer_common/tests/sanitizer_allocator_test.cc
@@ -29,9 +29,15 @@
 #if !SANITIZER_DEBUG
 
 #if SANITIZER_CAN_USE_ALLOCATOR64
+#if SANITIZER_WINDOWS
+static const uptr kAllocatorSpace = 0x10000000000ULL;
+static const uptr kAllocatorSize  =  0x10000000000ULL;  // 1T
+static const u64 kAddressSpaceSize = 1ULL << 40;
+#else
 static const uptr kAllocatorSpace = 0x700000000000ULL;
-static const uptr kAllocatorSize  = 0x010000000000ULL;  // 1T.
+static const uptr kAllocatorSize  = 0x010000000000ULL;  // 1T
 static const u64 kAddressSpaceSize = 1ULL << 47;
+#endif
 
 typedef SizeClassAllocator64<
   kAllocatorSpace, kAllocatorSize, 16, DefaultSizeClassMap> Allocator64;
@@ -236,7 +242,7 @@
   SizeClassAllocatorGetBlockBeginStress<Allocator64Compact>();
 }
 TEST(SanitizerCommon, SizeClassAllocator32CompactGetBlockBegin) {
-  SizeClassAllocatorGetBlockBeginStress<Allocator32Compact>();
+   SizeClassAllocatorGetBlockBeginStress<Allocator32Compact>();
 }
 #endif  // SANITIZER_CAN_USE_ALLOCATOR64
 
Index: lib/sanitizer_common/tests/CMakeLists.txt
===================================================================
--- lib/sanitizer_common/tests/CMakeLists.txt
+++ lib/sanitizer_common/tests/CMakeLists.txt
@@ -50,7 +50,7 @@
   -I${COMPILER_RT_SOURCE_DIR}/lib
   -I${COMPILER_RT_SOURCE_DIR}/lib/sanitizer_common
   -fno-rtti
-  -O2
+  -O0
   -Werror=sign-compare
   -Wno-non-virtual-dtor)
 
Index: lib/sanitizer_common/sanitizer_win.cc
===================================================================
--- lib/sanitizer_common/sanitizer_win.cc
+++ lib/sanitizer_common/sanitizer_win.cc
@@ -181,9 +181,11 @@
   return p;
 }
 
+// Memory space mapped by 'MmapFixedOrDie' must have been reserved by
+// 'MmapFixedNoAccess'.
 void *MmapFixedOrDie(uptr fixed_addr, uptr size) {
   void *p = VirtualAlloc((LPVOID)fixed_addr, size,
-      MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
+      MEM_COMMIT, PAGE_READWRITE);
   if (p == 0) {
     char mem_type[30];
     internal_snprintf(mem_type, sizeof(mem_type), "memory at address 0x%zx",
@@ -201,7 +203,7 @@
 void *MmapFixedNoAccess(uptr fixed_addr, uptr size, const char *name) {
   (void)name; // unsupported
   void *res = VirtualAlloc((LPVOID)fixed_addr, size,
-                           MEM_RESERVE | MEM_COMMIT, PAGE_NOACCESS);
+                           MEM_RESERVE, PAGE_NOACCESS);
   if (res == 0)
     Report("WARNING: %s failed to "
            "mprotect %p (%zd) bytes at %p (error code: %d)\n",
Index: lib/sanitizer_common/sanitizer_allocator.h
===================================================================
--- lib/sanitizer_common/sanitizer_allocator.h
+++ lib/sanitizer_common/sanitizer_allocator.h
@@ -323,12 +323,13 @@
   typedef SizeClassAllocatorLocalCache<ThisT> AllocatorCache;
 
   void Init() {
+    uptr TotalSpaceSize = kSpaceSize + AdditionalSize();
     if (kUsingConstantSpaceBeg) {
       CHECK_EQ(kSpaceBeg, reinterpret_cast<uptr>(
-                              MmapFixedNoAccess(kSpaceBeg, kSpaceSize)));
+                              MmapFixedNoAccess(kSpaceBeg, TotalSpaceSize)));
     } else {
       NonConstSpaceBeg =
-          reinterpret_cast<uptr>(MmapNoAccess(kSpaceSize + AdditionalSize()));
+          reinterpret_cast<uptr>(MmapNoAccess(TotalSpaceSize));
       CHECK_NE(NonConstSpaceBeg, ~(uptr)0);
     }
     MapWithCallback(SpaceEnd(), AdditionalSize());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21900.62932.patch
Type: text/x-patch
Size: 3561 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160706/29b4d6e9/attachment.bin>


More information about the llvm-commits mailing list