Skip to content

Commit 28f603b

Browse files
committed
Fix handling of exceptions from JIT
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.
1 parent 278ba85 commit 28f603b

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/coreclr/vm/excep.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -7771,7 +7771,7 @@ void UnwindAndContinueRethrowHelperInsideCatch(Frame* pEntryFrame, Exception* pE
77717771
// This does the work of the Unwind and Continue Hanlder after the catch clause of that handler. The stack has been
77727772
// unwound by the time this is called. Keep that in mind when deciding where to put new code :)
77737773
//
7774-
VOID DECLSPEC_NORETURN UnwindAndContinueRethrowHelperAfterCatch(Frame* pEntryFrame, Exception* pException)
7774+
VOID DECLSPEC_NORETURN UnwindAndContinueRethrowHelperAfterCatch(Frame* pEntryFrame, Exception* pException, bool nativeRethrow)
77757775
{
77767776
STATIC_CONTRACT_THROWS;
77777777
STATIC_CONTRACT_GC_TRIGGERS;
@@ -7788,7 +7788,7 @@ VOID DECLSPEC_NORETURN UnwindAndContinueRethrowHelperAfterCatch(Frame* pEntryFra
77887788
Exception::Delete(pException);
77897789

77907790
#ifdef FEATURE_EH_FUNCLETS
7791-
if (g_isNewExceptionHandlingEnabled)
7791+
if (g_isNewExceptionHandlingEnabled && !nativeRethrow)
77927792
{
77937793
DispatchManagedException(orThrowable);
77947794
}

src/coreclr/vm/exceptmacros.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ VOID DECLSPEC_NORETURN RaiseTheExceptionInternalOnly(OBJECTREF throwable, BOOL r
272272
#else // DACCESS_COMPILE
273273

274274
void UnwindAndContinueRethrowHelperInsideCatch(Frame* pEntryFrame, Exception* pException);
275-
VOID DECLSPEC_NORETURN UnwindAndContinueRethrowHelperAfterCatch(Frame* pEntryFrame, Exception* pException);
275+
VOID DECLSPEC_NORETURN UnwindAndContinueRethrowHelperAfterCatch(Frame* pEntryFrame, Exception* pException, bool nativeRethrow);
276276

277277
#ifdef TARGET_UNIX
278278
VOID DECLSPEC_NORETURN DispatchManagedException(PAL_SEHException& ex, bool isHardwareException);
@@ -349,7 +349,7 @@ VOID DECLSPEC_NORETURN DispatchManagedException(PAL_SEHException& ex, bool isHar
349349
SCAN_EHMARKER_TRY(); \
350350
DEBUG_ASSURE_NO_RETURN_BEGIN(IUACH);
351351

352-
#define UNINSTALL_UNWIND_AND_CONTINUE_HANDLER_NO_PROBE \
352+
#define UNINSTALL_UNWIND_AND_CONTINUE_HANDLER_NO_PROBE(nativeRethrow) \
353353
DEBUG_ASSURE_NO_RETURN_END(IUACH) \
354354
SCAN_EHMARKER_END_TRY(); \
355355
} \
@@ -366,12 +366,12 @@ VOID DECLSPEC_NORETURN DispatchManagedException(PAL_SEHException& ex, bool isHar
366366
if (__fExceptionCaught) \
367367
{ \
368368
SCAN_EHMARKER_CATCH(); \
369-
UnwindAndContinueRethrowHelperAfterCatch(__pUnCEntryFrame, __pUnCException); \
369+
UnwindAndContinueRethrowHelperAfterCatch(__pUnCEntryFrame, __pUnCException, nativeRethrow); \
370370
} \
371371
} \
372372

373373
#define UNINSTALL_UNWIND_AND_CONTINUE_HANDLER \
374-
UNINSTALL_UNWIND_AND_CONTINUE_HANDLER_NO_PROBE;
374+
UNINSTALL_UNWIND_AND_CONTINUE_HANDLER_NO_PROBE(false);
375375

376376
#endif // DACCESS_COMPILE
377377

src/coreclr/vm/jitinterface.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ __thread uint32_t t_GCThreadStaticBlocksSize;
9696
COOPERATIVE_TRANSITION_BEGIN(); \
9797

9898
#define EE_TO_JIT_TRANSITION() COOPERATIVE_TRANSITION_END(); \
99-
UNINSTALL_UNWIND_AND_CONTINUE_HANDLER_NO_PROBE;
99+
UNINSTALL_UNWIND_AND_CONTINUE_HANDLER_NO_PROBE(true);
100100

101101
#define JIT_TO_EE_TRANSITION_LEAF()
102102
#define EE_TO_JIT_TRANSITION_LEAF()

0 commit comments

Comments
 (0)