VFS hooks: the guard keeps the thread's last error #92

Manually merged
github merged 1 commit from gh-pr/92/head into gh-pr/92/base 2026-11-26 04:09:32 +00:00
Owner

@⁠ozimchuk on GitHub · 2026-11-23 10:42 UTC · original
ozimchuk:wine-keep-last-error → main · +2 −0 · 1 files · 1 commits · merged 2026-11-23 11:02 UTC

The hooks' re-entrancy guard is a thread_local. In a build with the GNU toolchain (x86_64-pc-windows-gnu) a thread_local access goes through TlsGetValue, which sets the thread's last error to 0. The guard is dropped after the original function has returned, so a failing call came back with GetLastError() == 0.

The visible effect: std::fs::create_dir_all on a directory that already exists fails with Success. (os error 0), and no title loads:

CRASH: loader: cache dir: Success. (os error 0)
xcl: loading the game failed: cache dir: Success. (os error 0)

The drop now saves the last error and puts it back. MSVC builds use static TLS and are not affected either way.

Validation

Linux, Wine with vkd3d-proton, GNU toolchain build, main at 1f82be3:

build test title (xcl run <testgame> -- --hello)
main + the other Wine fix (#93) only the failure above, 0 checks run
main + this change + #93 47 [PASS], 2 [FAIL] on an AMD iGPU (RADV) and on an RTX 5060 Ti

The two failing checks are not about this change (xmem working-set statistics; the console window "not cloaked" under Wine). The run needs a locally patched vkd3d-proton for reasons that have nothing to do with this change either (it asserts on objects whose vtable XCL replaced); that is a separate topic. Not run on Windows.

AI-assisted.

🤖 Generated with Claude Code

**@⁠ozimchuk** on GitHub · 2026-11-23 10:42 UTC · [original](https://github.com/xcl-dev/xcl/pull/92) `ozimchuk:wine-keep-last-error` → `main` · +2 −0 · 1 files · 1 commits · merged 2026-11-23 11:02 UTC The hooks' re-entrancy guard is a `thread_local`. In a build with the GNU toolchain (`x86_64-pc-windows-gnu`) a `thread_local` access goes through `TlsGetValue`, which sets the thread's last error to 0. The guard is dropped after the original function has returned, so a failing call came back with `GetLastError() == 0`. The visible effect: `std::fs::create_dir_all` on a directory that already exists fails with `Success. (os error 0)`, and no title loads: ``` CRASH: loader: cache dir: Success. (os error 0) xcl: loading the game failed: cache dir: Success. (os error 0) ``` The drop now saves the last error and puts it back. MSVC builds use static TLS and are not affected either way. ## Validation Linux, Wine with vkd3d-proton, GNU toolchain build, `main` at `1f82be3`: | build | test title (`xcl run <testgame> -- --hello`) | |---|---| | `main` + the other Wine fix (#93) only | the failure above, 0 checks run | | `main` + this change + #93 | 47 `[PASS]`, 2 `[FAIL]` on an AMD iGPU (RADV) and on an RTX 5060 Ti | The two failing checks are not about this change (`xmem` working-set statistics; the console window "not cloaked" under Wine). The run needs a locally patched vkd3d-proton for reasons that have nothing to do with this change either (it asserts on objects whose vtable XCL replaced); that is a separate topic. Not run on Windows. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The hooks' re-entrancy guard is a thread_local. In a build with the GNU
toolchain (x86_64-pc-windows-gnu) a thread_local access goes through
TlsGetValue, which sets the thread's last error to 0. The guard is dropped
after the original function has returned, so a failing call came back
with GetLastError() == 0: std::fs::create_dir_all on an existing directory
then fails with "Success. (os error 0)" and no title loads.

The drop now saves the last error and puts it back. MSVC builds use static
TLS and are not affected either way.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:09:31 +00:00
github manually merged commit 079b5414e1 into gh-pr/92/base 2026-11-26 04:09:32 +00:00
Author
Owner

@⁠ivall on GitHub · 2026-11-23 11:03 UTC · original

Merged – a no-op for MSVC builds as you say, and correct for the GNU toolchain. Checked on Windows 11 with an RX 9070 (RDNA4, MSVC build): cargo test --workspace green with the retail samples (shader pack, console DLLs, texture archive), natively and with XCL_SPLIT_WAVE64=1. Thanks!

**@⁠ivall** on GitHub · 2026-11-23 11:03 UTC · [original](https://github.com/xcl-dev/xcl/pull/92#issuecomment-7098952888) Merged – a no-op for MSVC builds as you say, and correct for the GNU toolchain. Checked on Windows 11 with an RX 9070 (RDNA4, MSVC build): `cargo test --workspace` green with the retail samples (shader pack, console DLLs, texture archive), natively and with `XCL_SPLIT_WAVE64=1`. Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.