Repository navigation
TLS: audit static TLS directory raw data sizing, alignment, and index allocation (#106) - #1431
slopgobblercobbler wants to merge 1 commit into
Conversation
…on, and index allocation
…README Integrates 12 additional open upstream PRs on top of upstream/main (b7aa9f3): - xcl-dev#1432: GFX10 to DXGI format mappings, depth SRVs, and byte sizing - xcl-dev#1447: Arena::take overflow/alignment and Uma::free pool validation - xcl-dev#1441: drop SC_KEYMENU so the window is never frozen in menu mode - xcl-dev#1431, xcl-dev#1436: TLS directory sizing/alignment and RegisterClassExA checks - xcl-dev#1430, xcl-dev#1446: XGameSave quota/URL and XAudio2 XMA channel validation - xcl-dev#1415, xcl-dev#1433: VFS merged-directory sync and CreateFile2 checks - xcl-dev#1418: XGameRuntime device association synchronization - xcl-dev#1410, xcl-dev#1413: wave64 form logging and XCL_SAFE_BARRIER cache bypass Also removes duplicate a_huge_constant_count_has_no_layout test left from pre-applying xcl-dev#1290 before upstream merged it, and updates README.md. Verified under GE-Proton11-14 (RX 9060 XT / RADV): - Release build (x86_64-pc-windows-msvc): ok (22.05s) - Proton unit test sweep across all merged/touched modules: 209 passed, 2 failed (known Wine/vkd3d-proton diffs: xma2_source_voice current_buffer_context before Start, and vkd3d-proton accepting UNORDERED_ACCESS without UAV flag), 1 ignored, 0 skipped.
|
Full-suite run, since this PR has no test report yet. Tested exact head Tested
Not tested
AI use
|
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
gut0to
left a comment
There was a problem hiding this comment.
AI-assisted review; I checked the RVA arithmetic against the supported 8 KiB alignment.
| let align = alignment_from_characteristics(opts.characteristics); | ||
| let template_size = carrier_template_size_aligned(template_size as u64, align); | ||
| let off_template = if align > 256 { | ||
| (OFF_TEMPLATE + align - 1) & !(align - 1) |
There was a problem hiding this comment.
This aligns the section-relative offset, but the final template RVA is DATA_RVA + off_template with DATA_RVA = 0x3000. For the supported 8 KiB alignment, this computes off_template = 0x2000, so the start RVA is 0x5000 and 0x5000 % 0x2000 == 0x1000; it is not 8 KiB aligned. The current 512-byte test passes because 0x3000 is divisible by 512. Could the offset be chosen from the absolute RVA and add an 8 KiB header test? AI-assisted review; I verified the arithmetic.
gut0to
left a comment
There was a problem hiding this comment.
CONTRIBUTING.md also requires paired real-title scripts/smoke.ps1 runs for this runtime change, with main and this head tested on the same title and duration. The current description has no regression blocks and says real-title execution was not tested. Please add the required pair before merge, documenting if the title does not exercise TLS installation. AI-assisted review; I checked the current description against the guide.
|
Regression run of Against the limits in CONTRIBUTING.md: 99 % of AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, AI use: Claude Code (Claude Opus 5.5) built both trees and ran |
…cl-dev#1431) Port upstream xcl-dev#1431 (live head 8052b9c, still OPEN): carrier template sizing with alignment + 0xFFFE_0000 cap, Characteristics align encode/decode 1..8192, .data offset fix for align>256, null and NO_INDEX guards, register-after-load with uninstall on failure, and plumbing t.characteristics into tls_install. tls.rs + loader.rs land verbatim (Windows-only); the xcl-dev#1403 build-clamp pin test is retained (still passes under the stricter cap). Linux twin: ImageSpec/PendingTls carry characteristics, blocks allocate with the decoded alignment (floor 16), index writes use write_unaligned, alloc guards null templates, uninstall() drops the registry entry and detaches blocks; init_dll/load_game_dll uninstall on failure. The template-exceeds-block check stays fail-closed (strictly stronger than upstream max()).
…ention (port upstream xcl-dev#196) Port upstream xcl-dev#196 (live head 49d28fc, still OPEN vs upstream/main). pe.rs (shared, direct): SCN_ALIGN_MASK + TlsDir::alignment/ align_characteristics + tls_alignment_from_characteristics/ sanitize_tls_characteristics (nibble 1..=14 -> 1..=8192, reserved/0xF cleared) + 2 tests (decoding runs everywhere; carrier round-trip gated cfg(windows) — builder lives in the cfg(windows) module). tls.rs (cfg(windows)): build_carrier_dll_with sanitizes Characteristics, aligns template-start RVA for every valid align (not just >256), clamps template_size against u32::MAX/DATA_RVA/off (kept xcl-dev#1431 0xFFFE_0000 effective-size cap — strictly stronger than the PR's 0xFFFEFFF0, so no MAX_CARRIER_TEMPLATE const); install_with_characteristics rejects oversize before any side effect (no file/LoadLibrary/publish, index_ptr untouched); on_thread_attach blocks on IMAGES.read with poison recovery instead of try_read-skip (lock order OS-loader -> MOVED -> IMAGES, write() held only for push). install() 6-arg + loader characteristics plumbing already on linux via xcl-dev#1431 — kept. Linux twin needs no change: tls_linux.rs rejects oversize before lock_install (usize/Layout checks) and never try_skips attach (zero try_* in file). Tests: adapted to xcl-dev#1431 sizing (0x2000 template exact for all nibbles; third oversize case is template-exceeds-carrier-max since total<vs>template widening is xcl-dev#1431 semantics); new alignment/contention/oversize tests are Windows-only (file never compiles on Linux — rustfmt-parse checked). Gates: both checks 0 errors, pe:: 24/24, lib 752/0/1, title e2e 12 unique FAILs all D3D12.X 0 non-GPU, retail HOLDS (+0x2237320, stubs 20).
|
Nothing has happened on this PR for 3 days, so it is marked |
|
This makes the same change as #196: loader.rs passes t.characteristics to the TLS install, tls.rs writes them into the carrier's IMAGE_TLS_DIRECTORY64, aligns the template start to the decoded alignment, and moves the IMAGES push after LoadLibraryW with the slot index already set. #196 was opened first, also sanitises the reserved/0xF alignment bits (this PR copies the raw Characteristics into the carrier) and merges cleanly; this PR conflicts with main. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
Summary
Fixes #106 Item 1:
crates/xcl/src/tls.rs):carrier_template_size_alignedtoMAX_CARRIER_TEMPLATE_SIZE = 0xFFFE_0000, usingsaturating_addand masking against requested alignment.install_with_characteristics, computedrequired_len = total_len.max(template_len as u64)to strictly prevent buffer overflow whentotal_len < template_len.saturating_addinbuild_carrier_dll_withfordata_vsizeandsize_of_image.alignment_from_characteristicsandcharacteristics_from_alignmentto decode/encode PEIMAGE_SCN_ALIGN_*bits (bits 20..24, 1..8192 bytes).Characteristicsin the synthesized carrier DLL'sIMAGE_TLS_DIRECTORY64, ensuring the OS loader allocates TLS blocks with requested alignment (e.g. 32/64 bytes for AVX/cachelines)..datatemplate offset whenalign > 256soStartAddressOfRawDataandEndAddressOfRawDatasatisfy the alignment requirement.NO_INDEXchecks intls_block_of,take_slot_zero,exchange_for_new_thread, andfill_block.TlsImageintoIMAGESonly after load success, and addeduninstall(img_name)for teardown cleanup.crates/xcl/src/loader.rs):t.characteristicsfrompe.tls()totls_installand wiredcrate::tls::uninstall(&module.name)andmodules::unregister_mapped(base)on installation failure.Changes
crates/xcl/src/tls.rs:carrier_template_size_aligned: alignment and saturating length bounds.alignment_from_characteristics/characteristics_from_alignment: PE alignment bit mapping.uninstall: TLS image cleanup helper.crates/xcl/src/loader.rs:Tested
cargo test -p xcl -- tls: 10 passed, 0 failed (100% pass rate).Not Tested
AI Use
Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity