Skip to content

Commit

Permalink
Fix handling of exceptions from JIT
Browse files Browse the repository at this point in the history
The `UNINSTALL_UNWIND_AND_CONTINUE_HANDLER_NO_PROBE` in the
`EE_TO_JIT_TRANSITION` needs to rethrow an exception (if any) using native
exception handling mechanism instead of calling the new managed
exception handling, as the native exception needs to propagate through
some native code layers from there.
This change adds parameter to the
`UNINSTALL_UNWIND_AND_CONTINUE_HANDLER_NO_PROBE` macro to select whether
to rethrow the exception as native or to invoke the new managed
exception handling.

This problem didn't show up until I ran the coreclr tests with tiered
compilation disabled.
  • Loading branch information
janvorli committed Aug 22, 2023
1 parent 278ba85 commit 28f603b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/coreclr/vm/excep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7771,7 +7771,7 @@ void UnwindAndContinueRethrowHelperInsideCatch(Frame* pEntryFrame, Exception* pE
// This does the work of the Unwind and Continue Hanlder after the catch clause of that handler. The stack has been
// unwound by the time this is called. Keep that in mind when deciding where to put new code :)
//
VOID DECLSPEC_NORETURN UnwindAndContinueRethrowHelperAfterCatch(Frame* pEntryFrame, Exception* pException)
VOID DECLSPEC_NORETURN UnwindAndContinueRethrowHelperAfterCatch(Frame* pEntryFrame, Exception* pException, bool nativeRethrow)
{
STATIC_CONTRACT_THROWS;
STATIC_CONTRACT_GC_TRIGGERS;
Expand All @@ -7788,7 +7788,7 @@ VOID DECLSPEC_NORETURN UnwindAndContinueRethrowHelperAfterCatch(Frame* pEntryFra
Exception::Delete(pException);

#ifdef FEATURE_EH_FUNCLETS
if (g_isNewExceptionHandlingEnabled)
if (g_isNewExceptionHandlingEnabled && !nativeRethrow)
{
DispatchManagedException(orThrowable);
}
Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/vm/exceptmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ VOID DECLSPEC_NORETURN RaiseTheExceptionInternalOnly(OBJECTREF throwable, BOOL r
#else // DACCESS_COMPILE

void UnwindAndContinueRethrowHelperInsideCatch(Frame* pEntryFrame, Exception* pException);
VOID DECLSPEC_NORETURN UnwindAndContinueRethrowHelperAfterCatch(Frame* pEntryFrame, Exception* pException);
VOID DECLSPEC_NORETURN UnwindAndContinueRethrowHelperAfterCatch(Frame* pEntryFrame, Exception* pException, bool nativeRethrow);

#ifdef TARGET_UNIX
VOID DECLSPEC_NORETURN DispatchManagedException(PAL_SEHException& ex, bool isHardwareException);
Expand Down Expand Up @@ -349,7 +349,7 @@ VOID DECLSPEC_NORETURN DispatchManagedException(PAL_SEHException& ex, bool isHar
SCAN_EHMARKER_TRY(); \
DEBUG_ASSURE_NO_RETURN_BEGIN(IUACH);

#define UNINSTALL_UNWIND_AND_CONTINUE_HANDLER_NO_PROBE \
#define UNINSTALL_UNWIND_AND_CONTINUE_HANDLER_NO_PROBE(nativeRethrow) \
DEBUG_ASSURE_NO_RETURN_END(IUACH) \
SCAN_EHMARKER_END_TRY(); \
} \
Expand All @@ -366,12 +366,12 @@ VOID DECLSPEC_NORETURN DispatchManagedException(PAL_SEHException& ex, bool isHar
if (__fExceptionCaught) \
{ \
SCAN_EHMARKER_CATCH(); \
UnwindAndContinueRethrowHelperAfterCatch(__pUnCEntryFrame, __pUnCException); \
UnwindAndContinueRethrowHelperAfterCatch(__pUnCEntryFrame, __pUnCException, nativeRethrow); \
} \
} \

#define UNINSTALL_UNWIND_AND_CONTINUE_HANDLER \
UNINSTALL_UNWIND_AND_CONTINUE_HANDLER_NO_PROBE;
UNINSTALL_UNWIND_AND_CONTINUE_HANDLER_NO_PROBE(false);

#endif // DACCESS_COMPILE

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ __thread uint32_t t_GCThreadStaticBlocksSize;
COOPERATIVE_TRANSITION_BEGIN(); \

#define EE_TO_JIT_TRANSITION() COOPERATIVE_TRANSITION_END(); \
UNINSTALL_UNWIND_AND_CONTINUE_HANDLER_NO_PROBE;
UNINSTALL_UNWIND_AND_CONTINUE_HANDLER_NO_PROBE(true);

#define JIT_TO_EE_TRANSITION_LEAF()
#define EE_TO_JIT_TRANSITION_LEAF()
Expand Down

0 comments on commit 28f603b

Please sign in to comment.