fix(libkernel): support NoOverwrite mappings on Windows #347
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/347"
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 Pouare514 on 2026-10-02T10:45:06Z.
What
Host-side enforcement for the NoOverwrite mapping flag (0x80,
MAP_FIXED_NOREPLACEsemantics) inMapPlacedon Windows: probe the range withVirtualQueryfirst and fail withEEXISTif anything is already committed there, instead of blindly placing withMAP_FIXED. The guest-registry overlap check one level up (RequireAvailable) cannot see host-side occupancy (e.g. a host-committed page inside the arena that no guest allocation tracks), so without the probe such a mapping silently overwrites host memory.Tested
guest_memorycaseCheckNoOverwriteRejectsHostOccupiedMapping: host-commits a page inside the arena without registering a guest allocation, then requests a Fixed|NoOverwrite direct mapping over it. This branch rejects (EEXIST from the probe); with the probe reverted to current main the same call returns 0 (verified by swapping in main'sDirectMemory.cpp: test fails there).libstarget andguest_memorytest build clean;guest_memorypasses.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T05:42:12Z.
Thanks for picking this up. Since #286, main already accepts NoOverwrite (0x80) fixed mappings on Windows, so the "unsupported flags" failure from the description no longer happens there. For guest ranges the overlap check also already happens one level up:
DoMapAnon,DoMapDirectandDoReserveVirtualcallmutation.RequireAvailablefor every fixed mapping while holding the registry lock, so a NoOverwrite mapping over a reservation or any other registered guest allocation is already refused on both platforms.What this branch adds is the host side
VirtualQueryprobe. Could you add a case tocore/libs/tests/GuestMemory.cppwith a Fixed|NoOverwrite mapping that this probe rejects and current main accepts? Without one I can't tell what it changes in practice. Also,GuestArena.hppis included twice now.Imported from boykopovar/AnyPS5. Originally posted by Pouare514 on 2026-10-04T14:48:08Z.
Done: added CheckNoOverwriteRejectsHostOccupiedMapping to guest_memory (Windows-only): host-commits a page inside the arena without registering a guest allocation, then requests a Fixed|NoOverwrite direct mapping over it. The probe rejects with EEXIST; with main's DirectMemory.cpp swapped in, the same call returns 0 and the test fails. Also removed the duplicated GuestArena.hpp include. guest_memory passes.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-04T18:37:33Z.
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/tests/GuestMemory.cppL29, L181Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T21:07:49Z.
Thanks, that test is what I was after. The guest heap commits arena pages through the same
GuestArenaCommitcall without a registry entry, so on Windows a Fixed|NoOverwrite mapping over heap pages was accepted before, and Linux's MAP_FIXED_NOREPLACE already refuses it. Ready to merge from my side.