fix(libkernel): report live mapping bounds in sceKernelVirtualQuery after partial unmap #2267
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2267"
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 saranxzi on 2026-10-09T14:03:40Z.
What
When an allocation was partially unmapped via
munmap,GuestAllocationssplit the live pieces and updated their active extents (addressandbytes) while preservingallocationAddressandallocationBytesfor the root OS reservation release.sceKernelVirtualQuerypreviously checkedallocationAddressandallocationBytesinstead ofaddressandbytes.The resulting wrong extent is structural, not title-specific:
sceKernelVirtualQueryreturned the root reservation bounds for any partially unmapped allocation, reporting unmapped holes as mapped and failing to advance to subsequent pieces underSCE_KERNEL_VQ_FIND_NEXT.Commercial title import evidence:
sceKernelVirtualQueryfromlibkernel.prx(NIDrVjRvHJ0X6c, recovered from the title's paired SELF binary).Update
sceKernelVirtualQueryto inspectaddressandbytes, returningSCE_KERNEL_ERROR_EACCESfor unmapped addresses and correctly locating the next live segment whenSCE_KERNEL_VQ_FIND_NEXTis passed.Closes #1894
Tested
CheckVirtualQueryPartialMunmapinGuestMemory.cppacts as an exact differential check:guest_memorypasses, binary exits 0.Export.cpp): aborts with exit code 134 atRequire(first.end == reinterpret_cast<std::uintptr_t>(memory) + page), confirming the bug reproduces deterministically on the old code.build-relinkerpassed.tools/testspassed.tools/check_conventions.pypassed with 0 findings.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-09T15:05:34Z.
Review: COMMENTED
Verified on Linux. Base
d70b8998(upstream/main) + head8073bda3, merged clean;guest_memory_testsremoved and rebuilt first so a stale binary could not make the pass meaningless.Arm A (PR head):
guest_memoryPassed, binary exits 0.Arm B (only
DirectMemory/Export.cppreverted tomain, the PR's test kept): aborts —exit 134, and it is the test's own assertion, not a crash elsewhere:That line is
Require(first.end == reinterpret_cast<std::uintptr_t>(memory) + page)— withmain's implementation the query answers with the root reservation's extent, which is exactly the misreport in the description. So the test has a negative control that fires on the old code and reports its own location, which is more than most of the changes I look at manage.Reading the change: all three call sites move from
allocationAddress/allocationBytestoaddress/bytes— including thefindNextcomparison, which is the one that would have been easy to miss while still passing a naive test. Good.The bar this has to clear, and the evidence I could not supply. A
libkernelchange lands with a title and the log line where that title goes wrong. I checked the one title I have a full import registry for — PPSA26344 (Ghost of Yotei): its executable does not import any*VirtualQuery*NID at all (0 matches over its 702 unique imports), so I cannot hand you the title evidence and I am not going to invent one. Which leaves two framings worth writing into the body:sceKernelVirtualQueryand misreports after a partial unmap, orThe second is a real argument here (a wrong answer returned to any caller), and the project has merged universal-impact changes when the measurement was shown — but it has to be said, because silence reads as "one synthetic fixture".
Not verified: any title runtime (no title reaches this path in the logs I have), and the Windows behaviour of the same code path.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-09T15:08:42Z.
Correction to my review above — the title-evidence sentence was wrong, and it was wrong in your favour.
I wrote that PPSA26344 "does not import any
*VirtualQuery*NID at all". That check was made by name against the import registry, and the registry names only 44 of its 702 imports — the other 658 are NID-only entries. So "0 matches" was an artefact of my method, not a fact about the title.Resolved properly, by NID: PPSA26344 does import
sceKernelVirtualQuery.The mapping is recovered by pairing the two artefacts the build emits for every module —
unpatched/*.prxstill carries symbol names,*.prxcarries the NIDs, and the same function sits at the same address in both. That yields 7,986 name↔NID pairs over 116 module pairs and names 683 of the 702 imports, where the name field alone named 44.What this does for the bar: the title half is satisfiable and now evidenced — a title that imports
sceKernelVirtualQueryis PPSA26344, NIDrVjRvHJ0X6c, fromlibkernel.prx. What is still missing is the other half, the log line: an import is not a call, and I have no run of that title reaching a partial unmap and re-querying. If the author (or anyone) has that log, it is worth one line in the body; if not, the universal framing I described above is the honest alternative.Sorry for the noise — the retraction is mine, and the corrected result is more useful than the one I posted first.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by saranxzi on 2026-10-09T15:39:38Z.
Thank you for the thorough verification and the negative control check on Linux!
I have updated the PR description with the universal structural framing and the commercial title evidence you uncovered (PPSA26344 importing
sceKernelVirtualQueryvia NIDrVjRvHJ0X6cfromlibkernel.prx).As demonstrated by the differential check in
GuestMemory.cpp, the defect is structural across any caller: querying after a partial unmap was answering with the root OS reservation instead of the live sub-allocation extents, treating decommitted holes as valid memory.Thanks again for the NID pairing analysis and review!
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-09T19:59:50Z.
Thank you for turning the framing around this quickly, and for giving the NID pairing its own line in the description —
PPSA26344importingsceKernelVirtualQueryviarVjRvHJ0X6cfromlibkernel.prxis the part a maintainer can act on, and it is the part that was missing before.One precision worth keeping, since it is my evidence and I would rather it be accurate: that dump's
eboot.binis a PS4-format SELF (PPSA title IDs ship both formats), so the import is read out of the PS4 binary. NIDs are library-level and identical across the two, so the pairing applies either way — but if a PS5-binary sample turns up it would be a stronger citation than mine.The differential check in
GuestMemory.cppis what convinced me, and describing the defect as structural across any caller rather than as a single title's symptom is the right call.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by saranxzi on 2026-10-09T20:06:12Z.
Thanks for the clarification on the binary format! That makes complete sense regarding the dual-format SELFs under PPSA IDs and how the library-level NID pairing holds across both.
I really appreciate your thorough verification, the Linux differential check, and helping refine the evidence for this change.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T22:08:05Z.
The fresh overlap check flagged #1929, and the source diffs do overlap in
sceKernelVirtualQuery: both switch the reported bounds from allocation extent to the live rangeaddress/bytes. #1929 also adds a flexible-range split/mprotect/partial-unmap test and a non-readable mapping test; #2267 adds a directmmappartial-unmap regression, which may provide distinct coverage. Could you and the maintainers coordinate whether #1929 subsumes the implementation while the direct-mmap test is carried with attribution, or whether a separate behavior remains? I have not changed your branch or closed either PR.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T22:08:43Z.
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.cppL1064-1066Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T22:15:05Z.
To avoid maintaining two overlapping fixes for #1894, I carried your direct-
mmapregression test into Marc’s existing PR #1929 as commite06c4595; Git records you, Saranxzi, as that commit’s author. #1929 is the better carrier because it includes the live-extent fix plus coverage for split flexible ranges and non-readable mappings, and now also includes your test. On currentmaine51d4e1f, the combinedguest_memoryCTest passes (1/1), and conventions/diff checks pass. Your reported Windows/Linux results remain attributed to your original head. Please consider closing #2267 after reviewing the consolidation; I have not changed your branch or closed the PR.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T22:34:32Z.
Closing as a duplicate of #1929, which makes the same
sceKernelVirtualQuerychange for #1894 and now carries your partial-unmap test (e06c4595, with you as its author).Pull request closed