fix(libkernel): return EPERM when unlocking an rwlock that is not held #3744

Merged
ArekatlaNishanthchowdary merged 2 commits from upstream-pr/3744 into main 2026-10-11 21:57:59 +00:00
ArekatlaNishanthchowdary commented 2026-10-11 16:17:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ArekatlaNishanthchowdary on 2026-10-11T16:17:39Z.


What

scePthreadRwlockUnlock called unlock_shared() whenever the caller was not the write owner, which is undefined behaviour on the host for a lock nobody holds or one write-held by another thread, and returned 0. It now returns EPERM in both cases, as FreeBSD libthr does (thr_rwlock.c, releng/11.4). Fixes #3096.

Carries @husseinkad's two commits from husseinkad:fix/pthread-rwlock-unlock-unowned (earlier PRs #2679 and #3615 were closed by intake limits), rebased onto current main with authorship kept. main already counts readers since #2978, so only the unlock path and the test change.

Tested

Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, NVIDIA RTX 4060 Laptop.

  • guest_pthread_rwlock passes 10/10 with the change and aborts (0xc0000409) with main's Rwlock.cpp and the new test.
  • Full ctest: 827/836 pass, 5 skipped. guest_kernel_sys, windows_exceptions (#3411), agc_driver_emulated_color_compare and guest_filesystem fail the same way with main's Rwlock.cpp on this host.
  • tools/check_conventions.py --base origin/main passes.
  • No title or homebrew run. Linux not run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4820482283 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3744). Originally posted by [ArekatlaNishanthchowdary](https://github.com/ArekatlaNishanthchowdary) on 2026-10-11T16:17:39Z. --- ### What `scePthreadRwlockUnlock` called `unlock_shared()` whenever the caller was not the write owner, which is undefined behaviour on the host for a lock nobody holds or one write-held by another thread, and returned 0. It now returns `EPERM` in both cases, as FreeBSD libthr does ([`thr_rwlock.c`](https://github.com/freebsd/freebsd-src/blob/releng/11.4/lib/libthr/thread/thr_rwlock.c), releng/11.4). Fixes #3096. Carries @husseinkad's two commits from `husseinkad:fix/pthread-rwlock-unlock-unowned` (earlier PRs #2679 and #3615 were closed by intake limits), rebased onto current `main` with authorship kept. `main` already counts readers since #2978, so only the unlock path and the test change. ### Tested Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, NVIDIA RTX 4060 Laptop. - `guest_pthread_rwlock` passes 10/10 with the change and aborts (`0xc0000409`) with `main`'s `Rwlock.cpp` and the new test. - Full `ctest`: 827/836 pass, 5 skipped. `guest_kernel_sys`, `windows_exceptions` (#3411), `agc_driver_emulated_color_compare` and `guest_filesystem` fail the same way with `main`'s `Rwlock.cpp` on this host. - `tools/check_conventions.py --base origin/main` passes. - No title or homebrew run. Linux not run. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
adriadam10 commented 2026-10-11 21:57:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:57:56Z.


Checked the unlock paths against FreeBSD libthr/do_rw_unlock (EPERM for a foreign write owner or zero readers), the new test fails without the change and passes with it (guest_pthread_rwlock, partial ctest 112/112 on Linux); merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114254161 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3744#issuecomment-6114254161). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T21:57:56Z. --- Checked the unlock paths against FreeBSD libthr/`do_rw_unlock` (EPERM for a foreign write owner or zero readers), the new test fails without the change and passes with it (`guest_pthread_rwlock`, partial ctest 112/112 on Linux); merging once CI is green.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!3744
No description provided.