]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: correct error handling in several FreeBSD syscall wrappers
authorNikhil Benesch <nikhil.benesch@gmail.com>
Wed, 9 Dec 2020 20:14:59 +0000 (15:14 -0500)
committerAustin Clements <austin@google.com>
Tue, 22 Dec 2020 15:59:17 +0000 (15:59 +0000)
The FreeBSD syscall convention uses the carry flag to indicate whether
an error has occured. The sys_umtx_op, thr_new, and pipe2 syscall
wrappers were failing to account for this convention and silently
suppressing errors as a result. This commit corrects these wrappers
by copying the pattern used by the other fallible syscall wrappers.

Note that futexsleep1 must now explicitly ignore the ETIMEDOUT error
from sys_umtx_op. Previously ETIMEDOUT was implicitly ignored because
sys_umtx_op never returned an error.

Fixes #43106.

Change-Id: I9c422b87cf4c6d308003bf42c3b419f785578b5d
Reviewed-on: https://go-review.googlesource.com/c/go/+/276892
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Trust: Than McIntosh <thanm@google.com>

src/runtime/defs_freebsd_386.go
src/runtime/defs_freebsd_amd64.go
src/runtime/defs_freebsd_arm.go
src/runtime/defs_freebsd_arm64.go
src/runtime/os_freebsd.go
src/runtime/sys_freebsd_386.s
src/runtime/sys_freebsd_amd64.s
src/runtime/sys_freebsd_arm.s
src/runtime/sys_freebsd_arm64.s

