Skip to content
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

Fix Win64 exception propagation in NativeCallable methods #33653

Merged
Merged
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
20 changes: 19 additions & 1 deletion src/coreclr/src/vm/exceptionhandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,8 @@ UINT_PTR ExceptionTracker::FinishSecondPass(
return uResumePC;
}

void CleanUpForSecondPass(Thread* pThread, bool fIsSO, LPVOID MemoryStackFpForFrameChain, LPVOID MemoryStackFp);

// On CoreARM, the MemoryStackFp is ULONG when passed by RtlDispatchException,
// unlike its 64bit counterparts.
EXTERN_C EXCEPTION_DISPOSITION
Expand Down Expand Up @@ -1262,6 +1264,22 @@ lExit: ;

if ((ExceptionContinueSearch == returnDisposition))
{
if (dwExceptionFlags & EXCEPTION_UNWINDING)
{
EECodeInfo codeInfo(pDispatcherContext->ControlPc);
if (codeInfo.IsValid())
{
GcInfoDecoder gcInfoDecoder(codeInfo.GetGCInfoToken(), DECODE_REVERSE_PINVOKE_VAR);
if (gcInfoDecoder.GetReversePInvokeFrameStackSlot() != NO_REVERSE_PINVOKE_FRAME)
{
// Exception is being propagated from a native callable method into its native caller.
// The explicit frame chain needs to be unwound at this boundary.
bool fIsSO = pExceptionRecord->ExceptionCode == STATUS_STACK_OVERFLOW;
CleanUpForSecondPass(pThread, fIsSO, (void*)MemoryStackFp, (void*)MemoryStackFp);
}
}
}

GCX_PREEMP_NO_DTOR();
}

Expand Down Expand Up @@ -5824,7 +5842,7 @@ BOOL IsSafeToUnwindFrameChain(Thread* pThread, LPVOID MemoryStackFpForFrameChain
// We're safe only if the managed method will be unwound also
LPVOID managedSP = dac_cast<PTR_VOID>(GetRegdisplaySP(&rd));

if (managedSP < MemoryStackFpForFrameChain)
if (managedSP <= MemoryStackFpForFrameChain)
{
return TRUE;
}
Expand Down