fix(libkernel): mark a destroyed condition variable with 1 and accept destroying a null one, as measured on a PS5 #10177

Merged
orezraey merged 3 commits from upstream-pr/10177 into main 2026-10-26 08:29:48 +00:00
orezraey commented 2026-10-23 12:02:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-23T12:02:34Z.


What

Destroyed condition variables measured on a retail PS5 (firmware 13.60) with homebrew probes calling libkernel_sys.sprx from a payload process. The sources and console logs are in this gist (pcond, pcond2). Split from #10130; @BunnyFl confirmed the same results against firmware 13.42 in #10130.

Destroyed condition variables. scePthreadCondDestroy stores 1 in the slot, FreeBSD libthr's THR_COND_DESTROYED. scePthreadCondWait, scePthreadCondTimedwait, scePthreadCondSignal, scePthreadCondBroadcast and scePthreadCondDestroy then all return EINVAL (0x80020016), and so does each of them for a slot that holds 1. AnyPS5 stored 2 and treated a slot holding 1 as a condition object, so it read through address 1.

Destroying an uninitialized slot (null) returns 0 and leaves it null. Before, it stored the destroyed marker. Signal, broadcast and wait on a null slot initialize it, as before.

Tested

  • Head after merging main (f4aabbb122, with #9165): 284884d40b. Kept #9165's new timed-lock entry and this PR's measured scePthreadCondWait entry in libkernel.md. guest_pthread_destroyed_objects, guest_pthread_mutex_errors, guest_pthread_join_detach and guest_pthread_condattr pass three runs in a row on Windows (MinGW) and on Linux (WSL Ubuntu, GCC); public_headers audit and check_conventions pass.
    Windows 11, MinGW (winlibs).
  • guest_pthread_destroyed_objects checks the stored 1 and a null slot through destroy, signal and broadcast. It fails on main and passes with the change.
  • 17 condition and destroyed-object tests pass three runs in a row.
  • tools/check_conventions.py 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 under Silent stubs in their library's technical debt file
  • 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: #9165 (merge order only: it edits the same lines; this PR is refreshed after it)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4982417163 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10177). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-23T12:02:34Z. --- ### What Destroyed condition variables measured on a retail PS5 (firmware 13.60) with homebrew probes calling `libkernel_sys.sprx` from a payload process. The sources and console logs are in [this gist](https://gist.github.com/orezraey/8a9b6c0b69a66e4387095ba8e6a5a9a2) (`pcond`, `pcond2`). Split from #10130; @BunnyFl confirmed the same results against firmware 13.42 in #10130. **Destroyed condition variables.** `scePthreadCondDestroy` stores **1** in the slot, FreeBSD libthr's `THR_COND_DESTROYED`. `scePthreadCondWait`, `scePthreadCondTimedwait`, `scePthreadCondSignal`, `scePthreadCondBroadcast` and `scePthreadCondDestroy` then all return `EINVAL` (`0x80020016`), and so does each of them for a slot that holds 1. AnyPS5 stored 2 and treated a slot holding 1 as a condition object, so it read through address 1. Destroying an uninitialized slot (null) returns 0 and leaves it null. Before, it stored the destroyed marker. Signal, broadcast and wait on a null slot initialize it, as before. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> - Head after merging `main` (`f4aabbb122`, with #9165): `284884d40b`. Kept #9165's new timed-lock entry and this PR's measured `scePthreadCondWait` entry in `libkernel.md`. `guest_pthread_destroyed_objects`, `guest_pthread_mutex_errors`, `guest_pthread_join_detach` and `guest_pthread_condattr` pass three runs in a row on Windows (MinGW) and on Linux (WSL Ubuntu, GCC); `public_headers` audit and `check_conventions` pass. Windows 11, MinGW (winlibs). - `guest_pthread_destroyed_objects` checks the stored 1 and a null slot through destroy, signal and broadcast. It fails on `main` and passes with the change. - 17 condition and destroyed-object tests pass three runs in a row. - `tools/check_conventions.py` 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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: #9165 (merge order only: it edits the same lines; this PR is refreshed after it) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-23 12:09:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T12:09:34Z.

Review: APPROVED


Reviewed the exact submitted head a431d14efe8d970737861fc157ef36c47a0e4524. The destroyed marker now matches the reported firmware behavior, and null destroy leaves an uninitialized slot untouched; the regression covers both cases and verifies that signal/broadcast still lazily initialize null slots. The PR reports 17 condition/destroyed-object tests passing three times on Windows, and the policy checks (eligibility, conventions, intake, labels and report) pass. Product jobs are skipped by repository path policy, and I could not independently run the focused executable because this checkout has no configured build tree. I initially raised and then retracted a condition-lifetime concern after tracing the shared ownership and initialization mutex; that concern is not a blocker.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5628006582 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10177#pullrequestreview-5628006582). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T12:09:34Z. **Review:** APPROVED --- Reviewed the exact submitted head `a431d14efe8d970737861fc157ef36c47a0e4524`. The destroyed marker now matches the reported firmware behavior, and null destroy leaves an uninitialized slot untouched; the regression covers both cases and verifies that signal/broadcast still lazily initialize null slots. The PR reports 17 condition/destroyed-object tests passing three times on Windows, and the policy checks (eligibility, conventions, intake, labels and report) pass. Product jobs are skipped by repository path policy, and I could not independently run the focused executable because this checkout has no configured build tree. I initially raised and then retracted a condition-lifetime concern after tracing the shared ownership and initialization mutex; that concern is not a blocker.
MarcZX10 commented 2026-10-23 12:38:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T12:38:46Z.

Review: COMMENTED


I checked the overlap warning against #9165. That PR adds a separate timed self-lock debt bullet; this PR updates the condition-wait entry and changes only Cond.cpp plus the destroyed-object regression. The implementation behavior is independent. If stale debt-file context causes a rebase conflict, preserve both entries; no Depends on relationship is needed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5628314178 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10177#pullrequestreview-5628314178). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T12:38:46Z. **Review:** COMMENTED --- I checked the overlap warning against #9165. That PR adds a separate timed self-lock debt bullet; this PR updates the condition-wait entry and changes only `Cond.cpp` plus the destroyed-object regression. The implementation behavior is independent. If stale debt-file context causes a rebase conflict, preserve both entries; no `Depends on` relationship is needed.
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!10177
No description provided.