TLS: harden take_slot_zero against TEB UAF and stale MOVED entries #1074

Merged
real-alponzo merged 1 commit from upstream-pr/1083 into main 2026-11-30 03:14:42 +00:00
real-alponzo commented 2026-11-24 11:24:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by real-alponzo on 2026-11-24T11:24:15Z.


Hardens tls::take_slot_zero and MOVED tracking against two concurrency bugs from #106:

  1. TEB / ThreadLocalStoragePointer UAF during take_slot_zero: previously thread_tebs() closed every thread handle immediately after reading ThreadBasicInformation, then take_slot_zero dereferenced the raw TEBs and wrote *arr = block after Sleep(20) without verifying the thread was still alive. Publishing XCL_SLOT only after the snapshot also left a window where concurrently starting or exiting threads bypassed MOVED serialization.
  2. Stale MOVED entries after TerminateThread: MOVED stored only raw TEB addresses (Vec<usize>). A thread killed without DLL_THREAD_DETACH left its TEB address in MOVED permanently, causing exchange_for_new_thread to skip swapping slot 0 and slot k when Windows later recycled that TEB address for a new thread.

Part of #106. (Disjoint from open TLS PRs #196, #431, and #464: only touches MOVED, take_slot_zero, exchange_for_new_thread, and on_thread_detach, and places new tests in a separate integration test file.)

What is in it

  • crates/xcl/src/tls.rs:
    • Replace MOVED: Mutex<Vec<usize>> with MovedTeb { teb, tid, handle: ThreadHandle } (Drop closes the handle). Keeping the handle open prevents Windows from reusing tid while tracked and lets exchange_for_new_thread and on_thread_detach prune threads that died without DLL_THREAD_DETACH via WaitForSingleObject(handle, 0) == WAIT_TIMEOUT.
    • Publish XCL_SLOT.store(k, Ordering::SeqCst) under MOVED.lock() before snapshotting peer threads so concurrent attach/detach serializes on MOVED.
    • Keep peer thread handles open (THREAD_QUERY_INFORMATION | THREAD_SUSPEND_RESUME | THREAD_SYNCHRONIZE) across both phases of take_slot_zero, suspending each peer individually with a RAII SuspendGuard across only raw syscalls (WaitForSingleObject, NtQueryInformationThread, ReadProcessMemory) and pointer updates (no heap allocations or locks while suspended). Skip threads mid-LdrpAllocateTls (arr == null, arr[0] == 0, or arr[k] == 0) so their upcoming on_thread_attach performs the swap cleanly.
    • Handle the current thread directly without adding it to MOVED.
  • crates/xcl/tests/tls_slot_zero.rs:
    • Process-isolated integration tests with a .CRT$XLY callback forwarding real DLL_THREAD_ATTACH / DLL_THREAD_DETACH events:
      • reused_teb_after_terminate_thread_still_exchanges_slots — verified to fail deterministically on unmodified main (47efa2e) on the first recycled TEB (host TLS corrupted on new thread), and passes with this fix.
      • take_slot_zero_survives_concurrent_thread_exit_and_termination — exercises take_slot_zero under concurrent thread spawn/exit churn and TerminateThread, validating both survivor TLS integrity and HeapValidate.

Regression run

Baseline (main, warm shader/PSO cache):

xcl-smoke v1
commit: 09940bb87fa11bc394fd9e5de570c2b7cfd16323
gpu: AMD Radeon RX 6800
title: YouKnowWho
seconds: 60
exit: 0x0
frames shown: 405 (PresentX 405)
presents per 2 s (last 3): 11 12 11
device removals: 0
crashes: 0
peak commit: 15870 MB

This PR (fix/tls-take-slot-zero-safety, warm shader/PSO cache):

xcl-smoke v1
commit: 39ea43e9d95d706aaa6ec679c7544d63c822a566
gpu: AMD Radeon RX 6800
title: YouKnowWho
seconds: 60
exit: 0x0
frames shown: 489 (PresentX 489)
presents per 2 s (last 3): 17 16 17
device removals: 0
crashes: 0
peak commit: 15868 MB

