Repository navigation
runtime/src: remove TLS-slot-0 dependencies in shader_library and queue_holds - #8326
Open
GustavoEllwanger wants to merge 1 commit into
Open
GustavoEllwanger wants to merge 1 commit into
GustavoEllwanger wants to merge 1 commit into
Conversation
Daiguol
approved these changes
Nov 23, 2026
|
Tested
|
This was referenced Nov 23, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claimed in the coordination issue as: #8047 (comment)
What and why
When a mapped Xbox Series executable owns static TLS slot 0 (
TEB->ThreadLocalStoragePointer[0], for/GAbuilds as in #4313 / #7524), host code reached on guest threads cannot rely on MSVC's thread-safe function-local static initialization (_Init_thread_headerreads_Init_thread_epochfrom slot 0) or hostthread_localvariables (which alias slot 0).Two core headers in
runtime/src/reached on guest threads during D3D12/Vulkan work still depended on TLS slot 0:runtime/src/shader_library.h(zlib_inflate, fixed Huffman blocks)static const auto tables = [] { ... }();.TEB->ThreadLocalStoragePointer[0]pointing at a zeroed guest TLS block, MSVC's_Init_thread_headerguard skips initialization and leaves zeroed Huffman tables, causingzlib_inflateto fail (false, 0 bytes) on fixed-Huffman streams.detail::build_huffmanconstexprand builddetail::kFixedHuffmanTablesat compile time (inline constexpr), eliminating the runtime init guard and any TLS access.runtime/src/queue_holds.h(QueueHolds::in_pump)static thread_local bool pumping = false;.in_pump()readstrueand causespump_ready()/remove_fence()to silently skip all held work; when slot 0 is zeroed,in_pump() = true/falsewrites into the guest's TLS slot 0.pumpingwas global across allQueueHolds<Semaphore>instances, pumping one instance also suppressed pumping a second distinct instance on the same thread.thread_local bool pumpingwith a per-instancestd::atomic<std::thread::id> pump_owner_{}and an RAIIPumpOwnerGuard(exception-safe, zero TLS access, independent per instance).runtime/test/runtime_src_tls_safe_test.cpp+runtime/CMakeLists.txtruntime_src_tls_safe) covering fixed-Huffmanzlib_inflate, same-instance re-entrancy (pump_readyandremove_fence), cross-instance pumping on the same thread, exception safety if a barrier callback throws, and multi-threaded pumping.TEB->ThreadLocalStoragePointer[0]pointed at zeroed,0x01-filled, andPAGE_READONLYscratch pages, verifying no TLS corruption or skipped work.Tested
main(dde82f27e) before the fix:zlib_inflateon the synthetic fixed-Huffman stream under a zeroed TLS slot 0 page:FAIL (out.size=0).QueueHolds::pump_ready()under a0x01-filled TLS slot 0 page:FAIL (releases=0).runtime_src_tls_safe_testcompiled with/std:c++20 /EHsc /W4 /permissive- /utf-8in both/O2and/Od(0 warnings):18 checks, 0 failures.shader_library_testcompiled with/std:c++20 /EHsc /W4 /permissive- /utf-8 /O2:SHA-256, inflate (stored/fixed/dynamic), JSON, FSSM extraction, FSPX programs and index lookup OK.runtime/shims/d3d12_xs_device.cppcompiled cleanly (/c /std:c++20 /EHsc /W4 /permissive- /utf-8 /O2, 0 warnings) against the updatedshader_library.h.python -I scripts/check_no_game_data.pyon all 4 changed/added files: passed (exit 0).AI-assisted: yes
Checklist
docs/design.md, with how it was confirmed. (N/A — runtime C++ headers only)