From c93193aec0f33e901d6802e61c966286785f57ee Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 11 Feb 2016 18:09:34 -0800 Subject: [PATCH] runtime: return errno value from Solaris mmap as expected The code in mem_bsd.go expects that when mmap fails it will return a positive errno value. This fixes the Solaris implementation of mmap to work as expected. Change-Id: Id1c34a9b916e8dc955ced90ea2f4af8321d92265 Reviewed-on: https://go-review.googlesource.com/19477 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Russ Cox --- src/runtime/os3_solaris.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/runtime/os3_solaris.go b/src/runtime/os3_solaris.go index 7bda07bd4a5..7ebb35c8e9c 100644 --- a/src/runtime/os3_solaris.go +++ b/src/runtime/os3_solaris.go @@ -442,7 +442,21 @@ func madvise(addr unsafe.Pointer, n uintptr, flags int32) { //go:nosplit func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) unsafe.Pointer { - return unsafe.Pointer(sysvicall6(&libc_mmap, uintptr(addr), uintptr(n), uintptr(prot), uintptr(flags), uintptr(fd), uintptr(off))) + p, err := doMmap(uintptr(addr), n, uintptr(prot), uintptr(flags), uintptr(fd), uintptr(off)) + if p == ^uintptr(0) { + return unsafe.Pointer(err) + } + return unsafe.Pointer(p) +} + +//go:nosplit +func doMmap(addr, n, prot, flags, fd, off uintptr) (uintptr, uintptr) { + var libcall libcall + libcall.fn = uintptr(unsafe.Pointer(&libc_mmap)) + libcall.n = 6 + libcall.args = uintptr(noescape(unsafe.Pointer(&addr))) + asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&libcall)) + return libcall.r1, libcall.err } //go:nosplit