fix(libkernel): return EBUSY when destroying a held rwlock #2978

Merged
MarcZX10 merged 2 commits from upstream-pr/2978 into main 2026-10-10 23:45:29 +00:00
MarcZX10 commented 2026-10-10 19:21:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T19:21:33Z.


What

Fixes #2836. Track active readers and check both reader and writer ownership before deleting a rwlock. Return SCE_KERNEL_ERROR_EBUSY and preserve the handle while a lock remains held; add SCE and POSIX regression coverage for local and remote readers/writers, failed acquisitions, and writer handoff.

This carries the issue-linked change authored by Zayd Zaari; the original commit author is preserved. Concurrent destruction with a simultaneous acquisition remains outside this fix.

Tested

Linux, GCC 12.2.0, Release: rebuilt libkernel.prx and guest_pthread_rwlock_tests from the existing configured build tree. guest_pthread_rwlock passed 10 consecutive runs. Conventions, diff checks, and the open-PR overlap check passed.

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
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4813812084 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2978). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T19:21:33Z. --- ### What Fixes #2836. Track active readers and check both reader and writer ownership before deleting a rwlock. Return `SCE_KERNEL_ERROR_EBUSY` and preserve the handle while a lock remains held; add SCE and POSIX regression coverage for local and remote readers/writers, failed acquisitions, and writer handoff. This carries the issue-linked change authored by Zayd Zaari; the original commit author is preserved. Concurrent destruction with a simultaneous acquisition remains outside this fix. ### Tested Linux, GCC 12.2.0, Release: rebuilt `libkernel.prx` and `guest_pthread_rwlock_tests` from the existing configured build tree. `guest_pthread_rwlock` passed 10 consecutive runs. Conventions, diff checks, and the open-PR overlap check passed. ### 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 - [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
screamm commented 2026-10-10 20:53:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-10T20:53:26Z.


Windows validation of the current head 8c790001 merged onto main 56fb1b3b.

Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON, full build including the libs target.

  • guest_pthread_rwlock passes 3/3 (--repeat until-fail:3).
  • ctest -j8 -E "^agc_|video_out" passes 388/388.
  • With main's Rwlock.cpp and Pthread.hpp and this PR's test, guest_pthread_rwlock aborts, so the coverage detects the previous behaviour.

Validation run with Claude Code assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102066903 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2978#issuecomment-6102066903). Originally posted by [screamm](https://github.com/screamm) on 2026-10-10T20:53:26Z. --- Windows validation of the current head `8c790001` merged onto `main` `56fb1b3b`. Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`, full build including the `libs` target. - `guest_pthread_rwlock` passes 3/3 (`--repeat until-fail:3`). - `ctest -j8 -E "^agc_|video_out"` passes 388/388. - With `main`'s `Rwlock.cpp` and `Pthread.hpp` and this PR's test, `guest_pthread_rwlock` aborts, so the coverage detects the previous behaviour. Validation run with Claude Code assistance.
adriadam10 commented 2026-10-10 23:39:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T23:39:42Z.


Checked the held-reader/held-writer destroy paths, the new SCE and POSIX tests (they fail without the change) and the rebase onto current main; thanks @screamm for the Windows run.

Added in our commit:

  • TechnicalDebt.md: EBUSY on destroy of a held rwlock follows KytyPS5; FreeBSD libthr and shadPS4 free without checking and the console's answer is unverified. Destroying while another thread is acquiring is documented as unguarded.

Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103399176 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2978#issuecomment-6103399176). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T23:39:42Z. --- Checked the held-reader/held-writer destroy paths, the new SCE and POSIX tests (they fail without the change) and the rebase onto current main; thanks @screamm for the Windows run. Added in our commit: - `TechnicalDebt.md`: `EBUSY` on destroy of a held rwlock follows KytyPS5; FreeBSD libthr and shadPS4 free without checking and the console's answer is unverified. Destroying while another thread is acquiring is documented as unguarded. 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!2978
No description provided.