Page MenuHomeFreeBSD

Bypass errno handling in _umtx_op_err on powerpc

Authored by bdragon on Jul 13 2019, 8:28 PM.



This was implemented previously in i386/amd64 (r177853) and sparc64 (r223228).

The original log message was:

Replace function _umtx_op with _umtx_op_err, the later function directly
returns errno, because errno can be mucked by user's signal handler and
most of pthread api heavily depends on errno to be correct, this change
should improve stability of the thread library.

This version of my patch does additional cleanup that might not be necessary. i386/amd64 and sparc64 don't check for this. It's possible (but I haven't figured out how to prove) that the contract with the kernel means that r3 will always be 0 on return to userspace for the non error condition, but since the same register (along with r4) is also used for aux returns as per cpu_set_syscall_retval(), I figured better safe than sorry. If that's not applicable to _umtx_op (i.e. if those never use the aux return stuff), I can take that back out and just blr after the sc.

Test Plan

Unknown. I'd like to have some sort of test that attempts to trip this up by messing with errno from a signal handler, but I don't know enough about threading and signal handlers to write one off the top of my head.

Diff Detail

rS FreeBSD src repository
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

bdragon created this revision.Jul 13 2019, 8:28 PM
bdragon edited the summary of this revision. (Show Details)Jul 13 2019, 8:29 PM
jhibbits added inline comments.Jul 14 2019, 3:53 AM
38–41 ↗(On Diff #59731)

This is unnecessary. On success %r3 will always be 0 (see exec_machdep.c:916-925, and trap.c:691), so there's no need for the safety belt here.

bdragon updated this revision to Diff 60566.Aug 8 2019, 4:00 AM

removing belt&suspenders bit.

jhibbits accepted this revision.Aug 8 2019, 7:40 PM

Looks good now.

This revision is now accepted and ready to land.Aug 8 2019, 7:40 PM
This revision was automatically updated to reflect the committed changes.