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

Open
mahfuzinam0045-spec wants to merge 1 commit from upstream-pr/1128 into main
mahfuzinam0045-spec commented 2026-11-24 12:10:50 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by mahfuzinam0045-spec on 2026-11-24T12:10:50Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:5471879286 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1128). Originally posted by [mahfuzinam0045-spec](https://github.com/mahfuzinam0045-spec) on 2026-11-24T12:10:50Z. --- 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.
JoaoPauluu commented 2026-11-24 14:06:38 +00:00 (Migrated from github.com)

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


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.
<!-- greyfinch-sync:ivall/xcl:comment:7133289872 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1128#issuecomment-7133289872). Originally posted by [JoaoPauluu](https://github.com/JoaoPauluu) on 2026-11-24T13:45:24Z. --- 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.
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:26Z.


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.
<!-- greyfinch-sync:ivall/xcl:comment:7137236273 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1128#issuecomment-7137236273). Originally posted by [Mischief8713](https://github.com/Mischief8713) on 2026-11-24T16:10:26Z. --- **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.
Toons29 commented 2026-11-25 04:10:19 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Toons29 on 2026-11-25T03:12:38Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7151697042 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1128#issuecomment-7151697042). Originally posted by [Toons29](https://github.com/Toons29) on 2026-11-25T03:12:38Z. --- 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.
DavidM1911 commented 2026-11-25 08:08:22 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T08:02:23Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7156535258 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1128#issuecomment-7156535258). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T08:02:23Z. --- 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!
github-actions[bot] commented 2026-11-29 07:40:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-29T07:40:25Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7252618877 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1128#issuecomment-7252618877). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-29T07:40:25Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 04:52:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:52:45Z.


Triage (#1607) – head 281fdd7

#1135 made the same change (save and restore the last error around the wine_get_version probe in util::under_wine); it is closed, unmerged, and main still has the unguarded probe. No other open PR touches it.
No problems found in the diff. Minor: the subject says Tests: but util.rs is runtime code, so the PR needs the smoke runs; the failing check is the PR description check.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7301195538 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1128#issuecomment-7301195538). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T04:52:45Z. --- **Triage (#1607)** – head 281fdd7 #1135 made the same change (save and restore the last error around the `wine_get_version` probe in `util::under_wine`); it is closed, unmerged, and main still has the unguarded probe. No other open PR touches it. No problems found in the diff. Minor: the subject says `Tests:` but `util.rs` is runtime code, so the PR needs the smoke runs; the failing check is the PR description check. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1128:upstream-pr/1128'
git switch 'upstream-pr/1128'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/1128'
git switch 'upstream-pr/1128'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1128'
git switch 'upstream-pr/1128'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1128'
git switch 'main'
git merge --squash 'upstream-pr/1128'
git switch 'main'
git merge --ff-only 'upstream-pr/1128'
git switch 'main'
git merge 'upstream-pr/1128'
git push origin 'main'
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!1119
No description provided.