Repository navigation
Conversation
The five function-local dynamic statics in library_loader.cpp (loader_mutex's mutex, pseudos' deque, host_module_name's names map, get_proc_address's once-per-name mutex and set) were each guarded by an MSVC _Init_thread_header ($TSS) check. The boot chain runs on threads whose TLS array the loader replaced (runtime/src/pe_loader.cpp: "Windows replaces a thread's TLS array ... when some thread loads a DLL with static TLS"), and on such a thread the guard can be skipped and left set, so the guarded pointer stays null: a retail boot on Wine 11.22 page-faulted at the names lookup in host_module_name (called from get_proc_address) with _Find_lower_bound(this=0) on a post-boot thread resolving a dynamically loaded module's export. The five pieces move into one namespace-scope heap block (Immortal* const = new Immortal), initialised by the CRT's single-threaded _initterm before any boot thread and never destroyed, so the immortality contract of the old statics (teardown calls into GetProcAddress/FreeLibrary on pseudo-handles) is kept and no thread guard is ever involved. Same accessor names and behaviour; dll_thread_calls_test compiles and runs this file on Windows. AI-assisted (Claude Code).
startup_trace.h's mutex() and skip_int3's flag and once-per-address set, and xmem.cpp's three once-per-attribute trace notes, were function-local dynamic statics: the same MSVC _Init_thread_header ($TSS) guard class the previous commit removes from library_loader.cpp. With --trace, a retail boot on Wine 11.22 page-faulted in note_attributes' seen-set emplace (null guarded static, read of 0x8) when the title's CRT init called an XMem shim from a thread whose TLS array the loader replaced; the host_frame stack was startup_trace's note path. They now share one rt::startup_trace::detail::immortal<T>(): every static involved is constant-initialised (atomic slot = nullptr) and a compare-exchange publishes the heap object once, so a losing allocation leaks on purpose and no thread guard is ever run. Callers keep their own mutex+set pairs as immortal locals of a function-local struct, so behaviour and trace output are unchanged. Depends on: the library_loader commit above (same PR stack, one build). AI-assisted (Claude Code).
This was referenced Nov 23, 2026
abnalstlll-byte
approved these changes
Nov 23, 2026
abnalstlll-byte
left a comment
Contributor
There was a problem hiding this comment.
Independent Windows review (commit b05caa004a0fadb0c946480302d728305bc4de0e)
What changed:
runtime/shims/startup_trace.h&runtime/shims/xmem.cpp:- Replaces function-local dynamic initialization of once-per-key / once-per-address trace statics with lock-free atomic
detail::immortal<T>(). - Removes MSVC
$TSS(_Init_thread_header) guards from trace paths, preventing page faults when static TLS arrays are modified by the PE loader during DLL mapping.
- Replaces function-local dynamic initialization of once-per-key / once-per-address trace statics with lock-free atomic
Verification:
- Verified on Windows host: clean compilation with MSVC, zero TSS overhead or TLS contention.
- Clean diff: no game files.
LGTM!
Contributor
|
Verified head
AI-assisted. |
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.
Item: follow-up to #9093 (same RT item, claim comment, continued in the thread). Depends on: #9093 — the branch stacks on it (the first commit is #9093's), so this PR's diff against #9093 is
startup_trace.h+xmem.cpponly.Why: with
--traceon the same retail boot (Wine 11.22, Linux, gta6rt from main867d922f0), the boot now passes the loader and reaches the title's CRT init, which calls an XMem shim — and crashes again in host code atxmem.cpp'snote_attributesseen-setemplace(null guarded static, read of 0x8). Same_Init_thread_header($TSS) class as #9093: a function-local dynamic static whose guard is skipped on a thread whose TLS array the loader replaced.What this PR changes: a guard-free primitive in
rt::startup_trace::detail—Every static involved is constant-initialised and a compare-exchange publishes the heap object once (a losing allocation leaks on purpose: immortal). Converted to it:
startup_trace.h:mutex()(wasstatic auto* m = new std::mutex),skip_int3'sstatic const bool skip = GetEnvironmentVariableW(...)and its once-per-address mutex+set;xmem.cpp: the three once-per-attribute trace notes (note_attributes,note_physical_attributes, theXMemTransferMemorynote) — each keeps its own mutex+set pair as locals of a function-local struct passed toimmortal<T>(), so the trace output is byte-for-byte unchanged.The
std::atomic<bool> warned{false}statics in xmem.cpp are left alone: they are constant-initialised already, so they never had a guard.Verified (Linux x86_64, Wine 11.22, retail boot, cross-compiled gta6rt): with this stack the two host page faults are gone; the boot proceeds past the loader into the title's CRT init and records the expected
xmem_attributesevents, andLEONIDA_SKIP_INT3=1now steps the title's soft asserts (int3_skippedat+0x1e1d01b,+0x1e1d04a,+0x1e1d3a7). The run then stops inside the title's code (game_scarlett_master.exe+0x1f67809, a write through a null object right after a skipped assert) — that part is guest-side, not this PR's scope; details are in the coordination issue. No game files in the PR. AI-assisted (Claude Code).