Skip to content

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

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
overlordxrz-source:feat/libkernel-sysctl-hw-ncpu
Oct 9, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
overlordxrz-source:feat/libkernel-sysctl-hw-ncpu

Conversation

@overlordxrz-source

@overlordxrz-source overlordxrz-source commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

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 1081602, 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 4b6ab6b, 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

ScreenTester5 (PPSA69420) stops at start-up on the unresolved sysctlbyname
import and also imports sysctl. hw.ncpu (CTL_HW.HW_NCPU) reports the same
processor count as sysconf(_SC_NPROCESSORS_ONLN). Other names and MIBs throw.
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

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

@LeandroLP23

Copy link
Copy Markdown
Contributor

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 4b6ab6b; title relinked with relinker --windows and run with the patched build/core/libs/libs/*.prx.

Tested with AI assistance (Claude Code).

@overlordxrz-source

Copy link
Copy Markdown
Contributor Author

@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

Copy link
Copy Markdown
Contributor

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 b7218b3 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

@adriadam10

Copy link
Copy Markdown
Collaborator

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.

@adriadam10
adriadam10 merged commit 870ac04 into boykopovar:main Oct 9, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants