Skip to content

library_loader: avoid MSVC thread-safe static guard for lazy-allocated maps - #7074

Closed
KewaiiGamer wants to merge 3 commits into
ItsNotRexed:mainfrom
KewaiiGamer:fix/host-module-name-static-init
Closed

KewaiiGamer wants to merge 3 commits into
ItsNotRexed:mainfrom
KewaiiGamer:fix/host-module-name-static-init

Conversation

@KewaiiGamer

Copy link
Copy Markdown

Summary

  • Fix null dereference in host_module_name (library_loader.cpp:75) when the game's entry point calls GetProcAddress under Wine — the MSVC thread-safe static init guard reports "already initialized" while the pointer is still zero.
  • Replace static auto* p = new T with explicit zero-init + lazy allocation under the already-held loader_mutex(). Constant initialization needs no guard; the mutex serializes first-use allocation.
  • Apply the same pattern to get_proc_address's logging set, reusing loader_mutex() instead of a separate static mutex.

Test plan

  • gta6rt --dry-run — 0 unimplemented imports
  • gta6rt --init — TLS + DllMain pass
  • gta6rt --run — no longer crashes in host_module_name; reaches game entry

Tested on Nobara 44 (Wine-staging 11.21), RTX 4090 (driver 570.133.07). AI-assisted.

🤖 Generated with Claude Code

…d maps

The static-local pattern `static auto* p = new T` relies on the MSVC
thread-safe static initialization guard (_Init_thread_header/footer).
Under Wine, when the game's entry point calls GetProcAddress before the
guard table is in a consistent state, the guard reports "already
initialized" while the pointer is still zero, causing a null dereference
in host_module_name at the first names->find().

Replace with explicit zero-init (`static T* p{}`) plus lazy allocation
under the already-held loader_mutex(). The zero-initialization is
constant initialization (no guard needed), and the mutex serializes
first-use allocation. Apply the same pattern to get_proc_address's
logging set, reusing loader_mutex() instead of a separate static mutex.

Tested on Nobara 44 (Wine-staging 11.21, RTX 4090): --dry-run, --init
and --run all pass the library_loader code. AI-assisted.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@KewaiiGamer KewaiiGamer reopened this Nov 23, 2026
@dadsmallbuk1

Copy link
Copy Markdown

Code review (not run): the diff adds an advertising line to runtime/shims/library_loader.cpp, // Sponsored by creativeproxies.com. It has nothing to do with the fix, and the repository allows no comments in code except licence notices (AGENTS.md). Please remove it.

On the change itself: zero-initialised pointers, allocated lazily under the already-held loader_mutex(), avoid the guard as described, and reusing loader_mutex() for the seen set looks fine. Two small notes:

AI-assisted (Claude Code).

Removed sponsorship comment from library_loader.cpp
@nullmarsh

Copy link
Copy Markdown

Tested c8ea74de natively on Windows 11 26200, MSVC 14.44 RelWithDebInfo, RX 9060 XT (AMD 26.11.2): pass on real Windows, with no deadlock from get_proc_address now taking loader_mutex().

  • ctest -R "loader|dll_|library|tiny_game|run_": 27 pass, 1 skipped (shader_library_corpus, no corpus), 1 fails. The failure is d3d12_pipeline_library_host, which fails the same way on main on this card, so it isn't from this PR.

AI-assisted (Claude Code), no game files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants