feat(libkernel): implement pthread_cleanup_push and pthread_cleanup_pop #8428
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8428"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-20T12:34:03Z.
What
Implements
pthread_cleanup_push(4ZeZWcMsAV0) andpthread_cleanup_pop(RVxb0Ssa5t0), which are absent today. Discussion #7941 reports them as missing imports for CUSA04865.In the decrypted
libkernel.sprxthey are the FreeBSD libthr pair:pthread_cleanup_push(0x50a0) allocates the handler record, marks it as heap-owned and links it on the current thread's handler list, the same list__pthread_cleanup_push_impuses with a caller-provided record.pthread_cleanup_pop(0x5100) has the same body as__pthread_cleanup_pop_imp(0x5050). It unlinks the newest record, runs it ifexecuteis non-zero, and frees it if it is heap-owned.Here:
pthread_cleanup_pushallocates aCleanupHandlerwithonHeap = 1, a field that already exists but was never set.pthread_cleanup_popforwards to__pthread_cleanup_pop_imp.__pthread_cleanup_pop_impnow deletes heap-owned records after running them. So records pushed bypthread_cleanup_pushand run byscePthreadExitor a cancellation are freed too.The console push also sets the thread's "unwind disabled" flag. That flag is not modelled, because guest frames are not unwound on exit here.
Tested
Linux (CachyOS, GCC, Release).
guest_pthread_cancelgainsHeapHandlers, which mixes__pthread_cleanup_push_impandpthread_cleanup_pushrecords, pops with and withoutexecutethrough both pop forms, then exits. It checks the run order (3, 4, 1), the count and the exit value. The test passes, as doguest_once,guest_pthread_cancel_recoveryandguest_pthread_cancel_recovery_coarse.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T12:34:39Z.
Progress report (
88942aa→fa0e7b8)📈 System libraries: 64.16% (+0.01%, +2 implemented functions)
✅ 2 implemented
pthread_cleanup_pop_nid_postfixpthread_cleanup_push_nid_postfixImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T12:45:26Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/tests/GuestPthreadCancel.cppcore/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/prx/libkernel/Pthread/src/Thread.cppImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T13:34:49Z.
Checked the push/pop pair against the existing
__pthread_cleanup_*_imppath: heap records are markedonHeap, freed after running in pop,scePthreadExitand cancellation; caller-provided records are untouched.HeapHandlerspins the order (3, 4, 1), the count and the exit value and cannot pass without the new exports; merged.