1
0
mirror of https://github.com/golang/go synced 2024-11-17 12:04:43 -07:00

runtime: print errno on clock_gettime failure on OpenBSD

For #49532.

Change-Id: I5afc64c987f0519903128550a7dac3a0f5e592cf
Reviewed-on: https://go-review.googlesource.com/c/go/+/368334
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Joel Sing <joel@sing.id.au>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
Austin Clements 2021-12-01 13:41:45 -05:00
parent d34051bf16
commit 28ec0fdeb5
5 changed files with 34 additions and 12 deletions

View File

@ -174,7 +174,13 @@ func nanotime1() int64 {
clock_id int32
tp unsafe.Pointer
}{_CLOCK_MONOTONIC, unsafe.Pointer(&ts)}
libcCall(unsafe.Pointer(abi.FuncPCABI0(clock_gettime_trampoline)), unsafe.Pointer(&args))
if errno := libcCall(unsafe.Pointer(abi.FuncPCABI0(clock_gettime_trampoline)), unsafe.Pointer(&args)); errno < 0 {
// Avoid growing the nosplit stack.
systemstack(func() {
println("runtime: errno", -errno)
throw("clock_gettime failed")
})
}
return ts.tv_sec*1e9 + int64(ts.tv_nsec)
}
func clock_gettime_trampoline()
@ -186,7 +192,13 @@ func walltime() (int64, int32) {
clock_id int32
tp unsafe.Pointer
}{_CLOCK_REALTIME, unsafe.Pointer(&ts)}
libcCall(unsafe.Pointer(abi.FuncPCABI0(clock_gettime_trampoline)), unsafe.Pointer(&args))
if errno := libcCall(unsafe.Pointer(abi.FuncPCABI0(clock_gettime_trampoline)), unsafe.Pointer(&args)); errno < 0 {
// Avoid growing the nosplit stack.
systemstack(func() {
println("runtime: errno", -errno)
throw("clock_gettime failed")
})
}
return ts.tv_sec, int32(ts.tv_nsec)
}

View File

@ -520,8 +520,11 @@ TEXT runtime·clock_gettime_trampoline(SB),NOSPLIT,$0
MOVL BX, 4(SP) // arg 2 - clock_id
CALL libc_clock_gettime(SB)
CMPL AX, $-1
JNE 2(PC)
MOVL $0xf1, 0xf1 // crash on failure
JNE noerr
CALL libc_errno(SB)
MOVL (AX), AX
NEGL AX // caller expects negative errno
noerr:
MOVL BP, SP
POPL BP
RET

View File

@ -369,8 +369,11 @@ TEXT runtime·clock_gettime_trampoline(SB),NOSPLIT,$0
MOVL 0(DI), DI // arg 1 clock_id
CALL libc_clock_gettime(SB)
TESTL AX, AX
JEQ 2(PC)
MOVL $0xf1, 0xf1 // crash
JEQ noerr
CALL libc_errno(SB)
MOVL (AX), AX // errno
NEGL AX // caller expects negative errno value
noerr:
POPQ BP
RET

View File

@ -407,9 +407,11 @@ TEXT runtime·clock_gettime_trampoline(SB),NOSPLIT,$0
MOVW 0(R0), R0 // arg 1 clock_id
BL libc_clock_gettime(SB)
CMP $-1, R0
BNE 3(PC)
MOVW $0, R8 // crash on failure
MOVW R8, (R8)
BNE noerr
BL libc_errno(SB)
MOVW (R0), R0 // errno
RSB.CS $0, R0 // caller expects negative errno
noerr:
MOVW R9, R13
RET

View File

@ -359,9 +359,11 @@ TEXT runtime·clock_gettime_trampoline(SB),NOSPLIT,$0
MOVD 0(R0), R0 // arg 1 - clock_id
CALL libc_clock_gettime(SB)
CMP $-1, R0
BNE 3(PC)
MOVD $0, R0 // crash on failure
MOVD R0, (R0)
BNE noerr
CALL libc_errno(SB)
MOVW (R0), R0 // errno
NEG R0, R0 // caller expects negative errno value
noerr:
RET
TEXT runtime·fcntl_trampoline(SB),NOSPLIT,$0