Skip to content

Commit

Permalink
Fea,vcruntime同步到14.34.31933
Browse files Browse the repository at this point in the history
  • Loading branch information
mingkuang-Chuyu committed Jan 25, 2023
1 parent e31dc84 commit d3e03ba
Show file tree
Hide file tree
Showing 13 changed files with 400 additions and 86 deletions.
29 changes: 14 additions & 15 deletions Sources/crt/i386/trnsctrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
#include <setjmp.h>
#include <trnsctrl.h>

#if 0
#include "../ehhelpers.h"
#else
#include "ehhelpers.h"
#endif

#include <Windows.h>

Expand All @@ -43,12 +47,12 @@
#define IS_DISPATCHING(Flag) ((Flag & EXCEPTION_UNWIND) == 0)
#define IS_TARGET_UNWIND(Flag) (Flag & EXCEPTION_TARGET_UNWIND)

#ifndef pFrameInfoChain

#if _CRT_NTDDI_MIN >= NTDDI_WIN6
#ifdef pFrameInfoChain
#elif WindowsTargetPlatformMinVersion >= __MakeVersion(10, 0, 10240)
#define pFrameInfoChain (*((FRAMEINFO **) &(RENAME_BASE_PTD(__vcrt_getptd)()->_pFrameInfoChain)))
#elif WindowsTargetPlatformMinVersion >= WindowsTargetPlatformWindows6
#define pFrameInfoChain (*((FRAMEINFO **) &(((_ptd_msvcrt_win6_shared*)__acrt_getptd())->_pFrameInfoChain)))
#else

static __inline void* __fastcall pFrameInfoChain_fun()
{
auto ptd = __acrt_getptd();
Expand All @@ -67,12 +71,9 @@ static __inline void* __fastcall pFrameInfoChain_fun()

return &(((_ptd_msvcrt_win6_shared*)ptd)->_pFrameInfoChain);
}

#define pFrameInfoChain (*((FRAMEINFO **) pFrameInfoChain_fun()))
#endif

#endif

#if 0
/////////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -240,7 +241,7 @@ extern "C" _VCRTIMP __declspec(naked) DECLSPEC_GUARD_SUPPRESS EXCEPTION_DISPOSIT

EHTRACE_FMT1("pRN = 0x%p", pRN);

result = __InternalCxxFrameHandler<RENAME_EH_EXTERN(__FrameHandler3)>( pExcept, pRN, (PCONTEXT)pContext, pDC, pFuncInfo, 0, nullptr, FALSE );
result = __InternalCxxFrameHandlerWrapper<RENAME_EH_EXTERN(__FrameHandler3)>( pExcept, pRN, (PCONTEXT)pContext, pDC, pFuncInfo, 0, nullptr, FALSE );

EHTRACE_HANDLER_EXIT(result);

Expand Down Expand Up @@ -294,7 +295,7 @@ extern "C" _VCRTIMP __declspec(naked) DECLSPEC_GUARD_SUPPRESS EXCEPTION_DISPOSIT

EHTRACE_FMT1("pRN = 0x%p", pRN);

result = __InternalCxxFrameHandler<RENAME_EH_EXTERN(__FrameHandler3)>( pExcept, pRN, (PCONTEXT)pContext, pDC, pFuncInfo, 0, nullptr, FALSE );
result = __InternalCxxFrameHandlerWrapper<RENAME_EH_EXTERN(__FrameHandler3)>( pExcept, pRN, (PCONTEXT)pContext, pDC, pFuncInfo, 0, nullptr, FALSE );

EHTRACE_HANDLER_EXIT(result);

Expand Down Expand Up @@ -344,7 +345,7 @@ extern "C" _VCRTIMP __declspec(naked) DECLSPEC_GUARD_SUPPRESS EXCEPTION_DISPOSIT

EHTRACE_FMT1("pRN = 0x%p", pRN);

