AnyPS5/core/libs/prx/libkernel/Pthread/Posix
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.cpp feat(libkernel): implement pthread_atfork 2026-10-13 07:38:13 +00:00
Attr.cpp feat(libkernel): implement pthread_attr_getstackaddr 2026-10-11 17:45:35 -04:00
Barrier.cpp fix(libkernel): let pthread_barrier_destroy wait for released waiters 2026-10-11 20:57:22 +00:00
Common.hpp Merge pull request #4005 from zmeizy/claude/posix-deadline-overflow 2026-10-12 16:12:38 +13:00
Cond.cpp feat(libkernel): implement pthread_cond_reltimedwait_np 2026-10-11 23:53:37 +02:00
Mutex.cpp fix(libkernel): try the lock before checking the pthread_mutex_timedlock deadline 2026-10-11 21:00:30 +00:00
Once.cpp fix(libkernel): leave a once initializer's own cleanup handlers alone when it throws 2026-10-12 07:49:09 +00:00
Rwlock.cpp feat(libkernel): implement pthread_rwlockattr_init and pthread_rwlockattr_destroy 2026-10-10 15:07:43 -04:00
Sem.cpp fix(libkernel): handle available sem_timedwait counts first 2026-10-11 23:54:18 +02:00
Spinlock.cpp feat(libkernel): implement the pthread spinlock calls 2026-10-11 23:53:36 +02:00
Thread.cpp feat(libkernel): report the process affinity from cpuset_getaffinity 2026-10-11 16:43:36 +00:00
Tsd.cpp feat(runtime): guest arena, kernel thread/sync/file APIs, crash hooks 2026-09-25 16:27:49 -07:00