Tested

Hardware: Windows 11 Pro for Workstations (Build 26300), Intel Core i9-9900K, 32 GB RAM, AMD Radeon RX 6800 (16337 MiB VRAM, Driver 32.0.21045.29003), rustc 1.100.0 (0ef1bc386 2026-11-09).

  • cargo test -p xcl --test tls_slot_zero (5 consecutive runs): 2 passed; 0 failed; 0 ignored; 0 skipped each run (on unmodified 47efa2e, reused_teb_after_terminate_thread_still_exchanges_slots failed with host TLS was corrupted on new thread (iter=234, reused=1)).
  • cargo test -p xcl --lib tls::: 4 passed; 0 failed; 1 ignored; 0 skipped.
  • cargo test -p xcl --test e2e: 3 passed; 0 failed; 0 ignored; 0 skipped.
  • XCL_REQUIRE_GPU=wave64,mesh cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 740 passed; 3 failed; 41 ignored; 0 skipped. All 3 failures are the pre-existing RDNA2 placed_title_textures_share_vram_and_preserve_pixels + 2 VRAM_TEST_LOCK PoisonError cascades on unmodified main (tracked in #470).
  • .\scripts\smoke.ps1 -Game '<game folder>\YouKnowWho' on 39ea43e9d95d706aaa6ec679c7544d63c822a566 (see Regression run above).

Not tested

  • MinGW / gnu target builds (MSVC toolchain only).
  • Non-AMD GPUs and Linux / Wine.

AI use

Antigravity (Gemini 4 Neon) audited crates/xcl/src/tls.rs, wrote the fix and process-isolated regression tests, and ran the local test suite and smoke runs.

<!-- greyfinch-sync:ivall/xcl:issue:5471209021 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1083). Originally posted by [real-alponzo](https://github.com/real-alponzo) on 2026-11-24T11:24:15Z. --- Hardens `tls::take_slot_zero` and `MOVED` tracking against two concurrency bugs from #106: 1. **TEB / `ThreadLocalStoragePointer` UAF during `take_slot_zero`**: previously `thread_tebs()` closed every thread handle immediately after reading `ThreadBasicInformation`, then `take_slot_zero` dereferenced the raw TEBs and wrote `*arr = block` after `Sleep(20)` without verifying the thread was still alive. Publishing `XCL_SLOT` only after the snapshot also left a window where concurrently starting or exiting threads bypassed `MOVED` serialization. 2. **Stale `MOVED` entries after `TerminateThread`**: `MOVED` stored only raw TEB addresses (`Vec<usize>`). A thread killed without `DLL_THREAD_DETACH` left its TEB address in `MOVED` permanently, causing `exchange_for_new_thread` to skip swapping slot `0` and slot `k` when Windows later recycled that TEB address for a new thread. Part of #106. (Disjoint from open TLS PRs #196, #431, and #464: only touches `MOVED`, `take_slot_zero`, `exchange_for_new_thread`, and `on_thread_detach`, and places new tests in a separate integration test file.) **What is in it** - **`crates/xcl/src/tls.rs`**: - Replace `MOVED: Mutex<Vec<usize>>` with `MovedTeb { teb, tid, handle: ThreadHandle }` (`Drop` closes the handle). Keeping the handle open prevents Windows from reusing `tid` while tracked and lets `exchange_for_new_thread` and `on_thread_detach` prune threads that died without `DLL_THREAD_DETACH` via `WaitForSingleObject(handle, 0) == WAIT_TIMEOUT`. - Publish `XCL_SLOT.store(k, Ordering::SeqCst)` under `MOVED.lock()` before snapshotting peer threads so concurrent attach/detach serializes on `MOVED`. - Keep peer thread handles open (`THREAD_QUERY_INFORMATION | THREAD_SUSPEND_RESUME | THREAD_SYNCHRONIZE`) across both phases of `take_slot_zero`, suspending each peer individually with a RAII `SuspendGuard` across only raw syscalls (`WaitForSingleObject`, `NtQueryInformationThread`, `ReadProcessMemory`) and pointer updates (no heap allocations or locks while suspended). Skip threads mid-`LdrpAllocateTls` (`arr == null`, `arr[0] == 0`, or `arr[k] == 0`) so their upcoming `on_thread_attach` performs the swap cleanly. - Handle the current thread directly without adding it to `MOVED`. - **`crates/xcl/tests/tls_slot_zero.rs`**: - Process-isolated integration tests with a `.CRT$XLY` callback forwarding real `DLL_THREAD_ATTACH` / `DLL_THREAD_DETACH` events: - `reused_teb_after_terminate_thread_still_exchanges_slots` — verified to fail deterministically on unmodified `main` (`47efa2e`) on the first recycled TEB (`host TLS corrupted on new thread`), and passes with this fix. - `take_slot_zero_survives_concurrent_thread_exit_and_termination` — exercises `take_slot_zero` under concurrent thread spawn/exit churn and `TerminateThread`, validating both survivor TLS integrity and `HeapValidate`. **Regression run** Baseline (`main`, warm shader/PSO cache): ``` xcl-smoke v1 commit: 09940bb87fa11bc394fd9e5de570c2b7cfd16323 gpu: AMD Radeon RX 6800 title: YouKnowWho seconds: 60 exit: 0x0 frames shown: 405 (PresentX 405) presents per 2 s (last 3): 11 12 11 device removals: 0 crashes: 0 peak commit: 15870 MB ``` This PR (`fix/tls-take-slot-zero-safety`, warm shader/PSO cache): ``` xcl-smoke v1 commit: 39ea43e9d95d706aaa6ec679c7544d63c822a566 gpu: AMD Radeon RX 6800 title: YouKnowWho seconds: 60 exit: 0x0 frames shown: 489 (PresentX 489) presents per 2 s (last 3): 17 16 17 device removals: 0 crashes: 0 peak commit: 15868 MB ``` **Tested** Hardware: Windows 11 Pro for Workstations (Build 26300), Intel Core i9-9900K, 32 GB RAM, AMD Radeon RX 6800 (16337 MiB VRAM, Driver `32.0.21045.29003`), `rustc 1.100.0 (0ef1bc386 2026-11-09)`. - `cargo test -p xcl --test tls_slot_zero` (5 consecutive runs): `2 passed; 0 failed; 0 ignored; 0 skipped` each run (on unmodified `47efa2e`, `reused_teb_after_terminate_thread_still_exchanges_slots` failed with `host TLS was corrupted on new thread (iter=234, reused=1)`). - `cargo test -p xcl --lib tls::`: `4 passed; 0 failed; 1 ignored; 0 skipped`. - `cargo test -p xcl --test e2e`: `3 passed; 0 failed; 0 ignored; 0 skipped`. - `XCL_REQUIRE_GPU=wave64,mesh cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4`: `740 passed; 3 failed; 41 ignored; 0 skipped`. All 3 failures are the pre-existing RDNA2 `placed_title_textures_share_vram_and_preserve_pixels` + 2 `VRAM_TEST_LOCK` `PoisonError` cascades on unmodified `main` (tracked in #470). - `.\scripts\smoke.ps1 -Game '<game folder>\YouKnowWho'` on `39ea43e9d95d706aaa6ec679c7544d63c822a566` (see Regression run above). **Not tested** - MinGW / `gnu` target builds (MSVC toolchain only). - Non-AMD GPUs and Linux / Wine. **AI use** Antigravity (Gemini 4 Neon) audited `crates/xcl/src/tls.rs`, wrote the fix and process-isolated regression tests, and ran the local test suite and smoke runs.
futurepro62 commented 2026-11-24 15:05:52 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T14:25:16Z.


Full-suite run, since this PR has no test report yet. Tested exact head 39ea43e (on its base 47efa2e).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 743 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: reused_teb_after_terminate_thread_still_exchanges_slots, take_slot_zero_survives_concurrent_thread_exit_and_termination.

Not tested

  • AMD, a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:ivall/xcl:comment:7134345475 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1083#issuecomment-7134345475). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T14:25:16Z. --- Full-suite run, since this PR has no test report yet. Tested exact head `39ea43e` (on its base `47efa2e`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4`: **743 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `reused_teb_after_terminate_thread_still_exchanges_slots`, `take_slot_zero_survives_concurrent_thread_exit_and_termination`. **Not tested** - AMD, a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
DavidM1911 commented 2026-11-25 09:08:17 +00:00 (Migrated from github.com)

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


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:7157254602 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1083#issuecomment-7157254602). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T08:36:49Z. --- 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!
upipibi commented 2026-11-25 21:05:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by upipibi on 2026-11-25T20:59:02Z.


NVIDIA test report for 39ea43e (head as is, base 47efa2e), for #1607's "one more test report" list. RTX 3070 8 GB (Ampere, 32-lane waves), driver 616.56, Windows 11, debug, after cargo build --workspace:

  • cargo test --workspace --no-fail-fast -- --test-threads=4 --skip hle::xaudio2: 734 passed, 0 failed, 41 ignored. The end-to-end title tests pass, and so does the new reused_teb_after_terminate_thread_still_exchanges_slots (tests/tls_slot_zero.rs).
  • Skipped hle::xaudio2, because its tests fail or hang on this machine on main too. The PR doesn't touch it.
  • SKIPPED lines: 2, both no wave64 on this card.

AI-assisted (Claude Code, Claude Opus 5.5). Synthetic tests only; no title run.

<!-- greyfinch-sync:ivall/xcl:comment:7174452005 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1083#issuecomment-7174452005). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-25T20:59:02Z. --- NVIDIA test report for `39ea43e` (head as is, base `47efa2e`), for #1607's "one more test report" list. RTX 3070 8 GB (Ampere, 32-lane waves), driver 616.56, Windows 11, debug, after `cargo build --workspace`: - `cargo test --workspace --no-fail-fast -- --test-threads=4 --skip hle::xaudio2`: **734 passed, 0 failed, 41 ignored**. The end-to-end title tests pass, and so does the new `reused_teb_after_terminate_thread_still_exchanges_slots` (`tests/tls_slot_zero.rs`). - Skipped `hle::xaudio2`, because its tests fail or hang on this machine on `main` too. The PR doesn't touch it. - SKIPPED lines: 2, both `no wave64` on this card. AI-assisted (Claude Code, Claude Opus 5.5). Synthetic tests only; no title run.
throny commented 2026-11-29 01:09:20 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-29T01:09:20Z.


merge-check claim
head: 39ea43e9d9

<!-- greyfinch-sync:ivall/xcl:comment:7248596876 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1083#issuecomment-7248596876). Originally posted by [throny](https://github.com/throny) on 2026-11-29T01:09:20Z. --- merge-check claim head: 39ea43e9d95d706aaa6ec679c7544d63c822a566
throny commented 2026-11-29 01:21:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-29T01:21:41Z.


merge-check
base: fa204595
head: 39ea43e9d9
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2610 passed, 0 failed, 49 ignored (27 SKIPPED lines). Base alone at fa204595: 2608 passed, 0 failed, 49 ignored.
review: no blocking finding; all hunks read with care for lifetimes and lock order. main's tls.rs is still the file this PR was written against. The stale entries are the thread blocks of threads ended by TerminateThread, which never run their detach; matching on block address plus thread id and keeping the thread's handle open (so its id cannot be reused) closes that. Other threads' blocks are now read through ReadProcessMemory, so such a read cannot fault; nothing allocates or takes a lock while a thread is suspended; the lock order is the one main has. Worth a follow-up, none worse than main: SuspendThread returns before the thread has really stopped (a GetThreadContext after it would make that certain); the two writes into another thread's TLS array are plain writes; and when suspending a live thread fails, that thread is skipped, which in the second phase would lose the title's block for it, where main would have written anyway (needs a failing suspend, which is rare). Costs: each thread attach and detach now does one wait per tracked entry. One of the new tests relies on Windows reusing a thread block within 2048 spawns, which could be flaky on some system. It will conflict textually with the open #464 on the same file.
performance: negligible (the slot work runs once per title; a short wait per tracked entry at thread attach and detach). No translator source.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).

