Skip to content

feat(libkernel): report hw.model from sysctl - #4667

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
babyhuey:feat/libkernel-sysctl-hw-model
Oct 13, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
babyhuey:feat/libkernel-sysctl-hw-model

Conversation

@babyhuey

@babyhuey babyhuey commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What

sysctl and sysctlbyname answer hw.model (MIB {6, 2}, CTL_HW/HW_MODEL), which used to throw unsupported name hw.model. It returns the host CPU's name, built the way FreeBSD 11 builds hw.model: the CPUID brand string (leaves 0x80000002 to 0x80000004) with leading spaces removed (identcpu.c L683-L691). Trailing padding stays, as it does there, so an AMD host's name ends in spaces.

  • This follows hw.ncpu and hw.physmem beside it, which already report host values. What a PS5 reports is unknown, and that is recorded in TechnicalDebt.
  • Reads use the existing CopyOut, so a short buffer gets a truncated copy and ENOMEM, as for the other names. A write returns EPERM.
  • A host CPU without a brand string throws rather than answering with something made up. The CPUID code (and its check) is built only for x86 hosts, so an Apple Silicon Mac throws here too.

PS5SX2 (PPSA99203) reads it once at start-up and only prints it (main-boot.cpp L1937-L1945):

if (sysctlbyname("hw.model", model, &len, nullptr, 0) == 0 && model[0])
    printf("[console] hw.model: %s\n", model);

Where a title reaches it

PS5SX2 relinks only with --trap-sdk-syscall-stubs (#3804), and its earlier stops are in open PRs, so it reaches this only on a stack: main 2a5eca1 + #4466, #4382, #4530, #3787, #4426, #4653 and #4569 (fork branch test/verify-hmbase).

On Linux, without this PR, it runs its start-up (USB scan, HEN config, [elevate] already root), then throws in sysctlbyname; gdb shows its first sysctlbyname call is hw.model. With this PR (test/verify-hmtop), hw.model and the kern.sdk_version read after it succeed, and it goes on to sceVideoOutOpen, as far as a headless run gets.

On Windows, now that #4569 exports fdopendir from libSceLibcInternal, the same stack (PS5SX2 build vk-285-162) dies 3.1 s in without this PR and keeps running to the 60 s limit with it; details in the comments.

Tested

On the PR head c69eb70, Linux (Ubuntu 24.04, GCC 13) and Windows 11 (MinGW-w64 GCC 15.2 from WinLibs), Release:

  • guest_system_configuration passes 5/5 (--repeat until-fail:5) on both. The new check covers the length query, the MIB and name reads, truncation with ENOMEM and the write with EPERM.
  • No warnings in SystemConfiguration.cpp or GuestSystemConfiguration.cpp; <cpuid.h> builds cleanly under MinGW too.

check_conventions.py passes.

Checklist

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed libkernel docs labels Oct 12, 2026
@babyhuey
babyhuey force-pushed the feat/libkernel-sysctl-hw-model branch from 73914e8 to ded2f40 Compare October 12, 2026 19:23
#include "prx/libkernel/DirectMemory/DirectMemory.hpp"
#include "prx/libkernel/KernelErrors.hpp"
#include <algorithm>
#include <cpuid.h>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is built for macOS too, including the project\u2019s macos-15 (Apple Silicon) target. Clang\u2019s bundled cpuid.h explicitly errors unless __x86_64__ or __i386__ is defined, so this unconditional include breaks the arm64 macOS build before hw.model is used. Could the include and CPUID implementation be guarded for x86, with a platform-appropriate fallback (or explicit unsupported behavior) on arm64? The current PR checks skip the full build, so they would not catch this.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 12, 2026
@babyhuey

Copy link
Copy Markdown
Contributor Author

Thanks, you're right: Clang's cpuid.h errors on anything but x86. Fixed in c69eb70 (also rebased onto main 9f8a108):

  • The <cpuid.h> include and the CPUID code are under #if defined(__x86_64__) || defined(__i386__). Elsewhere there is no brand string, so hw.model throws (the host CPU has no CPUID brand string for hw.model), and the technical-debt entry now says an Apple Silicon Mac throws.
  • CheckModelSysctl and its call have the same guard, so guest_system_configuration doesn't expect a name on arm64.

I can't build for macOS here, so I checked the file with clang++ --target=aarch64-linux-gnu -fsyntax-only. The previous head fails on cpuid.h:14: error: this header is for x86 only and its asm constraints; this one gets no cpuid.h errors. The only remaining error comes from borrowing x86 glibc headers for that check (__float128), not from this file. guest_system_configuration still passes 5/5 on Linux (GCC 13) and Windows (WinLibs GCC 15.2) on c69eb70, with no warnings in the two files.

@babyhuey
babyhuey force-pushed the feat/libkernel-sysctl-hw-model branch from ded2f40 to c69eb70 Compare October 12, 2026 20:21
@MarcZX10

Copy link
Copy Markdown
Contributor

Thanks for the fix. Guarding both the cpuid.h include and the CPUID implementation, with an explicit unsupported result on non-x86 hosts, addresses the arm64 compile concern I raised. The cross-target syntax check is useful; I’ll leave native macOS build confirmation to the project’s macOS job, which is currently skipped on pull requests.

@babyhuey

Copy link
Copy Markdown
Contributor Author

Windows evidence, now that #4569 exports fdopendir from libSceLibcInternal (f3b8ef7). Windows 11 (WinLibs GCC 15.2), --trap-sdk-syscall-stubs, PS5SX2 catalog build vk-285-162, on main 9f8a108 + #4382, #4530, #3787, #4653 and #4569:

  • Without this PR (test/verify-sx7base 536603d): it runs its start-up ([elevate] already root, [boot] t+402 ms: elevation took 0 ms) and dies 3.1 s in with 0xC0000409, the fail-fast of the unhandled sysctlbyname throw.
  • With this PR (test/verify-sx7 539a7bb): it keeps running to the 60 s limit, creates /data/PCSX2/covers, rewrites /data/PCSX2/ps5sx2-alive.txt and writes 15 shader-cache files. No throw.

One update for the newer catalog build, vk-285-163: it reads sysctlbyname("machdep.tsc_freq") before hw.model. On Linux that stack now stops there first; with machdep.tsc_freq answered as well, it reads hw.model and kern.sdk_version and reaches sceVideoOutOpen.

@oneandonlydean oneandonlydean self-assigned this Oct 13, 2026
@oneandonlydean
oneandonlydean merged commit 73a5f3a into boykopovar:main Oct 13, 2026
13 of 14 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.

3 participants