]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: print errno on clock_gettime failure on OpenBSD
authorAustin Clements <austin@google.com>
Wed, 1 Dec 2021 18:41:45 +0000 (13:41 -0500)
committerAustin Clements <austin@google.com>
Thu, 2 Dec 2021 15:48:58 +0000 (15:48 +0000)
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>
src/runtime/sys_openbsd2.go
src/runtime/sys_openbsd_386.s
src/runtime/sys_openbsd_amd64.s
src/runtime/sys_openbsd_arm.s
src/runtime/sys_openbsd_arm64.s

index a7786fe65a55de325a8704a5bf38c36786f0a456..4d50b4f6b136f23d5c615acadf1ad28748e130cc 100644 (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)
 }
 
index 7830b61b7d0eff6fd2c3f03260cb3495224a1683..890b96b673d434aeeef210be85718204091d1449 100644 (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
index fc89ee6cbbda990a4e01272c217732ce738c3b52..fc6d5dc387dd2c05500890e799dc4110fed3698e 100644 (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
 
index 143fcf0518422152c90269b762c6d16c238d3eaf..a9cb1fbafe1f276c0b63e751efe99fa00f0efba0 100644 (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
 
index 9b4acc90a58c88e3abc08d18b7d476a267c67692..3fa7e1ede25baedba45ef5181273d46acb65b066 100644 (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