TLS: installing an image leaves other threads' blocks to the loader #426

Open
Kalmarv wants to merge 1 commit from upstream-pr/431 into main
Kalmarv commented 2026-11-24 00:11:02 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-24T00:11:02Z.


cargo test -p xcl --lib sometimes dies with 0xC0000005 before any test fails (only with several test threads). The crash is in tls::install. After loading the carrier DLL, it filled every other thread's new TLS slot itself: a toolhelp snapshot, then each thread's TEB read and its TLS block written. A thread that exits in between has its TEB unmapped, which is the read AV, or its TLS block freed by LdrShutdownThread, which means heap corruption. Nothing outside the loader can hold a thread's TEB or TLS in place, so the walk can't be made safe:

  • a handle keeps only the thread object;
  • STILL_ACTIVE holds while the blocks are freed;
  • suspending doesn't stop a thread already exiting in the kernel.

The carrier now carries the image's template, so the loader fills every thread's block itself, under its own lock.

What is in it

  • build_carrier_dll_holding: the carrier's TLS initial data is the image's template (clamped to [16, MAX_CARRIER_TEMPLATE] to preserve #1403's overflow guard), with zeros after it. install uses it and build_carrier_dll_with delegates to it.
  • fill_existing_threads is removed, and the module docs say who fills the blocks now.
  • Nothing else changes: on_thread_attach still fills new threads (now with the same bytes), and take_slot_zero is untouched.
  • Tests:
    • carrier_holds_the_template;
    • a_thread_running_during_install_gets_the_template: a thread started before install finds the template in its own block, and nothing in XCL writes into it;
    • install_while_threads_exit: 200 installs while 8 threads keep starting and ending short threads. Its carriers go to one folder, %TEMP%\xcl_tls_test_churn, cleared of earlier runs' carriers at the start (cleanup_cache).

Tested

  • Rebased head 30378b241ece56458ce639e1e3a8bc33ffa03d1a on main 5ad98adbc360225ac8a57ad9661e16fe8df9d8dd:
    • Hardware & toolchain: NVIDIA GeForce RTX 5070 Ti (driver 610.74), AMD Ryzen 9 9950X, Windows 11 Pro 26200, rustc 1.99.0 (b940084d7 2026-09-28), DXC 1.9.2609.5, debug + release.
    • cargo build --release -p xcl: clean, 39 warnings (0 new vs main 5ad98adbc baseline of 39 warnings; 0 warnings in crates/xcl/src/tls.rs).
    • scripts/test.ps1 (cargo build --workspace, cargo bench -p xcl --bench '*' -- --test, cargo test --workspace -- --test-threads=4): 3008 passed, 0 failed, 52 ignored across 43 test targets + doc-tests (xcl lib: 2856 passed, 0 failed, 32 ignored; tls::tests: 8 passed, 0 failed, 1 ignored including all 3 new tests and carrier_size_and_build_clamp_without_overflow; tests/tls_slot_zero.rs: 2 passed, 0 failed). SKIPPED GPU tests: 24 (22 no wave64, 2 no heap windows).
    • title run: 60 s retail title smoke (title ea3b5e4d), 1511 frames shown (PresentX 1511), presents per 2 s 61 61 60, peak commit 14632 MB, 0 device removals, 0 crashes (exit 0x0).
  • Earlier verification on 940f7cb (same TLS logic):
    • The crash, named. On main 6da33fa, cargo test -p xcl --lib crashed in run 2 of 2 on tls::tests::install_without_an_index_variable reading TEB+0x58 in tls_block_of ← fill_existing_threads ← install; with --test-threads=1 it passed 6 of 6.
    • The churn test (install_while_threads_exit, debugger, CPU only): main d4f17ca with the test crashed 19 of 20 runs at the same read; this change passed 30 of 30.
    • Mutation check (carrier without template and no walk): fails install_without_an_index_variable, windows_loads_carrier_and_allocates_full_block_for_all_threads, and a_thread_running_during_install_gets_the_template.
    • Wine 11.21 Staging (windows-gnu, CPU only): tls:: and pe:: pass, and both new thread tests pass 10 of 10.
    • Independent AMD runs on earlier heads by @MesshM (RX 9060 XT, 3/3 crash on main vs 3/3 pass with this PR) and @srcamarda (RX 7800 XT, 90 s smoke pair clean).

Regression run

Release builds on RTX 5070 Ti (main 5ad98adbc vs rebased head 30378b241), no uncommitted changes.

main:

xcl-smoke v1
commit: 5ad98adbc360225ac8a57ad9661e16fe8df9d8dd
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1460 (PresentX 1460)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 15067 MB

PR:

xcl-smoke v1
commit: 30378b241ece56458ce639e1e3a8bc33ffa03d1a
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1511 (PresentX 1511)
presents per 2 s (last 3): 61 61 60
device removals: 0
crashes: 0
peak commit: 14632 MB

Not tested

  • AMD / Intel GPUs on rebased head 30378b241, native wave64 GPU tests (22 skipped on RTX 5070 Ti), and opt-in XCL_HEAP_WINDOWS=1 GPU tests (2 skipped).
  • Sample-gated tests (XCL_SAMPLE_* unset).
  • take_slot_zero is not changed here.
  • macOS / Linux: not built.

AI use

  • Claude Code (Claude Opus 5.5): diagnosed the crash via debugger capture, wrote the original change, tests, and earlier runs.
  • Antigravity (Gemini 4 Neon): rebased onto main 5ad98adbc (preserving #1403's MAX_CARRIER_TEMPLATE clamp in build_carrier_dll_holding), ran the release build comparison, scripts/test.ps1, 60 s smoke pair, and scripts/pr_check.py --local, and updated this description.
<!-- greyfinch-sync:ivall/xcl:issue:5463543030 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/431). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-24T00:11:02Z. --- `cargo test -p xcl --lib` sometimes dies with `0xC0000005` before any test fails (only with several test threads). The crash is in `tls::install`. After loading the carrier DLL, it filled every other thread's new TLS slot itself: a toolhelp snapshot, then each thread's TEB read and its TLS block written. A thread that exits in between has its TEB unmapped, which is the read AV, or its TLS block freed by `LdrShutdownThread`, which means heap corruption. Nothing outside the loader can hold a thread's TEB or TLS in place, so the walk can't be made safe: - a handle keeps only the thread object; - `STILL_ACTIVE` holds while the blocks are freed; - suspending doesn't stop a thread already exiting in the kernel. The carrier now carries the image's template, so the loader fills every thread's block itself, under its own lock. **What is in it** - `build_carrier_dll_holding`: the carrier's TLS initial data is the image's template (clamped to `[16, MAX_CARRIER_TEMPLATE]` to preserve #1403's overflow guard), with zeros after it. `install` uses it and `build_carrier_dll_with` delegates to it. - `fill_existing_threads` is removed, and the module docs say who fills the blocks now. - Nothing else changes: `on_thread_attach` still fills new threads (now with the same bytes), and `take_slot_zero` is untouched. - Tests: - `carrier_holds_the_template`; - `a_thread_running_during_install_gets_the_template`: a thread started before `install` finds the template in its own block, and nothing in XCL writes into it; - `install_while_threads_exit`: 200 installs while 8 threads keep starting and ending short threads. Its carriers go to one folder, `%TEMP%\xcl_tls_test_churn`, cleared of earlier runs' carriers at the start (`cleanup_cache`). **Tested** - Rebased head `30378b241ece56458ce639e1e3a8bc33ffa03d1a` on `main` `5ad98adbc360225ac8a57ad9661e16fe8df9d8dd`: - Hardware & toolchain: NVIDIA GeForce RTX 5070 Ti (driver 610.74), AMD Ryzen 9 9950X, Windows 11 Pro 26200, `rustc 1.99.0 (b940084d7 2026-09-28)`, DXC `1.9.2609.5`, debug + release. - `cargo build --release -p xcl`: clean, 39 warnings (`0` new vs `main` `5ad98adbc` baseline of 39 warnings; `0` warnings in `crates/xcl/src/tls.rs`). - `scripts/test.ps1` (`cargo build --workspace`, `cargo bench -p xcl --bench '*' -- --test`, `cargo test --workspace -- --test-threads=4`): **3008 passed, 0 failed, 52 ignored** across 43 test targets + doc-tests (`xcl` lib: `2856 passed, 0 failed, 32 ignored`; `tls::tests`: `8 passed, 0 failed, 1 ignored` including all 3 new tests and `carrier_size_and_build_clamp_without_overflow`; `tests/tls_slot_zero.rs`: `2 passed, 0 failed`). SKIPPED GPU tests: **24** (`22 no wave64`, `2 no heap windows`). - title run: 60 s retail title smoke (title ea3b5e4d), 1511 frames shown (PresentX 1511), presents per 2 s 61 61 60, peak commit 14632 MB, 0 device removals, 0 crashes (exit 0x0). - Earlier verification on `940f7cb` (same TLS logic): - **The crash, named.** On `main` `6da33fa`, `cargo test -p xcl --lib` crashed in run 2 of 2 on `tls::tests::install_without_an_index_variable` reading `TEB+0x58` in `tls_block_of` ← `fill_existing_threads` ← `install`; with `--test-threads=1` it passed 6 of 6. - **The churn test** (`install_while_threads_exit`, debugger, CPU only): `main` `d4f17ca` with the test crashed 19 of 20 runs at the same read; this change passed 30 of 30. - **Mutation check** (carrier without template and no walk): fails `install_without_an_index_variable`, `windows_loads_carrier_and_allocates_full_block_for_all_threads`, and `a_thread_running_during_install_gets_the_template`. - **Wine** 11.21 Staging (`windows-gnu`, CPU only): `tls::` and `pe::` pass, and both new thread tests pass 10 of 10. - Independent AMD runs on earlier heads by @MesshM (RX 9060 XT, 3/3 crash on `main` vs 3/3 pass with this PR) and @srcamarda (RX 7800 XT, 90 s smoke pair clean). **Regression run** Release builds on RTX 5070 Ti (`main` `5ad98adbc` vs rebased head `30378b241`), no uncommitted changes. main: ``` xcl-smoke v1 commit: 5ad98adbc360225ac8a57ad9661e16fe8df9d8dd gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 60 exit: 0x0 frames shown: 1460 (PresentX 1460) presents per 2 s (last 3): 60 60 61 device removals: 0 crashes: 0 peak commit: 15067 MB ``` PR: ``` xcl-smoke v1 commit: 30378b241ece56458ce639e1e3a8bc33ffa03d1a gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 60 exit: 0x0 frames shown: 1511 (PresentX 1511) presents per 2 s (last 3): 61 61 60 device removals: 0 crashes: 0 peak commit: 14632 MB ``` **Not tested** - AMD / Intel GPUs on rebased head `30378b241`, native wave64 GPU tests (`22` skipped on RTX 5070 Ti), and opt-in `XCL_HEAP_WINDOWS=1` GPU tests (`2` skipped). - Sample-gated tests (`XCL_SAMPLE_*` unset). - `take_slot_zero` is not changed here. - macOS / Linux: not built. **AI use** - Claude Code (Claude Opus 5.5): diagnosed the crash via debugger capture, wrote the original change, tests, and earlier runs. - Antigravity (Gemini 4 Neon): rebased onto `main` `5ad98adbc` (preserving #1403's `MAX_CARRIER_TEMPLATE` clamp in `build_carrier_dll_holding`), ran the release build comparison, `scripts/test.ps1`, 60 s smoke pair, and `scripts/pr_check.py --local`, and updated this description.
MesshM commented 2026-11-24 07:05:07 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by MesshM on 2026-11-24T00:59:57Z.


