Skip to content

Commit 6e2274c

Browse files
authored
Fix exception propagation from managed to native on Unix (#112957)
* Fix exception propagation from managed to native on Unix The new exception handling on Unix doesn't prevent propagation of exceptions from managed to external native code like the old one did. Instead of reporting an unhandled exception, it rethrows the PAL_SEHException that later ends up being reported as C++ unhandled exception. This change fixes that behavior by enabling exception propagation from managed to native code only for the case when the native caller is CallDescrWorkerInternal. * Fix condition polarity When doing final rebasing on main where the IsCallDescrWorkerInternalReturnAddress was added in the meanwhile, I've acidentally caused the condition to be reverse for the added check. That caused the CI test failures. * Fix case of exception in filter The exception in filter was incorrectly rejected as coming from external native code
1 parent 621bddc commit 6e2274c

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/coreclr/vm/exceptionhandling.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -8565,6 +8565,8 @@ extern "C" bool QCALLTYPE SfiNext(StackFrameIterator* pThis, uint* uExCollideCla
85658565
DecodeGCHdrInfo(pThis->m_crawl.GetCodeInfo()->GetGCInfoToken(), 0, &gcHdrInfo);
85668566
invalidRevPInvoke = gcHdrInfo.revPInvokeOffset != INVALID_REV_PINVOKE_OFFSET;
85678567
#endif // USE_GC_INFO_DECODER
8568+
bool isFilterFunclet = false;
8569+
bool isPropagatingToExternalNativeCode = false;
85688570

85698571
if (invalidRevPInvoke)
85708572
{
@@ -8580,6 +8582,10 @@ extern "C" bool QCALLTYPE SfiNext(StackFrameIterator* pThis, uint* uExCollideCla
85808582
pTopExInfo->m_propagateExceptionCallback = callback;
85818583
pTopExInfo->m_propagateExceptionContext = callbackCxt;
85828584
}
8585+
else
8586+
{
8587+
isPropagatingToExternalNativeCode = true;
8588+
}
85838589
#endif // HOST_UNIX
85848590
}
85858591
else
@@ -8592,6 +8598,10 @@ extern "C" bool QCALLTYPE SfiNext(StackFrameIterator* pThis, uint* uExCollideCla
85928598
{
85938599
invalidRevPInvoke = true;
85948600
}
8601+
else
8602+
{
8603+
isPropagatingToExternalNativeCode = true;
8604+
}
85958605
}
85968606

85978607
if (fUnwoundReversePInvoke)
@@ -8612,7 +8622,12 @@ extern "C" bool QCALLTYPE SfiNext(StackFrameIterator* pThis, uint* uExCollideCla
86128622
// DebuggerU2MCatchHandlerFrame with CatchesAllExceptions() returning true).
86138623
// If not, the exception is unhandled.
86148624
if ((pFrame == FRAME_TOP) ||
8615-
(IsTopmostDebuggerU2MCatchHandlerFrame(pFrame) && !((DebuggerU2MCatchHandlerFrame*)pFrame)->CatchesAllExceptions()))
8625+
(IsTopmostDebuggerU2MCatchHandlerFrame(pFrame) && !((DebuggerU2MCatchHandlerFrame*)pFrame)->CatchesAllExceptions())
8626+
#ifdef HOST_UNIX
8627+
// Don't allow propagating exceptions from managed to non-runtime native code
8628+
|| isPropagatingToExternalNativeCode
8629+
#endif
8630+
)
86168631
{
86178632
if (pTopExInfo->m_passNumber == 1)
86188633
{

0 commit comments

Comments
 (0)