fix(libkernel): map file pages past the end of the file on Windows #28006
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/28006"
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 Ducengarth on 2026-11-28T03:26:30Z.
What
On Windows,
mmapof a file failed withEOPNOTSUPPwhen the mapping reached a whole 16 KiB guest page past the end of the file. That applied to shared mappings (DoMapFileBacked_nid_no_patch) and private ones (MapPrivateFileCopy). FreeBSD and Linux map those pages and fault only when they are touched. This change maps them the same way:DirectMemory.cpp. A mapping that starts past the end of the file is made only of such pages and creates no file section.vm_fault_holdrefuses a page index at or past the vnode object's size withKERN_PROTECTION_FAILURE, andtrap()turns that intoSIGSEGVwithSEGV_ACCERRunder the defaultmachdep.prot_fault_translation. On Windows the guest already gotSIGSEGV, trap 12, the faulting address and an error code without the present bit for a reserved page;SegvCodenow also gives these pagesSEGV_ACCERRinstead ofSEGV_MAPERR. On Linux the host kernel raisesSIGBUSthere, as before, and the debt entry records it.mprotectrecords a new protection on those pages without committing them, so they stay inaccessible.munmap, and a fixed mapping that replaces the range (RemapFixedIntoRegistered), forget them.docs/dev/debt/changes/fix-libkernel-windows-mmap-past-eof.mdupdates the "Regular file mappings" entry oflibkernel.md.No title is known to need this; it removes a Windows-only refusal of a mapping that POSIX allows.
Overlaps: #27906 (mine) and #27303 change neighbouring lines of
DoMapFileBacked_nid_no_patch, and #27906 has its own fragment for the same debt entry. Whichever lands second needs a rebase that keeps both changes.Tested
Windows 11 (26300), WinLibs GCC 15.2, Release,
BUILD_TESTING=ON, onmaina4ebd9084c; the branch was then rebased onto3c88ba8ad3, whose 10 new commits do not touch the changed files.New and changed tests:
guest_exception_fault(TestFilePastEnd, shared and private), with a guest exception handler:mprotectto read-only and back, a write past the end still faults;munmapand a fixed anonymous mapping at the same address,mprotect(PROT_NONE)makes the old past-end page fault again, which shows the record was dropped;guest_siginfo_fault(Windows): anSA_SIGINFOhandler receivesSEGV_ACCERR, the address and trap 12 for a read past the end, shared and private.guest_memory(CheckRegularFileMapping): a three-page mapping of a 1.3-page file succeeds and reads the file bytes and zeros, shared and private. On Windows the page past the end is stillMEM_RESERVEaftermprotect. A mapping at an offset past the end succeeds. The previous Windows expectation ofEOPNOTSUPPis removed.Negative controls, each with a rebuild of
libkernel:mmap;SegvCodechange, onlyguest_siginfo_faultfails, on the code;mprotectfilter,guest_exception_faultandguest_memoryfail;munmap,guest_exception_faultfails at thePROT_NONEcheck.Full
ctest -j10(7,364 tests) on this branch: 2 failures.agc_driver_linear_target_import_creationfails onmaintoo (#26650).frame_capture_minimizetimed out under load and passes alone (3 of 3).Linux (Ubuntu 24.04 under WSL 2, GCC 13.3, Release):
guest_exception_fault,guest_siginfo_faultandguest_memorypass at this PR's head, with theSIGBUSexpectation. #28013 then delivers that fault asSIGSEGVon Linux too.python tools/check_conventions.py: no errors. The one warning is the length of the existing debt entry.python tools/debt_fold.py --check: passes.tools/pr_overlap.py --branch: line overlaps only with #27906 and #27303, described above.main6b222c7ccd, which moved the reservation placement inDoMapFileBacked_nid_no_patchinto itstry(a conflict, kept with the past-end pages), on #28013's merge82ba394e1e:guest_exception_fault,guest_memory,guest_mmap_fixed_anonymous,guest_mmap_executableandguest_siginfo_faultpass.APS5_NO_PROCMAP_QUERY=1, as on a kernel older than 6.11,guest_memoryaborts withGuestWritable: failed to open /proc/self/maps, and it aborts the same way onmain6b222c7ccd.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
Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-28T03:30:02Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
68d9706675:tools/check_conventions.pypassed.guest_exception_fault_tests,guest_memory_tests,guest_siginfo_fault_testsbuilt cleanly.guest_exception_fault,guest_memory,guest_mmap_fixed_anonymous,guest_mmap_executable,guest_siginfo_fault):Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-28T03:35:35Z.
Review: COMMENTED
Actionable comments posted: 1
62283a5c-9b02-4aea-8b12-d4d75f83f904Reviewing files that changed from the base of the PR and between
3c88ba8ad3and68d9706675.core/libs/prx/libkernel/DirectMemory/DirectMemory.cppcore/libs/prx/libkernel/DirectMemory/DirectMemory.hppcore/libs/prx/libkernel/DirectMemory/PosixMemory.cppcore/libs/prx/libkernel/System/src/Exception.cppcore/libs/tests/GuestExceptionFault.cppcore/libs/tests/GuestMemory.cppcore/libs/tests/GuestSiginfoFault.cppdocs/dev/debt/changes/fix-libkernel-windows-mmap-past-eof.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-11-28T07:40:27Z.
Review: APPROVED
Checked head
68d9706675. On Windows 11 with WinLibs GCC 15.2 (Release), I applied it tomain4c7578e0a4together with #27985, #28002, #28001, #27991, #27987, #28007 and #27994.tools/check_conventions.py --headandtools/debt_fold.py --checkpassed and the full build succeeded.guest_memory,guest_exception_fault,guest_siginfo_fault,guest_mmap_fixed_anonymousandguest_mmap_executablepass. In the full CPU suite (5,135 tests) the only failure iswindows_read_trap_unknown, which fails onmaintoo (fixed in #28028). The full GPU suite (2,249 tests) on an NVIDIA RTX 5080 and an AMD Radeon gfx1036 iGPU, withVK_LAYER_KHRONOS_validation1.4.363 inserted, matchesmain: onlyagc_driver_linear_target_import_creationfails (fixed in #28029), with noVUID-orSYNC-HAZARDline.The Linux
guest_memoryabort above (GuestWritable: failed to open /proc/self/maps) is not from this PR. On WSL Ubuntu 24.04, GCC 13.3, Release (kernel 6.18):guest_memorypasses on bothmainc6331cc61band this head, twice each.APS5_NO_PROCMAP_QUERY=1, it aborts with that message after about 10.8 s on bothmainand this head, twice each.So it shows up on kernels without
PROCMAP_QUERY(before 6.11, such as Ubuntu 24.04's stock 6.8).CheckFlexibleMemorySharedBackinglowersRLIMIT_NOFILEso no new descriptor can be opened, and then callssceKernelMapFlexibleMemory. That checks its output pointer withGuestWritable, and the maps scanner opens/proc/self/mapsagain and fails. WithPROCMAP_QUERYthe descriptor opened earlier is reused, so it passes. #28045 fixes the scanner.One non-blocking note:
check_conventions.pywarns that the debt fragment is 3,907 characters (debt-length, limit 1,000).AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T08:12:16Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change based on the code inspected; the author-reported checks are not independent runs.
What I ran
Reviewed head
68d9706675b322e29e88ea5edec5af954a487338. No tests or builds were run in this review.Results
Findings
Blocking
None identified in the inspected code.
Non-blocking
None.
Not verified
The author reports Windows and Linux test runs, negative controls, and convention checks; these were not independently confirmed. The review folder lists eight changed files, all included. I read the description, commits, manifest and diff, plus targeted ranges from
DirectMemory.cpp,PosixMemory.cpp,Exception.cpp, andGuestExceptionFault.cpp; I did not read the full text of every changed file.files.jsonwas unavailable through the reader.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T10:15:18Z.
Review: COMMENTED
Reviewed — no blocking findings
The changed mapping and fault-handling paths are supported by the source and tests I inspected; I did not run the reported checks, so this is a comment rather than an approval.
What I ran
Reviewed head
a5020a27e2a136d22426f8e8e2c154ee3a217988using the prepared diff andrepo_read.pysource reads. No commands or tests were run. Test results below are author-reported.Results
Findings
Blocking
None found in the inspected code.
Non-blocking
None.
Not verified
I did not run the build, tests, convention checks, debt check, or overlap check. Author reports Windows 11 and WSL 2 test runs, two failures in the full Windows suite, and passing convention and debt checks. I read the changed hunks and relevant source ranges in all eight changed files listed in the manifest; I did not read every line of the larger files.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-29T10:15:44Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
a5020a27e2:tools/check_conventions.pypassed.guest_exception_fault_tests,guest_memory_tests,guest_siginfo_fault_testsbuilt cleanly.guest_exception_fault,guest_memory,guest_mmap_fixed_anonymous,guest_mmap_executable,guest_siginfo_fault):Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-29T13:50:40Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
b769fa2d8f:tools/check_conventions.pypassed.guest_exception_fault_tests,guest_memory_tests,guest_siginfo_fault_testsbuilt cleanly.guest_exception_fault,guest_memory,guest_mmap_fixed_anonymous,guest_mmap_executable,guest_siginfo_fault):Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T13:56:34Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the prepared materials report successful targeted checks on Windows and Linux, and my inspection found no verified blocking defect.
What I ran
Reviewed head
b769fa2d8f58faf371a5cab1e7c6897ee53077af. Inspected the prepared description, commits, manifest and diff, plus all eight changed files and the relevant implementation context throughrepo_read.py. No commands or tests were run in this review.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not run tests or independently verify the author-reported results. I did not inspect the full repository beyond the changed files and targeted implementation context. The prepared manifest lists eight changed files, all marked included; all eight were read.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T15:59:43Z.
Review: COMMENTED
I ran
guest_memoryandguest_exception_faulton Linux with the patch applied. Both passed. The Windows file-tail mapping and access-fault behavior still need a Windows run.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.