index 767755425c125d8c9bcca51a5122449d30230d19..f822934d582c74b40700067c676199181692409c 100644 (file)
@@ -13,10 +13,11 @@ const (
 )
 
 const (
-       _EINTR  = 0x4
-       _EFAULT = 0xe
-       _EAGAIN = 0x23
-       _ENOSYS = 0x4e
+       _EINTR     = 0x4
+       _EFAULT    = 0xe
+       _EAGAIN    = 0x23
+       _ENOSYS    = 0x4e
+       _ETIMEDOUT = 0x3c
 
        _O_NONBLOCK = 0x4
        _O_CLOEXEC  = 0x100000
index 5a833426fd68e49e2a8087d29ad04aef53c51479..0b696cf227090112fc430fe4a68a2f43ee75157f 100644 (file)
@@ -13,10 +13,11 @@ const (
 )
 
 const (
-       _EINTR  = 0x4
-       _EFAULT = 0xe
-       _EAGAIN = 0x23
-       _ENOSYS = 0x4e
+       _EINTR     = 0x4
+       _EFAULT    = 0xe
+       _EAGAIN    = 0x23
+       _ENOSYS    = 0x4e
+       _ETIMEDOUT = 0x3c
 
        _O_NONBLOCK = 0x4
        _O_CLOEXEC  = 0x100000
index b55dfd88cf2e36cc0c630c4d0b59e6d9421de52d..b6f3e790cff9315b02d0db5eea9621425207f1c7 100644 (file)
@@ -13,10 +13,11 @@ const (
 )
 
 const (
-       _EINTR  = 0x4
-       _EFAULT = 0xe
-       _EAGAIN = 0x23
-       _ENOSYS = 0x4e
+       _EINTR     = 0x4
+       _EFAULT    = 0xe
+       _EAGAIN    = 0x23
+       _ENOSYS    = 0x4e
+       _ETIMEDOUT = 0x3c
 
        _O_NONBLOCK = 0x4
        _O_CLOEXEC  = 0x100000
index 5b9d504ba6f990a15285f1248e8c4e78d67fa717..0759a1238f940ced32e496aa3e7f5cc4282be83b 100644 (file)
@@ -13,10 +13,11 @@ const (
 )
 
 const (
-       _EINTR  = 0x4
-       _EFAULT = 0xe
-       _EAGAIN = 0x23
-       _ENOSYS = 0x4e
+       _EINTR     = 0x4
+       _EFAULT    = 0xe
+       _EAGAIN    = 0x23
+       _ENOSYS    = 0x4e
+       _ETIMEDOUT = 0x3c
 
        _O_NONBLOCK = 0x4
        _O_CLOEXEC  = 0x100000
index 730973a20296fc3c85da49e4698694b96f59d658..1c60ee2a57f4c6cabe73ee91e3614eb7703987b8 100644 (file)
@@ -166,7 +166,7 @@ func futexsleep1(addr *uint32, val uint32, ns int64) {
                utp = &ut
        }
        ret := sys_umtx_op(addr, _UMTX_OP_WAIT_UINT_PRIVATE, val, unsafe.Sizeof(*utp), utp)
-       if ret >= 0 || ret == -_EINTR {
+       if ret >= 0 || ret == -_EINTR || ret == -_ETIMEDOUT {
                return
        }
        print("umtx_wait addr=", addr, " val=", val, " ret=", ret, "\n")
@@ -208,7 +208,6 @@ func newosproc(mp *m) {
 
        var oset sigset
        sigprocmask(_SIG_SETMASK, &sigset_all, &oset)
-       // TODO: Check for error.
        ret := thr_new(&param, int32(unsafe.Sizeof(param)))
        sigprocmask(_SIG_SETMASK, &oset, nil)
        if ret < 0 {
index c346e719e14fe25fb8f106a8d678a652f40e0ad7..97e6d9ab36634ced64091e5831d2d4589405824d 100644 (file)
 TEXT runtime·sys_umtx_op(SB),NOSPLIT,$-4
        MOVL    $454, AX
        INT     $0x80
+       JAE     2(PC)
+       NEGL    AX
        MOVL    AX, ret+20(FP)
        RET
 
 TEXT runtime·thr_new(SB),NOSPLIT,$-4
        MOVL    $455, AX
        INT     $0x80
+       JAE     2(PC)
+       NEGL    AX
        MOVL    AX, ret+8(FP)
        RET
 
@@ -120,6 +124,8 @@ TEXT runtime·pipe2(SB),NOSPLIT,$12-16
        MOVL    flags+0(FP), BX
        MOVL    BX, 8(SP)
        INT     $0x80
+       JAE     2(PC)
+       NEGL    AX
        MOVL    AX, errno+12(FP)
        RET
 
index 010b2ec4d4dc2c82f1b923b1068a762c77da36f1..07734b0d7d7f71ba39d094816ff79bfa07256d6f 100644 (file)
@@ -18,6 +18,8 @@ TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0
        MOVQ ut+24(FP), R8
        MOVL $454, AX
        SYSCALL
+       JCC     2(PC)
+       NEGQ    AX
        MOVL    AX, ret+32(FP)
        RET
 
@@ -26,6 +28,8 @@ TEXT runtime·thr_new(SB),NOSPLIT,$0
        MOVL size+8(FP), SI
        MOVL $455, AX
        SYSCALL
+       JCC     2(PC)
+       NEGQ    AX
        MOVL    AX, ret+16(FP)
        RET
 
@@ -118,6 +122,8 @@ TEXT runtime·pipe2(SB),NOSPLIT,$0-20
        MOVL    flags+0(FP), SI
        MOVL    $542, AX
        SYSCALL
+       JCC     2(PC)
+       NEGQ    AX
        MOVL    AX, errno+16(FP)
        RET
 
index 1e12f9cfcb0815c4ca0213f691404079331fc496..b12e47c576daeb8a3b3556f405e5c5fbea0d4007 100644 (file)
@@ -51,6 +51,7 @@ TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0
        ADD $20, R13 // arg 5 is passed on stack
        MOVW $SYS__umtx_op, R7
        SWI $0
+       RSB.CS $0, R0
        SUB $20, R13
        // BCS error
        MOVW    R0, ret+20(FP)
@@ -61,6 +62,7 @@ TEXT runtime·thr_new(SB),NOSPLIT,$0
        MOVW size+4(FP), R1
        MOVW $SYS_thr_new, R7
        SWI $0
+       RSB.CS $0, R0
        MOVW    R0, ret+8(FP)
        RET
 
@@ -144,6 +146,7 @@ TEXT runtime·pipe2(SB),NOSPLIT,$0-16
        MOVW    flags+0(FP), R1
        MOVW    $SYS_pipe2, R7
        SWI     $0
+       RSB.CS $0, R0
        MOVW    R0, errno+12(FP)
        RET
 
index 8a4f9b7fa1462a024691a8e40a5895f93f8ce99b..1aa09e87ca1dc3fc304ff01f8925525a9c72dcf5 100644 (file)
@@ -60,6 +60,9 @@ TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0
        MOVD    ut+24(FP), R4
        MOVD    $SYS__umtx_op, R8
        SVC
+       BCC     ok
+       NEG     R0, R0
+ok:
        MOVW    R0, ret+32(FP)
        RET
 
@@ -69,6 +72,9 @@ TEXT runtime·thr_new(SB),NOSPLIT,$0
        MOVW    size+8(FP), R1
        MOVD    $SYS_thr_new, R8
        SVC
+       BCC     ok
+       NEG     R0, R0
+ok:
        MOVW    R0, ret+16(FP)
        RET