TLS: preserve Characteristics alignment and fix on_thread_attach contention (#106) #196
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!196
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-196"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@JGonzalezRodriguez on GitHub · 2026-11-23 20:17 UTC · original
JGonzalezRodriguez:fix/tls-alignment-and-attach→main· +529 −25 · 3 files · 2 commits · openPart of #106. Preserves
IMAGE_TLS_DIRECTORY64.Characteristicsalignment in synthetic carrier DLLs and fixeson_thread_attach()skipping TLS initialization underIMAGES.write()contention.What is in it
pe.rs,tls.rs,loader.rs: Decode and sanitizeIMAGE_TLS_DIRECTORY64.Characteristicsalignment bits (bits 20..23IMAGE_SCN_ALIGN_*BYTES, nibble1..=14→1..=8192B, clearing reserved bits and0xF). AlignStartAddressOfRawDatainbuild_carrier_dll_with()to the requested alignment, clampu32/u64carrier size arithmetic (MAX_CARRIER_TEMPLATE), and reject oversized requests intls::install()before creating files or writing*index_ptr.tls.rs: Fixon_thread_attach()silently skipping template initialization whenIMAGES.try_read()hitsWouldBlockduring the shortIMAGES.write()push. Move registration afterLoadLibraryW(avoidingNO_INDEXplaceholders on load failure), write*index_ptr = index(when non-null) only afterIMAGES.write()succeeds, and use blockingIMAGES.read()under the lock order OS loader lock →MOVED→IMAGES.Tested
610.57.4,rustc 1.98.1x86_64-pc-windows-msvcviaclang-cl 23.1.1+lld-link+xwinSDK10.0.26100, Proton Experimental + local relaxedvkd3d-proton):cargo build --release --workspace --target x86_64-pc-windows-msvc: 0 errors, 0 warnings.pe::tests::: 12 passed, 0 failed.tls::tests::(parallel &--test-threads=1): 8 passed, 0 failed, 1 ignored (carrier_variants_probe).loader::tests::: 2 passed, 0 failed.xcl_testtitle.exe: 47/50 passed (all TLS/loader/DLL/D3D12.X checks pass; 3 known Wine/FAudio diffs).@mmmhariuson49d28fcmerged onto60565c4(Windows + RTX 3060): fullscripts/test.ps1(incl. e2excl_testtitle) — 617 passed, 0 failed, 20 ignored (2 GPU skips:no wave64).@Kalmarvon prior commitdd71d57(Windows 11 Pro 26200, x64 MSVC,rustc 1.99.0): all 12 PE/TLS tests passed (including live 32..=8192 B alignment on invoking + 8 new threads; 4 carried-back behavior tests failed on base956a476).Regression run
scripts/smoke.ps1run by a tester with a retail title.Not tested
scripts/smoke.ps1regression run.AI use
@Kalmarv on GitHub · 2026-11-23 20:38 UTC · original
I built PR head
dd71d576f11e97faf4c332b30b5202316ea7d2dddirectly on native Windows 11 Pro build 26200, x64 MSVC, rustc 1.99.0. All 12 enabled PE and TLS tests passed in isolated processes. The live alignment check passed on the invoking thread and eight new threads for each requested alignment from 32 through 8192 bytes. The existing ignored carrier probe was skipped.On base
956a476bf738a098f39df4f4c8acef682e43030f, I carried four behavior tests back and adapted their calls to the old carrier and install signatures. All four failed as expected. The PE and carrier checks read zero in Characteristics, and workers in the contention check saw zero-filled blocks where the template contained 0xA5. Seven existing controls passed. The fifth new test calls alignment helpers introduced by this PR and ran on the head only.The alignment mask, RVA rounding and relocated-address checks agree. Moving registration after the successful carrier load also avoids retaining a placeholder on load failure. One wording detail in the PR description: the old write guard already ended at the push statement before LoadLibraryW. The contention bug comes from skipping initialization when try_read misses that short write. These checks used synthetic carrier DLLs. Issue #106 still needs a title-side run.
@JGonzalezRodriguez on GitHub · 2026-11-23 20:59 UTC · original
Thanks @Kalmarv for running the native Windows 11 verification (including the base-commit control checks) and for catching that PR description wording!
Pushed follow-up commit
466425daddressing independent review findings, and updated the PR description to clarify that the oldIMAGES.write()guard already ended beforeLoadLibraryW(so the contention bug wastry_read()missing that short write, while moving registration afterLoadLibraryWprevents leaking aNO_INDEXplaceholder on failure).Summary of what
466425dtightens:carrier_template_size_for()(MAX_CARRIER_TEMPLATE) andbuild_carrier_dll_with()againstu32/u64overflow, and madetls::install()reject oversized requests before creating files or writing*index_ptr(with new testinstall_rejects_oversized_requests, now 7/7tls::tests).*index_ptr = indexafterIMAGES.write()succeeds.carrier_respects_tls_block_alignment_on_all_threads(exercisingfill_existing_threads()), synchronized Part 2 stress workers viaCondvaruntilinstaller.join()so workers cannot exit and unmap their TEB mid-enumeration, loaded the mapped-PE inspection DLL withDONT_RESOLVE_DLL_REFERENCES+FreeLibrary+ cleanup to avoid burning extra static TLS slots, and verified all nibbles1..=14+0/0xF+ exactDIR64relocations.AI-assisted.
@mmmharius on GitHub · 2026-11-23 21:47 UTC · original
Tested on Windows with an NVIDIA RTX 3060 (32-lane waves), merged onto current main.
49d28fcmerged onto main60565c4(local merge, no conflicts).scripts/test.ps1(end-to-end test title included): all green.parses_tls_characteristics_from_pe,tls_characteristics_alignment_decoding,carrier_preserves_tls_characteristics_and_template_alignment,carrier_respects_tls_block_alignment_on_all_threads,install_rejects_oversized_requests,on_thread_attach_never_skips_init_under_images_write_contention.carrier_variants_probestays ignored.Synthetic tests only, no game data. tests were run by me.
@MesshM on GitHub · 2026-11-24 05:08 UTC · original
Test run of
49d28fc52e11553e9b0d5ddb1eeee528a16cdce3on AMD RDNA4. I merged it onto currentmaind5442d2locally (clean merge) and tested that tree.Tested
stable-x86_64-pc-windows-msvc, debugcargo build --workspace+cargo test --workspace -- --test-threads=4on the merge: 710 passed, 0 failed, 41 ignored, exit code 0;xcllib tests 669 passed, 0 failed, 21 ignoredSKIPPED; thetlsand loader tests pass.Review: Note the overlap with #431 (open), which removes
fill_existing_threadsthat this PR keeps and changes; #431's description says the two conflict in three places. I ran this one merged ontomainalone, not together with #431.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 ontomain.Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
@einfachama on GitHub · 2026-11-24 11:46 UTC · original
Regression run on a retail title for #196, since Not tested lists it: head
49d28fc52e11553e9b0d5ddb1eeee528a16cdce3merged ontomaind208e14(clean merge, local merge commitf3484b8). No regression at my retail title's first menu, and the title's TLS images now log their alignment.Tested
cargo test --workspace --no-fail-fast -- --test-threads=4: 710 passed, 0 failed, 41 ignored (maind208e14in its clean run: 704 / 0 / 41). SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.scripts/smoke.ps1 -Seconds 60, unattended, the learned window in both runs. XCL's log has the same TLS lines as onmain(3 images with TLS, the executable in slot 0, the same indices, block sizes and thread counts), now with analignvalue for each image (4 to 16 B here). No TLS error.The second block is the local merge onto
main, not the PR's head commit, so it can't stand in for the PR's own Regression run (pr_check.pywants the head commit there). It shows that the title's TLS setup is unchanged here apart from the alignment.Not tested
on_thread_attachcontention case under a real title (nothing I could provoke at the menu), and anything past the first menu.AI use
@DavidM1911 on GitHub · 2026-11-25 15:19 UTC · original
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!
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.