Test run of 526a17661f22431342f4a89c4f8925eb68fedd18 on AMD (RDNA4); the PR was tested on NVIDIA only. The branch is based on 9ab7d76, so I merged it onto current main a6f5f7a locally (clean merge, only tls.rs) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Ryzen 7 5700X (8C/16T), 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4) on the merge: 679 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 639 passed, 0 failed, 21 ignored (main on this machine: 636 / 676, the difference is the 3 new tests)
  • 0 SKIPPED; all tls::tests pass, including a_thread_running_during_install_gets_the_template and install_while_threads_exit
  • install_while_threads_exit copied unchanged into main's tls.rs (nothing else changed), cargo test -p xcl --lib tls::tests::install_while_threads_exit, 3 runs: 3 of 3 crashed with 0xc0000005, STATUS_ACCESS_VIOLATION
  • the same test on the merge, 3 runs: 3 of 3 passed (1.95–2.04 s)

So on this 16-thread machine the race reproduces every time, not 1 run in 3.

Review of the change: install runs in step 5 of loader::map, after relocations (step 3), so the template the carrier now carries is the relocated one, the same bytes fill_block used to copy; past template_len the block is zeros, as before. on_thread_attach still fills new threads from the image's live template, so that path is unchanged. I found nothing to change.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main; the overlap with #196 was not checked.

