From 796786cd0cc1ed71da65fe9f1760b390b189c5cd Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Tue, 12 May 2020 16:08:50 +0000 Subject: runtime: make maxOffAddr reflect the actual address space upper bound Currently maxOffAddr is defined in terms of the whole 64-bit address space, assuming that it's all supported, by using ^uintptr(0) as the maximal address in the offset space. In reality, the maximal address in the offset space is (1< Reviewed-by: Austin Clements Reviewed-by: Michael Pratt --- src/runtime/mpagealloc.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/runtime/mpagealloc.go') diff --git a/src/runtime/mpagealloc.go b/src/runtime/mpagealloc.go index a28dd26cb5..60f7f9ff58 100644 --- a/src/runtime/mpagealloc.go +++ b/src/runtime/mpagealloc.go @@ -99,12 +99,12 @@ type chunkIdx uint // chunkIndex returns the global index of the palloc chunk containing the // pointer p. func chunkIndex(p uintptr) chunkIdx { - return chunkIdx((p + arenaBaseOffset) / pallocChunkBytes) + return chunkIdx((p - arenaBaseOffset) / pallocChunkBytes) } // chunkIndex returns the base address of the palloc chunk at index ci. func chunkBase(ci chunkIdx) uintptr { - return uintptr(ci)*pallocChunkBytes - arenaBaseOffset + return uintptr(ci)*pallocChunkBytes + arenaBaseOffset } // chunkPageIndex computes the index of the page that contains p, @@ -136,13 +136,13 @@ func (i chunkIdx) l2() uint { // offAddrToLevelIndex converts an address in the offset address space // to the index into summary[level] containing addr. func offAddrToLevelIndex(level int, addr offAddr) int { - return int((addr.a + arenaBaseOffset) >> levelShift[level]) + return int((addr.a - arenaBaseOffset) >> levelShift[level]) } // levelIndexToOffAddr converts an index into summary[level] into // the corresponding address in the offset address space. func levelIndexToOffAddr(level, idx int) offAddr { - return offAddr{(uintptr(idx) << levelShift[level]) - arenaBaseOffset} + return offAddr{(uintptr(idx) << levelShift[level]) + arenaBaseOffset} } // addrsToSummaryRange converts base and limit pointers into a range @@ -159,8 +159,8 @@ func addrsToSummaryRange(level int, base, limit uintptr) (lo int, hi int) { // of a summary's max page count boundary for this level // (1 << levelLogPages[level]). So, make limit an inclusive upper bound // then shift, then add 1, so we get an exclusive upper bound at the end. - lo = int((base + arenaBaseOffset) >> levelShift[level]) - hi = int(((limit-1)+arenaBaseOffset)>>levelShift[level]) + 1 + lo = int((base - arenaBaseOffset) >> levelShift[level]) + hi = int(((limit-1)-arenaBaseOffset)>>levelShift[level]) + 1 return } -- cgit v1.3