From 9d79ea3416bfbe3acac50e47802ee9621bf53254 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 27 Apr 2016 15:55:05 +0000 Subject: 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 --- lib/sanitizer_common/sanitizer_win.cc | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'lib/sanitizer_common/sanitizer_win.cc') 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); + } } } -- cgit v1.2.3