Tests: preserve GetLastError() in util::under_wine() #1126

Closed
bigiello wants to merge 1 commit from upstream-pr/1135 into main
bigiello commented 2026-11-24 12:19:13 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bigiello on 2026-11-24T12:19:13Z.


The first call to xcl::util::under_wine() calls GetProcAddress(ntdll, "wine_get_version"). On native Windows that export does not exist, so GetProcAddress fails and sets the calling thread's last error to 127 (ERROR_PROC_NOT_FOUND), clobbering any Win32 error the caller was about to inspect.

Save and restore GetLastError() around the GetModuleHandleA / GetProcAddress probe so under_wine() never mutates the calling thread's last error, even on its first invocation.

Fixes #1125

What is in it

  • crates/xcl/src/util.rs:
    • Extract a private probe_under_wine() helper called by WINE.get_or_init(...) that saves GetLastError() before probing ntdll.dll for wine_get_version and restores it with SetLastError(saved).
    • Add util::tests::under_wine_preserves_last_error exercising both a cold under_wine() call and direct probe_under_wine() calls across 0, ERROR_ACCESS_DENIED, and a custom sentinel (0x1234_5678) so the test fails without the fix regardless of test order.

Tested
Hardware: Windows 11 x64, AMD Ryzen 5 5600, 32 GB RAM, NVIDIA GeForce RTX 4070 SUPER (12 GB VRAM, D3D12 SM 6.6), rustc 1.100.0 (stable-x86_64-pc-windows-msvc), Windows SDK DXC 1.8.2502.11, debug build. No XCL_SAMPLE_* variables set.

  • cargo test -p xcl --lib util::tests::under_wine_preserves_last_error -- --exact: 1 passed, 0 failed, 0 ignored (cold OnceLock initialization + direct probe).
  • cargo test -p xcl --lib util::tests: 6 passed, 0 failed, 0 ignored.
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 742 passed, 0 failed, 41 ignored, 2 GPU skipped (gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware: no wave64) — xcl --lib: 699 passed, 0 failed, 21 ignored; 15 integration test binaries: 43 passed, 0 failed, 20 ignored; bins and doc-tests: 0 passed, 0 failed.
  • cargo test -p xcl --lib -- --test-threads=1: 699 passed, 0 failed, 21 ignored, 2 GPU skipped (no wave64).
  • cargo test -p xcl --lib (default 12 threads, without --test-threads): process exited abnormally with 0xc0000005 (STATUS_ACCESS_VIOLATION) during parallel D3D12 tests (list_x::tests / readback_routing_tests, unrelated to util.rs).
  • cargo clippy --workspace --all-targets: 0 errors, 0 new warnings on the touched lines of crates/xcl/src/util.rs.
  • rustfmt --edition 2021 --check crates/xcl/src/util.rs: 0 diffs on the modified lines (pre-existing diffs on untouched lines left alone per AGENTS.md).

Not tested

  • Retail titles and scripts/smoke.ps1 regression runs (no game files on this machine; Draft PR until a contributor with a title runs smoke or maintainers waive it).
  • Linux / Wine and AMD GPUs (wave64 tests skipped on NVIDIA RTX 4070 SUPER).
  • Release build and XCL_SAMPLE_* tests.

AI use
Antigravity, Neon investigated #1125 and commit d78597d, implemented the GetLastError() save/restore and unit test in crates/xcl/src/util.rs, ran the test/clippy/rustfmt checks above, and drafted this PR description.

