xmem: 32-bit XMemAllocDefault blocks ignore alignments above 64 KiB #2183

Open
opened 2026-11-26 04:57:40 +00:00 by github-bot · 2 comments
Owner

@⁠BastienRodz on GitHub · 2026-11-25 07:08 UTC · original

What happens

XMemAllocDefault (behind XMemAlloc when the title installs no hooks) reads the alignment from attributes (log2 in 5 bits at 24) for host-heap blocks, but its 32-bit branch (attributes & ALLOC_32BIT) drops it:

if attributes & ALLOC_32BIT != 0 {
    return XMemVirtualAlloc(null, size, MEM_RESERVE | MEM_COMMIT, GRAPHICS | ADDRESS_32BIT, PAGE_READWRITE);
}

Without PAGES_2M in the kind, XMemVirtualAlloc passes MEM_ADDRESS_REQUIREMENTS::Alignment = 0, i.e. the 64 KiB allocation granularity. A 32-bit block asked for at 128 KiB, 256 KiB, 1 MiB or 2 MiB can come back only 64 KiB-aligned (0x10000 for a 128 KiB request in a quick synthetic run under Wine).

Expected

The module's own header says what constrains addresses is honoured: "what constrains addresses (alignment, 2 MiB pages, address-bit limits) is honoured." A 32-bit block should get the alignment the attributes ask for, as a host-heap block does. MEM_ADDRESS_REQUIREMENTS takes it directly ("Specifies power-of-2 alignment. Specifying 0 aligns the returned address on the system allocation granularity. If nonzero, this value must be greater than or equal to the system allocation granularity." — https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-mem_address_requirements).

Where

crates/victory-hle/src/modules/xmem.rs, XMemAllocDefault. The title imports xmem.dll!XMemAlloc; whether it asks for 32-bit blocks above 64 KiB alignment is not measured.

AI-assisted (Gemini 4 Neon found it, Claude Code reviewed and verified it); synthetic test only, no game data.

