Commit 7d65e3a8 authored by Russ Cox's avatar Russ Cox

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: default avatarKeith Randall <khr@golang.org>
parent 47df542f
...@@ -10,7 +10,7 @@ TEXT runtime·res_init_trampoline(SB),NOSPLIT,$0 ...@@ -10,7 +10,7 @@ TEXT runtime·res_init_trampoline(SB),NOSPLIT,$0
PUSHQ BP PUSHQ BP
MOVQ SP, BP MOVQ SP, BP
CALL libc_res_init(SB) CALL libc_res_init(SB)
CMPQ AX, $-1 CMPL AX, $-1
JNE ok JNE ok
CALL libc_error(SB) CALL libc_error(SB)
ok: ok:
...@@ -28,7 +28,7 @@ TEXT runtime·res_search_trampoline(SB),NOSPLIT,$0 ...@@ -28,7 +28,7 @@ TEXT runtime·res_search_trampoline(SB),NOSPLIT,$0
MOVQ 0(BX), DI // arg 1 name MOVQ 0(BX), DI // arg 1 name
CALL libc_res_search(SB) CALL libc_res_search(SB)
XORL DX, DX XORL DX, DX
CMPQ AX, $-1 CMPL AX, $-1
JNE ok JNE ok
CALL libc_error(SB) CALL libc_error(SB)
MOVLQSX (AX), DX // move return from libc_error into DX MOVLQSX (AX), DX // move return from libc_error into DX
......
...@@ -369,7 +369,7 @@ TEXT runtime·kevent_trampoline(SB),NOSPLIT,$0 ...@@ -369,7 +369,7 @@ TEXT runtime·kevent_trampoline(SB),NOSPLIT,$0
MOVQ 40(DI), R9 // arg 6 ts MOVQ 40(DI), R9 // arg 6 ts
MOVL 0(DI), DI // arg 1 kq MOVL 0(DI), DI // arg 1 kq
CALL libc_kevent(SB) CALL libc_kevent(SB)
CMPQ AX, $-1 CMPL AX, $-1
JNE ok JNE ok
CALL libc_error(SB) CALL libc_error(SB)
MOVLQSX (AX), AX // errno MOVLQSX (AX), AX // errno
...@@ -556,6 +556,9 @@ TEXT runtime·pthread_cond_signal_trampoline(SB),NOSPLIT,$0 ...@@ -556,6 +556,9 @@ TEXT runtime·pthread_cond_signal_trampoline(SB),NOSPLIT,$0
// } // }
// syscall must be called on the g0 stack with the // syscall must be called on the g0 stack with the
// C calling convention (use libcCall). // 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 TEXT runtime·syscall(SB),NOSPLIT,$0
PUSHQ BP PUSHQ BP
MOVQ SP, BP MOVQ SP, BP
...@@ -603,6 +606,9 @@ ok: ...@@ -603,6 +606,9 @@ ok:
// } // }
// syscallX must be called on the g0 stack with the // syscallX must be called on the g0 stack with the
// C calling convention (use libcCall). // 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 TEXT runtime·syscallX(SB),NOSPLIT,$0
PUSHQ BP PUSHQ BP
MOVQ SP, BP MOVQ SP, BP
...@@ -689,6 +695,9 @@ ok: ...@@ -689,6 +695,9 @@ ok:
// } // }
// syscall6 must be called on the g0 stack with the // syscall6 must be called on the g0 stack with the
// C calling convention (use libcCall). // 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 TEXT runtime·syscall6(SB),NOSPLIT,$0
PUSHQ BP PUSHQ BP
MOVQ SP, BP MOVQ SP, BP
...@@ -739,6 +748,9 @@ ok: ...@@ -739,6 +748,9 @@ ok:
// } // }
// syscall6X must be called on the g0 stack with the // syscall6X must be called on the g0 stack with the
// C calling convention (use libcCall). // 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 TEXT runtime·syscall6X(SB),NOSPLIT,$0
PUSHQ BP PUSHQ BP
MOVQ SP, BP MOVQ SP, BP
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment