Fix rethrow of managed exception from native code (#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)
commit91037acfac26eccd3ac17e58df3c7d0d0b2f645d
treeb0438fbbba2c1ff277f53073a6b57c7159c5492c
parentd6a00daeff8c7a799d3913eecd89daadbe14a2ac
Fix rethrow of managed exception from native code (#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.
src/pal/inc/pal.h
src/vm/exceptionhandling.cpp