[compiler-rt] r267730 - tsan: fix windows support

Dmitry Vyukov via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 27 08:55:05 PDT 2016


Author: dvyukov
Date: Wed Apr 27 10:55:05 2016
New Revision: 267730

URL: http://llvm.org/viewvc/llvm-project?rev=267730&view=rev
Log:
tsan: fix windows support

UnmapOrDie used to do MEM_DECOMMIT and so worked
on partial regions. But r263160 changed it to use
MEM_RELEASE and MEM_RELEASE can only work with
whole regions mapped by VirtualAlloc. This broke
windows as:

FATAL: ThreadSanitizer CHECK failed: gotsan.cc:8296 "((mbi.AllocationBase == addr && "Windows cannot unmap part of a previous mapping")) != (0)" (0x0, 0x0)

Restore the previous behavior.


Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc

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=267730&r1=267729&r2=267730&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc Wed Apr 27 10:55:05 2016
@@ -97,21 +97,19 @@ void UnmapOrDie(void *addr, uptr size) {
   if (!size || !addr)
     return;
 
-  // Make sure that this API is only used to unmap an entire previous mapping.
-  // Windows cannot unmap part of a previous mapping. Unfortunately,
-  // we can't check that size matches the original size because mbi.RegionSize
-  // doesn't describe the size of the full allocation if some of the pages were
-  // protected.
   MEMORY_BASIC_INFORMATION mbi;
   CHECK(VirtualQuery(addr, &mbi, sizeof(mbi)));
-  CHECK(mbi.AllocationBase == addr &&
-        "Windows cannot unmap part of a previous mapping");
 
+  // MEM_RELEASE can only be used to unmap whole regions previously mapped with
+  // VirtualAlloc. So we first try MEM_RELEASE since it is better, and if that
+  // fails try MEM_DECOMMIT.
   if (VirtualFree(addr, 0, MEM_RELEASE) == 0) {
-    Report("ERROR: %s failed to "
-           "deallocate 0x%zx (%zd) bytes at address %p (error code: %d)\n",
-           SanitizerToolName, size, size, addr, GetLastError());
-    CHECK("unable to unmap" && 0);
+    if (VirtualFree(addr, size, MEM_DECOMMIT) == 0) {
+      Report("ERROR: %s failed to "
+             "deallocate 0x%zx (%zd) bytes at address %p (error code: %d)\n",
+             SanitizerToolName, size, size, addr, GetLastError());
+      CHECK("unable to unmap" && 0);
+    }
   }
 }
 




More information about the llvm-commits mailing list