<!-- greyfinch-sync:ivall/xcl:comment:7248731633 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1083#issuecomment-7248731633). Originally posted by [throny](https://github.com/throny) on 2026-11-29T01:21:41Z. --- merge-check base: fa204595 head: 39ea43e9d95d706aaa6ec679c7544d63c822a566 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2610 passed, 0 failed, 49 ignored (27 SKIPPED lines). Base alone at fa204595: 2608 passed, 0 failed, 49 ignored. review: no blocking finding; all hunks read with care for lifetimes and lock order. main's tls.rs is still the file this PR was written against. The stale entries are the thread blocks of threads ended by TerminateThread, which never run their detach; matching on block address plus thread id and keeping the thread's handle open (so its id cannot be reused) closes that. Other threads' blocks are now read through ReadProcessMemory, so such a read cannot fault; nothing allocates or takes a lock while a thread is suspended; the lock order is the one main has. Worth a follow-up, none worse than main: SuspendThread returns before the thread has really stopped (a GetThreadContext after it would make that certain); the two writes into another thread's TLS array are plain writes; and when suspending a live thread fails, that thread is skipped, which in the second phase would lose the title's block for it, where main would have written anyway (needs a failing suspend, which is rare). Costs: each thread attach and detach now does one wait per tracked entry. One of the new tests relies on Windows reusing a thread block within 2048 spawns, which could be flaky on some system. It will conflict textually with the open #464 on the same file. performance: negligible (the slot work runs once per title; a short wait per tracked entry at thread attach and detach). No translator source. verdict: safe to merge hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).
relativespace2K commented 2026-11-30 02:52:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by relativespace2K on 2026-11-30T02:52:25Z.


merge-check
base: 53e85fb1
head: 39ea43e9d9
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2790 passed, 6 failed, 49 ignored; failing: gpu::dxil::compact_tests::gpu_compact_form_with_micro_blocks_and_literal_table_runs_as_the_plain_form, gpu::recomp::pso::shader_cache_tests::console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk, hle::d3d12x::standin::tests::concurrent_shell_miss_reuses_winner_and_releases_loser_pipeline, ram_budget::tests::windows_takes_a_working_set_maximum_and_lifts_it, and two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (in --test gpu_two_pass_cache_e2e, so 5 failing tests give 6 failures). The same five fail on base 53e85fb1 alone (2788 passed, 6 failed, 49 ignored there), so none comes from this PR; its two new tests in crates/xcl/tests/tls_slot_zero.rs passed, and they run in a child copy of the test binary so _tls_index really starts at 0 and the .CRT$XLY callback sees real attach/detach. 13 SKIPPED lines, all environmental: no D3D12 debug layer / d3d12SDKLayers.dll, no heap windows, no GPU_UPLOAD, per-lane f16/f32 forms refused.
review: no blocking finding; two files, every hunk read. The exchange now holds an open handle per peer, so a TID or TEB cannot be recycled under a stale MOVED entry, matches entries on TEB and tid, and prunes dead ones; SuspendThread/ResumeThread bracket only raw syscalls and ReadProcessMemory pointer reads, with no allocation or lock taken while a peer is suspended, so the "suspend then allocate" deadlock is not re-introduced; a peer that is mid-LdrpAllocateTls with empty slots is skipped and left to its own attach. XCL_SLOT is published before the snapshot now, which is the right order for threads attaching during the swap. read_own_ptr going through ReadProcessMemory rather than dereferencing is what makes a peer dying mid-read a None instead of an access violation. The tests are aggressive on purpose (TerminateThread, TEB reuse, churn) but they are process-isolated and they assert host TLS isolation and heap validity afterwards, which is the invariant the fix is about. Notes, not blocking: MOVED keeps handles for moved threads until they detach or are pruned, and the test helper spawns a child copy of the test binary (guarded by XCL_TLS_SLOT_ZERO_CHILD) which is the only process it starts. No duplicate: nothing else changes take_slot_zero; #431 and #196 touch other TLS paths.
performance: once per process, at start-up: one handle per thread, two short suspensions each, and the same 20 ms sleep as before; nothing per frame or per thread creation beyond a WaitForSingleObject(0) when MOVED is touched.
verdict: safe to merge
hardware / tool and model: AMD Radeon RX 6800 XT 16 GB (RDNA2, wave64), driver 32.0.21045.29003; Ryzen 5 5600, 32 GB RAM; Windows 10 IoT Enterprise LTSC 2024, 10.0.26100 build 26100.9974; Rust 1.100.0; DXC 1.9.2602.17; debug build. DeepSeek Harness coding agent, model DeepSeek V4.1 Flash.

