Skip to content

Commit 4d27c4c

Browse files
beneschaclements
authored andcommitted
runtime: correct error handling in several FreeBSD syscall wrappers
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 <[email protected]> Reviewed-by: Austin Clements <[email protected]> Trust: Than McIntosh <[email protected]>
1 parent 9b61471 commit 4d27c4c

9 files changed

+42
-18
lines changed

src/runtime/defs_freebsd_386.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ const (
1313
)
1414

1515
const (
16-
_EINTR = 0x4
17-
_EFAULT = 0xe
18-
_EAGAIN = 0x23
19-
_ENOSYS = 0x4e
16+
_EINTR = 0x4
17+
_EFAULT = 0xe
18+
_EAGAIN = 0x23
19+
_ENOSYS = 0x4e
20+
_ETIMEDOUT = 0x3c
2021

2122
_O_NONBLOCK = 0x4
2223
_O_CLOEXEC = 0x100000

src/runtime/defs_freebsd_amd64.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ const (
1313
)
1414

1515
const (
16-
_EINTR = 0x4
17-
_EFAULT = 0xe
18-
_EAGAIN = 0x23
19-
_ENOSYS = 0x4e
16+
_EINTR = 0x4
17+
_EFAULT = 0xe
18+
_EAGAIN = 0x23
19+
_ENOSYS = 0x4e
20+
_ETIMEDOUT = 0x3c
2021

2122
_O_NONBLOCK = 0x4
2223
_O_CLOEXEC = 0x100000

src/runtime/defs_freebsd_arm.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ const (
1313
)
1414

1515
const (
16-
_EINTR = 0x4
17-
_EFAULT = 0xe
18-
_EAGAIN = 0x23
19-
_ENOSYS = 0x4e
16+
_EINTR = 0x4
17+
_EFAULT = 0xe
18+
_EAGAIN = 0x23
19+
_ENOSYS = 0x4e
20+
_ETIMEDOUT = 0x3c
2021

2122
_O_NONBLOCK = 0x4
2223
_O_CLOEXEC = 0x100000

src/runtime/defs_freebsd_arm64.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ const (
1313
)
1414

1515
const (
16-
_EINTR = 0x4
17-
_EFAULT = 0xe
18-
_EAGAIN = 0x23
19-
_ENOSYS = 0x4e
16+
_EINTR = 0x4
17+
_EFAULT = 0xe
18+
_EAGAIN = 0x23
19+
_ENOSYS = 0x4e
20+
_ETIMEDOUT = 0x3c
2021

2122
_O_NONBLOCK = 0x4
2223
_O_CLOEXEC = 0x100000

src/runtime/os_freebsd.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func futexsleep1(addr *uint32, val uint32, ns int64) {
166166
utp = &ut
167167
}
168168
ret := sys_umtx_op(addr, _UMTX_OP_WAIT_UINT_PRIVATE, val, unsafe.Sizeof(*utp), utp)
169-
if ret >= 0 || ret == -_EINTR {
169+
if ret >= 0 || ret == -_EINTR || ret == -_ETIMEDOUT {
170170
return
171171
}
172172
print("umtx_wait addr=", addr, " val=", val, " ret=", ret, "\n")
@@ -208,7 +208,6 @@ func newosproc(mp *m) {
208208

209209
var oset sigset
210210
sigprocmask(_SIG_SETMASK, &sigset_all, &oset)
211-
// TODO: Check for error.
212211
ret := thr_new(&param, int32(unsafe.Sizeof(param)))
213212
sigprocmask(_SIG_SETMASK, &oset, nil)
214213
if ret < 0 {

src/runtime/sys_freebsd_386.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@
1313
TEXT runtime·sys_umtx_op(SB),NOSPLIT,$-4
1414
MOVL $454, AX
1515
INT $0x80
16+
JAE 2(PC)
17+
NEGL AX
1618
MOVL AX, ret+20(FP)
1719
RET
1820

1921
TEXT runtime·thr_new(SB),NOSPLIT,$-4
2022
MOVL $455, AX
2123
INT $0x80
24+
JAE 2(PC)
25+
NEGL AX
2226
MOVL AX, ret+8(FP)
2327
RET
2428

@@ -120,6 +124,8 @@ TEXT runtime·pipe2(SB),NOSPLIT,$12-16
120124
MOVL flags+0(FP), BX
121125
MOVL BX, 8(SP)
122126
INT $0x80
127+
JAE 2(PC)
128+
NEGL AX
123129
MOVL AX, errno+12(FP)
124130
RET
125131

src/runtime/sys_freebsd_amd64.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0
1818
MOVQ ut+24(FP), R8
1919
MOVL $454, AX
2020
SYSCALL
21+
JCC 2(PC)
22+
NEGQ AX
2123
MOVL AX, ret+32(FP)
2224
RET
2325

@@ -26,6 +28,8 @@ TEXT runtime·thr_new(SB),NOSPLIT,$0
2628
MOVL size+8(FP), SI
2729
MOVL $455, AX
2830
SYSCALL
31+
JCC 2(PC)
32+
NEGQ AX
2933
MOVL AX, ret+16(FP)
3034
RET
3135

@@ -118,6 +122,8 @@ TEXT runtime·pipe2(SB),NOSPLIT,$0-20
118122
MOVL flags+0(FP), SI
119123
MOVL $542, AX
120124
SYSCALL
125+
JCC 2(PC)
126+
NEGQ AX
121127
MOVL AX, errno+16(FP)
122128
RET
123129

src/runtime/sys_freebsd_arm.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0
5151
ADD $20, R13 // arg 5 is passed on stack
5252
MOVW $SYS__umtx_op, R7
5353
SWI $0
54+
RSB.CS $0, R0
5455
SUB $20, R13
5556
// BCS error
5657
MOVW R0, ret+20(FP)
@@ -61,6 +62,7 @@ TEXT runtime·thr_new(SB),NOSPLIT,$0
6162
MOVW size+4(FP), R1
6263
MOVW $SYS_thr_new, R7
6364
SWI $0
65+
RSB.CS $0, R0
6466
MOVW R0, ret+8(FP)
6567
RET
6668

@@ -144,6 +146,7 @@ TEXT runtime·pipe2(SB),NOSPLIT,$0-16
144146
MOVW flags+0(FP), R1
145147
MOVW $SYS_pipe2, R7
146148
SWI $0
149+
RSB.CS $0, R0
147150
MOVW R0, errno+12(FP)
148151
RET
149152

src/runtime/sys_freebsd_arm64.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0
6060
MOVD ut+24(FP), R4
6161
MOVD $SYS__umtx_op, R8
6262
SVC
63+
BCC ok
64+
NEG R0, R0
65+
ok:
6366
MOVW R0, ret+32(FP)
6467
RET
6568

@@ -69,6 +72,9 @@ TEXT runtime·thr_new(SB),NOSPLIT,$0
6972
MOVW size+8(FP), R1
7073
MOVD $SYS_thr_new, R8
7174
SVC
75+
BCC ok
76+
NEG R0, R0
77+
ok:
7278
MOVW R0, ret+16(FP)
7379
RET
7480

0 commit comments

Comments
 (0)