Skip to content

feat(libkernel): implement pthread_atfork registration - #4377

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
MarcZX10:codex/carry-pthread-atfork-3628
Oct 13, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
MarcZX10:codex/carry-pthread-atfork-3628

Conversation

@MarcZX10

@MarcZX10 MarcZX10 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What

Carries the pthread_atfork implementation from #3628, preserving its original commit author. It records prepare/parent/child handlers in registration order and returns ENOMEM on allocation failure. Null handlers are accepted. Since fork is not implemented, registered handlers do not run; unload-time removal is also not modeled, and both limits are documented in docs/dev/debt/libkernel.md.

Tested

  • Before this current-main rebase, Windows 10 MinGW GCC passed guest_pthread_atfork; a Linux rebase handoff reported the full suite passing.
  • The current-main rebase has not been built or tested locally. CI/reviewer validation should rerun against this head.

Current title evidence

PPSA97358 has a source-level pthread_atfork call, but a current-main run has not shown it as the active unresolved import. XPSemu's verified first stop is mlockall (#4386). No title-unblocks claim is made until a run records pthread_atfork as the next stop after the earlier imports are resolved.

Checklist

  • Based on current main; no other open PR implements this function
  • One topic: pthread_atfork
  • No comments in code except technical debt
  • No notes or investigation files added
  • Generic behavior, not title-specific
  • Depends on: none
  • AI-assisted: yes; original implementation author preserved

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Progress report (6d7b873 → 8d455b8)

➖ System libraries: 87.79% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel pthread_atfork_nid_postfix

@MarcZX10 MarcZX10 mentioned this pull request Oct 12, 2026
10 tasks done
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 12, 2026
@xXPBSXx

xXPBSXx commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Windows test: head 7a510b61c merged onto current main 3d8ffeb27 (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, -j4: full build 0 errors; ctest with the filter guest_pthread_atfork: guest_pthread_atfork passed (1 test(s), 0 failed); python tools/check_conventions.py --base upstream/main passed. I did not run the new tests against main without the change.

AI-assisted (Claude Code).

@blawesom

Copy link
Copy Markdown
Contributor

Rebase handoff — rebased onto current main, authorship unchanged (only a TechnicalDebt.md union conflict; both entries kept).

Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, AMD RX 9070 XT / RADV):

  • builds; tools/check_conventions.py --base origin/main passes
  • full suite: 954/954 passed

To pick it up:

git fetch https://github.com/blawesom/AnyPS5 rebase/4377
git checkout <your branch>
git merge --ff-only FETCH_HEAD

@MarcZX10
MarcZX10 force-pushed the codex/carry-pthread-atfork-3628 branch from 7a510b6 to 63a14ad Compare October 12, 2026 16:10
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 12, 2026
@MarcZX10
MarcZX10 force-pushed the codex/carry-pthread-atfork-3628 branch from 63a14ad to e2b64cc Compare October 12, 2026 18:35
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed labels Oct 12, 2026
@MarcZX10
MarcZX10 force-pushed the codex/carry-pthread-atfork-3628 branch from e2b64cc to f196b6f Compare October 12, 2026 18:49
@oneandonlydean oneandonlydean self-assigned this Oct 12, 2026
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 12, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 12, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

#3980 (setrlimit) is merged. Does PPSA97358 now stop at U9t5kJAWPnA on main? With that log line this can go in. The rebase needs redoing first: it deletes the sceAgcDcbSetWorkloadsActive entry from docs/dev/debt/libSceAgc.md, adds the kern.arandom line to docs/dev/debt/libkernel.md a second time, and conflicts with main in both files.

@MarcZX10

Copy link
Copy Markdown
Contributor Author

I do not have a runtime log showing PPSA97358 reaches pthread_atfork after #3980. The separate XPSemu report on #4386 establishes an mlockall import stop, not an atfork call, and the original #3628 report described these stops as predictions. I will not claim title validation for this PR without that log; the PR still needs the requested rebase and current-main evidence.

David and others added 2 commits October 13, 2026 07:38
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 f37bccf)
@MarcZX10
MarcZX10 force-pushed the codex/carry-pthread-atfork-3628 branch from f196b6f to 8d455b8 Compare October 13, 2026 07:39
@MarcZX10

Copy link
Copy Markdown
Contributor Author

Not yet. The current-main XPSemu run cited on #4386 stops first at the unresolved mlockall import; its separate pthread_atfork call site has not been shown to execute or become the next unresolved import. I rebased this PR onto current main, kept the existing AGC debt entries, removed the duplicate kern.arandom line, and updated the atfork debt note and PR description to distinguish source-level presence from runtime reachability. The older test reports predate this rebase, so this head still needs CI and a title rerun after the earlier stop is resolved.

@p3n1cillin

Copy link
Copy Markdown

Title run with this PR: Windows 11, MinGW GCC 15.2.0 (WinLibs), Release. Built on main 3faa9cb40 merged with this PR and the other open PRs that the catalog titles need (#4377, #4379, #4374, #4383, #3798, #4863, #4105, my #5013/#5061/#5078/#5098/#5009 and the carries #5183/#5186, plus screamm's chroot branch from #3632); every title converted from its catalog release, eboot.bin kept in app0, 60 s runs.

AI-assisted (Claude Code).

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#4725 docs/dev/debt/libkernel.md L168-169
#5275 docs/dev/debt/libkernel.md L168

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants