Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: several FreeBSD syscall wrappers seem to mishandle errors #43106

benesch opened this issue Dec 9, 2020 · 1 comment

runtime: several FreeBSD syscall wrappers seem to mishandle errors #43106

benesch opened this issue Dec 9, 2020 · 1 comment


Copy link

@benesch benesch commented Dec 9, 2020

I'm in the process of porting gccgo to FreeBSD and noticed something sketchy about some of the FreeBSD-specific syscall wrappers in the runtime package. Consider sys_umtx_op for example:

TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0
MOVQ addr+0(FP), DI
MOVL mode+8(FP), SI
MOVL val+12(FP), DX
MOVQ uaddr1+16(FP), R10
MOVQ ut+24(FP), R8
MOVL $454, AX
MOVL AX, ret+32(FP)

The caller of this function expects negative values to be errors and positive values to be successes:

ret := sys_umtx_op(addr, _UMTX_OP_WAIT_UINT_PRIVATE, val, unsafe.Sizeof(*utp), utp)
if ret >= 0 || ret == -_EINTR {

But sys_umtx_op returns the result of the syscall (the AX register) directly, and according to the FreeBSD calling convention, the carry flag indicates whether AX contains an error code or successful return code, not the sign of the result. Most of the other syscalls in the package seem to get this right (anything that contains a JCC instruction after SYSCALL, roughly speaking, looks right to me), but a few others seem broken in the same way, like thr_new and pipe2.

#10052 seems to be some prior art on this subject. As a result a number of these syscall wrappers were fixed to inspect the carry flag, but not all of them.

Clearly in practice this doesn't seem to matter much, but probably worth fixing nonetheless.

Copy link

@gopherbot gopherbot commented Dec 10, 2020

Change mentions this issue: runtime: correct errors handling in several FreeBSD syscall wrappers


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants