diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index b68820c9a7..3172d60911 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -588,6 +588,9 @@ func mallocinit() { topBits := (randHeapAddrBits - logHeapArenaBytes) randHeapBase = nextHeapRandBits(topBits) << (randHeapAddrBits - topBits) randHeapBase = alignUp(randHeapBase, heapArenaBytes) + if GOOS == "aix" { + randHeapBase += arenaBaseOffset + } randHeapBasePrefix = byte(randHeapBase >> (randHeapAddrBits - 8)) } @@ -623,7 +626,11 @@ func mallocinit() { } case randomizeHeapBase: prefix := uintptr(randHeapBasePrefix+byte(i)) << (randHeapAddrBits - 8) - p = prefix | (randHeapBase & randHeapBasePrefixMask) + if GOOS == "aix" { + p = arenaBaseOffset + (prefix | ((randHeapBase - arenaBaseOffset) & randHeapBasePrefixMask)) + } else { + p = prefix | (randHeapBase & randHeapBasePrefixMask) + } case GOARCH == "arm64" && GOOS == "ios": p = uintptr(i)<<40 | uintptrMask&(0x0013<<28) case GOARCH == "arm64": diff --git a/src/runtime/mem_aix.go b/src/runtime/mem_aix.go index 1203af5797..343f73c771 100644 --- a/src/runtime/mem_aix.go +++ b/src/runtime/mem_aix.go @@ -61,6 +61,10 @@ func sysReserveOS(v unsafe.Pointer, n uintptr, _ string) unsafe.Pointer { if err != 0 { return nil } + if uintptr(p) < arenaBaseOffsetUintptr { + munmap(p, n) + return nil + } return p }