Run and report by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

<!-- greyfinch-sync:ivall/xcl:comment:7118649688 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/431#issuecomment-7118649688). Originally posted by [MesshM](https://github.com/MesshM) on 2026-11-24T00:59:57Z. --- Test run of `526a17661f22431342f4a89c4f8925eb68fedd18` on AMD (RDNA4); the PR was tested on NVIDIA only. The branch is based on `9ab7d76`, so I merged it onto current `main` `a6f5f7a` locally (clean merge, only `tls.rs`) and tested that tree. **Tested** - AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Ryzen 7 5700X (8C/16T), 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 `stable-x86_64-pc-windows-msvc`, debug - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`) on the merge: **679 passed, 0 failed, 41 ignored**, exit code 0; `xcl` lib tests 639 passed, 0 failed, 21 ignored (`main` on this machine: 636 / 676, the difference is the 3 new tests) - **0 `SKIPPED`**; all `tls::tests` pass, including `a_thread_running_during_install_gets_the_template` and `install_while_threads_exit` - `install_while_threads_exit` copied unchanged into `main`'s `tls.rs` (nothing else changed), `cargo test -p xcl --lib tls::tests::install_while_threads_exit`, 3 runs: **3 of 3 crashed** with `0xc0000005, STATUS_ACCESS_VIOLATION` - the same test on the merge, 3 runs: 3 of 3 passed (1.95–2.04 s) So on this 16-thread machine the race reproduces every time, not 1 run in 3. **Review of the change:** `install` runs in step 5 of `loader::map`, after relocations (step 3), so the template the carrier now carries is the relocated one, the same bytes `fill_block` used to copy; past `template_len` the block is zeros, as before. `on_thread_attach` still fills new threads from the image's live template, so that path is unchanged. I found nothing to change. **Not tested:** no retail title or regression run (I have no unpacked game), no `XCL_SAMPLE_*` tests, release build; the PR's head on its old base was not run, only its merge onto `main`; the overlap with #196 was not checked. Run and report by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
QemmHD commented 2026-11-24 07:05:13 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by QemmHD on 2026-11-24T01:18:15Z.


NVIDIA run (only an AMD run so far) plus a short review.

Tested 526a17661 merged onto main a6f5f7a74 on Windows 11 Home 26200, RTX 4070 SUPER (driver 621.24, wave32), Rust 1.98, DXC 1.8.2502.11: pass.

  • cargo test --workspace -- --test-threads=4: 679 passed, 0 failed, 41 ignored (main: 676 / 0 / 41). SKIPPED: only the 2 no wave64 tests.
  • carrier_holds_the_template, a_thread_running_during_install_gets_the_template and install_while_threads_exit ran and passed; no TLS crash.
  • Not run: smoke.ps1 (no retail title on this machine), Wine.

Review – letting the loader seed every block from the carrier's template looks right; the template bytes sit outside the carrier's four DIR64 relocations (tls.rs:163-165), and the template_len == 0 branch avoids from_raw_parts(null).

  1. tls.rs:11-15 (module docs) still say existing threads are filled "right after the carrier is loaded (via their TEB)". The loader now does that from the template; could the paragraph be updated?
  2. Minor, tls.rs:601-614: each run writes 200 carrier DLLs to %TEMP%\xcl_tls_test_churn_<pid>\ and loads them into the shared --lib process, so they can't be deleted and pile up across runs. Fewer installs, or a fixed directory cleared at the start, would avoid that.

AI-assisted review (Claude Code, Claude Opus 5.5).
Discord: bigpeppa.

<!-- greyfinch-sync:ivall/xcl:comment:7118966784 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/431#issuecomment-7118966784). Originally posted by [QemmHD](https://github.com/QemmHD) on 2026-11-24T01:18:15Z. --- NVIDIA run (only an AMD run so far) plus a short review. **Tested** `526a17661` merged onto main `a6f5f7a74` on Windows 11 Home 26200, RTX 4070 SUPER (driver 621.24, wave32), Rust 1.98, DXC 1.8.2502.11: **pass**. - `cargo test --workspace -- --test-threads=4`: 679 passed, 0 failed, 41 ignored (main: 676 / 0 / 41). SKIPPED: only the 2 `no wave64` tests. - `carrier_holds_the_template`, `a_thread_running_during_install_gets_the_template` and `install_while_threads_exit` ran and passed; no TLS crash. - Not run: smoke.ps1 (no retail title on this machine), Wine. **Review** – letting the loader seed every block from the carrier's template looks right; the template bytes sit outside the carrier's four DIR64 relocations (`tls.rs:163-165`), and the `template_len == 0` branch avoids `from_raw_parts(null)`. 1. `tls.rs:11-15` (module docs) still say existing threads are filled "right after the carrier is loaded (via their TEB)". The loader now does that from the template; could the paragraph be updated? 2. Minor, `tls.rs:601-614`: each run writes 200 carrier DLLs to `%TEMP%\xcl_tls_test_churn_<pid>\` and loads them into the shared `--lib` process, so they can't be deleted and pile up across runs. Fewer installs, or a fixed directory cleared at the start, would avoid that. AI-assisted review (Claude Code, Claude Opus 5.5). Discord: bigpeppa.
Kalmarv commented 2026-11-24 07:05:27 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-24T02:02:27Z.


