From f323a7a371f2c66947f34f54757fe8972cd75247 Mon Sep 17 00:00:00 2001 From: mingkuang Date: Thu, 25 Jul 2024 00:11:38 +0800 Subject: [PATCH] =?UTF-8?q?Bug=20#107,=20=E8=A7=A3=E5=86=B3VS2010=E7=AD=89?= =?UTF-8?q?=E8=80=81=E7=BC=96=E8=AF=91=E5=99=A8=E6=89=BE=E4=B8=8D=E5=88=B0?= =?UTF-8?q?threadSafeInit=E3=80=81sizedDealloc=E7=9B=B8=E5=85=B3=E7=AC=A6?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Build.cmd | 4 +- src/Thunks/YY_Thunks.cpp | 99 ++++++++++++++++++++++++++++++++++++++++ src/Thunks/bcrypt.hpp | 2 +- src/Thunks/dwrite.hpp | 8 ++-- 4 files changed, 106 insertions(+), 7 deletions(-) diff --git a/src/Build.cmd b/src/Build.cmd index 1dda907..b05dbeb 100644 --- a/src/Build.cmd +++ b/src/Build.cmd @@ -26,7 +26,7 @@ goto:eof :BuildObj echo BuildObj %1 %2 %3 -cl /O1 /Os /Oi /GS- /std:c++17 /execution-charset:utf-8 /arch:IA32 /Z7 /MT /Fo"objs\\%Platform%\\%1" /Zl /c /D "NDEBUG" /D "YY_Thunks_Target=%2" "%~dp0Thunks\YY_Thunks.cpp" +cl /O1 /Os /Oi /GS- /std:c++17 /execution-charset:utf-8 /Zc:threadSafeInit- /Zc:sizedDealloc- /Zc:tlsGuards- /Zc:alignedNew- /arch:IA32 /Z7 /MT /Fo"objs\\%Platform%\\%1" /Zl /c /D "NDEBUG" /D "YY_Thunks_Target=%2" "%~dp0Thunks\YY_Thunks.cpp" if %ErrorLevel% NEQ 0 exit /b %ErrorLevel% ::生成weak符号,一些非必须符号安排为weak可以避免链接失败 @@ -52,7 +52,7 @@ echo BuildLib %1 %2 %3 md "Lib\\%1\\%Platform%" -cl /O1 /Os /Oi /GS- /std:c++17 /execution-charset:utf-8 /arch:IA32 /Z7 /MT /Fo"Lib\\%1\\%Platform%\\YY_Thunks_for_%1.obj" /Zl /c /D "__APPLY_CHROMIUM_WORKAROUNDS" /D "__USING_NTDLL_LIB" /D "NDEBUG" /D "YY_Thunks_Target=%2" /D "__FALLBACK_PREFIX=YY_Thunks_" "%~dp0Thunks\YY_Thunks.cpp" +cl /O1 /Os /Oi /GS- /std:c++17 /execution-charset:utf-8 /Zc:threadSafeInit- /Zc:sizedDealloc- /Zc:tlsGuards- /Zc:alignedNew- /arch:IA32 /Z7 /MT /Fo"Lib\\%1\\%Platform%\\YY_Thunks_for_%1.obj" /Zl /c /D "__APPLY_CHROMIUM_WORKAROUNDS" /D "__USING_NTDLL_LIB" /D "NDEBUG" /D "YY_Thunks_Target=%2" /D "__FALLBACK_PREFIX=YY_Thunks_" "%~dp0Thunks\YY_Thunks.cpp" if %ErrorLevel% NEQ 0 exit /b %ErrorLevel% diff --git a/src/Thunks/YY_Thunks.cpp b/src/Thunks/YY_Thunks.cpp index 8feca3c..c85d2f4 100644 --- a/src/Thunks/YY_Thunks.cpp +++ b/src/Thunks/YY_Thunks.cpp @@ -391,6 +391,105 @@ namespace YY::Thunks::internal } } + class CppAlloc + { + public: + _NODISCARD _Ret_notnull_ _Post_writable_byte_size_(_Size) _VCRT_ALLOCATOR + void* __CRTDECL operator new( + size_t _Size + ) + { + return Alloc(_Size); + } + + _NODISCARD _Ret_maybenull_ _Success_(return != NULL) _Post_writable_byte_size_(_Size) _VCRT_ALLOCATOR + void* __CRTDECL operator new( + size_t _Size, + ::std::nothrow_t const& + ) noexcept + { + return Alloc(_Size); + } + + _NODISCARD _Ret_notnull_ _Post_writable_byte_size_(_Size) _VCRT_ALLOCATOR + void* __CRTDECL operator new[]( + size_t _Size + ) + { + return Alloc(_Size); + } + + _NODISCARD _Ret_maybenull_ _Success_(return != NULL) _Post_writable_byte_size_(_Size) _VCRT_ALLOCATOR + void* __CRTDECL operator new[]( + size_t _Size, + ::std::nothrow_t const& + ) noexcept + { + return Alloc(_Size); + } + + /// + /// placement new + /// + /// + /// + /// + void* __CRTDECL operator new( + size_t _Size, + void* _Block + ) + { + return _Block; + } + + void __CRTDECL operator delete( + void* _Block + ) noexcept + { + Free(_Block); + } + + void __CRTDECL operator delete( + void* _Block, + ::std::nothrow_t const& + ) noexcept + { + Free(_Block); + } + + void __CRTDECL operator delete[]( + void* _Block + ) noexcept + { + Free(_Block); + } + + void __CRTDECL operator delete[]( + void* _Block, + ::std::nothrow_t const& + ) noexcept + { + Free(_Block); + } + + void __CRTDECL operator delete( + void* _Block, + size_t _Size + ) noexcept + { + Free(_Block); + } + + void __CRTDECL operator delete[]( + void* _Block, + size_t _Size + ) noexcept + { + Free(_Block); + } + }; + + //浠g爜鍧楋紝鍒嗗壊浠诲姟 template auto __forceinline Block(Callback&& _Callback, Params&&... args) -> decltype(_Callback(args...)) diff --git a/src/Thunks/bcrypt.hpp b/src/Thunks/bcrypt.hpp index 23062ae..7740510 100644 --- a/src/Thunks/bcrypt.hpp +++ b/src/Thunks/bcrypt.hpp @@ -56,7 +56,7 @@ namespace YY::Thunks Key, }; - class BCryptObject + class BCryptObject : public internal::CppAlloc { static constexpr auto kBCryptObjectMagic = 0x998u; diff --git a/src/Thunks/dwrite.hpp b/src/Thunks/dwrite.hpp index 8d1d07b..703e279 100644 --- a/src/Thunks/dwrite.hpp +++ b/src/Thunks/dwrite.hpp @@ -9,7 +9,7 @@ namespace YY::Thunks::Fallback namespace { #if (YY_Thunks_Target < __WindowsNT10_10240) - class DWriteRenderingParams : public IDWriteRenderingParams3 + class DWriteRenderingParams : public IDWriteRenderingParams3, public internal::CppAlloc { private: ULONG uRef = 1; @@ -166,7 +166,7 @@ namespace YY::Thunks::Fallback } }; - class DWriteFontCollection : public IDWriteFontCollection1 + class DWriteFontCollection : public IDWriteFontCollection1, public internal::CppAlloc { private: ULONG uRef = 1; @@ -340,7 +340,7 @@ namespace YY::Thunks::Fallback using IDWriteFontCollection::GetFontFamily; }; - class DWriteFontFallback : public IDWriteFontFallback + class DWriteFontFallback : public IDWriteFontFallback, public internal::CppAlloc { private: ULONG uRef = 1; @@ -446,7 +446,7 @@ namespace YY::Thunks::Fallback } }; - class DWriteFactory : public IDWriteFactory3 + class DWriteFactory : public IDWriteFactory3, public internal::CppAlloc { private: ULONG uRef = 1;