fix(libkernel): clamp mprotect ranges to the user map, as FreeBSD 11.4 does #27323
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27323"
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-25T20:53:54Z.
What
mprotectnow handles the range bounds as FreeBSD 11.4 does:EINVALonly when the page-rounded end of the range wraps, as inkern_mprotect.0x800000000000, asvm_map_protectclamps withVM_MAP_RANGE_CHECK.So a range at NULL or wholly outside the user map now returns 0 and changes nothing. It used to give
EINVAL, which came from35ae8742a9and was never measured. The only console measurement is the debt entry for firmware 13.60, which says unmapped ranges return 0, and this change agrees with it.On Windows,
DoMprotect'sVirtualQuerywalk now stops at an address above the process address space (ERROR_INVALID_PARAMETER) instead of throwing. A range that crosses0x800000000000therefore works there too, andsceKernelMprotectover that top window returns 0 as it already did on Linux.The new debt entry records two remaining gaps against
kern_mprotect:EINVAL.Map()andPlaceHintInReservationare not touched (#27303).Two open PRs touch the same lines: #15040 rewrites the
VirtualQueryline this PR changes inDoMprotect, and #20978 (tests only) adds assertions next to the oldmprotect(nullptr, ...)EINVALline, which this PR replaces with 0. Neither implements the clamping or the wrap check, and whichever merges second needs a small rebase.Tested
Windows 11, MinGW-w64 GCC 16.2, Release: these tests pass:
guest_memoryguest_mprotect_unmappedguest_kernel_stack_protectguest_jit_shared_memoryguest_low_address_memoryguest_kernel_mprotect_prot_noneThe new assertions in
guest_memorycover:0x800000000000;EINVAL);PosixMemory.cppandDirectMemory.cppwere syntax-checked with g++ 11 on Linux (WSL Ubuntu).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-25T21:11:42Z.
Review: COMMENTED
Reviewed — comments
The code review found no verified blocking defect, but I did not read every changed file or run the reported checks, so approval is not justified.
What I ran
Inspected the prepared diff and targeted source ranges at head
59c15fb0dc4653a249ebd548cff4904a0b673117using the PR reader. No tests or build checks were run. The description reports Windows 11 tests and Linux syntax checks; those results were not independently verified.Results
Findings
Blocking
None identified in the inspected code.
Non-blocking
None.
Not verified
I read
description.md,commits.md,manifest.json, anddiff.patch, plus targeted ranges inPosixMemory.cpp,DirectMemory.cpp, andGuestMemory.cpp, and the complete five-line debt entry. I did not read every line of the changed C++ files, run tests, or verify the author-reported console behavior. The manifest lists four changed files, all marked included; no excluded files were listed.To get this to a good state
Nothing is required. Optional: share the test results and console measurements when available.