Skip to content

Interpreter EH support in the runtime #114649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ class AsmOffsets

#if TARGET_64BIT
public const int OFFSETOF__REGDISPLAY__m_pCurrentContext = 0x8;
#if FEATURE_INTERPRETER
public const int SIZEOF__StackFrameIterator = 0x170;
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x168;
#else
public const int SIZEOF__StackFrameIterator = 0x150;
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x132;
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x148;
#endif
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x132;
#elif TARGET_X86
public const int OFFSETOF__REGDISPLAY__m_pCurrentContext = 0x4;
public const int SIZEOF__StackFrameIterator = 0x3cc;
Expand Down Expand Up @@ -119,9 +124,14 @@ class AsmOffsets

#if TARGET_64BIT
public const int OFFSETOF__REGDISPLAY__m_pCurrentContext = 0x8;
#if FEATURE_INTERPRETER
public const int SIZEOF__StackFrameIterator = 0x168;
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x160;
#else
public const int SIZEOF__StackFrameIterator = 0x148;
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x12a;
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x140;
#endif
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x12a;
#elif TARGET_X86
public const int OFFSETOF__REGDISPLAY__m_pCurrentContext = 0x4;
public const int SIZEOF__StackFrameIterator = 0x3c4;
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/clr.featuredefines.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<FeatureEHFunclets>true</FeatureEHFunclets>
</PropertyGroup>

<PropertyGroup Condition="('$(Platform)' == 'x64' OR '$(Platform)' == 'arm64') AND ('$(Configuration)' == 'debug' OR '$(Configuration)' == 'checked')">
<FeatureInterpreter>true</FeatureInterpreter>
</PropertyGroup>

<PropertyGroup>
<DefineConstants Condition="'$(FeatureComWrappers)' == 'true'">$(DefineConstants);FEATURE_COMWRAPPERS</DefineConstants>
<DefineConstants Condition="'$(FeatureCominterop)' == 'true'">$(DefineConstants);FEATURE_COMINTEROP</DefineConstants>
Expand All @@ -36,6 +40,7 @@
<DefineConstants Condition="'$(FeatureXplatEventSource)' == 'true'">$(DefineConstants);FEATURE_EVENTSOURCE_XPLAT</DefineConstants>
<DefineConstants Condition="'$(FeatureTypeEquivalence)' == 'true'">$(DefineConstants);FEATURE_TYPEEQUIVALENCE</DefineConstants>
<DefineConstants Condition="'$(FeatureEHFunclets)' == 'true'">$(DefineConstants);FEATURE_EH_FUNCLETS</DefineConstants>
<DefineConstants Condition="'$(FeatureInterpreter)' == 'true'">$(DefineConstants);FEATURE_INTERPRETER</DefineConstants>

<DefineConstants Condition="'$(ProfilingSupportedBuild)' == 'true'">$(DefineConstants);PROFILING_SUPPORTED</DefineConstants>
</PropertyGroup>
Expand Down
13 changes: 13 additions & 0 deletions src/coreclr/inc/eetwain.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ virtual void LeaveCatch(GCInfoToken gcInfoToken,
PCONTEXT pCtx)=0;
#else // FEATURE_EH_FUNCLETS
virtual DWORD_PTR CallFunclet(OBJECTREF throwable, void* pHandler, REGDISPLAY *pRD, ExInfo *pExInfo, bool isFilter) = 0;
virtual void ResumeAfterCatch(CONTEXT *pContext, size_t targetSSP, bool fIntercepted) = 0;
#if defined(HOST_AMD64) && defined(HOST_WINDOWS)
virtual void UpdateSSP(PREGDISPLAY pRD) = 0;
#endif // HOST_AMD64 && HOST_WINDOWS
#endif // FEATURE_EH_FUNCLETS

#ifdef FEATURE_REMAP_FUNCTION
Expand Down Expand Up @@ -553,6 +557,11 @@ virtual void LeaveCatch(GCInfoToken gcInfoToken,
PCONTEXT pCtx);
#else // FEATURE_EH_FUNCLETS
virtual DWORD_PTR CallFunclet(OBJECTREF throwable, void* pHandler, REGDISPLAY *pRD, ExInfo *pExInfo, bool isFilter);
virtual void ResumeAfterCatch(CONTEXT *pContext, size_t targetSSP, bool fIntercepted);

#if defined(HOST_AMD64) && defined(HOST_WINDOWS)
virtual void UpdateSSP(PREGDISPLAY pRD);
#endif // HOST_AMD64 && HOST_WINDOWS
#endif // FEATURE_EH_FUNCLETS

#ifdef FEATURE_REMAP_FUNCTION
Expand Down Expand Up @@ -762,6 +771,10 @@ virtual void LeaveCatch(GCInfoToken gcInfoToken,
}
#else // FEATURE_EH_FUNCLETS
virtual DWORD_PTR CallFunclet(OBJECTREF throwable, void* pHandler, REGDISPLAY *pRD, ExInfo *pExInfo, bool isFilter);
virtual void ResumeAfterCatch(CONTEXT *pContext, size_t targetSSP, bool fIntercepted);
#if defined(HOST_AMD64) && defined(HOST_WINDOWS)
virtual void UpdateSSP(PREGDISPLAY pRD);
#endif // HOST_AMD64 && HOST_WINDOWS
#endif // FEATURE_EH_FUNCLETS