result = __InternalCxxFrameHandler<RENAME_EH_EXTERN(__FrameHandler3)>( pExcept, pRN, (PCONTEXT)pContext, pDC, pFuncInfo, 0, nullptr, FALSE );
result = __InternalCxxFrameHandlerWrapper<RENAME_EH_EXTERN(__FrameHandler3)>( pExcept, pRN, (PCONTEXT)pContext, pDC, pFuncInfo, 0, nullptr, FALSE );

EHTRACE_HANDLER_EXIT(result);

Expand Down Expand Up @@ -473,7 +474,7 @@ extern "C" EXCEPTION_DISPOSITION __cdecl _CatchGuardHandler(
__security_check_cookie(pRN->RandomCookie ^ (UINT_PTR)pRN);

EXCEPTION_DISPOSITION result =
__InternalCxxFrameHandler<RENAME_EH_EXTERN(__FrameHandler3)>( pExcept,
__InternalCxxFrameHandlerWrapper<RENAME_EH_EXTERN(__FrameHandler3)>( pExcept,
pRN->pRN,
(PCONTEXT)pContext,
nullptr,
Expand Down Expand Up @@ -697,7 +698,7 @@ extern "C" EXCEPTION_DISPOSITION __cdecl _TranslatorGuardHandler(
//
// Check for a handler:
//
__InternalCxxFrameHandler<RENAME_EH_EXTERN(__FrameHandler3)>( pExcept, pRN->pRN, (PCONTEXT)pContext, nullptr, pRN->pFuncInfo, pRN->CatchDepth, pRN->pMarkerRN, TRUE );
__InternalCxxFrameHandlerWrapper<RENAME_EH_EXTERN(__FrameHandler3)>( pExcept, pRN->pRN, (PCONTEXT)pContext, nullptr, pRN->pFuncInfo, pRN->CatchDepth, pRN->pMarkerRN, TRUE );

if (!pRN->DidUnwind) {
//
Expand Down Expand Up @@ -797,7 +798,6 @@ extern "C" _VCRTIMP FRAMEINFO * __cdecl _CreateFrameInfo(
_LCRT_DEFINE_IAT_SYMBOL(_CreateFrameInfo);
#endif


/////////////////////////////////////////////////////////////////////////////
//
// _FindAndUnlinkFrame - Remove the frame information for this scope that was
Expand Down Expand Up @@ -828,5 +828,4 @@ extern "C" _VCRTIMP void __cdecl _FindAndUnlinkFrame(
}

_LCRT_DEFINE_IAT_SYMBOL(_FindAndUnlinkFrame);

#endif
#endif
24 changes: 24 additions & 0 deletions Sources/crt/vcruntime/c11_atomic_support.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// C11 atomic support routines: extern inline defitions
#include <vcruntime_c11_atomic_support.h>

extern inline void _Check_memory_order(const unsigned int _Order);
extern inline void _Atomic_thread_fence(const unsigned int _Order);

extern inline void _Atomic_store8(volatile char* _Ptr, char _Desired, int _Order);
extern inline void _Atomic_store16(volatile short* _Ptr, short _Desired, int _Order);
extern inline void _Atomic_store32(volatile int* _Ptr, int _Desired, int _Order);
extern inline void _Atomic_store64(volatile long long* _Ptr, long long _Desired, int _Order);

extern inline char _Atomic_load8(const volatile char* _Ptr, int _Order);
extern inline short _Atomic_load16(const volatile short* _Ptr, int _Order);
extern inline int _Atomic_load32(const volatile int* _Ptr, int _Order);
extern inline long long _Atomic_load64(const volatile long long* _Ptr, int _Order);

extern inline _Bool _Atomic_compare_exchange_strong8(volatile char* _Ptr, char* _Expected, char _Desired, int _Order);
extern inline _Bool _Atomic_compare_exchange_strong16(
volatile short* _Ptr, short* _Expected, short _Desired, int _Order);
extern inline _Bool _Atomic_compare_exchange_strong32(volatile int* _Ptr, int* _Expected, int _Desired, int _Order);
extern inline _Bool _Atomic_compare_exchange_strong64(
volatile long long* _Ptr, long long* _Expected, long long _Desired, int _Order);
17 changes: 8 additions & 9 deletions Sources/crt/vcruntime/ehhelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
#define _pForeignExcept (*((EHExceptionRecord **)&(((_ptd_msvcrt_win6_shared*)RENAME_BASE_PTD(__vcrt_getptd)())->_pForeignException)))
#else
#include <ptd_downlevel.h>

#define _pForeignExceptWin6 (*((EHExceptionRecord **)&(((_ptd_msvcrt_win6_shared*)RENAME_BASE_PTD(__vcrt_getptd)())->_pForeignException)))
#define _pForeignExceptdownlevel (*((EHExceptionRecord **)&(__LTL_get_ptd_downlevel(TRUE)->_pForeignException)))
#define _pForeignExcept (__LTL_GetOsMinVersion() >= MakeMiniVersion(6, 0) ? _pForeignExceptWin6 : _pForeignExceptdownlevel)

#endif

#endif
Expand All @@ -27,11 +25,9 @@
#elif WindowsTargetPlatformMinVersion >= WindowsTargetPlatformWindows6
#define pFrameInfoChain (*((FRAMEINFO **) &(((_ptd_msvcrt_win6_shared*)RENAME_BASE_PTD(__vcrt_getptd)())->_pFrameInfoChain)))
#elif WindowsTargetPlatformMinVersion >= WindowsTargetPlatformWindowsXP

#define pFrameInfoChainWin6 (*((FRAMEINFO **) &(((_ptd_msvcrt_win6_shared*)RENAME_BASE_PTD(__vcrt_getptd)())->_pFrameInfoChain)))
#define pFrameInfoChainWinXP (*((FRAMEINFO **) &(((_ptd_msvcrt_winxp*)RENAME_BASE_PTD(__vcrt_getptd)())->_pFrameInfoChain)))
#define pFrameInfoChain (__LTL_GetOsMinVersion() >= MakeMiniVersion(6, 0) ? pFrameInfoChainWin6 : pFrameInfoChainWinXP)

#endif

// Pre-V4 managed exception code
Expand All @@ -40,12 +36,15 @@
// V4 and later managed exception code
#define MANAGED_EXCEPTION_CODE_V4 0XE0434352

//extern "C" void
//__except_validate_context_record(
// _In_ PCONTEXT ContextRecord
// );
#if 0
extern "C" void
__except_validate_context_record(
_In_ PCONTEXT ContextRecord
);
#else
//这个函数仅仅是验证内存是否在堆栈中,而且要开启 guard ICall才行,所以直接砍掉吧
#define __except_validate_context_record(ContextRecord)
#endif

extern "C" _VCRTIMP void * __AdjustPointer(
void *,
Expand Down Expand Up @@ -95,7 +94,7 @@ extern "C" _VCRTIMP int __cdecl RENAME_EH_EXTERN(__TypeMatch)(
//

template<class T>
EXCEPTION_DISPOSITION __InternalCxxFrameHandler(
EXCEPTION_DISPOSITION __InternalCxxFrameHandlerWrapper(
EHExceptionRecord *pExcept,
EHRegistrationNode *pRN,
CONTEXT *pContext,
Expand Down
36 changes: 24 additions & 12 deletions Sources/crt/vcruntime/ehstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,30 @@
#include <trnsctrl.h>
#include <type_traits>
#include "ehhelpers.h"
#include <windows.h>

#if _EH_RELATIVE_FUNCINFO
#if defined(_M_ARM_NT) || defined(_M_ARM64) || defined(_CHPE_X86_ARM64_EH_)
#if defined(_M_ARM_NT) || defined(_M_ARM64) || defined(_CHPE_X86_ARM64_EH_) || defined(_M_ARM64EC)
static uintptr_t adjustIp(DispatcherContext *pDC, uintptr_t Ip)
{
//
// If this context came from an unwind to a call, then the ControlPc points
// to a return address, which could put us at the start of a neighboring
// scope. To correct for this, back the PC up by the minimum instruction
// size to ensure we are in the same scope as the original call opcode.
//
#if defined(_M_ARM64EC)
if(RtlIsEcCode(Ip)) {
PDISPATCHER_CONTEXT_ARM64EC pECDC;
pECDC = (PDISPATCHER_CONTEXT_ARM64EC) pDC;

if (pDC->ControlPcIsUnwound) {
if(pECDC->ControlPcIsUnwound != FALSE) {
Ip -= 4;
}
}
#else

//
// If this context came from an unwind to a call, then the ControlPc points
// to a return address, which could put us at the start of a neighboring
// scope. To correct for this, back the PC up by the minimum instruction
// size to ensure we are in the same scope as the original call opcode.
//
if (pDC->ControlPcIsUnwound) {

#if defined(_M_ARM_NT)

Expand All @@ -38,10 +49,11 @@ static uintptr_t adjustIp(DispatcherContext *pDC, uintptr_t Ip)

Ip -= 4;

#endif
#endif // _M_ARM_NT

}

#endif // _M_ARM64EC
return Ip;
}

Expand All @@ -50,7 +62,7 @@ static uintptr_t adjustIp(DispatcherContext* /*pDC*/, uintptr_t Ip)
{
return Ip;
}
#endif
#endif // (_M_ARM_NT) || defined(_M_ARM64) || defined(_CHPE_X86_ARM64_EH_) || defined(_M_ARM64EC)

__ehstate_t RENAME_EH_EXTERN(__FrameHandler4)::StateFromIp(
FuncInfo *pFuncInfo,
Expand Down Expand Up @@ -209,6 +221,7 @@ void RENAME_EH_EXTERN(__FrameHandler3)::SetState(
}
#endif

#else
#if 0
__ehstate_t RENAME_EH_EXTERN(__FrameHandler3)::GetCurrentState(
EHRegistrationNode *pRN,
Expand Down Expand Up @@ -237,6 +250,5 @@ void RENAME_EH_EXTERN(__FrameHandler3)::SetState(
{
pRN->state = newState;
}
#endif

#endif // 0
#endif
55 changes: 46 additions & 9 deletions Sources/crt/vcruntime/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,59 @@ static BOOLEAN Is_bad_exception_allowed(ESTypeList *pExceptionSpec);
#elif WindowsTargetPlatformMinVersion >= WindowsTargetPlatformWindows6
#define _pCurrentFuncInfo (*((ESTypeList **)&(((_ptd_msvcrt_win6_shared*)RENAME_BASE_PTD(__vcrt_getptd)())->_curexcspec)))
#elif WindowsTargetPlatformMinVersion >= WindowsTargetPlatformWindowsXP

#define _pCurrentFuncInfoWin6 (*((ESTypeList **)&(((_ptd_msvcrt_win6_shared*)RENAME_BASE_PTD(__vcrt_getptd)())->_curexcspec)))
#define _pCurrentFuncInfoWinXP (*((ESTypeList **)&(((_ptd_msvcrt_winxp*)RENAME_BASE_PTD(__vcrt_getptd)())->_curexcspec)))
#define _pCurrentFuncInfo (__LTL_GetOsMinVersion() >= MakeMiniVersion(6,0) ? _pCurrentFuncInfoWin6 : _pCurrentFuncInfoWinXP)

#endif

inline ESTypeList* RENAME_EH_EXTERN(__FrameHandler3)::getESTypes(FuncInfo* pFuncInfo)
{
return FUNC_PESTYPES(pFuncInfo);
}

////////////////////////////////////////////////////////////////////////////////
//
// __InternalCxxFrameHandlerWrapper - Wraps the frame handler so we have a place
// to apply cleanup on this function

template <class T>
EXCEPTION_DISPOSITION __InternalCxxFrameHandlerWrapper(
EHExceptionRecord* pExcept, // Information for this exception
EHRegistrationNode* pRN, // Dynamic information for this frame
CONTEXT* pContext, // Context info
DispatcherContext* pDC, // Context within subject frame
typename T::FuncInfo* pFuncInfo, // Static information for this frame
int CatchDepth, // How deeply nested are we?
EHRegistrationNode* pMarkerRN, // Marker node for when checking inside catch block
BOOLEAN recursive // Are we handling a translation?
) {

#if defined(_M_HYBRID_X86_ARM64) && !defined(_CHPE_X86_ARM64_EH_)
_HybridGenerateThunks(__InternalCxxFrameHandlerWrapper<T>, 1);
#endif

if constexpr (std::is_same_v<T, RENAME_EH_EXTERN(__FrameHandler4)>)
{
__try
{
return __InternalCxxFrameHandler<T>(pExcept, pRN, pContext, pDC, pFuncInfo, CatchDepth, pMarkerRN, recursive);
}
__finally
{
#if _VCRT_BUILD_FH4
// For FrameHandler4, this value should always be invalid past an invocation of this function.
CatchStateInParent = INVALID_CATCH_SPECIFIC_STATE;
#endif
}
}
else
{
// Compile-time disable the __try/__finally unless we need it. On x86 even a no-op finally triggers a call
// to local_unwind and can change behavior of the handler.
return __InternalCxxFrameHandler<T>(pExcept, pRN, pContext, pDC, pFuncInfo, CatchDepth, pMarkerRN, recursive);
}
}

////////////////////////////////////////////////////////////////////////////////
//
// __InternalCxxFrameHandler - the frame handler for all functions with C++ EH
Expand All @@ -252,8 +293,7 @@ EXCEPTION_DISPOSITION __InternalCxxFrameHandler(
DispatcherContext *pDC, // Context within subject frame
typename T::FuncInfo *pFuncInfo, // Static information for this frame
int CatchDepth, // How deeply nested are we?
EHRegistrationNode *pMarkerRN, // Marker node for when checking inside
// catch block
EHRegistrationNode *pMarkerRN, // Marker node for when checking inside catch block
BOOLEAN recursive // Are we handling a translation?
) {

Expand Down Expand Up @@ -378,7 +418,7 @@ EXCEPTION_DISPOSITION __InternalCxxFrameHandler(
} // __InternalCxxFrameHandler

#if 0
template EXCEPTION_DISPOSITION __InternalCxxFrameHandler<RENAME_EH_EXTERN(__FrameHandler3)>(
template EXCEPTION_DISPOSITION __InternalCxxFrameHandlerWrapper<RENAME_EH_EXTERN(__FrameHandler3)>(
EHExceptionRecord *pExcept,
EHRegistrationNode *pRN,
CONTEXT *pContext,
Expand All @@ -391,7 +431,7 @@ template EXCEPTION_DISPOSITION __InternalCxxFrameHandler<RENAME_EH_EXTERN(__Fram
#endif

#if _VCRT_BUILD_FH4
template EXCEPTION_DISPOSITION __InternalCxxFrameHandler<RENAME_EH_EXTERN(__FrameHandler4)>(
template EXCEPTION_DISPOSITION __InternalCxxFrameHandlerWrapper<RENAME_EH_EXTERN(__FrameHandler4)>(
EHExceptionRecord *pExcept,
EHRegistrationNode *pRN,
CONTEXT *pContext,
Expand Down Expand Up @@ -1000,7 +1040,6 @@ extern "C" _VCRTIMP int __cdecl RENAME_EH_EXTERN(__TypeMatch)(
}

_LCRT_DEFINE_IAT_SYMBOL(__TypeMatch);

#endif

#if 0
Expand Down Expand Up @@ -1915,7 +1954,6 @@ extern "C" _VCRTIMP int __cdecl RENAME_EH_EXTERN(__BuildCatchObjectHelper)(
}

_LCRT_DEFINE_IAT_SYMBOL(__BuildCatchObjectHelper);

#endif

#if 0
Expand Down Expand Up @@ -2029,7 +2067,6 @@ extern "C" _VCRTIMP void __cdecl RENAME_EH_EXTERN(__BuildCatchObject)(
}

_LCRT_DEFINE_IAT_SYMBOL(__BuildCatchObject);

#endif

#if 0
Expand Down
Loading

0 comments on commit d3e03ba

Please sign in to comment.