loader(native): populate static TLS blocks in live threads for late-loaded DLLs #22
No reviewers
Labels
No labels
accessibility
bug
claimed
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
tester report
urgent
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LakshanSivakumar--Native-Victory-macOS!22
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/22/head"
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?
@claytonblythe on GitHub · 2026-11-26 09:25 UTC · original
claytonblythe:fix/late-dll-static-tls→main· +103 −28 · 2 files · 1 commits · merged 2026-11-26 09:36 UTCSummary
Fixes an immediate
0xc0000005null-pointer read ([0 + 4]) when a title DLL with static TLS (such asamd_fidelityfx_upscaler_xbox.dllon Xbox Series S) is loaded after title threads are already running:teb::register_tlsincrates/victory-loader/src/native/teb.rsnow allocates and initializes a static TLS block for every already-live thread inLIVEand stores it atomically (Ordering::Release) into that thread'stls_array[index].TLS_MODULES->LIVE) betweenregister_tlsandThreadTeb::newso no thread can miss or double-allocate a module's TLS block.ThreadTeb::drop.apps/victory/src/native_run.rslog message from a warning to an info log when late static TLS is populated.Testing
cargo test --target x86_64-apple-darwin -p victory-loader --lib native::teb::tests— newlate_register_tls_populates_already_live_threadstest verifies that callingregister_tlsafter a thread's TEB is already live writes_tls_indexand populatesgs:[0x58][index]with initialized data + zero-filled BSS.--console series-s,VICTORY_GUESS_GRAPHICS=1):0xc0000005(info=[0, 4]) insideamd_fidelityfx_upscaler_xbox.dllat+0x1022right aftera DLL with static TLS loaded late.amd_fidelityfx_upscaler_xbox.dllloads and initializes cleanly with zero exceptions, reaching frame 1344 (recorded=2721 encoded=2721, 0 dropped draws) across a 65 s headless run.cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings(0 warnings) andcargo xtask policy(363 files ok).@LakshanSivakumar on GitHub · 2026-11-26 09:36 UTC · original · approved these changes
Tested merged with main (loader tests x3, Windows clippy). Good fix: Series S needs it now that run-native.sh defaults 16 GB Macs to it.
One non-blocking follow-up: the new test registers a TlsTemplate whose
startandindex_atpoint at the test's stack (init,tls_index), and it stays registered for the whole test process. Any thread a later test creates copies from that dead stack memory in ThreadTeb::new. Making bothstatic(or leaking them) would close that off. A small follow-up PR is welcome.