Fix Unix exception handling in finalizers
authorJan Vorlicek <janvorli@microsoft.com>
Mon, 7 Mar 2016 22:09:45 +0000 (23:09 +0100)
committerJan Vorlicek <janvorli@microsoft.com>
Tue, 8 Mar 2016 17:08:55 +0000 (18:08 +0100)
commit4d0fc442b272f3cb359f45681823ce95491bed65
tree8440f8e85c1cf1de69d526e5145200908dacad7d
parentc83c1dc29f5794ca3c7d1d6deb6238a947368a21
Fix Unix exception handling in finalizers

When unhandled exception happens in a finalizer thread and there are
no managed frames till the bottom of the stack,
the Thread::VirtualUnwindToFirstManagedCallFrame then fails fast.
The fix is to make the Thread::VirtualUnwindToFirstManagedCallFrame to
return even in case no managed frame is called, which is indicated by
its returning 0 as the resulting IP address. The DispatchManagedException
then checks that and rethrows the exception instead of trying to call
UnwindManagedExceptionPass1.
I have also added INSTALL_UNHANDLED_MANAGED_EXCEPTION_TRAP to the
FinalizerThread::FinalizerThreadStart so that the unhandled exception
doesn't escape the stack.
And I also needed to modify the UNINSTALL_UNHANDLED_MANAGED_EXCEPTION_TRAP
to detect case when the unhandled exception filter was already executed so
that it doesn't double-report the unhandled exception.

Commit migrated from https://github.com/dotnet/coreclr/commit/7f5d0a5b0546edf283e855d3ae95283485d180ea
src/coreclr/src/vm/exceptionhandling.cpp
src/coreclr/src/vm/exceptmacros.h
src/coreclr/src/vm/finalizerthread.cpp
src/coreclr/src/vm/stackwalk.cpp