feat(libkernel): implement cpuset_getaffinity for the calling thread #2859

Merged
babyhuey merged 1 commit from upstream-pr/2859 into main 2026-10-10 18:27:06 +00:00
babyhuey commented 2026-10-10 16:48:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-10T16:48:25Z.


What

Implements cpuset_getaffinity (Pdgml4rbxYk) in libkernel for the calling thread: level CPU_LEVEL_WHICH (3), which CPU_WHICH_TID (1), id -1. It returns the thread's affinity from scePthreadGetaffinity in the first 8 bytes of the set and zeroes the rest. A set size under 8 or over 32 bytes (256 CPUs) gives ERANGE and a null set EFAULT, as FreeBSD 11 kern_cpuset_getaffinity checks them. Any other level, which or id throws NotImplemented_nid_no_patch.

OpenNOW PS5 (PPSA99082) calls it as cpuset_getaffinity(3, 1, -1, 8, set) and stops at it on main 57f96fd2 (catalog build, eboot.bin and sce_module/libc.prx unwrapped as #2605 requires; tracked in #1578):

  • main, Linux: app.elf: symbol lookup error: app.elf: undefined symbol: Pdgml4rbxYk
  • with this PR, Linux: app.elf: symbol lookup error: app.elf: undefined symbol: xFebsA4YsFI (pthread_rwlockattr_init)
  • with this PR, Windows: FAIL: unresolved ELF import xFebsA4YsFI (pthread_rwlockattr_init) from libkernel.prx

pthread_rwlockattr_init is the next PR (babyhuey:feat/libkernel-rwlockattr), once this is in.

Tested

Linux (Ubuntu 24.04, GCC 13, Release) on 57f96fd2: guest_available_cpumask passes 5/5 (--repeat until-fail:5). The new case reads the set from a created thread with 8 bytes (equal to sceKernelGetAvailableCpumask, bytes past the size untouched) and 32 bytes (same mask, rest zeroed) and checks ERANGE for 4 and 33 bytes and EFAULT for a null set. Windows 11 (MinGW-w64 GCC 15.2 from WinLibs, Release): guest_available_cpumask 5/5 and the OpenNOW line above, on the same commit rebased onto 197ffac9 (the rebase onto 57f96fd2 had no conflicts and changes nothing in these files). 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 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:4812851623 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2859). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-10T16:48:25Z. --- ### What Implements `cpuset_getaffinity` (`Pdgml4rbxYk`) in libkernel for the calling thread: level `CPU_LEVEL_WHICH` (3), which `CPU_WHICH_TID` (1), id -1. It returns the thread's affinity from `scePthreadGetaffinity` in the first 8 bytes of the set and zeroes the rest. A set size under 8 or over 32 bytes (256 CPUs) gives `ERANGE` and a null set `EFAULT`, as FreeBSD 11 `kern_cpuset_getaffinity` checks them. Any other level, which or id throws `NotImplemented_nid_no_patch`. OpenNOW PS5 (PPSA99082) calls it as `cpuset_getaffinity(3, 1, -1, 8, set)` and stops at it on `main` 57f96fd2 (catalog build, `eboot.bin` and `sce_module/libc.prx` unwrapped as #2605 requires; tracked in #1578): - `main`, Linux: `app.elf: symbol lookup error: app.elf: undefined symbol: Pdgml4rbxYk` - with this PR, Linux: `app.elf: symbol lookup error: app.elf: undefined symbol: xFebsA4YsFI` (`pthread_rwlockattr_init`) - with this PR, Windows: `FAIL: unresolved ELF import xFebsA4YsFI (pthread_rwlockattr_init) from libkernel.prx` `pthread_rwlockattr_init` is the next PR (babyhuey:feat/libkernel-rwlockattr), once this is in. ### Tested Linux (Ubuntu 24.04, GCC 13, Release) on 57f96fd2: `guest_available_cpumask` passes 5/5 (`--repeat until-fail:5`). The new case reads the set from a created thread with 8 bytes (equal to `sceKernelGetAvailableCpumask`, bytes past the size untouched) and 32 bytes (same mask, rest zeroed) and checks `ERANGE` for 4 and 33 bytes and `EFAULT` for a null set. Windows 11 (MinGW-w64 GCC 15.2 from WinLibs, Release): `guest_available_cpumask` 5/5 and the OpenNOW line above, on the same commit rebased onto 197ffac9 (the rebase onto 57f96fd2 had no conflicts and changes nothing in these files). `check_conventions.py` passes. ### Checklist - [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
github-actions[bot] commented 2026-10-10 16:48:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T16:48:54Z.


Progress report (57f96fd → d2c160b)

📉 System libraries: 84.49% (-0.03%, +1 declared functions)

🆕 1 declared as stubs
Library Name
libkernel cpuset_getaffinity_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6099876490 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2859#issuecomment-6099876490). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T16:48:54Z. --- <!-- progress-report --> ### Progress report (57f96fd → d2c160b) 📉 **System libraries**: 84.49% (-0.03%, +1 declared functions) <details> <summary>🆕 1 declared as stubs</summary> | Library | Name | | - | - | | libkernel | `cpuset_getaffinity_nid_postfix` | </details>
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!2859
No description provided.