Thanks, @QemmHD. Both points were right, and both are fixed in da285ce (squashed into the PR's commit).

  1. The module docs (tls.rs:7-16) now say what the code does: the carrier's template is the game's, and ntdll starts every thread's block from it, both the threads running when the carrier loads and later ones. on_thread_attach copies it again for new threads.
  2. install_while_threads_exit now uses one folder, %TEMP%\xcl_tls_test_churn. It clears earlier runs' carriers at the start with the existing cleanup_cache, and the file names keep the process id, so runs at the same time don't clash. After each of 3 runs here the folder held 200 files, all from that run.

🤖 Claude Opus 5.5

<!-- greyfinch-sync:ivall/xcl:comment:7119695522 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/431#issuecomment-7119695522). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-24T02:02:27Z. --- Thanks, @QemmHD. Both points were right, and both are fixed in `da285ce` (squashed into the PR's commit). 1. The module docs (`tls.rs:7-16`) now say what the code does: the carrier's template is the game's, and ntdll starts every thread's block from it, both the threads running when the carrier loads and later ones. `on_thread_attach` copies it again for new threads. 2. `install_while_threads_exit` now uses one folder, `%TEMP%\xcl_tls_test_churn`. It clears earlier runs' carriers at the start with the existing `cleanup_cache`, and the file names keep the process id, so runs at the same time don't clash. After each of 3 runs here the folder held 200 files, all from that run. 🤖 Claude Opus 5.5
srcamarda commented 2026-11-24 07:05:31 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by srcamarda on 2026-11-24T02:16:52Z.


Regression run on a retail title, as asked under Regression run.

Tested

  • AMD Radeon RX 7800 XT (RDNA3), driver 32.0.32029.2010; Ryzen 5 5600G, 32 GB; Windows 11 Pro 26300; release builds
  • scripts/smoke.ps1 -Seconds 90, no input (the title stays on its account screen at 30 fps). Each binary was built from a clean checkout of its commit and run twice; the first run of each has a cold translation cache. Blocks below are from the second run.
  • main 508a0c7: 2343 / 2361 frames, peak 15764 / 15674 MB. This PR (da285ce): 2322 / 2359 frames, peak 16486 / 16414 MB. No crash or device removal in any run.
  • The changed path runs in this title: its log shows a TLS install for three images with other threads alive, e.g. TLS: game_scarlett_master.exe: template 5248 B, block 5248 B, index 18, threads initialized: 3 (also xboxbvhbuilder.dll and libhttpclient.gdk.dll), and the title then runs normally.
  • This head is based on 9ab7d76, 60 commits behind main. Its peak commit is ~0.7 GB above main's here, most likely from the base: main's memory changes since then aren't in it. #443 and #470, both close to main, match main. A rebase would settle it.

Regression run

main:

xcl-smoke v1
commit: 508a0c74d7c0625d6d2de8d24494e69dc2e1926f
gpu: AMD Radeon RX 7800 XT
title: RetailGame_Dump
seconds: 90
exit: 0x0
frames shown: 2361 (PresentX 2361)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15674 MB

this PR's head:

xcl-smoke v1
commit: da285ce79cbfc485e2a284da694c0d6dd41801b5
gpu: SudoMaker Virtual Display Adapter
title: RetailGame_Dump
seconds: 90
exit: 0x0
frames shown: 2359 (PresentX 2360)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16414 MB

gpu: in this PR's block names a virtual display adapter: the head predates 97dc49c, which reads the adapter from report.json. XCL ran on the RX 7800 XT in every run.

Not tested

  • Anything past the account screen.
  • The whole test suite at this head (only the title runs).

AI use

  • Claude Code with Claude Opus 5.5 built both commits, ran the smoke runs and wrote this report; the runs are from my machine.
<!-- greyfinch-sync:ivall/xcl:comment:7119961537 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/431#issuecomment-7119961537). Originally posted by [srcamarda](https://github.com/srcamarda) on 2026-11-24T02:16:52Z. --- Regression run on a retail title, as asked under **Regression run**. **Tested** - AMD Radeon RX 7800 XT (RDNA3), driver 32.0.32029.2010; Ryzen 5 5600G, 32 GB; Windows 11 Pro 26300; release builds - `scripts/smoke.ps1 -Seconds 90`, no input (the title stays on its account screen at 30 fps). Each binary was built from a clean checkout of its commit and run twice; the first run of each has a cold translation cache. Blocks below are from the second run. - `main` `508a0c7`: 2343 / 2361 frames, peak 15764 / 15674 MB. This PR (`da285ce`): 2322 / 2359 frames, peak 16486 / 16414 MB. No crash or device removal in any run. - The changed path runs in this title: its log shows a TLS install for three images with other threads alive, e.g. `TLS: game_scarlett_master.exe: template 5248 B, block 5248 B, index 18, threads initialized: 3` (also `xboxbvhbuilder.dll` and `libhttpclient.gdk.dll`), and the title then runs normally. - This head is based on `9ab7d76`, 60 commits behind `main`. Its peak commit is ~0.7 GB above `main`'s here, most likely from the base: `main`'s memory changes since then aren't in it. #443 and #470, both close to `main`, match `main`. A rebase would settle it. **Regression run** `main`: ``` xcl-smoke v1 commit: 508a0c74d7c0625d6d2de8d24494e69dc2e1926f gpu: AMD Radeon RX 7800 XT title: RetailGame_Dump seconds: 90 exit: 0x0 frames shown: 2361 (PresentX 2361) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15674 MB ``` this PR's head: ``` xcl-smoke v1 commit: da285ce79cbfc485e2a284da694c0d6dd41801b5 gpu: SudoMaker Virtual Display Adapter title: RetailGame_Dump seconds: 90 exit: 0x0 frames shown: 2359 (PresentX 2360) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16414 MB ``` `gpu:` in this PR's block names a virtual display adapter: the head predates 97dc49c, which reads the adapter from `report.json`. XCL ran on the RX 7800 XT in every run. **Not tested** - Anything past the account screen. - The whole test suite at this head (only the title runs). **AI use** - Claude Code with Claude Opus 5.5 built both commits, ran the smoke runs and wrote this report; the runs are from my machine.
raylitebull commented 2026-11-24 11:05:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-24T10:40:33Z.


Code/CI review only (not independently runtime-tested by me): clean merge with both checks green (Build and test + PR description). Cleanly fixes the intermittent tls::install crash by leaving other threads' TLS blocks to the loader. Recommend merging, @ivall.

<!-- greyfinch-sync:ivall/xcl:comment:7129095862 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/431#issuecomment-7129095862). Originally posted by [raylitebull](https://github.com/raylitebull) on 2026-11-24T10:40:33Z. --- Code/CI review only (not independently runtime-tested by me): clean merge with both checks green (`Build and test` + `PR description`). Cleanly fixes the intermittent `tls::install` crash by leaving other threads' TLS blocks to the loader. Recommend merging, @ivall.
DavidM1911 commented 2026-11-25 15:07:50 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T14:29:03Z.


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:7165348627 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/431#issuecomment-7165348627). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T14:29:03Z. --- 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 20:42:01 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-29T20:42:01Z.


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:7262288038 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/431#issuecomment-7262288038). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-29T20:42:01Z. --- 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 07:40:05 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:40:05Z.


merge-check
base: 7d86c5d2b7
head: 940f7cb734
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2899 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff. Still needed: main still fills existing threads by walking them (fill_existing_threads, tls.rs ~553-602, called from install ~653), and the only TLS change since this base (39ea43e9) is in take_slot_zero. Findings: (1) crates/xcl/tests/tls_slot_zero.rs, added after this PR, calls install with 16 parked threads and asserts their slot-0 template (~122, ~176); with this change those blocks come from ntdll instead of the walk, so that test was the one to watch: both its tests (take_slot_zero_survives_concurrent_thread_exit_and_termination, reused_teb_after_terminate_thread_still_exchanges_slots) pass in the run above. (2) a_thread_running_during_install_gets_the_template can also pass without the fix if the thread's attach runs after LoadLibrary (on_thread_attach then fills it), so it's weaker than described, though it won't fail by mistake. (3) install_while_threads_exit leaves 200 carriers loaded for the rest of the lib test process. Fine: the carrier layout change (raw size of .data, template copied at OFF_TEMPLATE after the index sentinel), build_carrier_dll_with kept as a wrapper, the PE accessors the new test uses still exist on main, and nothing outside tls.rs reads the removed log line. #196 overlaps, as the author notes.
performance: 60 s smoke of a retail title, main 7d86c5d2 vs this merge (d83eb0b4): 1663 -> 1670 frames shown (100 %; last presents per 2 s: 60 60 60), peak commit 17153 -> 17818 MB, 0 device removals, 0 crashes.
verdict: safe to merge (the new carrier test can also pass without the fix if the thread's attach runs after LoadLibrary, so it's weaker than described)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7304336064 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/431#issuecomment-7304336064). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T07:40:05Z. --- merge-check base: 7d86c5d2b7845695031eeea1327aa81b6c439323 head: 940f7cb7341c80a4bf493163962d1c0c2a0ee506 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2899 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none review: read the whole diff. Still needed: main still fills existing threads by walking them (`fill_existing_threads`, tls.rs ~553-602, called from `install` ~653), and the only TLS change since this base (39ea43e9) is in `take_slot_zero`. Findings: (1) `crates/xcl/tests/tls_slot_zero.rs`, added after this PR, calls `install` with 16 parked threads and asserts their slot-0 template (~122, ~176); with this change those blocks come from ntdll instead of the walk, so that test was the one to watch: both its tests (`take_slot_zero_survives_concurrent_thread_exit_and_termination`, `reused_teb_after_terminate_thread_still_exchanges_slots`) pass in the run above. (2) `a_thread_running_during_install_gets_the_template` can also pass without the fix if the thread's attach runs after `LoadLibrary` (on_thread_attach then fills it), so it's weaker than described, though it won't fail by mistake. (3) `install_while_threads_exit` leaves 200 carriers loaded for the rest of the lib test process. Fine: the carrier layout change (raw size of `.data`, template copied at `OFF_TEMPLATE` after the index sentinel), `build_carrier_dll_with` kept as a wrapper, the PE accessors the new test uses still exist on main, and nothing outside tls.rs reads the removed log line. #196 overlaps, as the author notes. performance: 60 s smoke of a retail title, main 7d86c5d2 vs this merge (d83eb0b4): 1663 -> 1670 frames shown (100 %; last presents per 2 s: 60 60 60), peak commit 17153 -> 17818 MB, 0 device removals, 0 crashes. verdict: safe to merge (the new carrier test can also pass without the fix if the thread's attach runs after LoadLibrary, so it's weaker than described) hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5 AI-written and posted by Foniass without a human check of each point.
Decodere commented 2026-12-02 09:55:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Decodere on 2026-12-02T09:55:26Z.


merge-check
base: 1c8b551475
head: 940f7cb734
merge: clean (trial-merge commit 065990dd2a2baf7ffa6b2f29be4e09b91bb73fbe, git diff --check clean)
build: cargo build --workspace ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture (43 targets): 2912 passed, 0 failed, 51 ignored (+3 new tests vs main baseline). Targeted tls::tests passed 7/7 (1 pre-existing ignored carrier_variants_probe), including all 3 new tests (carrier_holds_the_template, a_thread_running_during_install_gets_the_template, install_while_threads_exit) with 0 skips, and tests/tls_slot_zero.rs passed 2/2. 28 SKIPPED emissions (host environment only: 22 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 2 no heap windows, 1 cannot disable the driver cache (Windows Developer Mode required)).
review: Read the full merged diff (+88/-69 in crates/xcl/src/tls.rs). Embeds the image's TLS template bytes directly into the synthesized carrier DLL's .data section via build_carrier_dll_holding (sizing SizeOfRawData and SizeOfInitializedData to data_raw = (OFF_TEMPLATE + template.len()).next_multiple_of(FILE_ALIGN) while keeping virtual .data size at OFF_TEMPLATE + template_size), so ntdll initializes every existing and future thread's TLS block under the loader lock during LoadLibraryW. Removes the racy fill_existing_threads Toolhelp/TEB walk that dereferenced TEBs/TLS blocks of concurrently exiting threads without loader synchronization, while preserving on_thread_attach and template_len == 0 handling. The three new unit tests verify carrier PE template layout, live-thread initialization on install, and 200 installs under 8-thread churn. No scope creep or UB.
performance: not applicable (Tier 1 — PE loader / TLS carrier initialization only, runs once per loaded image; no hot runtime or GPU path changed).
verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 4060 8 GB (driver 621.40), Intel Core i5-11400F, 32 GB RAM, Windows 11 Build 26200, Rust 1.100.1 MSVC, DXC 1.9.2602.17 / Antigravity (Gemini 4 Neon)

<!-- greyfinch-sync:ivall/xcl:comment:7341690579 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/431#issuecomment-7341690579). Originally posted by [Decodere](https://github.com/Decodere) on 2026-12-02T09:55:26Z. --- merge-check base: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f head: 940f7cb7341c80a4bf493163962d1c0c2a0ee506 merge: clean (trial-merge commit 065990dd2a2baf7ffa6b2f29be4e09b91bb73fbe, git diff --check clean) build: cargo build --workspace ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture (43 targets): 2912 passed, 0 failed, 51 ignored (+3 new tests vs main baseline). Targeted tls::tests passed 7/7 (1 pre-existing ignored carrier_variants_probe), including all 3 new tests (carrier_holds_the_template, a_thread_running_during_install_gets_the_template, install_while_threads_exit) with 0 skips, and tests/tls_slot_zero.rs passed 2/2. 28 SKIPPED emissions (host environment only: 22 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 2 no heap windows, 1 cannot disable the driver cache (Windows Developer Mode required)). review: Read the full merged diff (+88/-69 in crates/xcl/src/tls.rs). Embeds the image's TLS template bytes directly into the synthesized carrier DLL's `.data` section via `build_carrier_dll_holding` (sizing `SizeOfRawData` and `SizeOfInitializedData` to `data_raw = (OFF_TEMPLATE + template.len()).next_multiple_of(FILE_ALIGN)` while keeping virtual `.data` size at `OFF_TEMPLATE + template_size`), so `ntdll` initializes every existing and future thread's TLS block under the loader lock during `LoadLibraryW`. Removes the racy `fill_existing_threads` Toolhelp/TEB walk that dereferenced TEBs/TLS blocks of concurrently exiting threads without loader synchronization, while preserving `on_thread_attach` and `template_len == 0` handling. The three new unit tests verify carrier PE template layout, live-thread initialization on install, and 200 installs under 8-thread churn. No scope creep or UB. performance: not applicable (Tier 1 — PE loader / TLS carrier initialization only, runs once per loaded image; no hot runtime or GPU path changed). verdict: safe to merge hardware / tool and model: NVIDIA GeForce RTX 4060 8 GB (driver 621.40), Intel Core i5-11400F, 32 GB RAM, Windows 11 Build 26200, Rust 1.100.1 MSVC, DXC 1.9.2602.17 / Antigravity (Gemini 4 Neon)
Kalmarv commented 2026-12-02 20:19:58 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T20:19:58Z.


Rebased onto main (5ad98adbc) as 30378b241 to resolve the crates/xcl/src/tls.rs conflict with #1403 (ce99e53ac, MAX_CARRIER_TEMPLATE clamp), preserving the [16, MAX_CARRIER_TEMPLATE] clamp inside build_carrier_dll_holding and keeping the TLS behavior and tests unchanged.

Still needed: main still walks existing threads' TEBs in fill_existing_threads, which races with thread exit in tls::install.

Verification at 30378b241 (RTX 5070 Ti, driver 610.74, rustc 1.99.0, DXC 1.9.2609.5):

  • cargo build --release -p xcl: clean, 39 warnings (0 new vs main 5ad98adbc).
  • scripts/test.ps1: 3008 passed, 0 failed, 52 ignored, 24 SKIPPED GPU tests (22 no wave64, 2 no heap windows); tls::tests 8/8 passed (1 ignored) and tests/tls_slot_zero.rs 2/2 passed.
  • title run: 60 s retail title smoke (title ea3b5e4d), 1511 frames shown (PresentX 1511), presents per 2 s 61 61 60, peak commit 14632 MB, 0 device removals, 0 crashes (exit 0x0; main 5ad98adbc baseline: 1460 frames, peak commit 15067 MB).
  • scripts/pr_check.py --local: clean (description ok).

Updated the PR description with the new head SHA and fresh xcl-smoke blocks. Ready for re-check on 30378b241.

<!-- greyfinch-sync:ivall/xcl:comment:7357571297 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/431#issuecomment-7357571297). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-12-02T20:19:58Z. --- Rebased onto `main` (`5ad98adbc`) as `30378b241` to resolve the `crates/xcl/src/tls.rs` conflict with #1403 (`ce99e53ac`, `MAX_CARRIER_TEMPLATE` clamp), preserving the `[16, MAX_CARRIER_TEMPLATE]` clamp inside `build_carrier_dll_holding` and keeping the TLS behavior and tests unchanged. Still needed: `main` still walks existing threads' TEBs in `fill_existing_threads`, which races with thread exit in `tls::install`. Verification at `30378b241` (RTX 5070 Ti, driver 610.74, `rustc 1.99.0`, DXC `1.9.2609.5`): - `cargo build --release -p xcl`: clean, 39 warnings (0 new vs `main` `5ad98adbc`). - `scripts/test.ps1`: **3008 passed, 0 failed, 52 ignored**, 24 SKIPPED GPU tests (22 no wave64, 2 no heap windows); `tls::tests` 8/8 passed (1 ignored) and `tests/tls_slot_zero.rs` 2/2 passed. - title run: 60 s retail title smoke (title ea3b5e4d), 1511 frames shown (PresentX 1511), presents per 2 s 61 61 60, peak commit 14632 MB, 0 device removals, 0 crashes (exit 0x0; `main` `5ad98adbc` baseline: 1460 frames, peak commit 15067 MB). - `scripts/pr_check.py --local`: clean (`description ok`). Updated the PR description with the new head SHA and fresh `xcl-smoke` blocks. Ready for re-check on `30378b241`.
fromthemoonx commented 2026-12-03 09:44:10 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-03T09:44:10Z.


merge-check
base: 16c2fd082a
head: 30378b241e
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3015 passed, 0 failed, 56 ignored in runs 2 and 3 (base: 3012 passed, 0 failed, 56 ignored, counted on 395405e4; only docs and scripts changed since); SKIPPED: 25, the same as base (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps); failing: none in runs 2 and 3. In run 1 the lib binary ended with 0xc0000005 during a thread dump in the GPU tests, before any tls:: test had run. That is the pattern of #3586, which main has too (#3743 fixes it). After that I ran the whole lib binary in alternation: main 4 of 4 and this PR 3 of 3 without a crash.
review: read the whole diff (1 file, +89 -69). No blocking finding.

  1. By reading, main's walk is unsafe as described: fill_existing_threads reads a TEB and writes a TLS block that only an open thread handle "protects", and a handle keeps neither alive. The PR removes the walk and lets the loader fill the blocks.
  2. I could not make main crash here. Main's code with this PR's install_while_threads_exit passed 20 of 20 runs, and 10 of 10 with a 1 ms sleep between the TEB query and its use. In that widened build the walk reached exactly 10 threads in every install, so on this machine (Windows 11 26300) the short threads were probably gone before it could open them. So my runs do not show the crash being fixed; that evidence is the author's and MesshM's.
  3. The tests do check the new path. With the carrier's template left empty in the merged tree, a_thread_running_during_install_gets_the_template, install_without_an_index_variable and windows_loads_carrier_and_allocates_full_block_for_all_threads fail. As submitted, install_while_threads_exit passed 30 of 30 and tls::tests 30 of 30 at 8 threads. I agree with Foniass above that the first of these should wait until its thread is running: it caught the empty template in my one run, but it depends on timing.
  4. The clamp of #1403 is kept: the template is cut to MAX_CARRIER_TEMPLATE before the size is computed, so the copy cannot run past the file buffer.
  5. Low: the carrier file now holds the title's TLS template bytes, where it held zeros before. It stays in the folder the carriers were already written to.
  6. Not tested: a retail title (none on this machine), AMD.
    performance: an install no longer takes a system-wide thread snapshot and opens each thread. The churn test's 200 installs took 11 s on main in one run, and 30 runs of it took 22 s with this PR. This happens at image load, not per frame.
    verdict: safe to merge
    hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)
