Skip to content

fix: avoid loader-lock work in DllMain detach#57

Open
H-Chris233 wants to merge 5 commits into
OpenSteam001:mainfrom
H-Chris233:fix-dllmain-detach-loaderlock
Open

fix: avoid loader-lock work in DllMain detach#57
H-Chris233 wants to merge 5 commits into
OpenSteam001:mainfrom
H-Chris233:fix-dllmain-detach-loaderlock

Conversation

@H-Chris233

@H-Chris233 H-Chris233 commented May 26, 2026

Copy link
Copy Markdown
Contributor

Problem

DllMain's DLL_PROCESS_DETACH path called SteamUI::CoreUnhook() and SteamClient::CoreUnhook(), which may perform LoadLibrary/FreeLibrary under the loader lock. This is unsafe during process termination and can cause deadlocks or undefined behavior.

Additionally, nothing prevented an external FreeLibrary from unloading the DLL while hooks and worker threads still reference its code.

Changes

  1. Pin the module on DLL_PROCESS_ATTACH via GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_PIN) so the DLL cannot be unmapped while still in use.

  2. Guard DETACH work: during process termination (pvReserved != nullptr), only call FileWatcher::Stop() to avoid std::thread's joinable-guard std::terminate. Skip CoreUnhook entirely since it may acquire the loader lock.

Testing

  • Verified DLL attaches/detaches cleanly in Steam processes.
  • FileWatcher thread joins properly during exit (no more std::terminate crashes).

@H-Chris233 H-Chris233 force-pushed the fix-dllmain-detach-loaderlock branch 2 times, most recently from 06f74a1 to 7c43c3f Compare May 27, 2026 00:27
@OpenSteam001

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

2 participants