From 193088b246f4bbe9a7d3a84ec7f4cc6786dac043 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Mon, 16 Oct 2017 20:28:29 -0400 Subject: runtime: separate error result for mmap Currently mmap returns an unsafe.Pointer that encodes OS errors as values less than 4096. In practice this is okay, but it borders on being really unsafe: for example, the value has to be checked immediately after return and if stack copying were ever to observe such a value, it would panic. It's also not remotely idiomatic. Fix this by making mmap return a separate pointer value and error, like a normal Go function. Updates #22218. Change-Id: Iefd965095ffc82cc91118872753a5d39d785c3a6 Reviewed-on: https://go-review.googlesource.com/71270 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/runtime/sys_linux_amd64.s | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/runtime/sys_linux_amd64.s') diff --git a/src/runtime/sys_linux_amd64.s b/src/runtime/sys_linux_amd64.s index b4b2a903b3..1b6a9920fd 100644 --- a/src/runtime/sys_linux_amd64.s +++ b/src/runtime/sys_linux_amd64.s @@ -411,10 +411,15 @@ TEXT runtime·sysMmap(SB),NOSPLIT,$0 MOVL $SYS_mmap, AX SYSCALL CMPQ AX, $0xfffffffffffff001 - JLS 3(PC) + JLS ok NOTQ AX INCQ AX - MOVQ AX, ret+32(FP) + MOVQ $0, p+32(FP) + MOVQ AX, err+40(FP) + RET +ok: + MOVQ AX, p+32(FP) + MOVQ $0, err+40(FP) RET // Call the function stored in _cgo_mmap using the GCC calling convention. -- cgit v1.3-5-g45d5