mirror of
https://github.com/Chuyu-Team/YY-Thunks.git
synced 2026-10-27 04:09:50 +08:00
Fea, 兼容用户自己编译的CRT DLL,如msvcr14x
This commit is contained in:
+1
-1
@@ -27,7 +27,7 @@ goto:eof
|
||||
cl /O1 /Os /Oi /GS- /arch:IA32 /Z7 /MT /Fo"objs\\%Platform%\\%1" /Zl /c /D "NDEBUG" /D "YY_Thunks_Support_Version=%2" "%~dp0Thunks\YY_Thunks.cpp"
|
||||
|
||||
::进行函数名称进行修正 __imp__%s_%u -> __imp__%s@%u
|
||||
LibMaker.exe FixObj "%~dp0..\\objs\\%Platform%\\%1" /WeakExternFix:__security_cookie=%PointType% /WeakExternFix:__YY_Thunks_Process_Terminating=4
|
||||
LibMaker.exe FixObj "%~dp0..\\objs\\%Platform%\\%1" /WeakExternFix:__security_cookie=%PointType% /WeakExternFix:__YY_Thunks_Process_Terminating=4 /WeakExternFix:__acrt_atexit_table=%PointType%
|
||||
|
||||
LibMaker.exe AppendWeak /MACHINE:%Platform% /DEF:"%~dp0def\\%Platform%\\PSAPI2Kernel32.def" /OUT:"%~dp0..\\objs\\%Platform%\\%1"
|
||||
|
||||
|
||||
+29
-3
@@ -396,8 +396,16 @@ static void* __fastcall try_get_function(
|
||||
#undef _APPLY
|
||||
|
||||
|
||||
static bool g_bUninitialize/* = false*/;
|
||||
|
||||
static void __cdecl __YY_uninitialize_winapi_thunks()
|
||||
{
|
||||
// 值反初始化一次
|
||||
if (g_bUninitialize)
|
||||
return;
|
||||
|
||||
g_bUninitialize = true;
|
||||
|
||||
//当DLL被强行卸载时,我们什么都不做。
|
||||
if (auto pRtlDllShutdownInProgress = (decltype(RtlDllShutdownInProgress)*)GetProcAddress(try_get_module_ntdll(), "RtlDllShutdownInProgress"))
|
||||
{
|
||||
@@ -466,19 +474,37 @@ static int __cdecl _YY_initialize_winapi_thunks()
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 外部weak符号,用于判断当前是否静态
|
||||
EXTERN_C extern void* __acrt_atexit_table;
|
||||
|
||||
static int __cdecl __YY_initialize_winapi_thunks()
|
||||
{
|
||||
_YY_initialize_winapi_thunks();
|
||||
|
||||
//只在节点位置插入 atexit 流程,避免CRT还没完全初始化好出现问题。
|
||||
atexit(__YY_uninitialize_winapi_thunks);
|
||||
// 如果 == null,那么有2种情况:
|
||||
// 1. 非UCRT,比如2008,VC6,这时,调用 atexit是安全的,因为atexit在 XIA初始化完成了。
|
||||
// 2. UCRT 并且处于MD状态。这时 atexit初始化 会提与 XIA,这时也是没有问题的。
|
||||
// 如果 != null:
|
||||
// 那么说明UCRT处于静态状态(CRT DLL其实也是静态的一种)
|
||||
// 这时,XTY是可以正确执行的,这时就不用调用atexit了
|
||||
// 由于XTY晚于onexit,所以它是可靠的。
|
||||
if (__acrt_atexit_table == nullptr)
|
||||
{
|
||||
atexit(__YY_uninitialize_winapi_thunks);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
typedef int(__cdecl* _PIFV)(void);
|
||||
typedef void(__cdecl* _PVFV)(void);
|
||||
|
||||
#pragma section(".CRT$XID", long, read) // CRT C Initializers
|
||||
// CRT C Initializers
|
||||
#pragma section(".CRT$XID", long, read)
|
||||
// CRT C Terminators(仅稍微之后于XTZ),这是故意的。
|
||||
// YY-Thunks属于API底层理应尽可能的滞后,且反初始化工作不依赖与CRT
|
||||
#pragma section(".CRT$XTY", long, read)
|
||||
|
||||
__declspec(allocate(".CRT$XID")) static _PIFV ___Initialization = __YY_initialize_winapi_thunks;
|
||||
__declspec(allocate(".CRT$XTY")) static _PVFV ___Uninitialization = __YY_uninitialize_winapi_thunks;
|
||||
|
||||
@@ -116,7 +116,7 @@
|
||||
<UseFullPaths>true</UseFullPaths>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
@@ -132,7 +132,7 @@
|
||||
<UseFullPaths>true</UseFullPaths>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
@@ -176,6 +176,12 @@
|
||||
<ClCompile Include="api-ms-win-core-path.UnitTest.cpp" />
|
||||
<ClCompile Include="api-ms-win-core-synch.UnitTest.cpp" />
|
||||
<ClCompile Include="api-ms-win-core-threadpool.UnitTest.cpp" />
|
||||
<ClCompile Include="weak.c">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="YY-Thunks.UnitTest.cpp" />
|
||||
<ClCompile Include="..\Thunks\YY_Thunks.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
||||
|
||||
@@ -66,6 +66,9 @@
|
||||
<ClCompile Include="api-ms-win-core-kernel32-legacy.UnitTest.cpp">
|
||||
<Filter>源文件\UnitTest</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="weak.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.h">
|
||||
|
||||
@@ -2,6 +2,4 @@
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
// 当使用预编译的头时,需要使用此源文件,编译才能成功。
|
||||
|
||||
EXTERN_C BOOL __YY_Thunks_Process_Terminating = 0;
|
||||
// 当使用预编译的头时,需要使用此源文件,编译才能成功。
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
const int __YY_Thunks_Process_Terminating;
|
||||
|
||||
const void* __acrt_atexit_table;
|
||||
Reference in New Issue
Block a user