fix(libkernel): copy scePthreadOnce control state through checked guest access #25283
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/25283"
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 jvexxxx on 2026-11-21T21:03:25Z.
What
Read and write the guest control word of
scePthreadOnce(and its cancellation/exception cleanup helperResetOnce) throughGuestCopyIn_nid_no_patchandGuestCopyOut_nid_no_patchwhile preservingerrno, matching the checked-copy pattern already used bypthread_once. ReturnSCE_KERNEL_ERROR_EFAULTwithout running the initializer if the control pointer is unreadable or unwritable, and add fault-handling test cases toGuestKernelPthreadOnce.cpp.Tested
Windows (MinGW-w64 WinLibs GCC 15.2.0, Ninja, Release):
libkernel.prx,guest_kernel_pthread_once_tests.exe,guest_once_tests.exe,guest_kernel_pthread_sync_tests.exe,guest_execute_once_tests.exe, andguest_std_execute_once_tests.exe.ctestforguest_execute_onceandguest_std_execute_once.python tools/check_conventions.py --base origin/main,python core/libs/tests/test_public_headers.py --audit-only, and verifiedscePthreadOnceis no longer reported bypython tools/guest_pointer_audit.py libkernel.guest_kernel_pthread_once,guest_once, andguest_kernel_pthread_syncwas not run locally because the host CPU (Intel Core i5-3330) lacks AVX2/BMI1/BMI2/FMA/LZCNT/MOVBE required bylibkernel'sHostCpustartup check.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)Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T21:55:42Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
f0d5d82ac4:tools/check_conventions.pypassed.guest_kernel_pthread_once_testsbuilt cleanly.guest_kernel_pthread_once):core/libs/prx/libkernel/Pthread/src/Thread.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T18:05:04Z.
Review: DISMISSED
Reviewed — changes requested
Changes are required before merge: ensure a failed final state write cannot leave the control permanently marked Running and block future callers.
What I ran
f0d5d82ac4134b9ea6819bb6bf09c7eed6b74e9busingrepo_read.py.Results
Findings
Blocking
core/libs/prx/libkernel/Pthread/src/Thread.cpp:1792: If the initializer makes the control page read-only, the final write ofDonefails and the function returnsSCE_KERNEL_ERROR_EFAULTwhile the control word remainsRunning. The test added for this case verifies the word remains2(core/libs/tests/GuestKernelPthreadOnce.cpp:362-365). A later call seesRunningand waits indefinitely, because no cleanup/reset is performed after this failed write. Ensure failure wakes waiters and does not leave the control stuck in a state that makes later calls wait forever.Non-blocking
None.
Not verified
manifest.json:Thread.cpp,GuestKernelPthreadOnce.cpp, and the debt change note. No changed files were excluded (files.jsonwas not available in the reader listing).To get this to a good state
Runningstate; add or update coverage for a subsequent call after the write failure.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T18:31:16Z.
Review: COMMENTED
Reviewed — comments
The change handles the reported guest memory faults, but
scePthreadOncecan deadlock when an initializer recursively calls it with the same control pointer.What I ran
842c086d92d337b51e4126c8d3fd6467df17439d; base ismain.description.md,commits.md,manifest.json,diff.patch, and all three changed files at the pinned head usingrepo_read.py.Results
Findings
Blocking
None.
Non-blocking
oncepointer deadlock. The thread that owns the active initializer blocks in the condition-variable wait atcore/libs/prx/libkernel/Pthread/src/Thread.cpp:1773-1775, waiting for its own initializer to erase the pointer. RecursivescePthreadOncecalls were previously exercised by the test suite for the POSIX implementation, but the new SCE concurrency test does not cover this case. Consider tracking the owner thread or otherwise detecting same-thread recursion.Not verified
files.jsonwas not available through the reader; no excluded files were reported in the manifest.To get this to a good state
Nothing is required. Consider adding a same-pointer recursive-call test and handling that case without deadlocking.