AnyPS5/core/libs/prx/libkernel/Pthread/include
David e8fd542f03 feat(libkernel): implement pthread_atfork
pthread_atfork (U9t5kJAWPnA, aerolib) appends the prepare, parent and
child handlers to a process-wide list under a lock and returns 0, or
ENOMEM when the entry cannot be allocated, as FreeBSD 11.4's
_pthread_atfork does (lib/libthr/thread/thr_fork.c:78-100, freebsd-src
8c639945a44588f6cfdddfb057bb5aad88735da0). Null handlers are accepted;
FreeBSD's fork skips them. The handlers never run: fork
(libkernel_sys) throws and vfork is absent, so no child process is
created. The list is kept, in registration order, for a later fork
(PthreadAtforkHandlers_nid_no_patch); recorded in TechnicalDebt.

XPSemu (PPSA97358) calls it from a constructor, before main
(ZiZc3/XPSemu 8eec07b4, util/rcu.c:488-495):

    static void __attribute__((__constructor__)) rcu_init(void)
    {
        smp_mb_global_init();
    #ifdef CONFIG_POSIX
        pthread_atfork(rcu_init_lock, rcu_init_unlock, rcu_init_child);
    #endif
        rcu_init_complete();
    }

so a throwing export would stop the title before main. Predicted stop
removed (registry index 255, not run):
FAIL: unresolved ELF import U9t5kJAWPnA from libkernel.prx

guest_pthread_atfork checks registration order, null handlers,
concurrent registration from four threads and that no handler runs.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit f37bccf6efd76edcde5d582800c89b83fdd30472)
2026-10-13 07:38:13 +00:00
..
Atfork.hpp feat(libkernel): implement pthread_atfork 2026-10-13 07:38:13 +00:00
Cancel.hpp fix(libkernel): leave a once initializer's own cleanup handlers alone when it throws 2026-10-12 07:49:09 +00:00
Cond.hpp feat(libkernel): impl pthread condition variables + posix thread attribute queries 2026-09-27 11:43:37 +03:00
Mutex.hpp feat(libkernel): implement posix mutex locking and timed waits 2026-09-27 11:43:37 +03:00
Pthread.hpp Merge pull request #4656 from milescoviello/fix/rwlock-writer-preference 2026-10-13 17:49:30 +13:00
Rwlock.hpp feat(libkernel): implement the pthread_rwlock try and timed lock functions 2026-10-04 17:13:36 +02:00
ThreadLifecycle.hpp fix(libkernel): run pthread key destructors before thread release 2026-10-11 12:21:40 -04:00
WindowsThreadLocal.hpp fix(libkernel): keep Unity GC delivery out of MinGW TLS waits 2026-10-10 03:06:40 +03:00