Fix Windows x86 exception handling issue (dotnet/coreclr#4830)
authorJan Vorlicek <janvorli@microsoft.com>
Fri, 6 May 2016 21:51:25 +0000 (23:51 +0200)
committerJan Vorlicek <janvorli@microsoft.com>
Fri, 6 May 2016 21:51:25 +0000 (23:51 +0200)
commitb332b59e5205dd16822cfda58aa3adaede75b702
tree8d2c6d9cfbcdeec2de640e46eed50bc8f81fff9e
parente24d1963433382a7da252c2c9c0610b7f8bbdc4d
Fix Windows x86 exception handling issue (dotnet/coreclr#4830)

This change fixes an exception handling issue that happens on x86 on Windows
when exception is raised in System.RuntimeType.MakeGenericType.
The problem was caused by GCPROTECT_HOLDER macro in RuntimeTypeHandle::GetTypeByName
that causes popping of GCFrame (and zeroing its m_next field) that's in the middle of the thread's frames list during
the stack unwinding.
That breaks the list and when UnwindFrames happen later and tries to walk the stack, the StackFrameIterator::NextRaw
asserts when checking the validity of the list.
The fix is to move the keepAlive to the managed caller of the RuntimeTypeHandle::GetTypeByName QCall, which removes
the need for the GCPROTECT_HOLDER.
Since it was the only usage of that holder and of the underlying FrameWithCookieHolder class, I've removed those.
In addition to that, I've modified COMModule::GetType and AssemblyNative::GetType to use the same pattern, since
they could also suffer from the problem the GCPROTECT_HOLDER was attempting to fix.

Commit migrated from https://github.com/dotnet/coreclr/commit/3c7e477ac50e50b616a64c72efb81388c045e63f
src/coreclr/src/mscorlib/src/System/Reflection/Assembly.cs
src/coreclr/src/mscorlib/src/System/Reflection/Module.cs
src/coreclr/src/mscorlib/src/System/RuntimeHandles.cs
src/coreclr/src/vm/assemblynative.cpp
src/coreclr/src/vm/assemblynative.hpp
src/coreclr/src/vm/commodule.cpp
src/coreclr/src/vm/commodule.h
src/coreclr/src/vm/excep.cpp
src/coreclr/src/vm/frames.h
src/coreclr/src/vm/runtimehandles.cpp
src/coreclr/src/vm/runtimehandles.h