mirror of
https://github.com/golang/go
synced 2024-11-19 12:04:43 -07:00
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/94776 Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: David du Colombier <0intro@gmail.com>
This commit is contained in:
parent
07f0f09563
commit
b1dbce31d7
@ -149,8 +149,15 @@ func sysAlloc(n uintptr, sysStat *uint64) unsafe.Pointer {
|
||||
func sysFree(v unsafe.Pointer, n uintptr, sysStat *uint64) {
|
||||
mSysStatDec(sysStat, n)
|
||||
lock(&memlock)
|
||||
memFree(v, n)
|
||||
memCheck()
|
||||
if uintptr(v)+n == bloc {
|
||||
// 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)
|
||||
}
|
||||
|
||||
@ -171,8 +178,16 @@ func sysFault(v unsafe.Pointer, n uintptr) {
|
||||
|
||||
func sysReserve(v unsafe.Pointer, n uintptr) unsafe.Pointer {
|
||||
lock(&memlock)
|
||||
p := memAlloc(n)
|
||||
memCheck()
|
||||
var p unsafe.Pointer
|
||||
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)
|
||||
return p
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user