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

llvm-svn: 167466
This commit is contained in:
Dmitry Vyukov 2012-11-06 16:48:46 +00:00
parent 33bfe09c34
commit da78be74f3
3 changed files with 8 additions and 15 deletions

View File

@ -74,11 +74,12 @@ void UnmapOrDie(void *addr, uptr size) {
}
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;

View File

@ -36,7 +36,7 @@ char buf[10];
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);

View File

@ -162,15 +162,7 @@ static void InitializeMemoryFlush() {
}
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) {