**@⁠BastienRodz** on GitHub · 2026-11-25 07:08 UTC · [original](https://github.com/Marvisak/VIctory/issues/2183) ### What happens `XMemAllocDefault` (behind `XMemAlloc` when the title installs no hooks) reads the alignment from `attributes` (log2 in 5 bits at 24) for host-heap blocks, but its 32-bit branch (`attributes & ALLOC_32BIT`) drops it: ```rust if attributes & ALLOC_32BIT != 0 { return XMemVirtualAlloc(null, size, MEM_RESERVE | MEM_COMMIT, GRAPHICS | ADDRESS_32BIT, PAGE_READWRITE); } ``` Without `PAGES_2M` in the kind, `XMemVirtualAlloc` passes `MEM_ADDRESS_REQUIREMENTS::Alignment = 0`, i.e. the 64 KiB allocation granularity. A 32-bit block asked for at 128 KiB, 256 KiB, 1 MiB or 2 MiB can come back only 64 KiB-aligned (`0x10000` for a 128 KiB request in a quick synthetic run under Wine). ### Expected The module's own header says what constrains addresses is honoured: "what constrains addresses (alignment, 2 MiB pages, address-bit limits) is honoured." A 32-bit block should get the alignment the attributes ask for, as a host-heap block does. `MEM_ADDRESS_REQUIREMENTS` takes it directly ("Specifies power-of-2 alignment. Specifying 0 aligns the returned address on the system allocation granularity. If nonzero, this value must be greater than or equal to the system allocation granularity." — https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-mem_address_requirements). ### Where `crates/victory-hle/src/modules/xmem.rs`, `XMemAllocDefault`. The title imports `xmem.dll!XMemAlloc`; whether it asks for 32-bit blocks above 64 KiB alignment is not measured. AI-assisted (Gemini 4 Neon found it, Claude Code reviewed and verified it); synthetic test only, no game data.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:57:40 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:49 UTC · original · edited 2026-11-26 06:48 UTC

Automated triage for the maintainers.

Confirmed on main: in crates/victory-hle/src/modules/xmem.rs, XMemAllocDefault's ALLOC_32BIT branch calls XMemVirtualAlloc without the attributes' alignment, and XMemVirtualAlloc sets a non-zero MEM_ADDRESS_REQUIREMENTS::Alignment only for 2 MiB pages. A 32-bit block therefore gets 64 KiB alignment at most.

Open PRs addressing it: #2184 and #2529. New since the last triage: a comparison on an RTX 4070 against main 63bcca4 found both tests fail on main and pass with either fix, both merge cleanly, and the fixes are functionally equivalent (#2529 additionally returns null when size + align overflows). The choice between them is for the maintainers.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 15:49 UTC · [original](https://github.com/Marvisak/VIctory/issues/2183#issuecomment-7167345427) · edited 2026-11-26 06:48 UTC <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-26T04:12:37Z at=2026-11-26T07:20:30Z --> Automated triage for the maintainers. Confirmed on `main`: in `crates/victory-hle/src/modules/xmem.rs`, `XMemAllocDefault`'s `ALLOC_32BIT` branch calls `XMemVirtualAlloc` without the attributes' alignment, and `XMemVirtualAlloc` sets a non-zero `MEM_ADDRESS_REQUIREMENTS::Alignment` only for 2 MiB pages. A 32-bit block therefore gets 64 KiB alignment at most. Open PRs addressing it: #2184 and #2529. **New since the last triage:** a comparison on an RTX 4070 against `main` `63bcca4` found both tests fail on `main` and pass with either fix, both merge cleanly, and the fixes are functionally equivalent (#2529 additionally returns null when `size + align` overflows). The choice between them is for the maintainers. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠pawrenity on GitHub · 2026-11-26 04:12 UTC · original

Comparative verification: #2184 and #2529

I checked both open PRs against current main (63bcca4) on NVIDIA GeForce RTX 4070, Windows 11 (x86_64-pc-windows-msvc).

PR Head Own test passes Own test fails on main (test only) Other PR's test on this fix Clippy -D warnings (victory-hle, all targets) Trial merge onto main Defects found
#2184 8954790 yes; victory-hle 144/144 yes, 4/4 runs (field 0x11: … is not 131072-byte aligned) #2529's test passes 3/3 clean clean; xmem tests 15/15 and clippy clean on the merged tree none
#2529 7a37340 yes; victory-hle 153/153 yes, 6/6 runs (the failing alignment varied: 128 KiB, 256 KiB, 1 MiB) #2184's test passes 3/3 clean clean; xmem tests 15/15 on the merged tree none

What each fix does. Both fixes pass the attribute's alignment to MEM_ADDRESS_REQUIREMENTS::Alignment only when it is above 64 KiB. XMemVirtualAlloc keeps its old behaviour in both. #2184 splits out virtual_alloc(…, alignment) and has the caller choose the value. #2529 adds virtual_alloc_aligned(…, align), which makes the > 0x10000 choice itself, and moves layout() ahead of the 32-bit branch. That means a 32-bit request whose size + align overflows Layout now returns null before reaching VirtualAlloc2. I don't see a practical effect from this.

Tests. I ran each test with only its test hunk on main, and it failed every time. #2529's test holds one block per alignment, so in principle it could pass by chance. #2184's test holds four live blocks per alignment, checks that they are writable, and also covers alignments at or below 64 KiB.

Recommendation. The two fixes are functionally equivalent, and I found no defect in either one. #2184 is the better one to merge. It is a single commit, its test is stronger, and it came first. #2529 is a duplicate. Its branch also carries two merge commits from the fork.

No title run. Synthetic tests only.

AI-assisted (Claude Code).

**@⁠pawrenity** on GitHub · 2026-11-26 04:12 UTC · [original](https://github.com/Marvisak/VIctory/issues/2183#issuecomment-7182392344) ### Comparative verification: #2184 and #2529 I checked both open PRs against current `main` (`63bcca4`) on NVIDIA GeForce RTX 4070, Windows 11 (x86_64-pc-windows-msvc). | PR | Head | Own test passes | Own test fails on `main` (test only) | Other PR's test on this fix | Clippy `-D warnings` (`victory-hle`, all targets) | Trial merge onto `main` | Defects found | | --- | --- | --- | --- | --- | --- | --- | --- | | #2184 | `8954790` | yes; `victory-hle` 144/144 | yes, 4/4 runs (`field 0x11: … is not 131072-byte aligned`) | #2529's test passes 3/3 | clean | clean; xmem tests 15/15 and clippy clean on the merged tree | none | | #2529 | `7a37340` | yes; `victory-hle` 153/153 | yes, 6/6 runs (the failing alignment varied: 128 KiB, 256 KiB, 1 MiB) | #2184's test passes 3/3 | clean | clean; xmem tests 15/15 on the merged tree | none | **What each fix does.** Both fixes pass the attribute's alignment to `MEM_ADDRESS_REQUIREMENTS::Alignment` only when it is above 64 KiB. `XMemVirtualAlloc` keeps its old behaviour in both. #2184 splits out `virtual_alloc(…, alignment)` and has the caller choose the value. #2529 adds `virtual_alloc_aligned(…, align)`, which makes the `> 0x10000` choice itself, and moves `layout()` ahead of the 32-bit branch. That means a 32-bit request whose `size + align` overflows `Layout` now returns null before reaching `VirtualAlloc2`. I don't see a practical effect from this. **Tests.** I ran each test with only its test hunk on `main`, and it failed every time. #2529's test holds one block per alignment, so in principle it could pass by chance. #2184's test holds four live blocks per alignment, checks that they are writable, and also covers alignments at or below 64 KiB. **Recommendation.** The two fixes are functionally equivalent, and I found no defect in either one. #2184 is the better one to merge. It is a single commit, its test is stronger, and it came first. #2529 is a duplicate. Its branch also carries two merge commits from the fork. No title run. Synthetic tests only. AI-assisted (Claude Code).
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory#2183
No description provided.