xmem: 32-bit XMemAllocDefault blocks get the alignment they ask for #2182
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2184"
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 Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-25T07:08:54Z.
What's wrong
XMemAllocDefaulthonours the alignment field ofattributes(log2, 5 bits at 24) for host-heap blocks, but itsALLOC_32BITbranch callsXMemVirtualAllocwith no alignment. That path setsMEM_ADDRESS_REQUIREMENTS::Alignmentonly forPAGES_2M, so a 32-bit block asked for at 128 KiB, 256 KiB, 1 MiB or 2 MiB gets the 64 KiB allocation granularity instead. The module header says alignment is one of the address constraints it honours.What the fix does
XMemVirtualAllocinto a privatevirtual_allocthat takes theAlignmentto request.XMemVirtualAllockeeps its behaviour (2 MiB forPAGES_2M, else 0).XMemAllocDefaultpasses the asked alignment when it is above 64 KiB, and 0 otherwise:MEM_ADDRESS_REQUIREMENTSrequires a nonzero alignment to be at least the allocation granularity, and 0 already gives 64 KiB.Tests
New
modules::xmem::tests::alloc_32bit_honours_alignments_above_64k: four live 32-bit blocks per alignment (16 B, 64 KiB, 128 KiB, 256 KiB, 2 MiB), each checked below 4 GiB, aligned, and writable.main(940d32f) it fails:field 0x11: 0x10000 is not 131072-byte aligned.modules::xmem::tests pass (11 of 11, Wine 10, x86_64-pc-windows-msvc).Not tested
No title run. The title imports
xmem.dll!XMemAlloc, but whether it asks for 32-bit blocks aligned above 64 KiB is not measured. #2022 changes the host-heap branch of the same function; the two don't overlap.Fixes #2183
AI-assisted (Gemini 4 Neon found and wrote it, Claude Code reviewed and verified it). No game data used.
🤖 Generated with Claude Code
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T07:17:39Z.
Review: COMMENTED
Static review only: victory-hle is Windows-only — nothing compiles or runs on macOS; source review of the diff.
xmem: 32-bit XMemAllocDefault blocks get their alignment — allocator alignment fix for 32-bit title heaps.
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T09:18:33Z.
Verified on Windows 10 / GTX 1050,
cargo test -p victory-hle --locked xmem: 11/11 pass, including the newalloc_32bit_honours_alignments_above_64k.Mechanics check out:
PAGEis 64 KiB, soalign > PAGEcorrectly maps "at or below the allocation granularity" toAlignment = 0, whichMEM_ADDRESS_REQUIREMENTSrequires (nonzero must be ≥64 KiB).XMemVirtualAllockeeps its old contract (2 MiB only forPAGES_2M), and the four-live-blocks-per-alignment test design guards against 64 KiB slots landing on coarse boundaries by chance — it does fail on940d32fas reported.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T12:38:20Z.
Automated triage for the maintainers.
Merge candidate.
XMemAllocDefaultwithALLOC_32BIT(crates/victory-hle/src/modules/xmem.rs) now honours the attributes' alignment field. It reads the same field aslayout(attributes >> ALIGNMENT_SHIFT & 0x1f). Alignments above the 64 KiB granularity are passed asMEM_ADDRESS_REQUIREMENTS::Alignment, and anything at or below it uses 0. That is right, becauseVirtualAlloc2only accepts 0 or at least the allocation granularity, and 0 already gives 64 KiB.XMemVirtualAllockeeps its old behaviour (2 MiB only forPAGES_2M) through the newvirtual_allochelper.alloc_32bit_honours_alignments_above_64kholds four live blocks per alignment, so a block can't pass by landing on a coarse boundary by chance. A reviewer in the thread reports that it fails onmain. CIcheckpasses, and the branch merges cleanly.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by jaschinski97-ops on 2026-11-25T16:18:22Z.
Review: COMMENTED
Native Windows 11 verification of unchanged head
8954790, including integration with #2022 and current main67e8ae1.940d32fand current main67e8ae1reproduces the failure: field0x11can return an address with remainder 65,536 modulo 131,072. This is a real before/after check on native Windows.Reproducible evidence branch, exact heads, commands and results. Original commits and authors are preserved; no implementation edits or competing PR.
Windows 11 Pro build 26300, Rust 1.98.1
x86_64-pc-windows-gnu, LLVM-MinGW. This native GNU run complements the existing MSVC CI. Synthetic fixtures only, no title data or gameplay claim. AI-assisted verification with Codex. Claim: https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7167502972.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T19:00:29Z.
Review: APPROVED
Reviewed
8954790b4fefmerged cleanly onto63bcca43.The change in
crates/victory-hle/src/modules/xmem.rs:87-115and305-319is minimal and exact:virtual_alloc(..., alignment)preservesXMemVirtualAlloc's existingPAGES_2M(2 * MIB) /0behavior verbatim.XMemAllocDefault'sALLOC_32BITpath (xmem.rs:306-318), extracting1usize << (attributes >> ALIGNMENT_SHIFT & 0x1f)and passingif align > PAGE { align } else { 0 }matchesMEM_ADDRESS_REQUIREMENTS::Alignment(0 for 64 KiB granularity and powers of two above 64 KiB) while keepingXMemFreeDefault'sVirtualFree(..., MEM_RELEASE)symmetry intact.Verification (native Windows 11):
cargo xtask policyandcargo clippy --locked -p victory-hle --all-targets -- -D warnings(default and--all-features) pass cleanly.cargo test --locked -p victory-hle xmem::passes 15/15 (includingalloc_32bit_honours_alignments_above_64k).0, 1, 12, 16..=26(64 KiBthrough64 MiB) with 4 simultaneous live allocations across sizes1 Bto256 KiB(all< 4 GiB, properly aligned, writable, freed viaXMemFreeDefault/XMemFree, and re-allocated), extreme fields30/31(1 GiB/2 GiBwith no panic or UB), andXMemVirtualAllocwithPAGES_2M(2 MiBaligned).LGTM.
Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-27T06:28:32Z.
#2184 and #2022 together on current
main(the check NEW-192 on #1633 asks for). Native Windows 11 26200, Rust 1.98.1 MSVC, no game data. Both are merge candidates and both editcrates/victory-hle/src/modules/xmem.rs.Together:
main63bcca4+ #2184 (8954790) + #2022 (8d8eee9) merge without conflicts.cargo test -p victory-hle --lib --locked -- --test-threads=1: 154 passed, 0 failed, both new tests included.cargo clippy -p victory-hle --all-targets --locked -- -D warnings: clean.Each test without its fix (each PR merged onto
main, then only its non-test hunks undone):alloc_32bit_honours_alignments_above_64kfails:left: 65536, right: 0at the alignment assertion.aligned_blocks_are_padded_oncetakes the test process down with0xc0000374(STATUS_HEAP_CORRUPTION).So both tests catch the bug they're for, and neither fix depends on the other.
AI use: Claude Code (Claude Opus 5.5).
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.