summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/sanitizer_win.cc
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2016-04-27 15:55:05 +0000
committerDmitry Vyukov <dvyukov@google.com>2016-04-27 15:55:05 +0000
commit9d79ea3416bfbe3acac50e47802ee9621bf53254 (patch)
tree228760d15b3d084f420d0b68641e9d0e1bccca4d /lib/sanitizer_common/sanitizer_win.cc
parent74527d700b4ee1c36ea7cfd137a7140227fd567a (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@267730 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_win.cc')
-rw-r--r--lib/sanitizer_common/sanitizer_win.cc20
1 files changed, 9 insertions, 11 deletions
diff --git a/lib/sanitizer_common/sanitizer_win.cc b/lib/sanitizer_common/sanitizer_win.cc
index 4221d5f12..2eb9ad820 100644
--- a/lib/sanitizer_common/sanitizer_win.cc
+++ b/lib/sanitizer_common/sanitizer_win.cc
@@ -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);
+ }
}
}