feat(libkernel): report hw.realmem through sysctl #5098

Merged
p3n1cillin merged 1 commit from upstream-pr/5098 into main 2026-10-14 01:44:32 +00:00
p3n1cillin commented 2026-10-13 11:38:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by p3n1cillin on 2026-10-13T11:38:13Z.


What

The Dolphin core that RetroArch (PPSA99169) ships, cores/dolphin_libretro.so, stops on Windows a few seconds into a GameCube boot:

terminate called after throwing an instance of 'std::runtime_error'
  what():  sysctl_nid_postfix: unsupported MIB 6.12

MIB {6, 12} is {CTL_HW, HW_REALMEM}. Dolphin's MemPhysical reads it on FreeBSD as the machine's memory size, into a size_t, without checking the result.

sysctl now answers {6, 12}, and sysctlbyname("hw.realmem") maps to it. It returns the same value and checks as hw.physmem {6, 5}: 8 bytes holding the _SC_PHYS_PAGES pages of 16 KiB, read-only (EPERM for a write) and ENOMEM for a short buffer, the same handling FreeBSD's sysctl_hw_realmem gives it next to sysctl_hw_physmem. FreeBSD reports there the memory the firmware describes, which is at least hw.physmem; AnyPS5 has one memory size and the console's values are unknown. This is recorded under Unknown function info in docs/dev/debt/libkernel.md.

