From 13cdd814ea0e8ef165ab54802f9f102b8b690df7 Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Sun, 14 May 2017 09:42:35 -0700 Subject: [PATCH] runtime: mmap(2) on Solaris & Illumos can return EAGAIN. 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 --- src/runtime/mem_bsd.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/runtime/mem_bsd.go b/src/runtime/mem_bsd.go index a65933fbfb80a..e0d234715fdf7 100644 --- a/src/runtime/mem_bsd.go +++ b/src/runtime/mem_bsd.go @@ -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) { @@ -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 { @@ -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 {