fix(libkernel): follow the console's set sizes in pthread_getaffinity_np #14039

Merged
EagleBearerYS merged 3 commits from upstream-pr/14039 into main 2026-11-02 19:45:45 +00:00
EagleBearerYS commented 2026-10-31 16:51:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-31T16:51:28Z.


What

pthread_getaffinity_np follows the set sizes measured on a PS5:

  • a set of fewer than 8 bytes, or of 24 bytes and more, returns ERANGE;
  • a set of 8 to 16 bytes gets the thread's mask in its first 8 bytes, then zeros up to the requested size.

Before, only 8 and 16 were answered, 32 and more returned ERANGE, and every other size threw.

Source: @rooklz's measurement of the console's libthr on a PS5 (comment on #9156).

  • Sizes tried: 0, 1, 4, 7, 8, 9, 12, 16, 24, 32, 64 and 128.
  • The result: 8 to 16 bytes are accepted and zero-filled past byte 8. Below 8, or from 24 up, the call returns ERANGE.
  • PS5_PayloadSDK's measurement of 8, 16 and 32 bytes agrees. This extends the measured sizes #11431 added.

Still throws: 17 to 23 bytes, which weren't measured. docs/dev/debt/libkernel.md records that, along with:

  • pthread_setaffinity_np's unmeasured 32-byte limit;
  • cpuset_getaffinity and cpuset_setaffinity, which still accept up to 32 bytes.

Overlap:

  • #13908 (DeveshB-1), now in main, changes how this function copies the set out (EFAULT for invalid memory). This PR changes only which sizes it accepts. The code merged cleanly, and the debt entry is merged as below.
  • #7135 changes cpuset_getaffinity and cpuset_setaffinity, where @rooklz posted the same measurement. This PR leaves those two functions to it.

Tested

guest_available_cpumask checks that:

  • 0, 1, 4, 7 and 24 bytes return ERANGE;
  • 9, 12 and 15 bytes return 0, with the thread's affinity in the first 8 bytes, zeros up to the size, and the bytes past it untouched.

Linux (Ubuntu 24.04, GCC 13.3, CI flags), 10 runs each:

  • main with the new test: 0/10. Each run stops at the 24-byte case, where main throws.
  • this PR: 10/10.

GitHub's runners (run), guest_available_cpumask:

runner main's Thread.cpp with the new test, 3 runs this PR, 10 runs libc and libkernel suites with this PR
Linux 0 / 3: each aborts on the NotImplemented throw 10 / 10 199 and 308 run, 0 failed
Windows 0 / 3: each aborts on the NotImplemented throw 10 / 10 226 and 330 run, 0 failed

On @bunbeans2-arch's machine (comment): Windows 11 Pro 10.0.22631, i9-9900K, MSYS2 UCRT64 GCC 16.1.0, Release, this PR's 6093634622 merged into main 422367d61a:

  • this PR: guest_available_cpumask passed 5 of 5;
  • the same tree with only Thread.cpp put back to main's: aborted in 5 of 5 with pthread_getaffinity_np with a set other than 8, 16 or 32 bytes and more not implemented;
  • main alone, with its own test: 3 of 3.

711f3a69f1, a merge of main 26fa1212b8, and 8cd23f7997 (run):

  • The merge: DeveshB-1's #13908 appended a sentence on the EFAULT fallback to the pthread_getaffinity_np debt entry that this PR rewrites, and that entry was the one conflict. The merge keeps this PR's entry, then #13908's sentence word for word. Thread.cpp and GuestAvailableCpumask.cpp merged cleanly, and this PR's diff is unchanged.
  • 8cd23f7997 shortens this PR's wording in that entry, from 1,120 to 961 characters, so it stays under the debt-length limit. Every behaviour it states is kept, and #13908's sentence is unchanged.
  • ×10: guest_available_cpumask, with #13908's test changes. Linux: 1 run, 1 pass, 0 skip, 0 fail. Windows: 1 run, 1 pass, 0 skip, 0 fail. The libc and libkernel suites run 207 and 308 tests on Linux and 234 and 330 on Windows, with 0 failed. The suites ran with APS5_SKIP_TIMING_TESTS=1, which relaxes precise_wait's median bounds on GitHub's hosted runners.

Checks:

  • tools/check_conventions.py: all passed.
  • tools/check_test_registration.py build: none new.
  • No comments added.

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: n/a, none
  • 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:5099581577 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14039). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-31T16:51:28Z. --- ### What `pthread_getaffinity_np` follows the set sizes measured on a PS5: - a set of fewer than 8 bytes, or of 24 bytes and more, returns `ERANGE`; - a set of 8 to 16 bytes gets the thread's mask in its first 8 bytes, then zeros up to the requested size. Before, only 8 and 16 were answered, 32 and more returned `ERANGE`, and every other size threw. **Source:** @rooklz's measurement of the console's libthr on a PS5 ([comment on #9156](https://github.com/boykopovar/AnyPS5/pull/9156#issuecomment-6391607043)). - **Sizes tried:** 0, 1, 4, 7, 8, 9, 12, 16, 24, 32, 64 and 128. - **The result:** 8 to 16 bytes are accepted and zero-filled past byte 8. Below 8, or from 24 up, the call returns `ERANGE`. - [PS5_PayloadSDK's measurement](https://github.com/mihawk-99/PS5_PayloadSDK/blob/3e31e0b1b68ada28beca68adc480cf0c3d17b9df/platform/docs/PROBE.md#L287-L297) of 8, 16 and 32 bytes agrees. This extends the measured sizes #11431 added. **Still throws:** 17 to 23 bytes, which weren't measured. `docs/dev/debt/libkernel.md` records that, along with: - `pthread_setaffinity_np`'s unmeasured 32-byte limit; - `cpuset_getaffinity` and `cpuset_setaffinity`, which still accept up to 32 bytes. **Overlap:** - #13908 (DeveshB-1), now in `main`, changes how this function copies the set out (`EFAULT` for invalid memory). This PR changes only which sizes it accepts. The code merged cleanly, and the debt entry is merged as below. - #7135 changes `cpuset_getaffinity` and `cpuset_setaffinity`, where @rooklz posted the same measurement. This PR leaves those two functions to it. ### Tested `guest_available_cpumask` checks that: - 0, 1, 4, 7 and 24 bytes return `ERANGE`; - 9, 12 and 15 bytes return 0, with the thread's affinity in the first 8 bytes, zeros up to the size, and the bytes past it untouched. **Linux** (Ubuntu 24.04, GCC 13.3, CI flags), 10 runs each: - main with the new test: 0/10. Each run stops at the 24-byte case, where main throws. - this PR: 10/10. **GitHub's runners** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41217783310)), `guest_available_cpumask`: | runner | main's `Thread.cpp` with the new test, 3 runs | this PR, 10 runs | libc and libkernel suites with this PR | |---|---|---|---| | Linux | 0 / 3: each aborts on the `NotImplemented` throw | **10 / 10** | 199 and 308 run, 0 failed | | Windows | 0 / 3: each aborts on the `NotImplemented` throw | **10 / 10** | 226 and 330 run, 0 failed | **On @bunbeans2-arch's machine** ([comment](https://github.com/boykopovar/AnyPS5/pull/14039#issuecomment-6549412535)): Windows 11 Pro 10.0.22631, i9-9900K, MSYS2 UCRT64 GCC 16.1.0, Release, this PR's `6093634622` merged into `main` `422367d61a`: - this PR: `guest_available_cpumask` passed 5 of 5; - the same tree with only `Thread.cpp` put back to `main`'s: aborted in 5 of 5 with `pthread_getaffinity_np with a set other than 8, 16 or 32 bytes and more not implemented`; - `main` alone, with its own test: 3 of 3. **711f3a69f1, a merge of `main` 26fa1212b8, and 8cd23f7997** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41291326119)): - **The merge:** DeveshB-1's #13908 appended a sentence on the `EFAULT` fallback to the `pthread_getaffinity_np` debt entry that this PR rewrites, and that entry was the one conflict. The merge keeps this PR's entry, then #13908's sentence word for word. `Thread.cpp` and `GuestAvailableCpumask.cpp` merged cleanly, and this PR's diff is unchanged. - **8cd23f7997** shortens this PR's wording in that entry, from 1,120 to 961 characters, so it stays under the debt-length limit. Every behaviour it states is kept, and #13908's sentence is unchanged. - **×10:** `guest_available_cpumask`, with #13908's test changes. Linux: 1 run, 1 pass, 0 skip, 0 fail. Windows: 1 run, 1 pass, 0 skip, 0 fail. The libc and libkernel suites run 207 and 308 tests on Linux and 234 and 330 on Windows, with 0 failed. The suites ran with `APS5_SKIP_TIMING_TESTS=1`, which relaxes `precise_wait`'s median bounds on GitHub's hosted runners. **Checks:** - `tools/check_conventions.py`: all passed. - `tools/check_test_registration.py build`: none new. - No comments added. ### 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: n/a, none - [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
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!14039
No description provided.