Skip to content

Commit 5811908

Browse files
authored
Fix EH transition on native to interpreted boundary (#120378)
* Fix EH transition on native to interpreted boundary There is a case where an interpreted code is called by CallDescrWorker and the code that called the CallDescrWorker was invoked via pinvoke. In that case, the SfiNextWorker was not detecting that the exception propagates to CallDescrWorker due to the fact that the final StackFrameIterator::GetFrameState() was returning SFITER_FRAME_FUNCTION for the next pinvoke and not reporting any intermediate SFITER_NATIVE_MARKER_FRAME. * Fix Unix build break
1 parent e85aa94 commit 5811908

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/coreclr/vm/exceptionhandling.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3899,15 +3899,19 @@ CLR_BOOL SfiNextWorker(StackFrameIterator* pThis, uint* uExCollideClauseIdx, CLR
38993899
bool doingFuncletUnwind = pThis->m_crawl.IsFunclet();
39003900
PCODE preUnwindControlPC = pThis->m_crawl.GetRegisterSet()->ControlPC;
39013901

3902+
bool isNativeTransition;
3903+
39023904
retVal = pThis->Next();
39033905
if (retVal == SWA_FAILED)
39043906
{
39053907
EH_LOG((LL_INFO100, "SfiNext (pass=%d): failed to get next frame", pTopExInfo->m_passNumber));
39063908
goto Exit;
39073909
}
39083910

3911+
isNativeTransition = (pThis->GetFrameState() == StackFrameIterator::SFITER_NATIVE_MARKER_FRAME);
3912+
39093913
#ifdef FEATURE_INTERPRETER
3910-
if ((pThis->GetFrameState() == StackFrameIterator::SFITER_NATIVE_MARKER_FRAME) &&
3914+
if (isNativeTransition &&
39113915
(GetIP(pThis->m_crawl.GetRegisterSet()->pCurrentContext) == InterpreterFrame::DummyCallerIP))
39123916
{
39133917
// The callerIP is InterpreterFrame::DummyCallerIP when we are going to unwind from the first interpreted frame belonging to an InterpreterFrame.
@@ -3931,15 +3935,16 @@ CLR_BOOL SfiNextWorker(StackFrameIterator* pThis, uint* uExCollideClauseIdx, CLR
39313935
pInterpreterFrame->UpdateRegDisplay(pThis->m_crawl.GetRegisterSet(), /* updateFloats */ true);
39323936
}
39333937
}
3938+
else
3939+
{
3940+
// The caller of the interpreted code is managed.
3941+
isNativeTransition = false;
3942+
}
39343943
}
39353944
#endif // FEATURE_INTERPRETER
39363945

39373946
// Check for reverse pinvoke or CallDescrWorkerInternal.
3938-
if ((pThis->GetFrameState() == StackFrameIterator::SFITER_NATIVE_MARKER_FRAME)
3939-
#ifdef FEATURE_INTERPRETER
3940-
|| (pThis->GetFrameState() == StackFrameIterator::SFITER_DONE)
3941-
#endif // FEATURE_INTERPRETER
3942-
)
3947+
if (isNativeTransition)
39433948
{
39443949
EECodeInfo codeInfo(preUnwindControlPC);
39453950
#ifdef USE_GC_INFO_DECODER

0 commit comments

Comments
 (0)