[compiler-rt] r200832 - tsan: ensure proper alignment of mmaps on windows
Dmitry Vyukov
dvyukov at google.com
Wed Feb 5 03:37:21 PST 2014
Author: dvyukov
Date: Wed Feb 5 05:37:20 2014
New Revision: 200832
URL: http://llvm.org/viewvc/llvm-project?rev=200832&view=rev
Log:
tsan: ensure proper alignment of mmaps on windows
Modified:
compiler-rt/trunk/lib/tsan/go/test.c
compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h
compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
Modified: compiler-rt/trunk/lib/tsan/go/test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/go/test.c?rev=200832&r1=200831&r2=200832&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/go/test.c (original)
+++ compiler-rt/trunk/lib/tsan/go/test.c Wed Feb 5 05:37:20 2014
@@ -29,15 +29,16 @@ void __tsan_release_merge(void *thr, voi
void symbolize_cb(void *ctx) {}
-char buf[10];
+char buf0[100<<10];
void foobar() {}
void barfoo() {}
int main(void) {
void *thr0 = 0;
+ char *buf = (char*)((unsigned long)buf0 + (64<<10) - 1 & ~((64<<10) - 1));
__tsan_init(&thr0, symbolize_cb);
- __tsan_map_shadow(buf, sizeof(buf) + 4096);
+ __tsan_map_shadow(buf, 4096);
__tsan_func_enter(thr0, (char*)&main + 1);
__tsan_malloc(thr0, buf, 10, 0);
__tsan_release(thr0, buf);
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h?rev=200832&r1=200831&r2=200832&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h Wed Feb 5 05:37:20 2014
@@ -140,8 +140,9 @@ const char *InitializePlatform();
void FinalizePlatform();
// The additional page is to catch shadow stack overflow as paging fault.
-const uptr kTotalTraceSize = (kTraceSize * sizeof(Event) + sizeof(Trace) + 4096
- + 4095) & ~4095;
+// Windows wants 64K alignment for mmaps.
+const uptr kTotalTraceSize = (kTraceSize * sizeof(Event) + sizeof(Trace)
+ + (64 << 10) + (64 << 10) - 1) & ~((64 << 10) - 1);
uptr ALWAYS_INLINE GetThreadTrace(int tid) {
uptr p = kTraceMemBegin + (uptr)tid * kTotalTraceSize;
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc?rev=200832&r1=200831&r2=200832&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc Wed Feb 5 05:37:20 2014
@@ -198,6 +198,7 @@ void DontNeedShadowFor(uptr addr, uptr s
}
void MapShadow(uptr addr, uptr size) {
+ CHECK_EQ(addr, addr & ~((64 << 10) - 1)); // windows wants 64K alignment
MmapFixedNoReserve(MemToShadow(addr), size * kShadowMultiplier);
}
@@ -205,6 +206,7 @@ void MapThreadTrace(uptr addr, uptr size
DPrintf("#0: Mapping trace at %p-%p(0x%zx)\n", addr, addr + size, size);
CHECK_GE(addr, kTraceMemBegin);
CHECK_LE(addr + size, kTraceMemBegin + kTraceMemSize);
+ CHECK_EQ(addr, addr & ~((64 << 10) - 1)); // windows wants 64K alignment
uptr addr1 = (uptr)MmapFixedNoReserve(addr, size);
if (addr1 != addr) {
Printf("FATAL: ThreadSanitizer can not mmap thread trace (%p/%p->%p)\n",
More information about the llvm-commits
mailing list