runtime: document, fix libc error checks on macOS
It matters whether we are calling a function that would
return a 32-bit or 64-bit -1 on error. A few sites were wrong
and this key detail was omitted from syscall/syscallX docs.
Change-Id: I48a421b6cc4d2d2b5e58f790cc947e3cb2f98940
Reviewed-on: https://go-review.googlesource.com/c/go/+/180841
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
diff --git a/src/runtime/lookup_darwin_amd64.s b/src/runtime/lookup_darwin_amd64.s
index 2e30686..587e436 100644
--- a/src/runtime/lookup_darwin_amd64.s
+++ b/src/runtime/lookup_darwin_amd64.s
@@ -10,7 +10,7 @@
PUSHQ BP
MOVQ SP, BP
CALL libc_res_init(SB)
- CMPQ AX, $-1
+ CMPL AX, $-1
JNE ok
CALL libc_error(SB)
ok:
@@ -28,7 +28,7 @@
MOVQ 0(BX), DI // arg 1 name
CALL libc_res_search(SB)
XORL DX, DX
- CMPQ AX, $-1
+ CMPL AX, $-1
JNE ok
CALL libc_error(SB)
MOVLQSX (AX), DX // move return from libc_error into DX
diff --git a/src/runtime/sys_darwin_amd64.s b/src/runtime/sys_darwin_amd64.s
index 016b056..bbe6bc1 100644
--- a/src/runtime/sys_darwin_amd64.s
+++ b/src/runtime/sys_darwin_amd64.s
@@ -369,7 +369,7 @@
MOVQ 40(DI), R9 // arg 6 ts
MOVL 0(DI), DI // arg 1 kq
CALL libc_kevent(SB)
- CMPQ AX, $-1
+ CMPL AX, $-1
JNE ok
CALL libc_error(SB)
MOVLQSX (AX), AX // errno
@@ -556,6 +556,9 @@
// }
// syscall must be called on the g0 stack with the
// C calling convention (use libcCall).
+//
+// syscall expects a 32-bit result and tests for 32-bit -1
+// to decide there was an error.
TEXT runtime·syscall(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
@@ -603,6 +606,9 @@
// }
// syscallX must be called on the g0 stack with the
// C calling convention (use libcCall).
+//
+// syscallX is like syscall but expects a 64-bit result
+// and tests for 64-bit -1 to decide there was an error.
TEXT runtime·syscallX(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
@@ -689,6 +695,9 @@
// }
// syscall6 must be called on the g0 stack with the
// C calling convention (use libcCall).
+//
+// syscall6 expects a 32-bit result and tests for 32-bit -1
+// to decide there was an error.
TEXT runtime·syscall6(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
@@ -739,6 +748,9 @@
// }
// syscall6X must be called on the g0 stack with the
// C calling convention (use libcCall).
+//
+// syscall6X is like syscall6 but expects a 64-bit result
+// and tests for 64-bit -1 to decide there was an error.
TEXT runtime·syscall6X(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP