Skip to content

Commit 024b6e8

Browse files
jkotasfilipnavara
authored andcommitted
Use funclets and new EH on win-x86
1 parent 1151925 commit 024b6e8

32 files changed

+546
-293
lines changed

src/coreclr/clr.featuredefines.props

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,13 @@
1616
<FeatureCominteropApartmentSupport>true</FeatureCominteropApartmentSupport>
1717
<FeatureTypeEquivalence>true</FeatureTypeEquivalence>
1818
<FeatureIjw>true</FeatureIjw>
19+
<FeatureEHFunclets>true</FeatureEHFunclets>
1920
</PropertyGroup>
2021

2122
<PropertyGroup Condition="'$(TargetsOSX)' == 'true' OR '$(TargetsMacCatalyst)' == 'true' OR '$(TargetsiOS)' == 'true' OR '$(TargetstvOS)' == 'true'">
2223
<FeatureObjCMarshal>true</FeatureObjCMarshal>
2324
</PropertyGroup>
2425

25-
<PropertyGroup Condition="!('$(TargetsWindows)' == 'true' AND '$(Platform)' == 'x86')">
26-
<FeatureEHFunclets>true</FeatureEHFunclets>
27-
</PropertyGroup>
28-
2926
<PropertyGroup>
3027
<DefineConstants Condition="'$(FeatureComWrappers)' == 'true'">$(DefineConstants);FEATURE_COMWRAPPERS</DefineConstants>
3128
<DefineConstants Condition="'$(FeatureCominterop)' == 'true'">$(DefineConstants);FEATURE_COMINTEROP</DefineConstants>

src/coreclr/clrdefinitions.cmake

+1-3
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,7 @@ if(CLR_CMAKE_TARGET_WIN32)
205205
endif(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_I386)
206206
endif(CLR_CMAKE_TARGET_WIN32)
207207

208-
if (NOT CLR_CMAKE_TARGET_ARCH_I386 OR NOT CLR_CMAKE_TARGET_WIN32)
209-
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_ARCH>>>:FEATURE_EH_FUNCLETS>)
210-
endif (NOT CLR_CMAKE_TARGET_ARCH_I386 OR NOT CLR_CMAKE_TARGET_WIN32)
208+
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_ARCH>>>:FEATURE_EH_FUNCLETS>)
211209

212210
if (CLR_CMAKE_TARGET_WIN32 AND (CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_ARM64))
213211
add_definitions(-DFEATURE_SPECIAL_USER_MODE_APC)

src/coreclr/cpp.hint

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
extern "C" _EXCEPTION_HANDLER_DECL(funcname)
3737

3838
#define EXCEPTION_HANDLER_IMPL(funcname) \
39-
_EXCEPTION_HANDLER_DECL(funcname)
39+
extern "C" _EXCEPTION_HANDLER_DECL(funcname)
4040

4141
#define EXCEPTION_HANDLER_FWD(funcname) \
4242
funcname(pExceptionRecord, pEstablisherFrame, pContext, pDispatcherContext)

src/coreclr/debug/ee/debugger.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -3994,7 +3994,7 @@ HANDLE OpenWin32EventOrThrow(
39943994
// Returns true if the specified IL offset has a special meaning (eg. prolog, etc.)
39953995
bool DbgIsSpecialILOffset(DWORD offset);
39963996

3997-
#if defined(TARGET_WINDOWS)
3997+
#if defined(TARGET_WINDOWS) && !defined(TARGET_X86)
39983998
void FixupDispatcherContext(T_DISPATCHER_CONTEXT* pDispatcherContext, T_CONTEXT* pContext, PEXCEPTION_ROUTINE pUnwindPersonalityRoutine = NULL);
39993999
#endif
40004000

src/coreclr/debug/ee/funceval.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -3990,7 +3990,7 @@ void * STDCALL FuncEvalHijackWorker(DebuggerEval *pDE)
39903990
}
39913991

39923992

3993-
#if defined(FEATURE_EH_FUNCLETS) && !defined(TARGET_UNIX)
3993+
#if defined(FEATURE_EH_FUNCLETS) && !defined(TARGET_UNIX) && !defined(TARGET_X86)
39943994

