From a06bea2813417c9d71449a6c54753122a9198404 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Tue, 27 Oct 2015 10:30:58 -0700 Subject: [PATCH] Add missing exception holder to EX_TRY When the exception handling was changed recently, the exception holder was added only to PAL_TRY / PAL_EXCEPT macros. But it needs to be in the EX_TRY as well, otherwise first pass of exception handling would incorrectly consider some exceptions unhandled. --- src/inc/ex.h | 22 ++++++++++++++++++---- src/pal/inc/pal.h | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/inc/ex.h b/src/inc/ex.h index 795c353fd8ed..d792911941dd 100644 --- a/src/inc/ex.h +++ b/src/inc/ex.h @@ -9,6 +9,15 @@ void RetailAssertIfExpectedClean(); // Defined in src/utilcode/debug.cpp +#ifdef FEATURE_PAL +#define EX_TRY_HOLDER \ + NativeExceptionHolderCatchAll __exceptionHolder; \ + __exceptionHolder.Push(); \ + +#else // FEATURE_PAL +#define EX_TRY_HOLDER +#endif // FEATURE_PAL + #ifdef CLR_STANDALONE_BINDER #define INCONTRACT(x) @@ -17,12 +26,16 @@ void RetailAssertIfExpectedClean(); // Defined in src/utilcode/debug void DECLSPEC_NORETURN ThrowLastError(); -#define EX_TRY try -#define EX_CATCH_HRESULT(_hr) catch (HRESULT hr) { _hr = hr; } -#define EX_CATCH catch(...) +#define EX_TRY \ + try \ + { \ + EX_TRY_HOLDER \ + +#define EX_CATCH_HRESULT(_hr) } catch (HRESULT hr) { _hr = hr; } +#define EX_CATCH } catch(...) #define EX_END_CATCH(a) #define EX_RETHROW throw -#define EX_SWALLOW_NONTERMINAL catch(...) {} +#define EX_SWALLOW_NONTERMINAL } catch(...) {} #define EX_END_CATCH_UNREACHABLE #define EX_CATCH_HRESULT_NO_ERRORINFO(_hr) \ EX_CATCH \ @@ -982,6 +995,7 @@ Exception *ExThrowWithInnerHelper(Exception *inner); { \ /* this is necessary for Rotor exception handling to work */ \ DEBUG_ASSURE_NO_RETURN_BEGIN(EX_TRY) \ + EX_TRY_HOLDER \ #define EX_CATCH_IMPL_EX(DerivedExceptionClass) \ diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h index 6cc997885776..cdf7ef704416 100644 --- a/src/pal/inc/pal.h +++ b/src/pal/inc/pal.h @@ -6796,6 +6796,25 @@ class NativeExceptionHolder : public NativeExceptionHolderBase } }; +// +// This is a native exception holder that is used when the catch catches +// all exceptions. +// +class NativeExceptionHolderCatchAll : public NativeExceptionHolderBase +{ + +public: + NativeExceptionHolderCatchAll() + : NativeExceptionHolderBase() + { + } + + virtual EXCEPTION_DISPOSITION InvokeFilter(PAL_SEHException& ex) + { + return EXCEPTION_EXECUTE_HANDLER; + } +}; + // // This factory class for the native exception holder is necessary because // templated functions don't need the explicit type parameter and can infer