xmem: a refused XMemVirtualAlloc leaves the host's reason in the last error #2855
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2855
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2855"
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?
@0xkn0wh3r3 on GitHub · 2026-11-25 22:27 UTC · original
0xkn0wh3r3:hle/xmem-virtual-alloc-keeps-last-error→main· +53 −3 · 1 files · 1 commits · openWhat
When
VirtualAlloc2refuses anXMemVirtualAlloc, the refusal is logged before the function returns:commit_refused, which appends a crash record;tracing::warn!.The crash record is written with
CreateFileW(OPEN_ALWAYS). Whencrashes.logalready exists, that call succeeds and sets the thread's last error toERROR_ALREADY_EXISTS(183). A file-backed tracing writer can do the same. So the title'sGetLastError()after a null return read the logger's code instead of the host's reason (ERROR_COMMITMENT_LIMIT,ERROR_INVALID_ADDRESS, …).The fix takes the code right after the allocation (and after the low-guard retry), uses it for the log, and puts it back with
SetLastErrorbefore returning.Where it came from
From DexNom's fork, DexNom/VIctory@570a941 (
crates/victory-hle/src/modules/xmem.rs). It saves and restores the error the same way and is credited withCo-authored-by: DexNom.Tested
xmem::tests::a_refused_reservation_keeps_the_hosts_last_error. It installs a subscriber whose events setERROR_ALREADY_EXISTS, the way a file-backed log does, then reserves over an existing reservation. The result must be null withERROR_INVALID_ADDRESS. On current main the test fails (left: 183, right: 487); with the change it passes. (DexNom's own version of the test passes on main too, because unit tests have no logger.)cargo test -p victory-hle: all pass (153 unit tests and the integration tests). Windows 11, RTX 5070 Ti.cargo clippy -p victory-hle --all-targets -- -D warnings: clean.Not tested
@Kajanos on GitHub · 2026-11-26 00:07 UTC · original
Windows 11 / NVIDIA test run, head
0630d7c0cemerged ontomain63bcca43c6.Setup: Windows 11 Home build 26300, RTX 5080, NVIDIA 621.40, rustc 1.98.1 MSVC, VS 2022 Build Tools, Windows SDK 10.0.26100 (
dxil.dllfrom the SDK).cargo test --locked -p victory-hle: 152 passed, 1 failed.lifecycle::tests::showing_a_title_window_shows_its_stand_in, and it also fails onmainin this run. The tests ran over SSH, i.e. in session 0 with no interactive desktop, so the window can't be shown. On the desktop session the same test passes onmain(12/12lifecycle). This PR doesn't touch lifecycle.Not run: the retail title, clippy, and other crates.
AI-assisted (Claude Code)
@Marvisak on GitHub · 2026-11-26 03:25 UTC · original
Automated triage for the maintainers.
Verdict: merge candidate. In
XMemVirtualAlloc(crates/victory-hle/src/modules/xmem.rs), a refusal now readsGetLastErrorright after the allocation (and afterlow_guards::retry, which already preserves the allocation's error). That code goes into the log, andSetLastErrorputs it back before returning. Onmain,commit_refused's crash-record append or a file-backed tracing writer can overwrite the last error (for example withERROR_ALREADY_EXISTS) before the title reads it. A null return with the host's reason in the last error is plain Win32 behaviour, so no further evidence is needed.The new test
a_refused_reservation_keeps_the_hosts_last_erroruses a subscriber that clobbers the last error, so it fails onmainand checks the real path. A second contributor's run on an RTX 5080 passed. The change is small and touches nothing else.CI: passing (
check). Merges cleanly.Generated by Claude Code
@kotekompotek on GitHub · 2026-11-25 22:50 UTC · original · reviewed
Classic last-error clobber, correctly fixed: capture GetLastError before any logging (a tracing append can set ERROR_ALREADY_EXISTS itself), restore via SetLastError before returning so the title sees VirtualAlloc2's real reason. The clobbering-subscriber test reproduces the actual hazard. LGTM.
@fuzeofficlal on GitHub · 2026-11-26 00:17 UTC · original · reviewed
Verified head
0630d7c0cleanly merged ontoorigin/main(63bcca43) on Windows 11 x64.Code Review
GetLastError()immediately whenat.is_null()(covering bothallocateandlow_guards::retry, which preserves its ownVirtualAlloc2error) and restoring it withSetLastError(code)right before returning cleanly preventscommit_refusedandtracinglogging from clobbering the host error code.a_refused_reservation_keeps_the_hosts_last_errortest directly verifies preservation against aClobbersLastErrortracing subscriber.Local Verification
cargo test --locked -p victory-hle: 153/153 unit tests (+ child-process test1/1),fidelityfx(1/1),no_dll_planting(1/1) passed.cargo clippy --locked -p victory-hle --tests -- -D warnings(default and--all-features) &cargo xtask policy(191 files ok): clean.Looks clean and ready to merge.
@Dukestar69 on GitHub · 2026-11-26 10:30 UTC · original · approved these changes
Verified against
origin/main(63bcca4):cargo test -p victory-hle --lib modules::xmem:: -- --test-threads=1: 15/15 passed (includinga_refused_reservation_keeps_the_hosts_last_error).cargo clippy -p victory-hle --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly preserves the host's last error when
XMemVirtualAllocfails.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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.