fix(libc): alias non-contiguous shared guest views on Windows #4367
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4367"
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 MarcZX10 on 2026-10-12T07:50:14Z.
What
Carries Angel21PC's alias-run implementation from closed PR #2254, preserving the original commit author. It lets
WindowsMappings::MapAliascompose one alias from adjacent shared pages even when they come from different sections or nonconsecutive section offsets. The existing single-view path remains for contiguous pages, and ranges containing private pages are still rejected.This covers the Windows alias part of #4260. It does not add host imports across registered ranges; that separate change remains outside this PR.
Tested
guest_memorypassed on code head5573e3238with all three alias checks;windows_exceptionsandfiberpassed too. The non-GPU suite was 589/590, withlog_macrosfailing the same way onmain.mainreaches a 368 MiB buffer spanning two direct-memory allocations;MapAliasrefuses it on the current base, forcing CPU copies. The exact current-main rebased head has not been run on Windows or in the title yet.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 repositoryImported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T11:46:32Z.
@MarcZX100 here is the Windows validation this draft asks for, plus a title run that needs exactly this change.
Unit tests on Windows, on exactly this head (5573e3238). Windows 11 Pro 26200, Ryzen 7 7730U, WinLibs GCC 15.2.0 r7, Release.
guest_memorypasses (1.49 s) with all three new checks:CheckAliasAcrossDirectAllocations,CheckAliasOfReorderedSharedPagesandCheckAliasRefusesPagesThatAreNotSharedViews.windows_exceptionsandfiberpass too. Of the non-GPU set (ctest -E "^agc_driver|^video_out|^guest_video"), 589 of 590 pass; the one failure,log_macros, fails the same way onmainon that machine.Sword of the Sea (PPSA25344). Its main menu binds a 368 MiB buffer across two adjacent direct memory ranges (320.75 MiB + 47.3 MiB). Each range is its own allocation, so the pair is views of two sections. An import that covers the buffer needs an alias across both, and on
mainMapAliasrefuses that ("the range is not one contiguous run of views of a section"). As a result the buffer is copied on the CPU on almost every use. A before/after on that title with this PR follows in a separate comment once the rows have run.Reading the change. I compared it with an alias-run version we had written for the same case. Both group the 16 KiB views into runs of one section's consecutive pages. Both map each run into a split placeholder, so no run needs 64 KiB alignment, and both refuse a range with a page that is not a shared view. Where they differ, yours is better:
releaseAliasreleases whatever the reservation holds by querying it (views and the remaining placeholders), so the cleanup doesn't depend on bookkeeping.UnmapAliasreleases every run and forgets the alias even if one unmap fails. Ours stopped at the first failure and kept the entry.Your tests cover what ours did: a run that starts at an offset into its section, two sections in one call, the views per run, the freed range after unmapping, and the refusal of a private page. So I'd drop ours.
One thing I'd add to the PR. The host-import entry in
docs/dev/TechnicalDebt.mdstill says: "On Windows, a run of adjacent registered ranges whose shared views are not one contiguous run of views of a section gets no read-write alias, so its ranges are imported one at a time, as before runs were imported whole, and a buffer that crosses two of them is copied." With this change only a run that is not all shared views (a private range next to a shared one) gets no alias. Shared views of several sections, or of one section at offsets that do not follow on, now get one alias made of one view per run in a placeholder reservation.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T12:20:24Z.
Windows test: head
5573e3238merged onto currentmainffa198407(clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release,-j4: full build 0 errors; ctest with the filterguest_memory: guest_memory_pool_stats passed, guest_memory passed (2 test(s), 0 failed);python tools/check_conventions.py --base upstream/mainpassed. I did not run the new tests againstmainwithout the change.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by queeeef on 2026-10-12T13:42:20Z.
Tested on Windows at this head (
5573e3238).BUILD_TESTING=ON.guest_memory: passes, includingCheckAliasAcrossDirectAllocations,CheckAliasOfReorderedSharedPagesandCheckAliasRefusesPagesThatAreNotSharedViews.WindowsMappings.hpprestored to the base and the rest of this PR kept,guest_memoryaborts withread-write alias of shared guest memory 0x200d60000+0xc000: the range is not one contiguous run of views of a section. That is the error behind cause 2 in #4260.I reviewed the change against a local equivalent I wrote for #4260 (one placeholder split into one view per run of section offsets). The two do the same thing, so I'm dropping mine in favour of this PR. In Palworld (PPSA23126) the local version made the 43 spans that failed at the alias import, and the CPU copies of the regions under them went from 2–56 GB per 10 s to 0. I'll run this PR together with oneandonlydean's
up4/host-import-bind-joinon that scene and report on #4260.AI-assisted (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T00:33:16Z.
The Windows runs above cover what the draft was waiting for, so please mark it ready. One change first: the host-import entry in
docs/dev/debt/libSceAgcDriver.mdstill says a run of adjacent registered ranges whose shared views are not one contiguous run of views of a section gets no read-write alias. With this, only a run with a page that is not a shared view is refused, so that sentence needs to say so.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T07:17:50Z.
Thanks, that debt sentence is stale. The current limitation is that alias creation refuses a run if any page is not a shared view; non-contiguous section offsets alone are now supported. I have not changed the PR text or marked it ready yet. I will correct the debt entry and then mark the PR ready once that edit is on the branch.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T07:32:05Z.
Addressed the debt wording in
docs/dev/debt/libSceAgcDriver.md: aliases are refused when a range contains a page that is not a shared view, while fully shared ranges can be mapped across section runs. I rebased onto currentmain(resolving thecleanRanges/freshRangesadditions alongside the alias-run helpers) and marked the PR ready. The Windows report remains for the code at5573e3238; the rebased head has not had a new Windows runtime run, and the PR description states that explicitly.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T07:33:08Z.
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)docs/dev/debt/libSceAgcDriver.mdL70-71