feat(libkernel): implement sysctl and sysctlbyname for hw.ncpu #1685

Merged
overlordxrz-source merged 1 commit from upstream-pr/1685 into main 2026-10-09 21:20:14 +00:00
overlordxrz-source commented 2026-10-08 16:23:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-08T16:23:22Z.


What

ScreenTester5 (PPSA69420, Marice/ScreenTester5 01.000.000) stops at start-up on main with, as reported in #1578:

FAIL: unresolved ELF import MhC53TKmjVA from libkernel.prx

MhC53TKmjVA is sysctlbyname (tools/nid_names.py). The title also imports sysctl (DFmMT80xcNI). In the #1578 audit, sysctl is absent for 27 of the 34 catalog titles and sysctlbyname for 14. The only hw./kern./vm. sysctl name string in PPSA69420's eboot.bin is hw.ncpu, which SDL2's SDL_GetCPUCount reads with sysctlbyname.

System/src/SystemConfiguration.cpp now exports both functions, but only for hw.ncpu (CTL_HW.HW_NCPU, MIB {6, 3}). It reports the same count as sysconf(_SC_NPROCESSORS_ONLN). Every other name or MIB throws with the name or MIB in the message, so the next one a title needs shows up in its log. The rest follows FreeBSD's kern_sysctl.c:

  • A name length below 2 or above CTL_MAXNAME (24) gives EINVAL. A null name gives EFAULT.
  • A null oldp stores the required size in *oldlenp.
  • A short buffer gets a partial copy, and *oldlenp is set to the bytes copied, with ENOMEM.
  • hw.ncpu is read-only, so a non-null newp gives EPERM.
  • errno is left alone on success.

Per review on #1405, nothing beyond what this title reaches is included. Other hw.*/kern.* nodes, such as hw.physmem, wait until a title stops on them.

Log

From #1578 (Windows, main 1081602d, relinker --windows): FAIL: unresolved ELF import MhC53TKmjVA from libkernel.prx for PPSA69420.

@LeandroLP23 ran the title with this PR (Windows 11, Radeon 860M, MinGW-w64 GCC 15.2.0, Release, main 4b6ab6bb, title relinked with relinker --windows). On main it stops at MhC53TKmjVA (sysctlbyname). With this PR it gets past it and stops at the next import:

FAIL: unresolved ELF import KiJEPEWRyUY from libkernel.prx

KiJEPEWRyUY is sigaction, which touches the signal masks #1431 is reworking, so it is left out of this PR.

Tested

