fix(libkernel): return EPERM or EINVAL when a condition wait gets a mutex the caller does not hold #2752
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2752"
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 husseinkad on 2026-10-10T12:54:35Z.
What
pthread_cond_wait,pthread_cond_timedwait,scePthreadCondWaitandscePthreadCondTimedwaitthrew a hoststd::runtime_errororstd::invalid_argument(ending the process) when the mutex was not held by the calling thread: an unlocked mutex, one locked by another thread, a statically initialised (null) one, and the adaptive static initialiser (pointer value 1) was dereferenced outright (a crash). FreeBSD libthr'scond_wait_commoncalls_mutex_ownedbefore touching any state (thr_cond.c, thr_mutex.c at releng/11.4), which returnsEPERMwhen the calling thread is not the owner (including theNULLand adaptive static initialisers, which it does not initialise on demand) andEINVALfor a destroyed mutex;pthread_cond_wait(3)lists[EPERM]for a mutex the calling thread does not hold. The mutex unlock and rwlock paths in this repo already returnEPERMthe same way.The ownership check (
mutexOwnership, replacinglockedMutex) runs before the trace, the owner clear, the unlock and the wait, so no waiter is registered and the mutex and the condition variable are left exactly as they were. It returnsSCE_KERNEL_ERROR_EPERMorSCE_KERNEL_ERROR_EINVAL(the POSIX wrappers 1 and 22); a null mutex or condition pointer still throws.Tested
Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release:
guest_cond_unowned_mutex(registered in the libkernelCMakeLists.txt, no sleeps) covers the four entry points, plain and timed, for an unlocked mutex, one held by another thread, a zeroed one, the adaptive static initialiser and a destroyed one; it fails without the change (exit0xc0000409) and passes with it.ctest -R "guest_cond|guest_pthread|guest_semaphore|guest_once|guest_thread|guest_kernel_sync"passes.main'sCond.cppand this branch's side by side over the samelibkernel: 40 producer/consumer stress scenarios of 3 s each (5 mutex types x untimed and timed waiters x lock/trylock/timedlock x two thread-count shapes): 0 falseEPERM, no lost wakeup, no hang, all identical tomain; a 96-case matrix of legitimate holds is byte-identical; 116 error-path cases wheremainthrew or segfaulted now returnEPERM/EINVALand leave the mutex (another thread can lock it) and the condition variable (a normal wait/signal pair works) intact; timeouts, thetv_nsecand null-abstimeEINVALand a recursive mutex locked twice behave as before; per-call cost unchanged (0.685 s against 0.691 s per million calls).tools/check_conventions.py --base origin/mainandtools/check_test_registration.py buildpass;tools/pr_overlap.py --branchreports no overlap.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T12:54:44Z.
Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
Pull request closed