39953995
EXTERN_C EXCEPTION_DISPOSITION
39963996
FuncEvalHijackPersonalityRoutine(IN PEXCEPTION_RECORD pExceptionRecord,
@@ -4028,7 +4028,6 @@ FuncEvalHijackPersonalityRoutine(IN PEXCEPTION_RECORD pExceptionRecord,
40284028
return ExceptionCollidedUnwind;
40294029
}
40304030

4031-
4032-
#endif // FEATURE_EH_FUNCLETS && !TARGET_UNIX
4031+
#endif // FEATURE_EH_FUNCLETS && !TARGET_UNIX && !TARGET_X86
40334032

40344033
#endif // ifndef DACCESS_COMPILE

src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ add_dependencies(coreclr coreclr_exports)
7676
set_property(TARGET coreclr APPEND_STRING PROPERTY LINK_FLAGS ${EXPORTS_LINKER_OPTION})
7777
set_property(TARGET coreclr APPEND_STRING PROPERTY LINK_DEPENDS ${EXPORTS_FILE})
7878

79-
if (CLR_CMAKE_HOST_UNIX)
79+
if (CLR_CMAKE_HOST_UNIX OR CLR_CMAKE_TARGET_ARCH_I386)
8080
set(LIB_UNWINDER unwinder_wks)
8181
endif (CLR_CMAKE_HOST_UNIX)
8282

src/coreclr/inc/crosscomp.h

+30
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,36 @@ typedef struct _T_KNONVOLATILE_CONTEXT_POINTERS {
667667
#define T_DISPATCHER_CONTEXT DISPATCHER_CONTEXT
668668
#define PT_DISPATCHER_CONTEXT PDISPATCHER_CONTEXT
669669

670+
#if defined(TARGET_WINDOWS) && defined(TARGET_X86)
671+
typedef struct _KNONVOLATILE_CONTEXT {
672+
673+
DWORD Edi;
674+
DWORD Esi;
675+
DWORD Ebx;
676+
DWORD Ebp;
677+
678+
} KNONVOLATILE_CONTEXT, *PKNONVOLATILE_CONTEXT;
679+
680+
typedef struct _KNONVOLATILE_CONTEXT_POINTERS_EX
681+
{
682+
// The ordering of these fields should be aligned with that
683+
// of corresponding fields in CONTEXT
684+
//
685+
// (See FillRegDisplay in inc/regdisp.h for details)
686+
PDWORD Edi;
687+
PDWORD Esi;
688+
PDWORD Ebx;
689+
PDWORD Edx;
690+
PDWORD Ecx;
691+
PDWORD Eax;
692+
693+
PDWORD Ebp;
694+
695+
} KNONVOLATILE_CONTEXT_POINTERS_EX, *PKNONVOLATILE_CONTEXT_POINTERS_EX;
696+
697+
#define KNONVOLATILE_CONTEXT_POINTERS KNONVOLATILE_CONTEXT_POINTERS_EX
698+
#define PKNONVOLATILE_CONTEXT_POINTERS PKNONVOLATILE_CONTEXT_POINTERS_EX
699+
#endif
670700
#define T_KNONVOLATILE_CONTEXT_POINTERS KNONVOLATILE_CONTEXT_POINTERS
671701
#define PT_KNONVOLATILE_CONTEXT_POINTERS PKNONVOLATILE_CONTEXT_POINTERS
672702

src/coreclr/inc/regdisp.h

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#ifndef __REGDISP_H
55
#define __REGDISP_H
66

7+
#include <clrnt.h>
78

89
#ifdef DEBUG_REGDISPLAY
910
class Thread;

src/coreclr/jit/targetx86.h

-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@
5252
// target
5353
#define FEATURE_EH 1 // To aid platform bring-up, eliminate exceptional EH clauses (catch, filter,
5454
// filter-handler, fault) and directly execute 'finally' clauses.
55-
#if !defined(UNIX_X86_ABI)
56-
#define FEATURE_EH_WINDOWS_X86 1 // Enable support for SEH regions
57-
#endif
5855
#define ETW_EBP_FRAMED 1 // if 1 we cannot use EBP as a scratch register and must create EBP based
5956
// frames for most methods
6057
#define CSE_CONSTS 1 // Enable if we want to CSE constants

src/coreclr/unwinder/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set(UNWINDER_SOURCES
1818

1919
convert_to_absolute_path(UNWINDER_SOURCES ${UNWINDER_SOURCES})
2020

21-
if(CLR_CMAKE_HOST_UNIX)
21+
if(CLR_CMAKE_HOST_UNIX OR CLR_CMAKE_TARGET_ARCH_I386)
2222
add_library_clr(unwinder_wks OBJECT ${UNWINDER_SOURCES})
2323
add_unwinder_include_directories(unwinder_wks)
2424
add_dependencies(unwinder_wks eventing_headers)

src/coreclr/unwinder/i386/unwinder.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,11 @@ BOOL OOPStackUnwinderX86::Unwind(T_CONTEXT* pContextRecord, T_KNONVOLATILE_CONTE
4444

4545
pContextRecord->ContextFlags |= CONTEXT_UNWOUND_TO_CALL;
4646

47-
#define ARGUMENT_AND_SCRATCH_REGISTER(reg) if (rd.pCurrentContextPointers->reg) pContextRecord->reg = *rd.pCurrentContextPointers->reg;
48-
ENUM_ARGUMENT_AND_SCRATCH_REGISTERS();
49-
#undef ARGUMENT_AND_SCRATCH_REGISTER
50-
5147
#define CALLEE_SAVED_REGISTER(reg) if (rd.pCurrentContextPointers->reg) pContextRecord->reg = *rd.pCurrentContextPointers->reg;
5248
ENUM_CALLEE_SAVED_REGISTERS();
5349
#undef CALLEE_SAVED_REGISTER
5450

55-
pContextRecord->Esp = rd.SP - codeInfo.GetCodeManager()->GetStackParameterSize(&codeInfo);
51+
pContextRecord->Esp = rd.SP;
5652
pContextRecord->Eip = rd.ControlPC;
5753

5854
return TRUE;

src/coreclr/vm/codeman.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -6090,6 +6090,11 @@ BOOL ReadyToRunJitManager::IsFilterFunclet(EECodeInfo * pCodeInfo)
60906090
if (!pCodeInfo->IsFunclet())
60916091
return FALSE;
60926092

6093+
#ifdef TARGET_X86
6094+
// x86 doesn't use personality routines in unwind data, so we have to fallback to
6095+
// the slow implementation
6096+
return IJitManager::IsFilterFunclet(pCodeInfo);
6097+
#else
60936098
// Get address of the personality routine for the function being queried.
60946099
SIZE_T size;
60956100
PTR_VOID pUnwindData = GetUnwindDataBlob(pCodeInfo->GetModuleBase(), pCodeInfo->GetFunctionEntry(), &size);
@@ -6114,6 +6119,7 @@ BOOL ReadyToRunJitManager::IsFilterFunclet(EECodeInfo * pCodeInfo)
61146119
_ASSERTE(fRet == IJitManager::IsFilterFunclet(pCodeInfo));
61156120

61166121
return fRet;
6122+
#endif
61176123
}
61186124

61196125
#endif // FEATURE_EH_FUNCLETS

src/coreclr/vm/excep.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -2494,7 +2494,7 @@ VOID DECLSPEC_NORETURN RealCOMPlusThrow(OBJECTREF throwable)
24942494
RealCOMPlusThrow(throwable, FALSE);
24952495
}
24962496

2497-
VOID DECLSPEC_NORETURN PropagateExceptionThroughNativeFrames(Object *exceptionObj)
2497+
VOID DECLSPEC_NORETURN __fastcall PropagateExceptionThroughNativeFrames(Object *exceptionObj)
24982498
{
24992499
CONTRACTL
25002500
{
@@ -11558,6 +11558,7 @@ void SoftwareExceptionFrame::Init()
1155811558
ENUM_CALLEE_SAVED_REGISTERS();
1155911559
#undef CALLEE_SAVED_REGISTER
1156011560

11561+
#ifndef TARGET_X86
1156111562
#ifndef TARGET_UNIX
1156211563
Thread::VirtualUnwindCallFrame(&m_Context, &m_ContextPointers);
1156311564
#else // !TARGET_UNIX
@@ -11568,6 +11569,7 @@ void SoftwareExceptionFrame::Init()
1156811569
EEPOLICY_HANDLE_FATAL_ERROR(COR_E_EXECUTIONENGINE);
1156911570
}
1157011571
#endif // !TARGET_UNIX
11572+
#endif
1157111573

1157211574
#define CALLEE_SAVED_REGISTER(regname) if (m_ContextPointers.regname == NULL) m_ContextPointers.regname = &m_Context.regname;
1157311575
ENUM_CALLEE_SAVED_REGISTERS();

src/coreclr/vm/excep.h

+10-11
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ VOID DECLSPEC_NORETURN RealCOMPlusThrowNonLocalized(RuntimeExceptionKind reKind,
252252
//==========================================================================
253253

254254
VOID DECLSPEC_NORETURN RealCOMPlusThrow(OBJECTREF throwable);
255-
VOID DECLSPEC_NORETURN PropagateExceptionThroughNativeFrames(Object *exceptionObj);
255+
VOID DECLSPEC_NORETURN __fastcall PropagateExceptionThroughNativeFrames(Object *exceptionObj);
256256

257257
//==========================================================================
258258
// Throw an undecorated runtime exception.
@@ -510,30 +510,29 @@ BOOL IsThreadHijackedForThreadStop(Thread* pThread, EXCEPTION_RECORD* pEx
510510
void AdjustContextForThreadStop(Thread* pThread, T_CONTEXT* pContext);
511511
OBJECTREF CreateCOMPlusExceptionObject(Thread* pThread, EXCEPTION_RECORD* pExceptionRecord, BOOL bAsynchronousThreadStop);
512512

513+
#if defined(TARGET_WINDOWS) && defined(TARGET_X86)
514+
// Pop off any SEH handlers we have registered below pTargetSP
515+
VOID PopSEHRecords(LPVOID pTargetSP);
516+
517+
// Misc functions to access and update the SEH chain. Be very, very careful about updating the SEH chain.
518+
PEXCEPTION_REGISTRATION_RECORD GetCurrentSEHRecord();
519+
VOID SetCurrentSEHRecord(EXCEPTION_REGISTRATION_RECORD *pSEH);
520+
#endif
521+
513522
#if !defined(FEATURE_EH_FUNCLETS)
514523
EXCEPTION_HANDLER_DECL(COMPlusFrameHandler);
515524
EXCEPTION_HANDLER_DECL(COMPlusNestedExceptionHandler);
516525
#ifdef FEATURE_COMINTEROP
517526
EXCEPTION_HANDLER_DECL(COMPlusFrameHandlerRevCom);
518527
#endif // FEATURE_COMINTEROP
519528

520-
// Pop off any SEH handlers we have registered below pTargetSP
521-
VOID PopSEHRecords(LPVOID pTargetSP);
522-
523529
#ifdef DEBUGGING_SUPPORTED
524530
VOID UnwindExceptionTrackerAndResumeInInterceptionFrame(ExInfo* pExInfo, EHContext* context);
525531
#endif // DEBUGGING_SUPPORTED
526532

527533
BOOL PopNestedExceptionRecords(LPVOID pTargetSP, BOOL bCheckForUnknownHandlers = FALSE);
528534
VOID PopNestedExceptionRecords(LPVOID pTargetSP, T_CONTEXT *pCtx, void *pSEH);
529535

530-
// Misc functions to access and update the SEH chain. Be very, very careful about updating the SEH chain.
531-
// Frankly, if you think you need to use one of these function, please
532-
// consult with the owner of the exception system.
533-
PEXCEPTION_REGISTRATION_RECORD GetCurrentSEHRecord();
534-
VOID SetCurrentSEHRecord(EXCEPTION_REGISTRATION_RECORD *pSEH);
535-
536-
537536
#define STACK_OVERWRITE_BARRIER_SIZE 20
538537
#define STACK_OVERWRITE_BARRIER_VALUE 0xabcdefab
539538

0 commit comments

Comments
 (0)