aarch64 Debian 13 host. The full project cannot be built here because it needs x86-64.

  • core/libs/tests/GuestSystemConfiguration.cpp gains CheckProcessorCountSysctl. It covers the size query, the read through both entry points, the partial copy with ENOMEM, EPERM, EINVAL, EFAULT, an unchanged errno on success, and the throw for an unknown name and an unknown MIB. Linked with SystemConfiguration.cpp, it passes natively against glibc.
  • Without the change the test does not link (sysctl_nid_postfix and sysctlbyname_nid_postfix are undefined). Three mutants of the new code each make it abort: no ENOMEM on a short buffer, no EPERM on newp, and a wrong size query.
  • SystemConfiguration.cpp and the test compile for x86_64-linux-gnu and x86_64-windows-gnu with -Wall -Wextra (Zig 0.17 clang) without warnings.
  • python3 tools/check_conventions.py --base origin/main passes.
  • Run with PPSA69420 by @LeandroLP23 (see Log). I haven't run it myself.

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:4789762678 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1685). Originally posted by [overlordxrz-source](https://github.com/overlordxrz-source) on 2026-10-08T16:23:22Z. --- ### What ScreenTester5 (PPSA69420, [Marice/ScreenTester5](https://github.com/Marice/ScreenTester5) 01.000.000) stops at start-up on `main` with, as reported in #1578: ``` FAIL: unresolved ELF import MhC53TKmjVA from libkernel.prx ``` `MhC53TKmjVA` is `sysctlbyname` (`tools/nid_names.py`). The title also imports `sysctl` (`DFmMT80xcNI`). In the #1578 audit, `sysctl` is absent for 27 of the 34 catalog titles and `sysctlbyname` for 14. The only `hw.`/`kern.`/`vm.` sysctl name string in PPSA69420's `eboot.bin` is `hw.ncpu`, which SDL2's `SDL_GetCPUCount` reads with `sysctlbyname`. `System/src/SystemConfiguration.cpp` now exports both functions, but only for `hw.ncpu` (`CTL_HW`.`HW_NCPU`, MIB `{6, 3}`). It reports the same count as `sysconf(_SC_NPROCESSORS_ONLN)`. Every other name or MIB throws with the name or MIB in the message, so the next one a title needs shows up in its log. The rest follows FreeBSD's `kern_sysctl.c`: - A name length below 2 or above `CTL_MAXNAME` (24) gives `EINVAL`. A null name gives `EFAULT`. - A null `oldp` stores the required size in `*oldlenp`. - A short buffer gets a partial copy, and `*oldlenp` is set to the bytes copied, with `ENOMEM`. - `hw.ncpu` is read-only, so a non-null `newp` gives `EPERM`. - `errno` is left alone on success. Per review on #1405, nothing beyond what this title reaches is included. Other `hw.*`/`kern.*` nodes, such as `hw.physmem`, wait until a title stops on them. ### Log From #1578 (Windows, `main` 1081602d, `relinker --windows`): `FAIL: unresolved ELF import MhC53TKmjVA from libkernel.prx` for PPSA69420. @LeandroLP23 ran the title with this PR (Windows 11, Radeon 860M, MinGW-w64 GCC 15.2.0, Release, `main` 4b6ab6bb, title relinked with `relinker --windows`). On `main` it stops at `MhC53TKmjVA` (`sysctlbyname`). With this PR it gets past it and stops at the next import: ``` FAIL: unresolved ELF import KiJEPEWRyUY from libkernel.prx ``` `KiJEPEWRyUY` is `sigaction`, which touches the signal masks #1431 is reworking, so it is left out of this PR. ### Tested aarch64 Debian 13 host. The full project cannot be built here because it needs x86-64. - `core/libs/tests/GuestSystemConfiguration.cpp` gains `CheckProcessorCountSysctl`. It covers the size query, the read through both entry points, the partial copy with `ENOMEM`, `EPERM`, `EINVAL`, `EFAULT`, an unchanged `errno` on success, and the throw for an unknown name and an unknown MIB. Linked with `SystemConfiguration.cpp`, it passes natively against glibc. - Without the change the test does not link (`sysctl_nid_postfix` and `sysctlbyname_nid_postfix` are undefined). Three mutants of the new code each make it abort: no `ENOMEM` on a short buffer, no `EPERM` on `newp`, and a wrong size query. - `SystemConfiguration.cpp` and the test compile for x86_64-linux-gnu and x86_64-windows-gnu with `-Wall -Wextra` (Zig 0.17 clang) without warnings. - `python3 tools/check_conventions.py --base origin/main` passes. - Run with PPSA69420 by @LeandroLP23 (see Log). I haven't run it myself. ### 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-08 16:25:49 +00:00 (Migrated from github.com)

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


Progress report (4b005b2 → 1879862)

📈 System libraries: 84.77% (+0.01%, +2 implemented functions)

✅ 2 implemented
Library Name
libkernel sysctl_nid_postfix
libkernel sysctlbyname_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6064349552 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1685#issuecomment-6064349552). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T16:25:49Z. --- <!-- progress-report --> ### Progress report (4b005b2 → 1879862) 📈 **System libraries**: 84.77% (+0.01%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libkernel | `sysctl_nid_postfix` | | libkernel | `sysctlbyname_nid_postfix` | </details>
LeandroLP23 commented 2026-10-08 20:16:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-08T20:16:19Z.


Run with the title on Windows. ScreenTester5 (PPSA69420 01.000.000) on main stops at FAIL: unresolved ELF import MhC53TKmjVA from libkernel.prx (sysctlbyname). With this PR merged it gets past it and stops at the next import, FAIL: unresolved ELF import KiJEPEWRyUY from libkernel.prx (sigaction), which touches the signal masks #1431 is reworking.

Windows 11, Radeon 860M, MinGW-w64 GCC 15.2.0, Release, main 4b6ab6bb; title relinked with relinker --windows and run with the patched build/core/libs/libs/*.prx.

Tested with AI assistance (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6068252148 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1685#issuecomment-6068252148). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-08T20:16:19Z. --- Run with the title on Windows. ScreenTester5 (PPSA69420 01.000.000) on `main` stops at `FAIL: unresolved ELF import MhC53TKmjVA from libkernel.prx` (`sysctlbyname`). With this PR merged it gets past it and stops at the next import, `FAIL: unresolved ELF import KiJEPEWRyUY from libkernel.prx` (`sigaction`), which touches the signal masks #1431 is reworking. Windows 11, Radeon 860M, MinGW-w64 GCC 15.2.0, Release, `main` 4b6ab6bb; title relinked with `relinker --windows` and run with the patched `build/core/libs/libs/*.prx`. Tested with AI assistance (Claude Code).
overlordxrz-source commented 2026-10-09 04:13:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-09T04:13:38Z.


@LeandroLP23 thanks for running it with the title. That's the stop line this PR was missing. I've added your run to the Log and Tested sections. sigaction (KiJEPEWRyUY) is next, but it touches the signal masks #1431 is reworking, so I'm leaving it out of this PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6074119697 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1685#issuecomment-6074119697). Originally posted by [overlordxrz-source](https://github.com/overlordxrz-source) on 2026-10-09T04:13:38Z. --- @LeandroLP23 thanks for running it with the title. That's the stop line this PR was missing. I've added your run to the Log and Tested sections. `sigaction` (`KiJEPEWRyUY`) is next, but it touches the signal masks #1431 is reworking, so I'm leaving it out of this PR.
popcoder565 commented 2026-10-09 10:03:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T10:03:58Z.


First Windows run, since the description says it wasn't tested on Windows.

Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Merged onto main b7218b3c together with nine other small libc/libkernel PRs: #1975, #1976, #1977, #1859, #1676, #1675, #1641, #1656, #1807.

  • guest_system_configuration passes.
  • Full ctest: 510/510 (one GPU test skipped for a device limit).

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078729317 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1685#issuecomment-6078729317). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T10:03:58Z. --- First Windows run, since the description says it wasn't tested on Windows. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Merged onto `main` b7218b3c together with nine other small libc/libkernel PRs: #1975, #1976, #1977, #1859, #1676, #1675, #1641, #1656, #1807. - `guest_system_configuration` passes. - Full ctest: 510/510 (one GPU test skipped for a device limit). _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
adriadam10 commented 2026-10-09 21:20:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T21:20:10Z.


Checked on Linux (PR merged onto current main): build + full ctest green, guest_system_configuration passes and fails to link without the change. No overlap with open PRs (#2090 touches the same test file, merges cleanly). Error handling matches FreeBSD kern_sysctl.c; unmodelled names/MIBs throw. Windows run on a real title by @LeandroLP23 and ctest by @popcoder565 confirm the rest. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6089448543 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1685#issuecomment-6089448543). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T21:20:10Z. --- Checked on Linux (PR merged onto current `main`): build + full ctest green, `guest_system_configuration` passes and fails to link without the change. No overlap with open PRs (#2090 touches the same test file, merges cleanly). Error handling matches FreeBSD `kern_sysctl.c`; unmodelled names/MIBs throw. Windows run on a real title by @LeandroLP23 and ctest by @popcoder565 confirm the rest. Merging.
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!1685
No description provided.