Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions openless-all/app/windows-ime/OpenLessIme.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
<PreprocessorDefinitions>WIN32;_WINDOWS;_USRDLL;OPENLESSIME_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<!-- 静态链接 CRT:让 OpenLessIme.dll 自带 MSVCP / VCRUNTIME / UCRT,
避免被宿主进程(如 QQ)app/ 目录下的私有 MSVCP140 副本劫持。
QQ 把 MSVCP140.dll 放在 versions/<ver>/resources/app/,DLL 搜索
顺序优先 → 我们的 std::* 调用会跑 QQ 那份旧版 → ABI 漂移 → 0xc0000005。
DLL 大小 +~300 KB;DLL 内部 STL 不再可跨边界共享(我们也不需要)。 -->
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -89,6 +95,7 @@
<PreprocessorDefinitions>WIN32;_WINDOWS;_USRDLL;OPENLESSIME_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -105,6 +112,7 @@
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;OPENLESSIME_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -123,6 +131,7 @@
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;OPENLESSIME_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove DisableThreadLibraryCalls when using /MT

With the Release builds now linked to the static CRT (MultiThreaded), this DLL still calls DisableThreadLibraryCalls(instance) in windows-ime/src/dllmain.cpp; the Win32 API documentation explicitly says not to call DisableThreadLibraryCalls from a DLL linked to the static CRT because the CRT needs thread attach/detach notifications. In host processes that create threads after loading the TSF DLL, suppressing those callbacks can break CRT per-thread initialization/cleanup and reintroduce crashes or leaks in exactly the arbitrary-host-process scenario this change is meant to harden, so remove that call when using /MT (same issue applies to the Win32 Release setting).

Useful? React with 👍 / 👎.

</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down
6 changes: 5 additions & 1 deletion openless-all/app/windows-ime/src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ LONG g_object_count = 0;
BOOL APIENTRY DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) {
UNREFERENCED_PARAMETER(reserved);

// 不调用 DisableThreadLibraryCalls:DLL 现在用 /MT 静态链接 CRT,CRT 需要
// DLL_THREAD_ATTACH / DLL_THREAD_DETACH 通知做 per-thread TLS 初始化与清理。
// 在 host 进程(如 QQ / Office)切输入法新建 input thread 时禁用通知,会让
// 静态 CRT 的 thread-local 资源泄漏 / 行为不稳定,反而把这次想修的崩溃问题
// 重新引回来。详见 Microsoft 文档 DisableThreadLibraryCalls 备注。
if (reason == DLL_PROCESS_ATTACH) {
g_module = instance;
DisableThreadLibraryCalls(instance);
}

return TRUE;
Expand Down
Loading