#ifdef FEATURE_REMAP_FUNCTION
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/interpreter/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3263,6 +3263,12 @@ int InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)
}
break;

case CEE_THROW:
AddIns(INTOP_THROW);
m_pLastNewIns->SetSVar(m_pStackPointer[-1].var);
m_ip += 1;
break;

default:
assert(0);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/interpreter/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class InterpCompiler
CORINFO_METHOD_INFO* m_methodInfo;
#ifdef DEBUG
const char *m_methodName;
bool m_verbose;
bool m_verbose = false;
#endif

static int32_t InterpGetMovForType(InterpType interpType, bool signExtend);
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/interpreter/intops.def
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ OPDEF(INTOP_CALL_HELPER_PP, "call.helper.pp", 5, 1, 0, InterpOpThreeInts)
OPDEF(INTOP_ZEROBLK_IMM, "zeroblk.imm", 3, 0, 1, InterpOpInt)
OPDEF(INTOP_LOCALLOC, "localloc", 3, 1, 1, InterpOpNoArgs)
OPDEF(INTOP_BREAKPOINT, "breakpoint", 1, 0, 0, InterpOpNoArgs)

OPDEF(INTOP_THROW, "throw", 4, 0, 1, InterpOpInt)

OPDEF(INTOP_FAILFAST, "failfast", 1, 0, 0, InterpOpNoArgs)
OPDEF(INTOP_GC_COLLECT, "gc.collect", 1, 0, 0, InterpOpNoArgs)

Expand Down
40 changes: 40 additions & 0 deletions src/coreclr/vm/amd64/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,46 @@ inline TADDR GetFP(const CONTEXT * context)
return (TADDR)(context->Rbp);
}

inline void SetFirstArgReg(CONTEXT *context, TADDR value)
{
LIMITED_METHOD_DAC_CONTRACT;
#ifdef UNIX_AMD64_ABI
context->Rdi = (DWORD64)value;
#else
context->Rcx = (DWORD64)value;
#endif
}

inline TADDR GetFirstArgReg(CONTEXT *context)
{
LIMITED_METHOD_DAC_CONTRACT;
#ifdef UNIX_AMD64_ABI
return (TADDR)(context->Rdi);
#else
return (TADDR)(context->Rcx);
#endif
}

inline void SetSecondArgReg(CONTEXT *context, TADDR value)
{
LIMITED_METHOD_DAC_CONTRACT;
#ifdef UNIX_AMD64_ABI
context->Rsi = (DWORD64)value;
#else
context->Rdx = (DWORD64)value;
#endif
}

inline TADDR GetSecondArgReg(CONTEXT *context)
{
LIMITED_METHOD_DAC_CONTRACT;
#ifdef UNIX_AMD64_ABI
return (TADDR)(context->Rsi);
#else
return (TADDR)(context->Rdx);
#endif
}

extern "C" TADDR GetCurrentSP();

// Emits:
Expand Down
24 changes: 24 additions & 0 deletions src/coreclr/vm/arm/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,30 @@ inline TADDR GetFP(const T_CONTEXT * context)
return (TADDR)(context->R11);
}

inline void SetFirstArgReg(T_CONTEXT *context, TADDR value)
{
LIMITED_METHOD_DAC_CONTRACT;
context->R0 = DWORD(value);
}

inline TADDR GetFirstArgReg(T_CONTEXT *context)
{
LIMITED_METHOD_DAC_CONTRACT;
return (TADDR)(context->R0);
}

inline void SetSecondArgReg(T_CONTEXT *context, TADDR value)
{
LIMITED_METHOD_DAC_CONTRACT;
context->R1 = DWORD(value);
}

inline TADDR GetSecondArgReg(T_CONTEXT *context)
{
LIMITED_METHOD_DAC_CONTRACT;
return (TADDR)(context->R1);
}

inline void ClearITState(T_CONTEXT *context) {
LIMITED_METHOD_DAC_CONTRACT;
context->Cpsr = context->Cpsr & 0xf9ff03ff;
Expand Down
23 changes: 23 additions & 0 deletions src/coreclr/vm/arm64/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,29 @@ inline TADDR GetFP(const T_CONTEXT * context)
return (TADDR)(context->Fp);
}

inline void SetFirstArgReg(T_CONTEXT *context, TADDR value)
{
LIMITED_METHOD_DAC_CONTRACT;
SetReg(context, 0, value);
}

inline TADDR GetFirstArgReg(T_CONTEXT *context)
{
LIMITED_METHOD_DAC_CONTRACT;
return GetReg(context, 0);
}

inline void SetSecondArgReg(T_CONTEXT *context, TADDR value)
{
LIMITED_METHOD_DAC_CONTRACT;
SetReg(context, 1, value);
}

inline TADDR GetSecondArgReg(T_CONTEXT *context)
{
LIMITED_METHOD_DAC_CONTRACT;
return GetReg(context, 1);
}

inline TADDR GetMem(PCODE address, SIZE_T size, bool signExtend)
{
Expand Down
Loading