Skip to content

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

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
p3n1cillin:claude/sysctl-hw-realmem
Oct 14, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
p3n1cillin:claude/sysctl-hw-realmem

Conversation

@p3n1cillin

Copy link
Copy Markdown

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 feat(libkernel): select on pipes on Windows #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 feat(libkernel): select on pipes on Windows #5013)
  • Unblocks: the Dolphin core of RetroArch (PPSA99169)
  • AI-assisted: yes

🤖 Generated with Claude Code

@p3n1cillin

Copy link
Copy Markdown
Author

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

Copy link
Copy Markdown

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

  • 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.

The dolphin_libretro core of RetroArch (PPSA99169) reads {CTL_HW,
HW_REALMEM} as the machine's memory size and stopped on the unsupported
MIB. It reports the same value as hw.physmem.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oneandonlydean
oneandonlydean force-pushed the claude/sysctl-hw-realmem branch from b16f8f3 to fe54938 Compare October 14, 2026 01:25
@oneandonlydean

Copy link
Copy Markdown
Collaborator

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

@oneandonlydean
oneandonlydean merged commit dff25dd into boykopovar:main Oct 14, 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