diff options
author | Jan Kotas <jkotas@microsoft.com> | 2015-12-09 03:27:08 +0300 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2015-12-09 03:27:08 +0300 |
commit | c8ee7fb0e5f8273cfb26a0fc1aee8f3ee01585cd (patch) | |
tree | 1484267a976ca13573fe36240f5827a027576289 /src/Native | |
parent | d455aa270e712faa970e77225b5e74787f6851ab (diff) | |
parent | 8ec6efd7183c2ee6fc859d7a301d487224e90ae1 (diff) |
Merge pull request #502 from dotnet-bot/from-tfs
Merge changes from TFS
Diffstat (limited to 'src/Native')
-rw-r--r-- | src/Native/Runtime/EHHelpers.cpp | 11 | ||||
-rw-r--r-- | src/Native/Runtime/thread.cpp | 15 | ||||
-rw-r--r-- | src/Native/Runtime/thread.h | 1 |
3 files changed, 25 insertions, 2 deletions
diff --git a/src/Native/Runtime/EHHelpers.cpp b/src/Native/Runtime/EHHelpers.cpp index d83c1282e..22ce0051a 100644 --- a/src/Native/Runtime/EHHelpers.cpp +++ b/src/Native/Runtime/EHHelpers.cpp @@ -274,14 +274,16 @@ EXTERN_C Int32 __stdcall RhpPInvokeExceptionGuard(PEXCEPTION_RECORD pExcep if (pThread->IsDoNotTriggerGcSet()) RhFailFast(); + IntNative pinvokeCallsiteReturnAddr = (IntNative)pThread->GetCurrentThreadPInvokeReturnAddress(); + // We promote exceptions that were not converted to managed exceptions to a FailFast. However, we have to // be careful because we got here via OS SEH infrastructure and, therefore, don't know what GC mode we're // currently in. As a result, since we're calling back into managed code to handle the FailFast, we must // correctly call either a NativeCallable or a RuntimeExport version of the same method. if (pThread->IsCurrentThreadInCooperativeMode()) - RhpFailFastForPInvokeExceptionCoop((IntNative)pDispatcherContext->ControlPc, pExceptionRecord, pContextRecord); + RhpFailFastForPInvokeExceptionCoop(pinvokeCallsiteReturnAddr, pExceptionRecord, pContextRecord); else - RhpFailFastForPInvokeExceptionPreemp((IntNative)pDispatcherContext->ControlPc, pExceptionRecord, pContextRecord); + RhpFailFastForPInvokeExceptionPreemp(pinvokeCallsiteReturnAddr, pExceptionRecord, pContextRecord); return 0; } @@ -451,5 +453,10 @@ Int32 __stdcall RhpVectoredExceptionHandler(PEXCEPTION_POINTERS pExPtrs) } } +COOP_PINVOKE_HELPER(void, RhpFallbackFailFast, ()) +{ + RhFailFast(); +} + #endif // !DACCESS_COMPILE diff --git a/src/Native/Runtime/thread.cpp b/src/Native/Runtime/thread.cpp index 91ab8ec43..a814116e1 100644 --- a/src/Native/Runtime/thread.cpp +++ b/src/Native/Runtime/thread.cpp @@ -177,6 +177,21 @@ bool Thread::IsCurrentThreadInCooperativeMode() return (m_pTransitionFrame == NULL); } +// +// This is used by the EH system to find the place where execution left managed code when an exception leaks out of a +// pinvoke and we need to FailFast via the appropriate class library. +// +// May only be used from the same thread and while in preemptive mode with an active pinvoke on the stack. +// +#ifndef DACCESS_COMPILE +void * Thread::GetCurrentThreadPInvokeReturnAddress() +{ + ASSERT(ThreadStore::GetCurrentThread() == this); + ASSERT(!IsCurrentThreadInCooperativeMode()); + return ((PInvokeTransitionFrame*)m_pTransitionFrame)->m_RIP; +} +#endif // !DACCESS_COMPILE + PTR_UInt8 Thread::GetTEB() diff --git a/src/Native/Runtime/thread.h b/src/Native/Runtime/thread.h index aefc7e3d9..2fe85c23f 100644 --- a/src/Native/Runtime/thread.h +++ b/src/Native/Runtime/thread.h @@ -214,6 +214,7 @@ public: bool IsCurrentThreadInCooperativeMode(); PTR_VOID GetTransitionFrameForStackTrace(); + void * GetCurrentThreadPInvokeReturnAddress(); // ------------------------------------------------------------------------------------------------------- // LEGACY APIs: do not use except from GC itself |