Tested

  • RetroArch PPSA99169 v1.0.0-beta.1 on Windows 11 (MinGW GCC 15.2.0), converted with --executable picker/picker.bin --executable es-de/es-de.bin and started in its game mode (--ps5-mode=game). The game request names /app0/cores/dolphin_libretro.so and a 288-byte GameCube DOL I wrote: one text section at 0x80003100 holding b .. No game files were involved.
    • Before, it stops as above after about 7 s.
    • After, Dolphin logs Starting core = GameCube mode, loads its Vulkan shader caches and Booting from executable: /app0/selftest/loop.dol, then runs for the whole 75 s run.
    • The run also had my open #5013 (select on pipes, which RetroArch's web server needs) merged.
  • guest_system_configuration: the hw.physmem check now also runs for {6, 12} and hw.realmem (length query, value, short buffer, EPERM for a write through sysctl and sysctlbyname). All 124 libkernel tests pass on Windows; Linux was not built locally.
  • python tools/check_conventions.py --base origin/main 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 under Silent stubs in their library's technical debt file
  • 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 (reaching RetroArch's cores needs #5013)
  • Unblocks: the Dolphin core of RetroArch (PPSA99169)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4842627620 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5098). Originally posted by [p3n1cillin](https://github.com/p3n1cillin) on 2026-10-13T11:38:13Z. --- ### What The Dolphin core that RetroArch (PPSA99169) ships, `cores/dolphin_libretro.so`, stops on Windows a few seconds into a GameCube boot: ``` terminate called after throwing an instance of 'std::runtime_error' what(): sysctl_nid_postfix: unsupported MIB 6.12 ``` MIB {6, 12} is {`CTL_HW`, `HW_REALMEM`}. Dolphin's [`MemPhysical`](https://github.com/dolphin-emu/dolphin/blob/8d2ad1a662472955497e5bb79d7b9ec6999e1f0d/Source/Core/Common/MemoryUtil.cpp#L253-L273) reads it on FreeBSD as the machine's memory size, into a `size_t`, without checking the result. `sysctl` now answers {6, 12}, and `sysctlbyname("hw.realmem")` maps to it. It returns the same value and checks as `hw.physmem` {6, 5}: 8 bytes holding the `_SC_PHYS_PAGES` pages of 16 KiB, read-only (`EPERM` for a write) and `ENOMEM` for a short buffer, the same handling FreeBSD's [`sysctl_hw_realmem`](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/sys/kern/kern_mib.c#L191-L204) gives it next to `sysctl_hw_physmem`. FreeBSD reports there the memory the firmware describes, which is at least `hw.physmem`; AnyPS5 has one memory size and the console's values are unknown. This is recorded under Unknown function info in `docs/dev/debt/libkernel.md`. ### Tested - RetroArch PPSA99169 v1.0.0-beta.1 on Windows 11 (MinGW GCC 15.2.0), converted with `--executable picker/picker.bin --executable es-de/es-de.bin` and started in its game mode (`--ps5-mode=game`). The game request names `/app0/cores/dolphin_libretro.so` and a 288-byte GameCube DOL I wrote: one text section at 0x80003100 holding `b .`. No game files were involved. - Before, it stops as above after about 7 s. - After, Dolphin logs `Starting core = GameCube mode`, loads its Vulkan shader caches and `Booting from executable: /app0/selftest/loop.dol`, then runs for the whole 75 s run. - The run also had my open #5013 (`select` on pipes, which RetroArch's web server needs) merged. - `guest_system_configuration`: the `hw.physmem` check now also runs for {6, 12} and `hw.realmem` (length query, value, short buffer, `EPERM` for a write through `sysctl` and `sysctlbyname`). All 124 libkernel tests pass on Windows; Linux was not built locally. - `python tools/check_conventions.py --base origin/main` 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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 (reaching RetroArch's cores needs #5013) - [x] Unblocks: the Dolphin core of RetroArch (PPSA99169) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
p3n1cillin commented 2026-10-13 11:59:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by p3n1cillin on 2026-10-13T11:59:10Z.


Linux run of this change: Ubuntu in WSL2, GCC 15.2.0, Ninja Release, BUILD_TESTING=ON, full build. Built from a local integration head a14a49d8d, which is main 5d50886ee with this PR and my other open library PRs merged (#5013, #5009, #5061, #5078, #5098; no conflicts). All 121 libkernel tests and all 68 libc tests pass, including guest_system_configuration, guest_getrlimit and guest_select. Not run alone on Linux; no title run on Linux.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6145034135 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5098#issuecomment-6145034135). Originally posted by [p3n1cillin](https://github.com/p3n1cillin) on 2026-10-13T11:59:10Z. --- Linux run of this change: Ubuntu in WSL2, GCC 15.2.0, Ninja Release, `BUILD_TESTING=ON`, full build. Built from a local integration head `a14a49d8d`, which is `main` `5d50886ee` with this PR and my other open library PRs merged (#5013, #5009, #5061, #5078, #5098; no conflicts). All 121 libkernel tests and all 68 libc tests pass, including `guest_system_configuration`, `guest_getrlimit` and `guest_select`. Not run alone on Linux; no title run on Linux.
coltken95 commented 2026-10-13 12:48:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-13T12:48:10Z.


Tested on Linux x86-64 (Release build), with b16f8f35d cherry-picked onto main 14036cb0e:

  • With the PR: guest_system_configuration passes.
  • With main's SystemConfiguration.cpp and the PR's test it aborts with
    sysctl_nid_postfix: unsupported MIB 6.12

It also cherry-picks cleanly together with #5078, which edits the same files.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6145897794 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5098#issuecomment-6145897794). Originally posted by [coltken95](https://github.com/coltken95) on 2026-10-13T12:48:10Z. --- Tested on Linux x86-64 (Release build), with b16f8f35d cherry-picked onto main 14036cb0e: - With the PR: `guest_system_configuration` passes. - With main's `SystemConfiguration.cpp` and the PR's test it aborts with `sysctl_nid_postfix: unsupported MIB 6.12` It also cherry-picks cleanly together with #5078, which edits the same files.
oneandonlydean commented 2026-10-14 01:25:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T01:25:36Z.


Rebased onto main to resolve the conflict in docs/dev/debt/libkernel.md after #5185; no other change.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6158799042 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5098#issuecomment-6158799042). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T01:25:36Z. --- Rebased onto main to resolve the conflict in `docs/dev/debt/libkernel.md` after #5185; no other change.
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!5098
No description provided.