Page MenuHomeFreeBSD

Several fixes for libthr, related to cancellation
ClosedPublic

Authored by kib on Dec 25 2024, 4:43 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Jan 19, 2:31 PM
Unknown Object (File)
Wed, Jan 15, 5:12 AM
Unknown Object (File)
Sun, Jan 5, 11:28 AM
Unknown Object (File)
Fri, Jan 3, 12:13 AM
Unknown Object (File)
Thu, Jan 2, 7:56 AM
Unknown Object (File)
Tue, Dec 31, 5:25 PM
Unknown Object (File)
Sat, Dec 28, 5:20 PM
Unknown Object (File)
Dec 27 2024, 8:04 AM
Subscribers

Details

Summary
thr_cancel.c: style

thr_sig.c: style


libthr: move dlerror_msg into zeroed part of struct thread

struct thread reuse might cause stalled rtld error message to propagate
to the new thread.


thr_cancel.c: use testcancel() instead of manually expanding it


pthread_setcancelstate(3): make it async-signal-safe

by setting new cancel state and reading old cancel state from the
curthread structure atomic.

Note that this does not play well with async cancellation, since if
cancellation is enabled from a signal handler and cancellation request
is pending, the thread is cancelled immediately, calling user-defined
destructors, which all must be async-signal-safe (but this is a general
requirement for async cancellation anyway).


check_cancel: when in_sigsuspend, send SIGCANCEL unconditionally

not only when check_cancel is called from the signal handler.
_thr_wake() is not enough to get the sigsuspend(2) syscall out of the
loop, since it only terminates sleep when an unblocked signal is
delivered.

PR:     283101
Tested by:      pho

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kib requested review of this revision.Dec 25 2024, 4:43 PM
lib/libthr/thread/thr_cancel.c
108

Don't you need to set *oldstate using the return value of atomic_swap? This code is setting *oldstate to state.

lib/libthr/thread/thr_sig.c
702 ↗(On Diff #148393)
kib marked 2 inline comments as done.

More style.
Fix atomic_swap() use.

This revision is now accepted and ready to land.Sat, Dec 28, 4:46 PM