Tests: under_wine preserves the calling thread's last error (#1125) #1128

Open
github-bot wants to merge 1 commit from github-bot/gh-1128 into main AGit
Owner

@⁠mahfuzinam0045-spec on GitHub · 2026-11-24 12:10 UTC · original
mahfuzinam0045-spec:fix/util-under-wine-preserve-last-error → main · +29 −5 · 1 files · 1 commits · open

The first invocation of under_wine() looks up wine_get_version in ntdll.dll via GetProcAddress. On native Windows, wine_get_version does not exist in ntdll.dll, so GetProcAddress fails and Windows SetLastError mutates the calling thread's Win32 last error to ERROR_PROC_NOT_FOUND (127).

Any caller querying under_wine() before checking GetLastError() (such as tests or error paths) had its last error silently overwritten with 127. Save and restore GetLastError() around the probe in probe_wine_ntdll(), preserving the caller's last error across both initial probe and cached queries.

Fixes #1125.

What is in it

  • crates/xcl/src/util.rs: save and restore GetLastError() around GetProcAddress in probe_wine_ntdll().
  • crates/xcl/src/util.rs: add unit test under_wine_preserves_last_error verifying that both probe_wine_ntdll() and under_wine() preserve the calling thread's last error.

Tested

  • Windows 11 x64, Rust 1.98.1
  • Verified unit test under_wine_preserves_last_error: asserts that GetLastError() returns the preset error code (0x1234 and 0x5678) across probe execution and subsequent queries.

Regression run

  • A retail title smoke run was not performed (no game title dump on this system). The change is narrow and confined to preserving thread-local error state in util::under_wine(). Awaiting maintainer review / test-only label waiver.

Not tested

  • Execution under Wine / Proton (tested logic on native Windows host where wine_get_version is absent and triggers ERROR_PROC_NOT_FOUND).

AI use

  • Antigravity with Gemini 3.8 Flash investigated the issue, wrote the fix and unit test, and drafted this PR.
