feat(libkernel): report the guest address-space map through kern.proc.vmmap #7070
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7070"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-17T10:04:21Z.
What
sysctl{CTL_KERN,KERN_PROC,KERN_PROC_VMMAP, pid} (MIB 1.14.32.pid) threwunsupported MIB. It now returns the calling process's map as packed FreeBSD 11kinfo_vmentryrecords, the formatkinfo_getvmmapreads: a size query with no buffer, then the records, each withkve_structsizeset to its packed size.GuestArena's used map), in address order. That map is what a guestmmapis placed against: guest mappings and reservations, plus host mappings and the system-reserved range inside the arena.GuestArenagainsGuestArenaNextUsed_nid_no_patch, which returns the used range at or after an address.sceKernelVirtualQueryreports for the range's first page (0 where it reports none). The type isKVME_TYPE_DEFAULT. Offset, object, resident counts, flags and path are 0, so each record is 144 bytes.ESRCH, including -1, as FreeBSD'spgetgives for this node (unlikekern.proc.pathname). A write returnsEPERM, a MIB of the wrong lengthEINVAL, and a short bufferENOMEMwith the bytes that fit.docs/dev/debt/libkernel.md.Ranges outside the arena are not reported, because guest code cannot map there: a fixed anonymous guest
mmapoutside the arena is refused withEINVAL.Tested
Ubuntu 24.04, GCC 13.3, Release, RTX 4070 Ti (NVIDIA 595.99.02).
CheckVmmapSysctlinguest_system_configuration:mmapand requires a record that covers the mapping with read and write protection.munmap, it requires that no record overlaps the range.ENOMEM, nothing written past it), a write (EPERM), a foreign pid and -1 (ESRCH), and 3- and 5-element MIBs (EINVAL).main'sSystemConfiguration.cppthe test aborts onsysctl_nid_postfix: unsupported MIB 1.14.32.<pid>. With this change it passes 3 of 3.^guest_|libcpass.sysctl(1.14.32.getpid(), NULL, &len), allocateslen + len / 4, reads the records and walkskve_start/kve_end(offsets 8 and 16) bykve_structsize. It records the 64 KiB-aligned gaps in [0x10000, 0x68000000) as free ranges.mainare covered by open PRs, so I ran it onmainwith #6915, #6028, #6939 and #6787 merged locally.unsupported MIB 1.14.32.3(2 of 2).ntdll.soloads,wineboot.exe -istarts and reads its NLS files (2 of 2).virtual_alloc_first_teb("failed to map the shared user data"). Wine maps that page at the fixed address 0x7ffe0000, below the guest arena, which a fixed guest mapping cannot reach. That is a separate topic and is not changed here.mainc9e6c45de.guest_system_configurationpasses 3 of 3, and withmain'sSystemConfiguration.cppandGuestArena.cppit aborts onunsupported MIB 1.14.32.<pid>. They also compiled FreeBSD 11.0'sstruct kinfo_vmentrynext toGuestVmEntry, and every offset matches. None of their four local titles issueskern.proc.vmmapin 60 s.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T10:19:53Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libkernel/System/src/SystemConfiguration.cppL75docs/dev/debt/libkernel.mdL163-164core/libs/tests/GuestSystemConfiguration.cppL380, L492core/libs/prx/libkernel/System/src/SystemConfiguration.cppL75Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libc/src/GuestArena.cppcore/libs/prx/libc/src/GuestArena.cppdocs/dev/debt/libkernel.mdcore/libs/tests/GuestSystemConfiguration.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libc/src/GuestArena.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libc/src/GuestArena.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libc/src/GuestArena.cppcore/libs/prx/libc/src/GuestArena.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libc/include/GuestArena.hppcore/libs/prx/libc/src/GuestArena.cppdocs/dev/debt/libkernel.mdImported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-17T14:05:10Z.
Windows run of head
68bd39751, merged ontomainc9e6c45de(clean; also stacked with #7068).libspass, no warnings inSystemConfiguration.cpporGuestArena.cpp.guest_system_configuration(withCheckVmmapSysctl): 3/3 pass with--repeat until-fail:3.SystemConfiguration.cppandGuestArena.cppreverted tomainand the test kept,guest_system_configurationaborts withwhat(): sysctl_nid_postfix: unsupported MIB 1.14.32.<pid>. With the sources restored it passes 3/3.struct kinfo_vmentry(sys/sys/user.h,PATH_MAX1024) and the PR'sGuestVmEntryside by side. Every offset is identical (kve_structsize0,kve_type4,kve_start8,kve_end16,kve_protection56,kve_path136). FreeBSD writesoffsetof(kve_path) + strlen + 1rounded up to 8 withKERN_VMMAP_PACK_KINFO, which is 144 for an empty path, as in the PR. FreeBSD has no end record either: the reader (kinfo_getvmmap.c) walkskve_structsizeup to the returned length, and the PR returns the length of the whole records.kern_proc.c:EPERMfor a write (the node is read-only),ESRCHfor another pid and for -1 (pget),ENOMEMwith the bytes that fit for a short buffer. TheEINVALfor a MIB of 3 or 5 elements is not from FreeBSD (its handler does not check the length) but is the usual contract here.ctest -j8 --timeout 120 -E '^agc_driver_|^video_out_flip'): 884 tests (my throwaway probe included), 872 pass, 2 skipped, 10 failed on the first pass: theconventions_function_bodiesscan and its 5 shards,hardware_oracle_compare,guest_none_relocationsandtls_function_coverage_register_address_loadstimed out under load, andguest_sce_netaborted once at-j8. All pass on serial reruns (shard 4 on its second serial try, 20.5 s against its 30 s limit;guest_sce_net5/5). None of them touches code from these PRstools/check_conventions.py --base c9e6c45deandgit diff --checkpass. There are no new exports.Titles.
sysctlis imported by 43 of my local relinked titles andsysctlbynameby 23. I ran Ruffle PPSA68091, RetroArch PPSA99169 (the picker and the process it starts), PPSA99203 and PPSA01153 for 60 s each onmainand on this PR, with a local diagnosticlibkernelthat logs everysysctlMIB (with buffer and length) and everysysctlbynamename:sysctlsysctlbyname1.37,kern.arandom)So no local title issues
kern.proc.vmmap: onmainnone hitsunsupported MIB 1.14.32.<pid>, and on this PR none runs the new branch. The Ruffle and RetroArch runs make nosysctlcall at all in 60 s, so I cannot confirm that they probe the map. The Forever Launcher run in the description (PPSA99030) is not among my titles, so the only title evidence for this change is the author's. No stop line in any run (all killed at the limit).Small points from the diff, none blocking: the records are collected one range at a time under the arena lock, not under one lock for the whole walk, so a concurrent
mmapcan change the list between two steps (FreeBSD holds the map lock for the walk). That could go in the debt entry next to the unverified type and path.Not checked: Linux, macOS, PS5 hardware, PPSA99030.
Written with Claude Code assistance (validation by a subagent, reviewed in this session).
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-17T14:06:43Z.
Thanks @screamm, the side-by-side compile against FreeBSD 11's
kinfo_vmentryand the negative control are both useful. Good point on the lock. The walk takes the arena lock once per range, so a concurrentmmapormunmapcan change the list between two records. FreeBSD holds the map lock for the whole walk. I added that to the debt entry (c8b5cec671, doc only) rather than holding the lock across the walk, which would mean exposing a whole-walk API fromGuestArena. I added your run to the description.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T17:37:53Z.
Checked the
kinfo_vmentrylayout (static_assert on offsets 8/16/56/136, 144 bytes), the errno set (EPERM, EINVAL, ESRCH for other pids and -1, ENOMEM on a short buffer) and thatCheckVmmapSysctlaborts onmainwithout the change (also confirmed by @screamm's Windows run); the debt entry is accurate; merged.