fix(libkernel): report thread attribute inheritance and null-output errors as measured on a PS5 #10130

Merged
orezraey merged 8 commits from upstream-pr/10130 into main 2026-10-26 14:45:11 +00:00
orezraey commented 2026-10-23 10:35:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-23T10:35:17Z.


What

Thread-attribute edge cases measured on a retail PS5 (firmware 13.60) with three homebrew probes calling libkernel_sys.sprx from a payload process. The sources and console logs are in this gist (pcond, pcond2, pattr).

The condition-variable change moved to #10177, as requested in review.

scePthreadAttrGet reports the inheritance a thread was created with: 0 for an explicit-scheduling thread and 4 for an inheriting one or one created from a freshly initialised attribute. Before, it always reported 4. pthread_attr_get_np now copies the same inheritance, as FreeBSD's copies the whole attribute; before, it left the caller's value. A null attribute at creation was not measured. The policy and priority it reports already matched:

  • the creator's for an inheriting thread (1 and 700 here, even when the attribute said round-robin 700);
  • the attribute's for an explicit one.

scePthreadAttrGetinheritsched with a null output returns EINVAL, as scePthreadAttrGetschedpolicy does. Before, it threw. Both also return EINVAL for a null or uninitialized attribute, which AnyPS5 already did. A new attribute holds policy 1, inheritance 4 and priority 700, also as before.

