fix(libkernel): fall back below a mapping hint with no room above it #5218
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5218"
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 YossiYad on 2026-10-13T14:54:28Z.
What
A mapping without
MAP_FIXEDtreated its address as the lowest place it could go, and a hint at or above the end of the guest arena threw on the host (mapping address hint is above the guest address space arena). FreeBSD 11.4'svm_mmap_objectplaces such mappings withvm_map_find_min, which takes the address as a hint only: it tries at or above it, then again from its minimum address.GuestArenaAllocateFromHintdoes the same in the arena: at or above the hint when the hint lies below the arena's end and a range fits there, otherwise from the arena's start.MapPlaced(Linux) andmmap_aligned(Windows) use it for hinted mappings.GuestArenaAllocateAtOrAbovekeeps its meaning for the callers that need a range above an address (CheckArenaHonoursHintsWithoutGoingBelowThemstill passes).guest_memoryreserves with a hint above the arena and with a hint on the arena's last page for two pages; both land inside the arena, the second below its hint.Title. PS5CEMU-HAR (PPSA99360) reserves its 3DS JIT range with
sceKernelReserveVirtualRangeand a hint near its own code. With the title's earlier stops applied (#4514, #4469, #4467), launching a 3DS homebrew aborted the process with the throw above. With this PR the reservation succeeds and the title reports its ownAzahar did not start: can't allocand returns to its library instead of terminating. The emulator still cannot start, because the relinked executable lies outside the guest arena; that is #5217 and not changed here.Refs #5217.
Tested
Linux (Bazzite 44, GCC 16.2.1, Ninja, Release,
-DBUILD_TESTING=ON), based onmain0f2683cb:ctest: 1054 of 1059 pass. The five others fail identically on unchangedmainhere:agc_driver_tessellation(segfault),guest_kernel_stack_protect,guest_module_directories, andguest_ampr_cpp_error/video_out_mouse(not built: the first does not link with this machine's non-static toolchain).guest_memoryfails with the previous call inMapPlaced, and with the fallback to the arena's start removed.what(): mapping address hint is above the guest address space arenaand SIGABRT; after, the title's own error message and a running launcher.tools/check_conventions.py --base upstream/main,git diff --checkandtools/pr_overlap.py(no overlap) pass. Windows was not built here.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-13T21:19:40Z.
Tested on Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, full build, this PR (
3fbf4fb82) merged ontomain0aa4cb1c2(AI-assisted: Claude Code). This exercises the Windows call site (mmap_alignedinDirectMemory.cpp), which the Linux run does not reach.main'sDirectMemory.cppand the rest of the PR kept:guest_memoryaborts withwhat(): mapping address hint is above the guest address space arena(exit 0xc0000409).guest_memorypasses 10/10 (--repeat until-fail:10), and the fullctestpasses 1098/1098.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T18:05:53Z.
Checked the arena fallback against FreeBSD's
vm_map_find_minretry from the minimum address, built and ran the libc/libkernel ctest scope (240 tests, all pass), and confirmedguest_memoryfails with the code change reverted. Windows call site covered by @simonbronk's run above; merging.Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-14T18:50:19Z.
@adriadam10 thanks for checking it against
vm_map_find_min, and @simonbronk for the Windows run. The branch still merges into currentmain(2b7e3ce69) without conflicts, so it can go in as it is.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T19:05:26Z.
Partly fixed by #5218: mapping hints with no room above them fall back to the arena start (covered by
guest_memory); the relinked executable still lies outside the arena.