tsan: round Go shadow to page boundary

There is a corner case reported in Go issue tracker:
https://github.com/golang/go/issues/17065
On darwin data/bss segments may not be aligned to page bounary
and mmap seems to be behaving differently than on linux
(shrinks instead of enlarge unaligned regions).

Explicitly round shadow to page bounary before mapping
to avoid any such problems.

llvm-svn: 285454
This commit is contained in:
Dmitry Vyukov 2016-10-28 21:24:29 +00:00
parent 8586b78692
commit 0b00a7fc6e
1 changed files with 4 additions and 1 deletions

View File

@ -242,7 +242,10 @@ void MapShadow(uptr addr, uptr size) {
// Global data is not 64K aligned, but there are no adjacent mappings, // Global data is not 64K aligned, but there are no adjacent mappings,
// so we can get away with unaligned mapping. // so we can get away with unaligned mapping.
// CHECK_EQ(addr, addr & ~((64 << 10) - 1)); // windows wants 64K alignment // CHECK_EQ(addr, addr & ~((64 << 10) - 1)); // windows wants 64K alignment
MmapFixedNoReserve(MemToShadow(addr), size * kShadowMultiplier, "shadow"); const uptr kPageSize = GetPageSizeCached();
uptr shadow_begin = RoundDownTo((uptr)MemToShadow(addr), kPageSize);
uptr shadow_end = RoundUpTo((uptr)MemToShadow(addr + size), kPageSize);
MmapFixedNoReserve(shadow_begin, shadow_end - shadow_begin, "shadow");
// Meta shadow is 2:1, so tread carefully. // Meta shadow is 2:1, so tread carefully.
static bool data_mapped = false; static bool data_mapped = false;