Under Wine, report.json is not rewritten at a title's exit: the exe's TLS callback never gets DLL_PROCESS_DETACH #1461

Open
opened 2026-11-26 04:54:31 +00:00 by github-bot · 0 comments
Owner

@⁠crastinator on GitHub · 2026-11-24 16:27 UTC · original

Under Wine, a title's normal exit leaves report.json as it was written before the title ran. called_stubs, the d3d12 / audio / dstorage counters, vfs and the rest from that run are missing. That affects every Linux and macOS report shared in #175 and #258. The cause is on the Wine side: Wine never calls the exe's TLS callbacks with DLL_PROCESS_DETACH, and that callback is where XCL writes its final report.

Where

  • main.rs registers xcl.exe's TLS callback (.CRT$XLY), which calls loader::on_tls_event. On DLL_PROCESS_DETACH (reason 0) it calls report::write_final(None) ("write the report while everything is alive", loader.rs:413).
  • host.rs also writes the report before run_main (:142) and after it returns (:145). A title that ends through ExitProcess / CRT exit never comes back to :145, so that one does not run either.
  • eh::hk_nt_terminate_process runs on that exit under Wine too (it logs process ends (thread …)), but it only logs.

Measured (main 930e8b4)

  • A minimal exe with a .CRT$XLY TLS callback that appends each reason to a file, under Proton Experimental 11.0-20261112's Wine and under Wine 11.22 (Arch). Whether main returns or calls std::process::exit(0), the callback gets 1 2 3 (process attach, thread attach, thread detach) and never 0. On Windows an exe's TLS callbacks get DLL_PROCESS_DETACH at process exit.
  • crates/xcl/tests/e2e.rs under Wine, once the test title's own checks pass (with #794, #890 and a test-title change for the cloaking check, PR to follow): report.json has "called_stubs": [], although the title called XclDefinitelyMissingFunction and stubbed_imports lists it. The test fails at e2e.rs:164 (report.called_stubs: []). exit_code is 0, because the launcher sets it afterwards.

Possible fix
Under Wine (util::under_wine()), have hk_nt_terminate_process call report::write_final(None) before it logs and flushes, for status 0 and a nonzero status alike. That is the last point Wine gives us before the process ends. Keeping it to Wine leaves Windows exactly as it is, with the TLS detach still writing the report there. It's a runtime change, so it needs a smoke run on a real title. I can do it once I have the game to run it with, unless you'd rather handle it differently.

AI use

  • Claude Code (Claude Opus 5.5) wrote the probe, traced the code and wrote this; I checked the results.
**@⁠crastinator** on GitHub · 2026-11-24 16:27 UTC · [original](https://github.com/xcl-dev/xcl/issues/1461) Under Wine, a title's normal exit leaves `report.json` as it was written before the title ran. `called_stubs`, the `d3d12` / `audio` / `dstorage` counters, `vfs` and the rest from that run are missing. That affects every Linux and macOS report shared in #175 and #258. The cause is on the Wine side: Wine never calls the **exe's** TLS callbacks with `DLL_PROCESS_DETACH`, and that callback is where XCL writes its final report. **Where** - `main.rs` registers xcl.exe's TLS callback (`.CRT$XLY`), which calls `loader::on_tls_event`. On `DLL_PROCESS_DETACH` (reason 0) it calls `report::write_final(None)` ("write the report while everything is alive", `loader.rs:413`). - `host.rs` also writes the report before `run_main` (`:142`) and after it returns (`:145`). A title that ends through `ExitProcess` / CRT `exit` never comes back to `:145`, so that one does not run either. - `eh::hk_nt_terminate_process` runs on that exit under Wine too (it logs `process ends (thread …)`), but it only logs. **Measured** (main `930e8b4`) - A minimal exe with a `.CRT$XLY` TLS callback that appends each `reason` to a file, under Proton Experimental 11.0-20261112's Wine and under Wine 11.22 (Arch). Whether `main` returns or calls `std::process::exit(0)`, the callback gets `1 2 3` (process attach, thread attach, thread detach) and never `0`. On Windows an exe's TLS callbacks get `DLL_PROCESS_DETACH` at process exit. - `crates/xcl/tests/e2e.rs` under Wine, once the test title's own checks pass (with #794, #890 and a test-title change for the cloaking check, PR to follow): `report.json` has `"called_stubs": []`, although the title called `XclDefinitelyMissingFunction` and `stubbed_imports` lists it. The test fails at `e2e.rs:164` (`report.called_stubs: []`). `exit_code` is 0, because the launcher sets it afterwards. **Possible fix** Under Wine (`util::under_wine()`), have `hk_nt_terminate_process` call `report::write_final(None)` before it logs and flushes, for status 0 and a nonzero status alike. That is the last point Wine gives us before the process ends. Keeping it to Wine leaves Windows exactly as it is, with the TLS detach still writing the report there. It's a runtime change, so it needs a smoke run on a real title. I can do it once I have the game to run it with, unless you'd rather handle it differently. **AI use** - Claude Code (Claude Opus 5.5) wrote the probe, traced the code and wrote this; I checked the results.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:54:31 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.