<!-- greyfinch-sync:ivall/xcl:comment:7267390352 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1083#issuecomment-7267390352). Originally posted by [relativespace2K](https://github.com/relativespace2K) on 2026-11-30T02:52:25Z. --- merge-check base: 53e85fb1 head: 39ea43e9d95d706aaa6ec679c7544d63c822a566 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2790 passed, 6 failed, 49 ignored; failing: gpu::dxil::compact_tests::gpu_compact_form_with_micro_blocks_and_literal_table_runs_as_the_plain_form, gpu::recomp::pso::shader_cache_tests::console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk, hle::d3d12x::standin::tests::concurrent_shell_miss_reuses_winner_and_releases_loser_pipeline, ram_budget::tests::windows_takes_a_working_set_maximum_and_lifts_it, and two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (in `--test gpu_two_pass_cache_e2e`, so 5 failing tests give 6 failures). The same five fail on base 53e85fb1 alone (2788 passed, 6 failed, 49 ignored there), so none comes from this PR; its two new tests in `crates/xcl/tests/tls_slot_zero.rs` passed, and they run in a child copy of the test binary so `_tls_index` really starts at 0 and the `.CRT$XLY` callback sees real attach/detach. 13 SKIPPED lines, all environmental: no D3D12 debug layer / d3d12SDKLayers.dll, no heap windows, no GPU_UPLOAD, per-lane f16/f32 forms refused. review: no blocking finding; two files, every hunk read. The exchange now holds an open handle per peer, so a TID or TEB cannot be recycled under a stale `MOVED` entry, matches entries on TEB *and* tid, and prunes dead ones; `SuspendThread`/`ResumeThread` bracket only raw syscalls and `ReadProcessMemory` pointer reads, with no allocation or lock taken while a peer is suspended, so the "suspend then allocate" deadlock is not re-introduced; a peer that is mid-`LdrpAllocateTls` with empty slots is skipped and left to its own attach. `XCL_SLOT` is published before the snapshot now, which is the right order for threads attaching during the swap. `read_own_ptr` going through `ReadProcessMemory` rather than dereferencing is what makes a peer dying mid-read a `None` instead of an access violation. The tests are aggressive on purpose (TerminateThread, TEB reuse, churn) but they are process-isolated and they assert host TLS isolation and heap validity afterwards, which is the invariant the fix is about. Notes, not blocking: `MOVED` keeps handles for moved threads until they detach or are pruned, and the test helper spawns a child copy of the test binary (guarded by `XCL_TLS_SLOT_ZERO_CHILD`) which is the only process it starts. No duplicate: nothing else changes `take_slot_zero`; #431 and #196 touch other TLS paths. performance: once per process, at start-up: one handle per thread, two short suspensions each, and the same 20 ms sleep as before; nothing per frame or per thread creation beyond a `WaitForSingleObject(0)` when `MOVED` is touched. verdict: safe to merge hardware / tool and model: AMD Radeon RX 6800 XT 16 GB (RDNA2, wave64), driver 32.0.21045.29003; Ryzen 5 5600, 32 GB RAM; Windows 10 IoT Enterprise LTSC 2024, 10.0.26100 build 26100.9974; Rust 1.100.0; DXC 1.9.2602.17; debug build. DeepSeek Harness coding agent, model DeepSeek V4.1 Flash.
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!1074
No description provided.