Already matching, so nothing in this diff changes them:

  • scePthreadCondTimedwait returns EPERM (0x80020001) for an unowned mutex of each type (default, error-checking, recursive, normal, adaptive), the adaptive static initializer (slot 1), a null slot and a mutex held by another thread.
  • It returns EINVAL for the destroyed mutex (slot 2).
  • It times out with 0x8002003c, also for 0 µs.
  • A recursive mutex locked twice is released completely during the wait (another thread's trylock succeeds) and relocked to depth 2.

The debt entries are updated.

Not modelled: a slot of 2 or 3 crashed the console's condition calls, and so does AnyPS5, which dereferences it. pthread_attr_get_np returned EINVAL for the payload's main thread, so its answer for other threads stays unmeasured.

Tested

Windows 11, MinGW (winlibs), and Linux (Ubuntu on WSL 2, GCC), at head 3345e2047d (main merged in after #9573, keeping its createSuspended field next to this PR's inheritance).

  • guest_pthread_attr checks the inheritance scePthreadAttrGet and pthread_attr_get_np report for an explicit and an inheriting thread.
  • guest_pthread_attr_errors checks EINVAL for a null scePthreadAttrGetinheritsched output.
  • These are the only tests this diff changes. Both fail with main's Pthread sources and pass with this branch's.
  • The thread and attribute tests pass three runs in a row on both systems: guest_pthread_attr, guest_pthread_attr_errors, guest_pthread_attr_stack, guest_pthread_create_suspended, guest_pthread_schedparam, guest_pthread_start, guest_pthread_join_detach and guest_kernel_sys_thread_defaults.
  • The condition-variable tests, including guest_pthread_destroyed_objects, belong to #10177 and are reported there.
  • 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: none (#9573, which edited the same lines, has merged and this PR is refreshed over it)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4981440401 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10130). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-23T10:35:17Z. --- ### What Thread-attribute edge cases measured on a retail PS5 (firmware 13.60) with three 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`, `pattr`). The condition-variable change moved to #10177, as requested in review. **`scePthreadAttrGet`** reports the inheritance a thread was created with: 0 for an explicit-scheduling thread and 4 for an inheriting one or one created from a freshly initialised attribute. Before, it always reported 4. `pthread_attr_get_np` now copies the same inheritance, as FreeBSD's copies the whole attribute; before, it left the caller's value. A null attribute at creation was not measured. The policy and priority it reports already matched: - the creator's for an inheriting thread (1 and 700 here, even when the attribute said round-robin 700); - the attribute's for an explicit one. **`scePthreadAttrGetinheritsched` with a null output** returns `EINVAL`, as `scePthreadAttrGetschedpolicy` does. Before, it threw. Both also return `EINVAL` for a null or uninitialized attribute, which AnyPS5 already did. A new attribute holds policy 1, inheritance 4 and priority 700, also as before. **Already matching, so nothing in this diff changes them:** - `scePthreadCondTimedwait` returns `EPERM` (`0x80020001`) for an unowned mutex of each type (default, error-checking, recursive, normal, adaptive), the adaptive static initializer (slot 1), a null slot and a mutex held by another thread. - It returns `EINVAL` for the destroyed mutex (slot 2). - It times out with `0x8002003c`, also for 0 µs. - A recursive mutex locked twice is released completely during the wait (another thread's trylock succeeds) and relocked to depth 2. The debt entries are updated. **Not modelled:** a slot of 2 or 3 crashed the console's condition calls, and so does AnyPS5, which dereferences it. `pthread_attr_get_np` returned `EINVAL` for the payload's main thread, so its answer for other threads stays unmeasured. ### 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. --> Windows 11, MinGW (winlibs), and Linux (Ubuntu on WSL 2, GCC), at head `3345e2047d` (main merged in after #9573, keeping its `createSuspended` field next to this PR's inheritance). - `guest_pthread_attr` checks the inheritance `scePthreadAttrGet` and `pthread_attr_get_np` report for an explicit and an inheriting thread. - `guest_pthread_attr_errors` checks `EINVAL` for a null `scePthreadAttrGetinheritsched` output. - These are the only tests this diff changes. Both fail with `main`'s `Pthread` sources and pass with this branch's. - The thread and attribute tests pass three runs in a row on both systems: `guest_pthread_attr`, `guest_pthread_attr_errors`, `guest_pthread_attr_stack`, `guest_pthread_create_suspended`, `guest_pthread_schedparam`, `guest_pthread_start`, `guest_pthread_join_detach` and `guest_kernel_sys_thread_defaults`. - The condition-variable tests, including `guest_pthread_destroyed_objects`, belong to #10177 and are reported there. - `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: none (#9573, which edited the same lines, has merged and this PR is refreshed over it) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-23 10:50:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T10:50:32Z.

Review: CHANGES_REQUESTED


The PS5 probe evidence supports the destroyed condition marker, null-destroy behavior, inherited scheduling query, and null-output error changes; GCC 12.2 syntax checks passed for the changed implementation and tests, as did conventions, diff-check, and main-sync (5 ahead/29 behind; merge clean). The author reports the three directly affected tests and 14 related Windows thread/condition tests passing three times. Please split the condition-variable changes (Cond.cpp and destroyed-object tests) from the independent thread-attribute changes (Attr.cpp, inheritance state/query tests) into separate topic branches, as required by the repository’s one-branch-per-topic rule. The attribute portion also conflicts with open PR #10133 in docs/dev/debt/libkernel.md; coordinate a single combined entry and landing order with that author, preserving both sets of measured attribute behavior. Add Depends on if either branch needs the other first, then refresh and rerun focused tests and checks. Hosted policy checks pass; product jobs are skipped by the workflow.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5627214507 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10130#pullrequestreview-5627214507). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T10:50:32Z. **Review:** CHANGES_REQUESTED --- The PS5 probe evidence supports the destroyed condition marker, null-destroy behavior, inherited scheduling query, and null-output error changes; GCC 12.2 syntax checks passed for the changed implementation and tests, as did conventions, diff-check, and main-sync (5 ahead/29 behind; merge clean). The author reports the three directly affected tests and 14 related Windows thread/condition tests passing three times. Please split the condition-variable changes (`Cond.cpp` and destroyed-object tests) from the independent thread-attribute changes (`Attr.cpp`, inheritance state/query tests) into separate topic branches, as required by the repository’s one-branch-per-topic rule. The attribute portion also conflicts with open PR #10133 in `docs/dev/debt/libkernel.md`; coordinate a single combined entry and landing order with that author, preserving both sets of measured attribute behavior. Add `Depends on` if either branch needs the other first, then refresh and rerun focused tests and checks. Hosted policy checks pass; product jobs are skipped by the workflow.
MarcZX10 commented 2026-10-23 13:22:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T13:22:58Z.

Review: DISMISSED


Re-review of current head 886a2b249cf0dcbe75f954e89dbdaadea960e1ef. The condition-variable implementation and its test were successfully moved out to #10177, leaving the thread-attribute behavior as this PR's topic. #10133 now declares Depends on: #10130, so the debt-file landing order is recorded. The remaining review issue is that this PR's Tested section still attributes guest_pthread_destroyed_objects and the condition-variable cases to this change, and says all three affected tests fail on main and pass with it. Those condition changes are no longer in this PR's file diff; please update the test report to identify the attribute tests actually changed here and distinguish any checks that now belong to #10177. The focused attribute evidence can remain; the report should match the exact current diff. Hosted product jobs are path-skipped.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5628834649 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10130#pullrequestreview-5628834649). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T13:22:58Z. **Review:** DISMISSED --- Re-review of current head `886a2b249cf0dcbe75f954e89dbdaadea960e1ef`. The condition-variable implementation and its test were successfully moved out to #10177, leaving the thread-attribute behavior as this PR's topic. #10133 now declares `Depends on: #10130`, so the debt-file landing order is recorded. The remaining review issue is that this PR's Tested section still attributes `guest_pthread_destroyed_objects` and the condition-variable cases to this change, and says all three affected tests fail on main and pass with it. Those condition changes are no longer in this PR's file diff; please update the test report to identify the attribute tests actually changed here and distinguish any checks that now belong to #10177. The focused attribute evidence can remain; the report should match the exact current diff. Hosted product jobs are path-skipped.
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!10130
No description provided.