fix(libkernel): return EPERM from scePthreadRwlockUnlock when the lock is not held #2679
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2679"
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-10T10:49:29Z.
What
scePthreadRwlockUnlock(andpthread_rwlock_unlock) calledunlock_shared()on the hostshared_timed_mutexfor any caller that was not the write owner. When the rwlock is not held at all, or is write-held by another thread, that is undefined behaviour, and the call returned 0.FreeBSD libthr (
_Tthr_rwlock_unlockinlib/libthr/thread/thr_rwlock.c,do_rw_unlockinsys/kern/kern_umtx.c) returnsEPERMwhen the lock has no write owner and a zero reader count, and when the write owner is another thread.pthread_rwlock_unlock(3)lists[EPERM]"The current thread does not own the read/write lock".PthreadRwlockPrivatenow keeps an atomic reader count, incremented after every successful read acquisition (rdlock,tryrdlock,timedrdlock; failed or timed-out attempts do not count) and decremented by a compare-exchange loop in unlock that returnsEPERMat 0. Like libthr, the count is per lock, not per thread, so a thread that holds no read lock can still unlock while another thread holds one; what this catches is unlocking a lock that nobody holds and unlocking a write lock owned by another thread.Tested
Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release:
guest_pthread_rwlock: new cases unlock of a never-locked rwlock, double unlock aftertryrdlock, unlock aftertrywrlock, unlock from the main thread while another thread holds the write lock, and that timed-out reads leave no count; all expectEPERM. The test fails without the change (exit0xc0000409) and passes with it.rdlock/tryrdlock/timedrdlock/wrlock/trywrlock/timedwrlockfound no falseEPERM, no leaked or negative reader count, no torn write and no hang; onmainthe same probe confirms the double unlock returns 0.tools/check_conventions.py --base origin/mainpasses;tools/pr_overlap.py --branchreports no overlap. Open PR #2051 edits the lock-acquire lines of the same file, so whichever lands second needs a rebase; the increment has to stay after the acquire.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-10T10:50:08Z.
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