Commit b1dbce31 authored by Richard Miller's avatar Richard Miller Committed by David du Colombier

runtime: don't ignore address hint for sysReserve in Plan 9

On Plan 9, sysReserve was ignoring the address hint and allocating
memory wherever it is available.  This causes the new
TestArenaCollision test to fail on 32-bit Plan 9.  We now use the
address hint in the specific case where sysReserve is extending the
process address space at its end, and similarly we contract the
address space in the case where sysFree is releasing memory at
the end.

Fixes #23860

Change-Id: Ia5254779ba8f1698c999832720a88de400b5f91a
Reviewed-on: https://go-review.googlesource.com/94776Reviewed-by: default avatarAustin Clements <austin@google.com>
Reviewed-by: default avatarDavid du Colombier <0intro@gmail.com>
parent 07f0f095
...@@ -149,8 +149,15 @@ func sysAlloc(n uintptr, sysStat *uint64) unsafe.Pointer { ...@@ -149,8 +149,15 @@ func sysAlloc(n uintptr, sysStat *uint64) unsafe.Pointer {
func sysFree(v unsafe.Pointer, n uintptr, sysStat *uint64) { func sysFree(v unsafe.Pointer, n uintptr, sysStat *uint64) {
mSysStatDec(sysStat, n) mSysStatDec(sysStat, n)
lock(&memlock) lock(&memlock)
memFree(v, n) if uintptr(v)+n == bloc {
memCheck() // address range being freed is at the end of memory,
// so shrink the address space
bloc -= n
brk_(unsafe.Pointer(bloc))
} else {
memFree(v, n)
memCheck()
}
unlock(&memlock) unlock(&memlock)
} }
...@@ -171,8 +178,16 @@ func sysFault(v unsafe.Pointer, n uintptr) { ...@@ -171,8 +178,16 @@ func sysFault(v unsafe.Pointer, n uintptr) {
func sysReserve(v unsafe.Pointer, n uintptr) unsafe.Pointer { func sysReserve(v unsafe.Pointer, n uintptr) unsafe.Pointer {
lock(&memlock) lock(&memlock)
p := memAlloc(n) var p unsafe.Pointer
memCheck() if uintptr(v) == bloc {
// address hint is the current end of memory,
// so try to extend the address space
p = sbrk(n)
}
if p == nil {
p = memAlloc(n)
memCheck()
}
unlock(&memlock) unlock(&memlock)
return p return p
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment