Fix rethrow of managed exception from native code (dotnet/coreclr#5697)
authorJan Vorlicek <janvorli@microsoft.com>
Fri, 10 Jun 2016 21:44:24 +0000 (23:44 +0200)
committerGitHub <noreply@github.com>
Fri, 10 Jun 2016 21:44:24 +0000 (23:44 +0200)
commit77fbdf4489658d6011d437295081e6b9bfd38e52
treea76b38449c1462915df5bab47e29f7e6def0cceb
parent8c0f573445452b163282b268dd13e5c5b772c6d6
Fix rethrow of managed exception from native code (dotnet/coreclr#5697)

This change fixes a problem that happens when managed exception is caught
in native code, rethrown and then caught and passed to DispatchManagedException
to be propagated further through managed code frames.
The problem is that while the exception was rethrown, it still has the
TargetFrameSp member set to the frame that has caught it and so the
DispatchManagedException thinks it is just continuing to propagate it in the
second pass instead of starting a new first pass.
The UnwindManagedExceptionPass2 then asserts, because the TargetFrameSp is
below the frame it is about to process.

The fix is to reset the TargetFrameSp to NoTargetFrameSp when the exception
is caught in native code - in PAL_EXCEPT and EX_CATCH_IMPL_EX (which catches
all exceptions).

I have also added few stress log messages for processing exception in native
frames that helped debug the issue.

Commit migrated from https://github.com/dotnet/coreclr/commit/91037acfac26eccd3ac17e58df3c7d0d0b2f645d
src/coreclr/src/pal/inc/pal.h
src/coreclr/src/vm/exceptionhandling.cpp