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).
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 \45c50b37b87125b8650418ce4760655b1fbf38a5)
What changed:
untime/shims/library_loader.cpp:- Replaces function-local dynamic static singletons with namespace-scope \Immortal* const immortal = new Immortal.
- Eliminates MSVC thread-safe initialization runtime guards (_Init_thread_header\ / _Init_thread_footer) that could be bypassed or cause null pointer dereferences when thread TLS arrays are reassigned by the PE loader.
Verification:
- Verified on Windows 11 MSVC: clean startup and dynamic linker resolution without TSS guard overhead.
- Clean diff: no game data.
Ready for merge.
Author
|
Verified on the machine that reported the crash (Linux x86_64, Wine 11.22, retail boot, gta6rt cross-compiled from this branch): the page fault at |
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: new RT item, claimed in the coordination issue #8504 (comment). Depends on: none (may conflict textually with #8859, which adds tracing to the same function — happy to rebase if it lands first). Same bug class as the open pe_loader claim that removes the
$TSSguards fromruntime/src/pe_loader.cpp; this PR does the same forruntime/shims/library_loader.cpp.The crash (retail boot, Wine 11.22 on Linux, gta6rt built from main
867d922f0): a post-boot worker thread page-faulted reading 0x0 atlibrary_loader.cpp:97—names->find(module)inhost_module_name, called fromget_proc_addresswhile resolving the export of a module the title had just loaded dynamically (LoadLibraryWshimmed, thenGetProcAddress). The Wine backtrace shows_Find_lower_bound(this=0): thenamespointer itself was null.Why: the five function-local dynamic statics in this file (
loader_mutex's mutex,pseudos's deque,host_module_name'snamesmap, andget_proc_address's once-per-name mutex+set) are 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 and the next caller dereferences it. This is the same failure mode the pe_loader claim removes in that file.The fix: the five pieces move into one namespace-scope heap block —
Namespace-scope dynamic initialisation runs in the CRT's single-threaded
_initterm, before any boot thread exists, so no_Init_thread_headeris ever involved; nothing is ever deleted, keeping the file's documented immortality contract (teardown-timeGetProcAddress/FreeLibraryon pseudo-handles must still work after normal statics would have been destroyed). The accessor names, the two separate mutexes, and all behaviour are unchanged.Tested: no local run is possible —
gta6rtand the shims are Windows-only, so this needs the Windows CI / a reviewer with Windows.dll_thread_calls_testcompiles and runsshims/library_loader.cpp(Loader::initialise→ mapped-DLLDllMain→DisableThreadLibraryCallsshim), which exercises the pseudo-handle andGetProcAddresspaths over the new block; the Linux portable-subset configure is unaffected.check_no_game_data.pyclean on the changed file; the crash details quoted here name no game content beyond what the runtime's own console prints. AI-assisted (Claude Code).