HLE/xmem: track and coalesce fragmented placeholders on remap, snapshot map_alias sources #299
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/299"
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 fxceless/victory-fork. Originally posted by AscilCH on 2026-11-24T23:25:27Z.
Problem
Two bugs in physical-page remapping in
crates/victory-hle/src/modules/xmem.rs:XMemMapPhysicalPagesremapping:UnmapViewOfFile2(..., MEM_PRESERVE_PLACEHOLDER)turns each unmapped view back into an independent placeholder of that view's exact size; Windows does not auto-coalesce adjacent placeholders (andVirtualQueryExmerges identical reserved regions, hiding placeholder boundaries).map()only calledVirtualFree(base, len, MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER), which can split one larger placeholder but cannot coalesce multiple adjacent placeholders.a, map 1 page ata(splitting into view[a, a+PAGE)+ placeholder[a+PAGE, a+3*PAGE)), then remap 2 contiguous physical pages ata. Unmapping[a, a+PAGE)leaves two separate placeholders;XMemMapPhysicalPagescoalesces the physical run to2 * PAGEandMapViewOfFile3(..., MEM_REPLACE_PLACEHOLDER)fails withERROR_INVALID_ADDRESS(487), returningNULLand leaving[a, a+PAGE)unmapped.map_aliasunmaps destination before resolving source slices:map_alias(to, from, len)calledunmap(&mut physical, to, len)before reading[from, from + len)fromphysical.views. Overlapping aliases destroyed their own source mappings, and a missing source page lefttounmapped before returningfalse.Fix
Physical::placeholders(updated inXMemVirtualAlloc,map, andunmap).prepare_placeholder(physical, base, len): splits any tracked placeholder straddlingbaseorbase + len, then callsVirtualFree(base, len, MEM_RELEASE | MEM_COALESCE_PLACEHOLDERS)whenever multiple placeholders tile[base, base + len)beforeMapViewOfFile3.map_alias, snapshot all sourceSliceentries for[from, from + len)before callingunmap(&mut physical, to, len).remapping_contiguous_run_over_fragmented_placeholders_succeedsandmap_alias_handles_overlapping_ranges_and_missing_sources.Verification
rustfmt --edition 2024 --check crates/victory-hle/src/modules/xmem.rs(changed hunks): cleancargo test -p victory-hle --locked xmem -- --test-threads=1: 13 passed, 0 failedcargo xtask policy: 169 files okcargo clippy -p victory-hle --all-targets --locked -- -D warnings: cleancargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings: clean(AI-assisted; synthetic tests only, no game data.)
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.