Skip to content

Commit

Permalink
runtime: mmap(2) on Solaris & Illumos can return EAGAIN.
Browse files Browse the repository at this point in the history
In low memory situations mmap(2) on Illumos[2] can return EAGAIN when it
is unable to reserve the necessary space for the requested mapping.  Go
was not previously handling this correctly for Illumos and would fail to
recognize it was in a low-memory situation, the result being the program
would terminate with a panic instead of running the GC.

Fixes: #14930

[1]: https://www.illumos.org/man/2/mmap

Change-Id: I889cc0547e23f9d6c56e4fdd7bcbd0e15403873a
Reviewed-on: https://go-review.googlesource.com/43461
Reviewed-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
Sean Chittenden authored and bradfitz committed May 16, 2017
1 parent 3b263e4 commit 13cdd81
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/runtime/mem_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func sysReserve(v unsafe.Pointer, n uintptr, reserved *bool) unsafe.Pointer {
return p
}

const _sunosEAGAIN = 11
const _ENOMEM = 12

func sysMap(v unsafe.Pointer, n uintptr, reserved bool, sysStat *uint64) {
Expand All @@ -76,7 +77,7 @@ func sysMap(v unsafe.Pointer, n uintptr, reserved bool, sysStat *uint64) {
flags |= _MAP_FIXED
}
p := mmap(v, n, _PROT_READ|_PROT_WRITE, flags, -1, 0)
if uintptr(p) == _ENOMEM {
if uintptr(p) == _ENOMEM || (GOOS == "solaris" && uintptr(p) == _sunosEAGAIN) {
throw("runtime: out of memory")
}
if p != v {
Expand All @@ -87,7 +88,7 @@ func sysMap(v unsafe.Pointer, n uintptr, reserved bool, sysStat *uint64) {
}

p := mmap(v, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_FIXED|_MAP_PRIVATE, -1, 0)
if uintptr(p) == _ENOMEM {
if uintptr(p) == _ENOMEM || (GOOS == "solaris" && uintptr(p) == _sunosEAGAIN) {
throw("runtime: out of memory")
}
if p != v {
Expand Down

0 comments on commit 13cdd81

Please sign in to comment.