diff options
Diffstat (limited to 'src/vm')
-rw-r--r-- | src/vm/corhost.cpp | 2 | ||||
-rw-r--r-- | src/vm/exceptionhandling.cpp | 7 | ||||
-rw-r--r-- | src/vm/exceptmacros.h | 22 |
3 files changed, 26 insertions, 5 deletions
diff --git a/src/vm/corhost.cpp b/src/vm/corhost.cpp index 451043fc45..161b2a1fae 100644 --- a/src/vm/corhost.cpp +++ b/src/vm/corhost.cpp @@ -1270,6 +1270,7 @@ HRESULT CorHost2::ExecuteAssembly(DWORD dwAppDomainId, return HOST_E_INVALIDOPERATION; } + INSTALL_UNHANDLED_MANAGED_EXCEPTION_TRAP; INSTALL_UNWIND_AND_CONTINUE_HANDLER; _ASSERTE (!pThread->PreemptiveGCDisabled()); @@ -1302,6 +1303,7 @@ HRESULT CorHost2::ExecuteAssembly(DWORD dwAppDomainId, } UNINSTALL_UNWIND_AND_CONTINUE_HANDLER; + UNINSTALL_UNHANDLED_MANAGED_EXCEPTION_TRAP; ErrExit: diff --git a/src/vm/exceptionhandling.cpp b/src/vm/exceptionhandling.cpp index 6a4d4d70c3..20035adbb0 100644 --- a/src/vm/exceptionhandling.cpp +++ b/src/vm/exceptionhandling.cpp @@ -4623,11 +4623,8 @@ VOID DECLSPEC_NORETURN UnwindManagedExceptionPass1(PAL_SEHException& ex) if (controlPc == 0) { - if (!GetThread()->HasThreadStateNC(Thread::TSNC_ProcessedUnhandledException)) - { - LONG disposition = InternalUnhandledExceptionFilter_Worker(&ex.ExceptionPointers); - _ASSERTE(disposition == EXCEPTION_CONTINUE_SEARCH); - } + // The unhandled exceptions should be caught by the high level exception filter + _ASSERTE(!"UnwindManagedExceptionPass1: Exception escaped the stack"); EEPOLICY_HANDLE_FATAL_ERROR(COR_E_EXECUTIONENGINE); } diff --git a/src/vm/exceptmacros.h b/src/vm/exceptmacros.h index 3c426fd3bd..0c66913aef 100644 --- a/src/vm/exceptmacros.h +++ b/src/vm/exceptmacros.h @@ -339,10 +339,32 @@ VOID DECLSPEC_NORETURN DispatchManagedException(PAL_SEHException& ex); DispatchManagedException(exCopy); \ } +// Install trap that catches unhandled managed exception and dumps its stack +#define INSTALL_UNHANDLED_MANAGED_EXCEPTION_TRAP \ + try { \ + auto exceptionFilter = [](PAL_SEHException& ex) \ + { \ + return EXCEPTION_EXECUTE_HANDLER; \ + }; \ + auto __exceptionHolder = NativeExceptionHolderFactory::CreateHolder(&exceptionFilter); \ + __exceptionHolder.Push(); + +// Uninstall trap that catches unhandled managed exception and dumps its stack +#define UNINSTALL_UNHANDLED_MANAGED_EXCEPTION_TRAP \ + } \ + catch (PAL_SEHException& ex) \ + { \ + LONG disposition = InternalUnhandledExceptionFilter_Worker(&ex.ExceptionPointers); \ + _ASSERTE(disposition == EXCEPTION_CONTINUE_SEARCH); \ + EEPOLICY_HANDLE_FATAL_ERROR(COR_E_EXECUTIONENGINE); \ + } + #else #define INSTALL_MANAGED_EXCEPTION_DISPATCHER #define UNINSTALL_MANAGED_EXCEPTION_DISPATCHER +#define INSTALL_UNHANDLED_MANAGED_EXCEPTION_TRAP +#define UNINSTALL_UNHANDLED_MANAGED_EXCEPTION_TRAP #endif // FEATURE_PAL |