HomeFreeBSD

libthr: allow very early atfork registration

Description

libthr: allow very early atfork registration

LSan wants to be able to register atfork handlers at __lsan_init time,
which can happen either at the first intercepted function call or in a
.preinit_array function. Both of these end up being very early in rtld
and executed with the bind lock held, which ends up causing problems
when we go to _libpthread_init().

Instead of requiring libpthread to be initialized, just insert the new
atfork handler straight into the list if it's not ready yet. The
critical section and locking should not be necessary if we're really
executing this early, as there won't be any threads to contend with.

Reviewed by: kib (earlier version), markj
Differential Revision: https://reviews.freebsd.org/D47349

Details

Provenance
kevansAuthored on Nov 14 2024, 1:33 AM
Reviewer
kib
Differential Revision
D47349: libthr: allow very early atfork registration
Parents
rG7e6ac503ffeb: libthr: add some tests for pthread_atfork() handling
Branches
Unknown
Tags
Unknown