<!-- greyfinch-sync:ivall/xcl:issue:6581625434 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1135). Originally posted by [bigiello](https://github.com/bigiello) on 2026-11-24T12:19:13Z. --- The first call to `xcl::util::under_wine()` calls `GetProcAddress(ntdll, "wine_get_version")`. On native Windows that export does not exist, so `GetProcAddress` fails and sets the calling thread's last error to `127` (`ERROR_PROC_NOT_FOUND`), clobbering any Win32 error the caller was about to inspect. Save and restore `GetLastError()` around the `GetModuleHandleA` / `GetProcAddress` probe so `under_wine()` never mutates the calling thread's last error, even on its first invocation. Fixes #1125 **What is in it** - `crates/xcl/src/util.rs`: - Extract a private `probe_under_wine()` helper called by `WINE.get_or_init(...)` that saves `GetLastError()` before probing `ntdll.dll` for `wine_get_version` and restores it with `SetLastError(saved)`. - Add `util::tests::under_wine_preserves_last_error` exercising both a cold `under_wine()` call and direct `probe_under_wine()` calls across `0`, `ERROR_ACCESS_DENIED`, and a custom sentinel (`0x1234_5678`) so the test fails without the fix regardless of test order. **Tested** Hardware: Windows 11 x64, AMD Ryzen 5 5600, 32 GB RAM, NVIDIA GeForce RTX 4070 SUPER (12 GB VRAM, D3D12 SM 6.6), `rustc 1.100.0` (`stable-x86_64-pc-windows-msvc`), Windows SDK DXC `1.8.2502.11`, debug build. No `XCL_SAMPLE_*` variables set. - `cargo test -p xcl --lib util::tests::under_wine_preserves_last_error -- --exact`: 1 passed, 0 failed, 0 ignored (cold `OnceLock` initialization + direct probe). - `cargo test -p xcl --lib util::tests`: 6 passed, 0 failed, 0 ignored. - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`): 742 passed, 0 failed, 41 ignored, 2 GPU skipped (`gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`: `no wave64`) — `xcl --lib`: 699 passed, 0 failed, 21 ignored; 15 integration test binaries: 43 passed, 0 failed, 20 ignored; bins and doc-tests: 0 passed, 0 failed. - `cargo test -p xcl --lib -- --test-threads=1`: 699 passed, 0 failed, 21 ignored, 2 GPU skipped (`no wave64`). - `cargo test -p xcl --lib` (default 12 threads, without `--test-threads`): process exited abnormally with `0xc0000005` (`STATUS_ACCESS_VIOLATION`) during parallel D3D12 tests (`list_x::tests` / `readback_routing_tests`, unrelated to `util.rs`). - `cargo clippy --workspace --all-targets`: 0 errors, 0 new warnings on the touched lines of `crates/xcl/src/util.rs`. - `rustfmt --edition 2021 --check crates/xcl/src/util.rs`: 0 diffs on the modified lines (pre-existing diffs on untouched lines left alone per `AGENTS.md`). **Not tested** - Retail titles and `scripts/smoke.ps1` regression runs (no game files on this machine; Draft PR until a contributor with a title runs smoke or maintainers waive it). - Linux / Wine and AMD GPUs (wave64 tests skipped on NVIDIA RTX 4070 SUPER). - Release build and `XCL_SAMPLE_*` tests. **AI use** Antigravity, Neon investigated #1125 and commit `d78597d`, implemented the `GetLastError()` save/restore and unit test in `crates/xcl/src/util.rs`, ran the test/clippy/rustfmt checks above, and drafted this PR description.
JoaoPauluu commented 2026-11-24 14:06:39 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by JoaoPauluu on 2026-11-24T13:45:25Z.


The Wine side of this change.

Tested

  • RTX 3060 12 GB (NVIDIA 620.70.06, 32-lane waves), i5-10400F, 16 GB, CachyOS (kernel 7.3.3), Proton Experimental 11.0-20261112 with the patched vkd3d-proton 3.1 from #257 (DXIL → SPIR-V through dxil-spirv), DXC 1.9.2609.5. Release, cross-built for x86_64-pc-windows-gnu. 8da86a5 as it is (based on 47efa2e), no uncommitted changes. The lib test binary runs under Wine.
  • util::tests::under_wine_preserves_last_error (--exact, one process): ok.
  • Under Wine, ntdll.dll exports wine_get_version, so the probe's GetProcAddress succeeds and does not set the last error. This run therefore checks that the save and restore does no harm on Wine. It does not exercise the Windows failure from #1125, so it would pass without the fix too.

Not tested

  • native Windows; the rest of the suite on this head.

AI use

  • Claude Code (Claude Opus 5.5) built the head, ran the tests and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.
<!-- greyfinch-sync:ivall/xcl:comment:7133290370 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1135#issuecomment-7133290370). Originally posted by [JoaoPauluu](https://github.com/JoaoPauluu) on 2026-11-24T13:45:25Z. --- The Wine side of this change. **Tested** - RTX 3060 12 GB (NVIDIA 620.70.06, 32-lane waves), i5-10400F, 16 GB, CachyOS (kernel 7.3.3), Proton Experimental 11.0-20261112 with the patched vkd3d-proton 3.1 from #257 (DXIL → SPIR-V through dxil-spirv), DXC 1.9.2609.5. Release, cross-built for `x86_64-pc-windows-gnu`. `8da86a5` as it is (based on `47efa2e`), no uncommitted changes. The lib test binary runs under Wine. - `util::tests::under_wine_preserves_last_error` (`--exact`, one process): **ok**. - Under Wine, `ntdll.dll` exports `wine_get_version`, so the probe's `GetProcAddress` succeeds and does not set the last error. This run therefore checks that the save and restore does no harm on Wine. It does not exercise the Windows failure from #1125, so it would pass without the fix too. **Not tested** - native Windows; the rest of the suite on this head. **AI use** - Claude Code (Claude Opus 5.5) built the head, ran the tests and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.
upipibi commented 2026-11-24 14:06:53 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by upipibi on 2026-11-24T14:06:21Z.


This and #1128 (opened 9 minutes earlier) make the same change for #1125. Both save GetLastError() around the wine_get_version lookup and restore it, and both run the probe through OnceLock::get_or_init. Their tests check the same two paths: the probe called directly, and under_wine(). They differ only in names and comments, and they conflict in util.rs, so CONTRIBUTING's one-of-several rule applies. Read from the diffs only; I have not run either.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ivall/xcl:comment:7133846847 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1135#issuecomment-7133846847). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-24T14:06:21Z. --- This and #1128 (opened 9 minutes earlier) make the same change for #1125. Both save `GetLastError()` around the `wine_get_version` lookup and restore it, and both run the probe through `OnceLock::get_or_init`. Their tests check the same two paths: the probe called directly, and `under_wine()`. They differ only in names and comments, and they conflict in `util.rs`, so CONTRIBUTING's one-of-several rule applies. Read from the diffs only; I have not run either. AI-assisted (Claude Code).
Mischief8713 commented 2026-11-24 17:06:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Mischief8713 on 2026-11-24T16:10:28Z.


Native Windows run of 8da86a5 (NVIDIA GTX 1660 Ti): the new test passes with the fix and fails without it, with 127 (ERROR_PROC_NOT_FOUND)

Tested

  • Windows 11 (10.0.26300) native, Ryzen 5 2600X, rustc 1.100.0, debug build. The existing report is Wine only.
  • cargo test -p xcl --lib util::tests::under_wine_preserves_last_error on the head: 1 passed.
  • Same test with only the SetLastError(saved); line in probe_under_wine deleted: FAILED at util.rs:491, left 127, right 305419896 (0x12345678).
  • The head does not contain current main; it was run as it is.
  • #1128 changes the same function the same way and passes and fails the same way here, so one of the two can be closed as a duplicate.

Not tested

  • The whole suite, no retail title, AMD GPUs. This is a CPU-only test.

AI use

  • Claude Code with Claude Sonnet 5.5 ran the commands and wrote this report. I checked the output.
<!-- greyfinch-sync:ivall/xcl:comment:7137236893 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1135#issuecomment-7137236893). Originally posted by [Mischief8713](https://github.com/Mischief8713) on 2026-11-24T16:10:28Z. --- **Native Windows run of `8da86a5` (NVIDIA GTX 1660 Ti): the new test passes with the fix and fails without it, with 127 (`ERROR_PROC_NOT_FOUND`)** **Tested** - Windows 11 (10.0.26300) native, Ryzen 5 2600X, rustc 1.100.0, debug build. The existing report is Wine only. - `cargo test -p xcl --lib util::tests::under_wine_preserves_last_error` on the head: 1 passed. - Same test with only the `SetLastError(saved);` line in `probe_under_wine` deleted: FAILED at `util.rs:491`, left 127, right 305419896 (`0x12345678`). - The head does not contain current `main`; it was run as it is. - #1128 changes the same function the same way and passes and fails the same way here, so one of the two can be closed as a duplicate. **Not tested** - The whole suite, no retail title, AMD GPUs. This is a CPU-only test. **AI use** - Claude Code with Claude Sonnet 5.5 ran the commands and wrote this report. I checked the output.
upstream-sync closed this pull request 2026-11-24 19:05:04 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
xcl-dev/xcl!1126
No description provided.