fix(libkernel): return EBUSY when destroying a locked mutex #1483

Merged
Aryansh1520 merged 1 commit from upstream-pr/1483 into main 2026-10-09 23:32:33 +00:00
Aryansh1520 commented 2026-10-08 08:55:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Aryansh1520 on 2026-10-08T08:55:22Z.


What

scePthreadMutexDestroy threw Cannot destroy a locked mutex when the mutex was held. FreeBSD libthr, which the console's libkernel follows, returns EBUSY in that case and leaves the mutex intact. PPSA28997 (God of War Sons of Sparta) destroys a locked mutex during its intro and was aborted by the exception. The function now returns SCE_KERNEL_ERROR_EBUSY; pthread_mutex_destroy maps it to EBUSY through the existing conversion.

Tested

  • Linux (CachyOS, kernel 7.2), GCC: PPSA28997 no longer aborts in its intro.
  • guest_kernel_errors passes with a new check that destroying a locked mutex returns EBUSY and that the mutex can then be unlocked and destroyed.
  • tools/check_conventions.py --base origin/main passes.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4784311537 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1483). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-08T08:55:22Z. --- ### What `scePthreadMutexDestroy` threw `Cannot destroy a locked mutex` when the mutex was held. FreeBSD libthr, which the console's libkernel follows, returns `EBUSY` in that case and leaves the mutex intact. PPSA28997 (God of War Sons of Sparta) destroys a locked mutex during its intro and was aborted by the exception. The function now returns `SCE_KERNEL_ERROR_EBUSY`; `pthread_mutex_destroy` maps it to `EBUSY` through the existing conversion. ### Tested - Linux (CachyOS, kernel 7.2), GCC: PPSA28997 no longer aborts in its intro. - `guest_kernel_errors` passes with a new check that destroying a locked mutex returns `EBUSY` and that the mutex can then be unlocked and destroyed. - `tools/check_conventions.py --base origin/main` passes. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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
popcoder565 commented 2026-10-08 10:35:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-08T10:35:25Z.


Tested on Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, Intel Core i7-12700H, merged onto main e28fa01c together with #1501 and #1483 to share one build.

  • guest_kernel_errors: 10 of 10 runs pass.
  • Mutation check (Mutex.cpp put back to main, test kept): 3 of 3 runs abort with Cannot destroy a locked mutex.
  • Full ctest on that build: 435 of 436 pass. The one failure is agc_driver_srgb8_color_target, an NVIDIA import flake (#1434).

Tested with AI assistance (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6057988294 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1483#issuecomment-6057988294). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-08T10:35:25Z. --- Tested on Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, Intel Core i7-12700H, merged onto `main` e28fa01c together with #1501 and #1483 to share one build. - `guest_kernel_errors`: 10 of 10 runs pass. - Mutation check (`Mutex.cpp` put back to `main`, test kept): 3 of 3 runs abort with `Cannot destroy a locked mutex`. - Full ctest on that build: 435 of 436 pass. The one failure is `agc_driver_srgb8_color_target`, an NVIDIA import flake (#1434). Tested with AI assistance (Claude Code).
adriadam10 commented 2026-10-09 23:32:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T23:32:30Z.


Checked on Linux/GCC: guest_kernel_errors passes with the change and fails without it; the extra check (destroy while locked returns EBUSY, then unlock and destroy succeed) matches FreeBSD libthr _pthread_mutex_destroy. CI is green and popcoder565 confirmed it on Windows/MinGW. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6091045968 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1483#issuecomment-6091045968). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T23:32:30Z. --- Checked on Linux/GCC: `guest_kernel_errors` passes with the change and fails without it; the extra check (destroy while locked returns `EBUSY`, then unlock and destroy succeed) matches FreeBSD libthr `_pthread_mutex_destroy`. CI is green and popcoder565 confirmed it on Windows/MinGW. Merging.
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!1483
No description provided.