Skip to content

Commit 39b1172

Browse files
authored
Add support for building runtime with FEATURE_EH_FUNCLETS on win-x86 (#114157)
This doesn't change the runtime configuration, but it enables the code paths necessary to support it in future if we decide to switch.
1 parent 6dc03c2 commit 39b1172

22 files changed

+483
-179
lines changed

src/coreclr/debug/ee/debugger.h

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 3 deletions
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/gcdump/i386/gcdumpx86.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#endif
1414
#include "gcdump.h"
1515

16-
1716
/*****************************************************************************/
1817

1918
#define castto(var,typ) (*(typ *)&var)
@@ -323,11 +322,7 @@ size_t GCDump::DumpGCTable(PTR_CBYTE table,
323322

324323
gcPrintf("%s%s pointer\n",
325324
(lowBits & byref_OFFSET_FLAG) ? "byref " : "",
326-
#ifndef FEATURE_EH_FUNCLETS
327-
(lowBits & this_OFFSET_FLAG) ? "this" : ""
328-
#else
329325
(lowBits & pinned_OFFSET_FLAG) ? "pinned" : ""
330-
#endif
331326
);
332327

333328
_ASSERTE(endOffs <= methodSize);
@@ -456,10 +451,6 @@ size_t GCDump::DumpGCTable(PTR_CBYTE table,
456451
/* non-ptr arg push */
457452

458453
curOffs += (val & 0x07);
459-
#ifndef FEATURE_EH_FUNCLETS
460-
// For funclets, non-ptr arg pushes can be reported even for EBP frames
461-
_ASSERTE(!header.ebpFrame);
462-
#endif // FEATURE_EH_FUNCLETS
463454
argCnt++;
464455

465456
DumpEncoding(bp, table-bp); bp = table;
@@ -681,9 +672,6 @@ size_t GCDump::DumpGCTable(PTR_CBYTE table,
681672
{
682673
argTab += decodeUnsigned(argTab, &val);
683674

684-
#ifndef FEATURE_EH_FUNCLETS
685-
assert((val & this_OFFSET_FLAG) == 0);
686-
#endif
687675
unsigned stkOffs = val & ~byref_OFFSET_FLAG;
688676
unsigned lowBit = val & byref_OFFSET_FLAG;
689677

src/coreclr/inc/crosscomp.h

Lines changed: 30 additions & 0 deletions
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(HOST_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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,10 @@ inline void FillRegDisplay(const PREGDISPLAY pRD, PT_CONTEXT pctx, PT_CONTEXT pC
523523
// This will setup the PC and SP
524524
SyncRegDisplayToCurrentContext(pRD);
525525

526+
#ifdef TARGET_X86
527+
pRD->PCTAddr = (UINT_PTR)&(pctx->Eip);
528+
#endif
529+
526530
#if !defined(DACCESS_COMPILE)
527531
#if defined(TARGET_AMD64) && defined(TARGET_WINDOWS)
528532
pRD->SSP = GetSSP(pctx);

src/coreclr/vm/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ elseif(CLR_CMAKE_TARGET_ARCH_I386)
652652
set(VM_SOURCES_WKS_ARCH_ASM
653653
${ARCH_SOURCES_DIR}/RedirectedHandledJITCase.asm
654654
${ARCH_SOURCES_DIR}/asmhelpers.asm
655+
${ARCH_SOURCES_DIR}/ehhelpers.asm
655656
${ARCH_SOURCES_DIR}/gmsasm.asm
656657
${ARCH_SOURCES_DIR}/jithelp.asm
657658
${ARCH_SOURCES_DIR}/PInvokeStubs.asm

src/coreclr/vm/codeman.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6562,6 +6562,11 @@ BOOL ReadyToRunJitManager::IsFilterFunclet(EECodeInfo * pCodeInfo)
65626562
if (!pCodeInfo->IsFunclet())
65636563
return FALSE;
65646564

6565+
#ifdef TARGET_X86
6566+
// x86 doesn't use personality routines in unwind data, so we have to fallback to
6567+
// the slow implementation
6568+
return IJitManager::IsFilterFunclet(pCodeInfo);
6569+
#else
65656570
// Get address of the personality routine for the function being queried.
65666571
SIZE_T size;
65676572
PTR_VOID pUnwindData = GetUnwindDataBlob(pCodeInfo->GetModuleBase(), pCodeInfo->GetFunctionEntry(), &size);
@@ -6586,6 +6591,7 @@ BOOL ReadyToRunJitManager::IsFilterFunclet(EECodeInfo * pCodeInfo)
65866591
_ASSERTE(fRet == IJitManager::IsFilterFunclet(pCodeInfo));
65876592

65886593
return fRet;
6594+
#endif
65896595
}
65906596

65916597
#endif // FEATURE_EH_FUNCLETS

src/coreclr/vm/excep.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,6 @@ VOID DECLSPEC_NORETURN RealCOMPlusThrowInvalidCastException(TypeHandle thCastFro
396396

397397
VOID DECLSPEC_NORETURN RealCOMPlusThrowInvalidCastException(OBJECTREF *pObj, TypeHandle thCastTo);
398398

399-
400399
#ifndef FEATURE_EH_FUNCLETS
401400

402401
#include "eexcp.h"
@@ -510,30 +509,29 @@ BOOL IsThreadHijackedForThreadStop(Thread* pThread, EXCEPTION_RECORD* pEx
510509
void AdjustContextForThreadStop(Thread* pThread, T_CONTEXT* pContext);
511510
OBJECTREF CreateCOMPlusExceptionObject(Thread* pThread, EXCEPTION_RECORD* pExceptionRecord, BOOL bAsynchronousThreadStop);
512511

512+
#if defined(TARGET_WINDOWS) && defined(TARGET_X86)
513+
// Pop off any SEH handlers we have registered below pTargetSP
514+
VOID PopSEHRecords(LPVOID pTargetSP);
515+
516+
// Misc functions to access and update the SEH chain. Be very, very careful about updating the SEH chain.
517+
PEXCEPTION_REGISTRATION_RECORD GetCurrentSEHRecord();
518+
VOID SetCurrentSEHRecord(EXCEPTION_REGISTRATION_RECORD *pSEH);
519+
#endif
520+
513521
#if !defined(FEATURE_EH_FUNCLETS)
514522
EXCEPTION_HANDLER_DECL(COMPlusFrameHandler);
515523
EXCEPTION_HANDLER_DECL(COMPlusNestedExceptionHandler);
516524
#ifdef FEATURE_COMINTEROP
517525
EXCEPTION_HANDLER_DECL(COMPlusFrameHandlerRevCom);
518526
#endif // FEATURE_COMINTEROP
519527

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

527532
BOOL PopNestedExceptionRecords(LPVOID pTargetSP, BOOL bCheckForUnknownHandlers = FALSE);
528533
VOID PopNestedExceptionRecords(LPVOID pTargetSP, T_CONTEXT *pCtx, void *pSEH);
529534

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-
537535
#define STACK_OVERWRITE_BARRIER_SIZE 20
538536
#define STACK_OVERWRITE_BARRIER_VALUE 0xabcdefab
539537

0 commit comments

Comments
 (0)