fix(libkernel): round an unaligned munmap address down like FreeBSD #10550
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10550"
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 GitamarT045T3R on 2026-10-24T09:34:03Z.
What
munmapfailed withEINVALfor an address that is not page aligned. FreeBSD 11'ssys_munmaprejects only a zero length and an address wrap. Otherwise it moves the address down to its page and grows the length by the same offset before rounding it up (pageoff = addr & PAGE_MASK; addr -= pageoff; size += pageoff), so every page the range touches is unmapped.munmapnow does the same with the 16 KiB guest page.The zero-length check still comes first, so
munmap(addr + 1, 0)still fails withEINVAL, as in FreeBSD. The existing checks for a null address, an overflowing length and a range past the address space are unchanged.sceKernelMunmap, which has its own path, is not touched.guest_memorychecked thatmunmap(memory + 1, page)fails withEINVAL. That came with the original anonymous-mapping implementation (1bbdf7daa), not from a console measurement. It now checks the zero-length case at that address instead. The next check, which unmapped page 1 withmunmap(memory + page, 1), now does it throughmemory + page + 1. The checks after it are unchanged: pages 0 and 2 are intact andmincoresees page 1 gone. Unalignedmunmapon the console itself has not been measured.Tested
Windows 10 Pro 22H2 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Ninja, Release,
BUILD_TESTING=ON, onmain19cb822f8:guest_memoryfails withmain'sPosixMemory.cppand passes with this change.guest_flexible_memory_budget,guest_mprotect_unmapped,guest_low_address_memory,guest_msyncandguest_jit_shared_memorystill pass.python tools/check_conventions.py --base origin/mainpasses.git merge-treeagainst the 13 open PRs that touch these two files is clean. #6321 and #5021 already conflict withmainthere.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T10:37:09Z.
Review: APPROVED
Reviewed the range arithmetic against the stated FreeBSD rule: the page offset is subtracted from the start, added to length with overflow protection, and the rounded span retains the existing zero/null/end-overflow checks. The test now preserves the zero-length error at an unaligned address and verifies that an unaligned start removes the touched page while adjacent pages remain mapped. The contributor reports the focused Windows guest-memory tests and conventions check passing. Hosted eligibility, conventions, intake, labels, and report pass; platform build jobs were skipped by the eligibility gate. I did not rerun the test locally.