fix(libkernel): accept shared anonymous, MAP_ALIGNED and hint flags in mmap, as FreeBSD 11.4 does #27303
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27303"
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 kiansaeidnia on 2026-11-25T19:14:38Z.
What
mmapfailed withEOPNOTSUPPfor several flags that FreeBSD 11.4kern_mmap_fpcheckandvm_mmap_objectaccept. It now handles them as FreeBSD does:MAP_SHARED | MAP_ANON, with or withoutMAP_FIXED, maps zero-filled memory through the private anonymous path.fd-1 and offset 0 are still required.MAP_ALIGNED(n)withoutMAP_FIXEDplaces the map at a 2^n-aligned address, for anonymous and file maps. It fails withEINVALfor n below the 16 KiB page shift or from 64. From n = 47 no user address is that aligned, so it fails withENOMEM. WithMAP_FIXEDthe alignment is ignored.MAP_HASSEMAPHORE,MAP_NOSYNC,MAP_NOCOREandMAP_PREFAULT_READare accepted.A hint inside a
sceKernelReserveVirtualRangereservation is now rounded up to the requested alignment before it is placed there, becausevm_map_findsearches upward from the hint. This applies tommap,sceKernelMapDirectMemoryandsceKernelMapDirectMemory2.MAP_ALIGNED_SUPERaligns only maps of 2 MiB or more to 2 MiB, aspmap_align_superpagedoes, so a smaller superpage map keeps its hint. The caller's out address is now written only after the map succeeds.Other flags still fail with
EOPNOTSUPPand are recorded under Silent stubs. FreeBSD drops 0x20 and 0x40 and returnsEINVALfor its other unknown bits. A new Unknown function info entry records that this behaviour is not measured on a console, and the reservation-hint entry now describes the rounding.Tested
Windows 11, MinGW-w64 GCC 16.2, Release:
guest_memorypasses. The tests inGuestMemory.cppcover:CheckPosixMappingFlags:MAP_FIXED | MAP_EXCL, and theirEINVALcases (fd, offset, alignment, protection).MAP_ALIGNED(n)for n = 14, 22 and 30 placed 2^n-aligned; n = 2, 13, 64 and 0xFF givingEINVAL; n = 47, 50 and 63 givingENOMEM.MAP_FIXED.CheckAlignedHintInsideReservation:sceKernelMapDirectMemorywith a hint at reservation + 16 KiB and 4 MiB alignment lands at reservation + 4 MiB. A hint whose rounded range leaves the reservation stays a plain hint (sceKernelMapDirectMemory2). Flexible, unaligned and top-of-space hints are also checked.CheckSuperpageHintInsideReservation: a 16 KiBMAP_ALIGNED_SUPERmap hinted inside a reservation lands at its hint, and a 2 MiB one lands at the next 2 MiB boundary.PosixMemory.cpp,DirectMemory.cppand the test were syntax-checked with g++ 11 on Linux (WSL Ubuntu); the Linux and macOS paths have not been run here.The overlap check reports #24034 (remap alias recheck, a different change) on adjacent lines of
DirectMemory.cpp; whichever merges second rebases them.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 MarcZX10 on 2026-11-25T19:34:47Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the prepared diff and all four changed files were read, but the Windows test run described by the author was not independently verified.
What I ran
Reviewed head
2de888d9fe2c1be1fa33a9564f8942eb17810515using the prepared review artifacts and the pinned repository reader. No commands, builds, or tests were run; no merged preview was checked.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The reported Windows 11 / MinGW-w64 GCC 16.2
guest_memoryrun and Linux syntax checks were not independently run. Linux and macOS paths, physical-console behavior, and compatibility with FreeBSD 11.4 were not verified. All changed files listed in the manifest'sreviewedset were read:DirectMemory.cpp,PosixMemory.cpp,GuestMemory.cpp, andfix-libkernel-mmap-freebsd-flags.md.To get this to a good state
Nothing is required.