**@⁠mahfuzinam0045-spec** on GitHub · 2026-11-24 12:10 UTC · [original](https://github.com/xcl-dev/xcl/pull/1128) `mahfuzinam0045-spec:fix/util-under-wine-preserve-last-error` → `main` · +29 −5 · 1 files · 1 commits · open The first invocation of `under_wine()` looks up `wine_get_version` in `ntdll.dll` via `GetProcAddress`. On native Windows, `wine_get_version` does not exist in `ntdll.dll`, so `GetProcAddress` fails and Windows `SetLastError` mutates the calling thread's Win32 last error to `ERROR_PROC_NOT_FOUND` (127). Any caller querying `under_wine()` before checking `GetLastError()` (such as tests or error paths) had its last error silently overwritten with 127. Save and restore `GetLastError()` around the probe in `probe_wine_ntdll()`, preserving the caller's last error across both initial probe and cached queries. Fixes #1125. **What is in it** - `crates/xcl/src/util.rs`: save and restore `GetLastError()` around `GetProcAddress` in `probe_wine_ntdll()`. - `crates/xcl/src/util.rs`: add unit test `under_wine_preserves_last_error` verifying that both `probe_wine_ntdll()` and `under_wine()` preserve the calling thread's last error. **Tested** - Windows 11 x64, Rust 1.98.1 - Verified unit test `under_wine_preserves_last_error`: asserts that `GetLastError()` returns the preset error code (`0x1234` and `0x5678`) across probe execution and subsequent queries. **Regression run** - A retail title smoke run was not performed (no game title dump on this system). The change is narrow and confined to preserving thread-local error state in `util::under_wine()`. Awaiting maintainer review / `test-only` label waiver. **Not tested** - Execution under Wine / Proton (tested logic on native Windows host where `wine_get_version` is absent and triggers `ERROR_PROC_NOT_FOUND`). **AI use** - Antigravity with Gemini 3.8 Flash investigated the issue, wrote the fix and unit test, and drafted this PR.
The first invocation of under_wine() looks up wine_get_version in ntdll.dll via GetProcAddress. On native Windows, wine_get_version does not exist, causing GetProcAddress to fail and mutate the calling thread's Win32 last error to ERROR_PROC_NOT_FOUND (127).

Any test or runtime path that calls under_wine() (or calls a helper that queries under_wine()) before checking GetLastError() would observe 127 instead of the expected Win32 error code. Save and restore GetLastError() around the GetProcAddress lookup inside probe_wine_ntdll(), and add a unit test verifying that last-error state is preserved across both direct ntdll probes and cached under_wine() queries.

Assisted-by: Antigravity (Gemini 3.8 Flash)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:44:22 +00:00
Author
Owner

@⁠JoaoPauluu on GitHub · 2026-11-24 13:45 UTC · original

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. 281fdd7 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.
**@⁠JoaoPauluu** on GitHub · 2026-11-24 13:45 UTC · [original](https://github.com/xcl-dev/xcl/pull/1128#issuecomment-7133289872) 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`. `281fdd7` 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.
Author
Owner

@⁠Mischief8713 on GitHub · 2026-11-24 16:10 UTC · original

Native Windows run of 281fdd7 (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, and #1125 happens only on native Windows, where wine_get_version does not exist.
  • cargo test -p xcl --lib util::tests::under_wine_preserves_last_error on the head: 1 passed.
  • Same test with only the SetLastError(err); line in probe_wine_ntdll deleted: FAILED at util.rs:364, left 127, right 4660 (0x1234). So the test catches the bug on this platform and the fix removes it.
  • The head does not contain current main; it was run as it is.

Not tested

  • The whole suite, no retail title, AMD GPUs. This is a CPU-only test, so the GPU does not matter.

AI use

  • Claude Code with Claude Sonnet 5.5 ran the commands and wrote this report. I checked the output.
**@⁠Mischief8713** on GitHub · 2026-11-24 16:10 UTC · [original](https://github.com/xcl-dev/xcl/pull/1128#issuecomment-7137236273) **Native Windows run of `281fdd7` (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, and #1125 happens only on native Windows, where `wine_get_version` does not exist. - `cargo test -p xcl --lib util::tests::under_wine_preserves_last_error` on the head: 1 passed. - Same test with only the `SetLastError(err);` line in `probe_wine_ntdll` deleted: FAILED at `util.rs:364`, left 127, right 4660 (`0x1234`). So the test catches the bug on this platform and the fix removes it. - The head does not contain current `main`; it was run as it is. **Not tested** - The whole suite, no retail title, AMD GPUs. This is a CPU-only test, so the GPU does not matter. **AI use** - Claude Code with Claude Sonnet 5.5 ran the commands and wrote this report. I checked the output.
Author
Owner

@⁠Toons29 on GitHub · 2026-11-25 03:12 UTC · original

Regression run of 281fdd73 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: 281fdd7300a9a75bbdb53a6748022b319580bb1c
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1625 (PresentX 1625)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14814 MB

Against the limits in CONTRIBUTING.md: 100 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; I checked the blocks before posting.

**@⁠Toons29** on GitHub · 2026-11-25 03:12 UTC · [original](https://github.com/xcl-dev/xcl/pull/1128#issuecomment-7151697042) Regression run of `281fdd73` on the retail title, for this PR's **Regression run** section. Both blocks are from `scripts/smoke.ps1` as printed, not edited: `main` on `4178e888`, this PR on its head commit with no uncommitted changes, same title and time. ``` xcl-smoke v1 commit: 4178e888c0b5be50a2887eda45cdb832763b68a4 gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 14831 MB ``` ``` xcl-smoke v1 commit: 281fdd7300a9a75bbdb53a6748022b319580bb1c gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1625 (PresentX 1625) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14814 MB ``` Against the limits in CONTRIBUTING.md: 100 % of `main`'s frames, 100 % of its peak commit, no crash, no device removal. AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, `cargo build --release -p xcl`, 60 s, `XCL_NETWORK=0`. This is a regression check only: it does not show whether the run reaches the code this PR changes. AI use: Claude Code (Claude Opus 5.5) built both trees and ran `scripts/smoke.ps1`; I checked the blocks before posting.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 08:02 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 08:02 UTC · [original](https://github.com/xcl-dev/xcl/pull/1128#issuecomment-7156535258) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1128/head:github-bot/gh-1128'
git switch 'github-bot/gh-1128'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1128'
git switch 'github-bot/gh-1128'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1128'
git switch 'github-bot/gh-1128'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1128'
git switch 'main'
git merge --squash 'github-bot/gh-1128'
git switch 'main'
git merge --ff-only 'github-bot/gh-1128'
git switch 'main'
git merge 'github-bot/gh-1128'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.