fix(libkernel): return EINVAL for pthread mutex and cond operations on a destroyed object #6244
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6244"
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 xXPBSXx on 2026-10-15T06:57:59Z.
Replaces #4971 (closed 14.10. with the note to reopen with a title ID and a log line; GitHub does not let me reopen it). Same branch, same head
9284312ac.What
Locking, trylocking and unlocking a destroyed mutex, and signalling, broadcasting, waiting on or destroying a destroyed condition variable threw a C++ exception into the guest (
Mutex has been destroyed,Condition variable has been destroyed,Condition variable has already been destroyed), which terminates the process. FreeBSD 11.4 libthr returnsEINVALin every one of these cases:thr_mutex.c:check_and_init_mutexreturnsEINVALwhen*m == THR_MUTEX_DESTROYED(lock, timedlock, trylock);mutex_unlock_commonreturnsEINVALfor it;_pthread_mutex_destroyreturnsEINVALfor an already destroyed mutex.thr_cond.c:CHECK_AND_INIT_CONDreturnsEINVALforTHR_COND_DESTROYED(signal, broadcast, wait);_pthread_cond_destroysetsEINVALfor an already destroyed condition variable.The change makes
resolveMutexandresolveCondreport the destroyed state and the callers returnSCE_KERNEL_ERROR_EINVAL(the POSIX wrappers map it toEINVAL). The mutex destroy path and the condition wait path (mutexOwnership) already returnedEINVALfor a destroyed mutex; this makes the rest consistent. Thesce*entry points share these functions, so they change too; I did not check what a PS5 returns there, the choice follows the shared libthr behavior. This includesscePthreadCondSignalto: it now returnsSCE_KERNEL_ERROR_EINVALfor a destroyed condition variable instead of throwing; for a live one it still wakes all waiters (NotifyAll) and still ignores its thread argument, as before. This follows from the code (resolveCondreturns null for a destroyed condition variable); the new test does not callscePthreadCondSignalto.Left as is: NULL pointer arguments still throw (FreeBSD would fault there), as does the use of an uninitialized condition attribute in
scePthreadCondInit.Overlap: #5429 (wake guest mutex waiters on release) is merged (main
d1670009f). It rewrote the same lock call sites inMutex.cpp; the branch now contains a merge commit ofmain(9284312ac) that resolves the conflict there: the three lock paths (pthread_mutex_timedlock'sMutexOperations::Timedlock,scePthreadMutexLock,scePthreadMutexTimedlock) keepacquireResolved(a destroyed mutex answersEINVAL) and hand the resolved mutex to #5429's parking calls (TimedWait::ParkAcquire,TimedWait::AcquireUntil).Cond.cppand the libkernelCMakeLists.txtmerged without a conflict.Title evidence
Ship of Harkinian (PPSA99320), reported by @milescoviello on the previous pull request #4971 (Linux, Ubuntu 24.04, GCC 13.3, Release, RTX 4070 Ti,
maina077a88df+ #6217): with no ROM installed the title shows its "Game files needed" dialog; pressing Cross on its OK button quits the title. Onmain+ #6217 the quit stops withwhat(): Mutex has been destroyed; with the head of this branch the same quit exits with code 0. A run ended by its 75 s timeout stops the same way without the change. I have not run that title myself. The title needs #6217 (malloc_stats_fast) to get that far.Tested
maind92a8dad390af1807cc91622b924252141816a5a+ this branch (clean merge, treedb30968fb):guest_pthread_destroyed_objects(ctest) passes with the change, ctest exit 0; without it (Cond.cppandMutex.cppfrommain, the new test kept, libkernel rebuilt) it fails with test exit code0xc0000409andwhat(): Mutex has been destroyed, ctest exit 8.9284312ac(merge ofmaind1670009finto the previous head6ddb7e5c5): the 27 test executables of the targetsguest_cond_*,guest_mutex_*,guest_posix_sem,guest_pthread_*andguest_semaphoreall exit with code 0.python tools/check_conventions.py --base upstream/mainpasses on this head.maind92a8dad3, Linux, a console, the title itself. The expected values come from the FreeBSD 11.4 sources above, read fromrelease/11.4.0on GitHub.Checklist
main(d92a8dad3) without conflict (the branch contains a merge ofmain; the conflict with the merged #5429 is resolved, see Overlap)NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repositoryAI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T07:33:12Z.
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/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtImported from boykopovar/AnyPS5. Originally posted by isnisk on 2026-10-15T14:50:17Z.
Checked on Linux: Ubuntu 26.04 (WSL2), GCC 15.2.0, Release, this head (
9284312ac) merged ontomain489466d3f(clean merge).guest_pthread_destroyed_objectsand the other 26guest_cond_*,guest_pthread_*,guest_posix_semandguest_semaphoretests pass, 3 rounds; no warnings from the changed files.main'sCond.cppandMutex.cpp, the new test kept): the test aborts 3 of 3 withwhat(): Mutex has been destroyed, as on Windows.check_conventions.py --base origin/mainpasses.Not checked: macOS, the title.
AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-15T17:14:23Z.
@adriadam10 a short request for review of this PR. Head
9284312acisMERGEABLE, the Conventions, Eligibility and Intake checks are green, and a Linux check from isnisk above shows the new test aborting 3 of 3 runs without the change and passing with it. The description names the title (PPSA99320), the log line and the test. If a review or a full Build run is possible, I will answer any finding the same day.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-16T20:36:44Z.
A title this fixes: Ship of Harkinian (Vulkan) (PPSA99320, catalog 01.000.000), Linux, RTX 4070 Ti, release build, 30 s runs with pad input. Without a ROM, the app opens its menu and quits about 8 s in.
main1b1f8483c: 2 of 2 runs abort during that exit, right after the pipeline-cache teardown, withMutex has been destroyed(EXIT-134). A sweep run on the samemaindid the same.9284312acmerged onto thatmain(clean merge): 2 of 2 runs exit with status 0 at 8–9 s, and the log has no exception.AI-assisted: yes