From 12b7db3d578f9764416ae987a4fa2e90125f379c Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Thu, 4 Apr 2013 09:11:34 +1100 Subject: [PATCH] runtime: fix data/bss shadow memory mapping for race detector Fixes #5175. Race detector runtime expects values passed to MapShadow() to be page-aligned, because they are used in mmap() call. If they are not aligned mmap() trims either beginning or end of the mapping. R=golang-dev, r CC=golang-dev https://golang.org/cl/8325043 --- src/pkg/runtime/race.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pkg/runtime/race.c b/src/pkg/runtime/race.c index cfd97041a8..ce250b5b63 100644 --- a/src/pkg/runtime/race.c +++ b/src/pkg/runtime/race.c @@ -36,11 +36,14 @@ static bool onstack(uintptr argp); uintptr runtime·raceinit(void) { - uintptr racectx; + uintptr racectx, start, size; m->racecall = true; runtime∕race·Initialize(&racectx); - runtime∕race·MapShadow(noptrdata, enoptrbss - noptrdata); + // Round data segment to page boundaries, because it's used in mmap(). + start = (uintptr)noptrdata & ~(PageSize-1); + size = ROUND((uintptr)enoptrbss - start, PageSize); + runtime∕race·MapShadow((void*)start, size); m->racecall = false; return racectx; } -- 2.50.0