<!-- greyfinch-sync:ivall/xcl:comment:7374145918 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/431#issuecomment-7374145918). Originally posted by [fromthemoonx](https://github.com/fromthemoonx) on 2026-12-03T09:44:10Z. --- merge-check base: 16c2fd082ae2e96967a2ab553bc2e1032e491f70 head: 30378b241ece56458ce639e1e3a8bc33ffa03d1a merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3015 passed, 0 failed, 56 ignored in runs 2 and 3 (base: 3012 passed, 0 failed, 56 ignored, counted on 395405e4; only docs and scripts changed since); SKIPPED: 25, the same as base (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps); failing: none in runs 2 and 3. In run 1 the lib binary ended with 0xc0000005 during a thread dump in the GPU tests, before any `tls::` test had run. That is the pattern of #3586, which main has too (#3743 fixes it). After that I ran the whole lib binary in alternation: main 4 of 4 and this PR 3 of 3 without a crash. review: read the whole diff (1 file, +89 -69). No blocking finding. 1) By reading, main's walk is unsafe as described: `fill_existing_threads` reads a TEB and writes a TLS block that only an open thread handle "protects", and a handle keeps neither alive. The PR removes the walk and lets the loader fill the blocks. 2) I could not make main crash here. Main's code with this PR's `install_while_threads_exit` passed 20 of 20 runs, and 10 of 10 with a 1 ms sleep between the TEB query and its use. In that widened build the walk reached exactly 10 threads in every install, so on this machine (Windows 11 26300) the short threads were probably gone before it could open them. So my runs do not show the crash being fixed; that evidence is the author's and MesshM's. 3) The tests do check the new path. With the carrier's template left empty in the merged tree, `a_thread_running_during_install_gets_the_template`, `install_without_an_index_variable` and `windows_loads_carrier_and_allocates_full_block_for_all_threads` fail. As submitted, `install_while_threads_exit` passed 30 of 30 and `tls::tests` 30 of 30 at 8 threads. I agree with Foniass above that the first of these should wait until its thread is running: it caught the empty template in my one run, but it depends on timing. 4) The clamp of #1403 is kept: the template is cut to `MAX_CARRIER_TEMPLATE` before the size is computed, so the copy cannot run past the file buffer. 5) Low: the carrier file now holds the title's TLS template bytes, where it held zeros before. It stays in the folder the carriers were already written to. 6) Not tested: a retail title (none on this machine), AMD. performance: an install no longer takes a system-wide thread snapshot and opens each thread. The churn test's 200 installs took 11 s on main in one run, and 30 runs of it took 22 s with this PR. This happens at image load, not per frame. verdict: safe to merge hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)
Foniass commented 2026-12-03 10:20:02 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T10:20:02Z.


