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

Merged
babyhuey merged 1 commit from upstream-pr/4667 into main 2026-10-13 04:48:21 +00:00
babyhuey commented 2026-10-12 18:21:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-12T18:21:00Z.


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 2a5eca11 + #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 c69eb702, 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

  • 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: #4776 (machdep.tsc_freq, which the current PS5SX2 build reads first) for PS5SX2 to reach it; #4530, #4466, #4426, #3800 (setitimer), #3787, #4653 and #4569 have merged. The change itself builds and passes alone on main
  • Unblocks: PPSA99203 #4850
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4833368634 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4667). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-12T18:21:00Z. --- ### 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](https://github.com/freebsd/freebsd-src/blob/release/11.0.0/sys/x86/x86/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](https://github.com/Swordpdf/PS5SX2/blob/b4cf55e87c34/ps5/coreorbis/main-boot.cpp#L1937-L1945)): ```cpp 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` 2a5eca11 + #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 c69eb702, 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 - [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: #4776 (`machdep.tsc_freq`, which the current PS5SX2 build reads first) for PS5SX2 to reach it; #4530, #4466, #4426, #3800 (setitimer), #3787, #4653 and #4569 have merged. The change itself builds and passes alone on `main` - [x] Unblocks: PPSA99203 #4850 - [x] AI-assisted: yes
MarcZX10 commented 2026-10-12 19:24:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T19:24:43Z.

Code review location: core/libs/prx/libkernel/System/src/SystemConfiguration.cpp; line 5

@@ -2,6 +2,7 @@
 #include "prx/libkernel/DirectMemory/DirectMemory.hpp"
 #include "prx/libkernel/KernelErrors.hpp"
 #include <algorithm>
+#include <cpuid.h>

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review-comment:4251594020 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4667#discussion_r4251594020). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T19:24:43Z. **Code review location:** `core/libs/prx/libkernel/System/src/SystemConfiguration.cpp`; line 5 ~~~~diff @@ -2,6 +2,7 @@ #include "prx/libkernel/DirectMemory/DirectMemory.hpp" #include "prx/libkernel/KernelErrors.hpp" #include <algorithm> +#include <cpuid.h> ~~~~ --- 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.
babyhuey commented 2026-10-12 20:21:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-12T20:21:04Z.


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

  • 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 c69eb702, with no warnings in the two files.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6131955321 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4667#issuecomment-6131955321). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-12T20:21:04Z. --- Thanks, you're right: Clang's `cpuid.h` errors on anything but x86. Fixed in c69eb702 (also rebased onto `main` 9f8a1080): - 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 c69eb702, with no warnings in the two files.
MarcZX10 commented 2026-10-12 20:31:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T20:31:37Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6132109637 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4667#issuecomment-6132109637). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T20:31:37Z. --- 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 commented 2026-10-12 20:38:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-12T20:38:41Z.


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

  • Without this PR (test/verify-sx7base 536603dd): 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 539a7bbd): 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6132212795 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4667#issuecomment-6132212795). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-12T20:38:41Z. --- Windows evidence, now that #4569 exports `fdopendir` from libSceLibcInternal (f3b8ef7a). Windows 11 (WinLibs GCC 15.2), `--trap-sdk-syscall-stubs`, PS5SX2 catalog build vk-285-162, on `main` 9f8a1080 + #4382, #4530, #3787, #4653 and #4569: - Without this PR (`test/verify-sx7base` 536603dd): 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` 539a7bbd): 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`.
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!4667
No description provided.