tsan: slightly relax requirements for lazy shadow memory (can overlap and may not be properly aligned)
it's problematic on windows where allocation granularity is much larger than page size



git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@167466 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/sanitizer_common/sanitizer_posix.cc b/lib/sanitizer_common/sanitizer_posix.cc
index 521271e..8117fd4 100644
--- a/lib/sanitizer_common/sanitizer_posix.cc
+++ b/lib/sanitizer_common/sanitizer_posix.cc
@@ -74,11 +74,12 @@
 }
 
 void *MmapFixedNoReserve(uptr fixed_addr, uptr size) {
-  void *p = internal_mmap((void*)fixed_addr, size,
-                      PROT_READ | PROT_WRITE,
-                      MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE,
-                      -1, 0);
-  if (p != (void*)fixed_addr)
+  void *p = internal_mmap((void*)(fixed_addr & ~(kPageSize - 1)),
+      RoundUpTo(size, kPageSize),
+      PROT_READ | PROT_WRITE,
+      MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE,
+      -1, 0);
+  if (p == (void*)-1)
     Report("ERROR: Failed to allocate 0x%zx (%zd) bytes at address %p (%d)\n",
            size, size, fixed_addr, errno);
   return p;
diff --git a/lib/tsan/go/test.c b/lib/tsan/go/test.c
index 865da4e..ae63d66 100644
--- a/lib/tsan/go/test.c
+++ b/lib/tsan/go/test.c
@@ -36,7 +36,7 @@
 
 int main(void) {
   __tsan_init();
-  __tsan_map_shadow((unsigned long)buf & ~(4096-1), 4096);
+  __tsan_map_shadow(buf, sizeof(buf));
   __tsan_func_enter(0, &main);
   __tsan_malloc(0, buf, 10, 0);
   __tsan_release(0, buf);
diff --git a/lib/tsan/rtl/tsan_rtl.cc b/lib/tsan/rtl/tsan_rtl.cc
index f5b5d46..bb3f1a1 100644
--- a/lib/tsan/rtl/tsan_rtl.cc
+++ b/lib/tsan/rtl/tsan_rtl.cc
@@ -162,15 +162,7 @@
 }
 
 void MapShadow(uptr addr, uptr size) {
-  uptr saddr = MemToShadow(addr);
-  uptr ssize = size * kShadowMultiplier;
-  void *p = MmapFixedNoReserve(saddr, ssize);
-  if ((uptr)p != saddr) {
-    Printf("FATAL: ThreadSanitizer failed to mmap shadow memory"
-        " %p(%p) -> %p(%p) = %p\n",
-        addr, size, saddr, ssize, p);
-    Die();
-  }
+  MmapFixedNoReserve(MemToShadow(addr), size * kShadowMultiplier);
 }
 
 void Initialize(ThreadState *thr) {