merge-check
base: 16c2fd082a
head: 30378b241e
merge: clean
build: ok
tests: 3015 passed, 0 failed, 56 ignored; 28 skipped, the same as on main
review: 1 medium, 2 nits (below)
performance: 60 s smoke run: 1683 → 1655 frames (98 % of main), peak commit 18505 → 17668 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 228 s there, 0 device removals, 0 crashes, 3.9 presents/s; run with XCL_SKIP_CS=95cc13288a27a96e (the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590)
verdict: safe to merge: no blocking finding (the points below are medium or nits), the suite passes and the smoke run is clean
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5


In short: Lets ntdll fill every thread's TLS block from a carrier DLL that now carries the image's template, and drops the racy walk over other threads' TEBs in install. Since my last merge-check the only change is the rebase onto #1403, which keeps its template clamp; the TLS logic and tests are the same. Nothing blocks.

Medium

  1. The running-thread test can pass without the code it checks. Still open from my last merge-check. a_thread_running_during_install_gets_the_template (tls.rs ~755) spawns the thread and calls install without waiting for the thread to start. If it starts after LoadLibrary, on_thread_attach fills its block and the test passes whatever ntdll did. It also passes on main, where the walk fills the block. Have the thread signal that it is running before install is called.

Nit

  1. The churn test leaves 200 carriers loaded. Still open from my last merge-check. install_while_threads_exit (tls.rs ~772) loads 200 carrier DLLs, each with its own TLS slot and loader entry, and they stay loaded for the rest of the lib test process. Fewer installs would do.
  2. Conflicts with open #196. #196 also changes build_carrier_dll_with and how install builds the carrier, and a test merge of the two heads conflicts in tls.rs. Whichever lands second has to rebase.
