]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: mmap(2) on Solaris & Illumos can return EAGAIN.
authorSean Chittenden <seanc@joyent.com>
Sun, 14 May 2017 16:42:35 +0000 (09:42 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 16 May 2017 21:01:42 +0000 (21:01 +0000)
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 <bradfitz@golang.org>
src/runtime/mem_bsd.go

index a65933fbfb80ae4c8071ed6655f853d18b8c8a64..e0d234715fdf78763f642c732d861a66ce9b4cbe 100644 (file)
@@ -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 {