Repository navigation
fix(libkernel): fall back below a mapping hint with no room above it - #5218
Conversation
|
Tested on Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, full build, this PR (
|
A mapping without MAP_FIXED treated 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. FreeBSD 11.4's vm_mmap_object places such mappings with vm_map_find_min, which takes the address as a hint only: it tries at or above it, then again from its minimum address. GuestArenaAllocateFromHint does the same in the arena: at or above the hint when it lies below the arena's end and a range fits there, otherwise from the arena's start. MapPlaced and the Windows mmap_aligned use it for hinted mappings; GuestArenaAllocateAtOrAbove keeps its meaning for the callers that need a range above an address. PS5CEMU-HAR (PPSA99360) reserves its JIT range with sceKernelReserveVirtualRange and a hint near its own code, a host address above the arena here, and aborted with "mapping address hint is above the guest address space arena" when launching a 3DS title.
guest_memory reserves with a hint above the guest arena and with a hint on the arena's last page for two pages, and checks that both land inside the arena, the second below its hint.
3fbf4fb to
aca7a3a
Compare
|
Checked the arena fallback against FreeBSD's |
|
@adriadam10 thanks for checking it against |
|
Partly fixed by #5218: mapping hints with no room above them fall back to the arena start (covered by |
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 repository