Checked and fine
  • The rebase keeps #1403's clamp: the template is cut to MAX_CARRIER_TEMPLATE, the size is clamped to [16, MAX_CARRIER_TEMPLATE], and the raw size of .data comes from the cut template
  • The template bytes sit after the index sentinel and outside the carrier's four DIR64 relocations; a template_len of 0 takes the old builder and never calls from_raw_parts on a null pointer
  • on_thread_attach and take_slot_zero are unchanged, and nothing outside tls.rs reads the removed "threads initialized" log line
How this was tested
  • Merged onto main 16c2fd08, then cargo build --workspace and cargo test --workspace --no-fail-fast -- --test-threads=4.
  • The skipped GPU tests are those this card can't run (no wave64 on NVIDIA, no D3D12 debug layer, and similar).
  • scripts/smoke.ps1: 60 s of a retail title on main 16c2fd08 and on this merge; presents per 2 s at the end: 60 60 60.
  • Title run: the release build of this merge launched the retail title with XCL_RUN_SECONDS=300 and scripted A presses counted from the first frame (XCL_PRESS_BASE=frame, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7375080200 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/431#issuecomment-7375080200). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-03T10:20:02Z. --- merge-check base: 16c2fd082ae2e96967a2ab553bc2e1032e491f70 head: 30378b241ece56458ce639e1e3a8bc33ffa03d1a merge: clean build: ok tests: 3015 passed, 0 failed, 56 ignored; 28 skipped, the same as on main review: 1 medium, 2 nits (below) performance: 60 s smoke run: 1683 → 1655 frames (98 % of main), peak commit 18505 → 17668 MB, no device removal, no crash title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 228 s there, 0 device removals, 0 crashes, 3.9 presents/s; run with `XCL_SKIP_CS=95cc13288a27a96e` (the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590) verdict: safe to merge: no blocking finding (the points below are medium or nits), the suite passes and the smoke run is clean hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5 --- **In short:** Lets ntdll fill every thread's TLS block from a carrier DLL that now carries the image's template, and drops the racy walk over other threads' TEBs in install. Since my last merge-check the only change is the rebase onto #1403, which keeps its template clamp; the TLS logic and tests are the same. Nothing blocks. #### Medium 1. **The running-thread test can pass without the code it checks.** Still open from my last merge-check. a_thread_running_during_install_gets_the_template (tls.rs ~755) spawns the thread and calls install without waiting for the thread to start. If it starts after LoadLibrary, on_thread_attach fills its block and the test passes whatever ntdll did. It also passes on main, where the walk fills the block. Have the thread signal that it is running before install is called. #### Nit 2. **The churn test leaves 200 carriers loaded.** Still open from my last merge-check. install_while_threads_exit (tls.rs ~772) loads 200 carrier DLLs, each with its own TLS slot and loader entry, and they stay loaded for the rest of the lib test process. Fewer installs would do. 3. **Conflicts with open #196.** #196 also changes build_carrier_dll_with and how install builds the carrier, and a test merge of the two heads conflicts in tls.rs. Whichever lands second has to rebase. <details><summary>Checked and fine</summary> - The rebase keeps #1403's clamp: the template is cut to MAX_CARRIER_TEMPLATE, the size is clamped to [16, MAX_CARRIER_TEMPLATE], and the raw size of .data comes from the cut template - The template bytes sit after the index sentinel and outside the carrier's four DIR64 relocations; a template_len of 0 takes the old builder and never calls from_raw_parts on a null pointer - on_thread_attach and take_slot_zero are unchanged, and nothing outside tls.rs reads the removed "threads initialized" log line </details> <details><summary>How this was tested</summary> - Merged onto main `16c2fd08`, then `cargo build --workspace` and `cargo test --workspace --no-fail-fast -- --test-threads=4`. - The skipped GPU tests are those this card can't run (no wave64 on NVIDIA, no D3D12 debug layer, and similar). - `scripts/smoke.ps1`: 60 s of a retail title on main `16c2fd08` and on this merge; presents per 2 s at the end: 60 60 60. - Title run: the release build of this merge launched the retail title with `XCL_RUN_SECONDS=300` and scripted A presses counted from the first frame (`XCL_PRESS_BASE=frame`, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
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/431:upstream-pr/431'
git switch 'upstream-pr/431'

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