Repository navigation
fix(PIMETextService): defer ImeModule initialization out of DllMain (#940) - #948
Merged
Merged
Conversation
PCMan
force-pushed
the
fix/issue-940-defer-imemodule-init
branch
2 times, most recently
from
October 18, 2026 06:32
9b1d9c7 to
0e40b0c
Compare
…940) WHAT: - Save module handle during DLL_PROCESS_ATTACH without constructing PIME::ImeModule. - Lazily instantiate PIME::ImeModule on first use (DllGetClassObject, DllRegisterServer, DllUnregisterServer) under std::mutex protection. - Add releaseImeModule() helper to encapsulate destruction under mutex lock. - Only release ImeModule in DLL_PROCESS_DETACH when lpReserved == NULL (dynamic unload). - Update DllCanUnloadNow() to return S_OK if the module was never initialized without triggering initialization. WHY: - Constructing ImeModule in DllMain violates the Windows loader lock contract by performing COM initialization, Shell API calls, and disk I/O under LdrpLoaderLock, which causes deadlocks and crashes in sandboxed processes. - Deferring construction to COM entry points ensures safe initialization after loader lock is released. - Avoiding initialization in DllCanUnloadNow prevents COM garbage collection from eagerly loading the module. - Skipping Release() during process termination prevents teardown deadlocks and crashes. Generated with assistance from Antigravity (Gemini 3.8 Flash).
PCMan
force-pushed
the
fix/issue-940-defer-imemodule-init
branch
from
October 18, 2026 06:35
0e40b0c to
ac0bab0
Compare
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.
Fixes #940
Summary of Changes
hModuleduringDLL_PROCESS_ATTACHwithout eagerly constructingPIME::ImeModule.getImeModule()helper withstd::mutexsynchronization to lazily instantiatePIME::ImeModuleupon first invocation (DllGetClassObject,DllRegisterServer,DllUnregisterServer).releaseImeModule()helper to encapsulate thread-safe destruction.DLL_PROCESS_DETACHonly during dynamic unloads (lpReserved == NULL).DllCanUnloadNow()to safely check ifg_imeModuleis null under mutex lock and returnS_OKimmediately if the module was never initialized, avoiding eager instantiation during COM garbage collection.Rationale
Constructing
ImeModuledirectly insideDllMainviolates Windows OS guidelines regarding the OS loader lock (LdrpLoaderLock), as it initializes environment paths and reads filesystem/registry while holding the lock. Deferring construction to the COM exports avoids deadlock and crashes during DLL injection.Generated with assistance from Antigravity (Gemini 3.8 Flash).