fix(libkernel): store only rwlock attribute types 1 and 2 #10173

Merged
EagleBearerYS merged 2 commits from upstream-pr/10173 into main 2026-10-24 17:39:51 +00:00
EagleBearerYS commented 2026-10-23 12:01:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-23T12:01:35Z.


What

scePthreadRwlockattrSettype stores only types 1 and 2. Any other type, 0 included, and a null attribute or object return SCE_KERNEL_ERROR_EINVAL and store nothing. On main it stores any type and throws on a null attribute.

The answers come from BunnyFl's measurements of firmware 13.42's libkernel and libkernel_sys, run in an emulator. There, scePthreadRwlockattrSettype is the same function as pthread_rwlockattr_settype_np, with a non-zero result turned into 0x80020000 + errno: types 1 and 2 are stored, and every other type (0, 3, -1 and 0x80000000 were tried) and a null attribute or object return EINVAL, so 0x80020016 here.

The stored type is still not applied: scePthreadRwlockInit ignores its attribute, as before. #9632 takes the same measurement for pthread_rwlockattr_settype_np, which forwards types 1 and 2 to this function; the two PRs touch different files.

Tested

  • guest_pthread_rwlock, new CheckAttrSettype: types 1 and 2 return SCE_OK and a rwlock made from the attribute locks and unlocks; types 0, 3, -1 and 0x80000000, a destroyed attribute and a null attribute return SCE_KERNEL_ERROR_EINVAL.
  • Red, the new case on main 777bdbb4f8's code (run): on Linux and on Windows, 1 of the 2 tests passes, none skipped. guest_pthread_rwlock fails on both, aborting on Linux and exiting with 0xc0000409 on Windows; guest_rwlock_retire passes 10 runs in a row.
  • Green (run): on Linux and on Windows, guest_pthread_rwlock and guest_rwlock_retire pass 10 runs in a row, 2 of 2, none skipped or failed. The libc and libkernel suites run 118 and 200 tests on Linux and 145 and 210 on Windows, none failing, run with APS5_SKIP_TIMING_TESTS=1, which relaxes precise_wait's median bounds on GitHub's hosted runners.
  • check_conventions.py passes, with no comment lines added.
  • Not tested on a console or with a title.
  • 49b6188c63, a merge of main 3fcb5e4d76. The only conflict was tests/GuestPthreadRwlock.cpp, where #8373 added CheckAttrType next to this PR's CheckAttrSettype: both are kept, and CheckAttrType's type loop is now {1, 2} (see Overlap). The Rwlock.cpp change is unchanged. On GitHub's runners (run), guest_pthread_rwlock passes 10 runs in a row on Linux and on Windows, 1 of 1, none skipped or failed. The libc and libkernel suites run 142 and 204 tests on Linux and 169 and 217 on Windows, none failing, run with APS5_SKIP_TIMING_TESTS=1, which relaxes precise_wait's median bounds on GitHub's hosted runners.

Overlap: checked with git merge-tree against the open PRs touching these files.

  • #8373 (slider, pthread attribute accessors) has merged. Its CheckAttrType set type 0 through scePthreadRwlockattrSettype and expected SCE_OK, which the measurement above refuses. This PR's merge of main keeps both check functions and drops type 0 from that function's {1, 2, 0} loop, as planned here. Type 0's SCE_KERNEL_ERROR_EINVAL is checked in CheckAttrSettype, and the initial type 0 after pthread_rwlockattr_init stays as #8373 checks it.
  • #9632 (ours) merges cleanly with this PR.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4982405604 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10173). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-23T12:01:35Z. --- ### What `scePthreadRwlockattrSettype` stores only types 1 and 2. Any other type, 0 included, and a null attribute or object return `SCE_KERNEL_ERROR_EINVAL` and store nothing. On `main` it stores any type and throws on a null attribute. The answers come from [BunnyFl's measurements](https://github.com/boykopovar/AnyPS5/pull/9632#issuecomment-6363402814) of firmware 13.42's `libkernel` and `libkernel_sys`, run in an emulator. There, `scePthreadRwlockattrSettype` is the same function as `pthread_rwlockattr_settype_np`, with a non-zero result turned into `0x80020000 + errno`: types 1 and 2 are stored, and every other type (0, 3, -1 and `0x80000000` were tried) and a null attribute or object return `EINVAL`, so `0x80020016` here. The stored type is still not applied: `scePthreadRwlockInit` ignores its attribute, as before. #9632 takes the same measurement for `pthread_rwlockattr_settype_np`, which forwards types 1 and 2 to this function; the two PRs touch different files. ### Tested - **`guest_pthread_rwlock`, new `CheckAttrSettype`:** types 1 and 2 return `SCE_OK` and a rwlock made from the attribute locks and unlocks; types 0, 3, -1 and `0x80000000`, a destroyed attribute and a null attribute return `SCE_KERNEL_ERROR_EINVAL`. - **Red**, the new case on `main` 777bdbb4f8's code ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39948039799)): on Linux and on Windows, 1 of the 2 tests passes, none skipped. `guest_pthread_rwlock` fails on both, aborting on Linux and exiting with `0xc0000409` on Windows; `guest_rwlock_retire` passes 10 runs in a row. - **Green** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/39948110627)): on Linux and on Windows, `guest_pthread_rwlock` and `guest_rwlock_retire` pass 10 runs in a row, 2 of 2, none skipped or failed. The libc and libkernel suites run 118 and 200 tests on Linux and 145 and 210 on Windows, none failing, run with `APS5_SKIP_TIMING_TESTS=1`, which relaxes `precise_wait`'s median bounds on GitHub's hosted runners. - `check_conventions.py` passes, with no comment lines added. - Not tested on a console or with a title. - **49b6188c63, a merge of `main` 3fcb5e4d76.** The only conflict was `tests/GuestPthreadRwlock.cpp`, where #8373 added `CheckAttrType` next to this PR's `CheckAttrSettype`: both are kept, and `CheckAttrType`'s type loop is now `{1, 2}` (see Overlap). The `Rwlock.cpp` change is unchanged. On GitHub's runners ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/40108320420)), `guest_pthread_rwlock` passes 10 runs in a row on Linux and on Windows, 1 of 1, none skipped or failed. The libc and libkernel suites run 142 and 204 tests on Linux and 169 and 217 on Windows, none failing, run with `APS5_SKIP_TIMING_TESTS=1`, which relaxes `precise_wait`'s median bounds on GitHub's hosted runners. **Overlap:** checked with `git merge-tree` against the open PRs touching these files. - **#8373** (slider, pthread attribute accessors) has merged. Its `CheckAttrType` set type 0 through `scePthreadRwlockattrSettype` and expected `SCE_OK`, which the measurement above refuses. This PR's merge of `main` keeps both check functions and drops type 0 from that function's `{1, 2, 0}` loop, as planned here. Type 0's `SCE_KERNEL_ERROR_EINVAL` is checked in `CheckAttrSettype`, and the initial type 0 after `pthread_rwlockattr_init` stays as #8373 checks it. - **#9632** (ours) merges cleanly with this PR. ### 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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-23 12:36:13 +00:00 (Migrated from github.com)

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

Review: APPROVED


Reviewed exact head dd5a4a3e5a515ab33ec9636b93532aca42a0dd88. The measured 1/2 range is enforced before writing the attribute, invalid and destroyed/null attributes are covered, and the valid-type test exercises a lock/unlock using the stored attribute. The PR documents the firmware/emulator evidence, the un-applied stored type limitation, and the merge-order-only test conflict with #8373. The author reports the focused rwlock and dependent suites passing 10x on Linux and Windows; current hosted eligibility, intake, conventions, labels and report checks pass. Runtime jobs were skipped by path policy, so I did not treat those as a hosted build result.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5628287384 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10173#pullrequestreview-5628287384). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T12:36:13Z. **Review:** APPROVED --- Reviewed exact head `dd5a4a3e5a515ab33ec9636b93532aca42a0dd88`. The measured 1/2 range is enforced before writing the attribute, invalid and destroyed/null attributes are covered, and the valid-type test exercises a lock/unlock using the stored attribute. The PR documents the firmware/emulator evidence, the un-applied stored type limitation, and the merge-order-only test conflict with #8373. The author reports the focused rwlock and dependent suites passing 10x on Linux and Windows; current hosted eligibility, intake, conventions, labels and report checks pass. Runtime jobs were skipped by path policy, so I did not treat those as a hosted build result.
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!10173
No description provided.