From c668ca03cff6b702eb0ff19c4b35d9e5d9ccee92 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 15 Jun 2024 15:59:48 +0800 Subject: [PATCH 1/9] Guard GetErrorInfo and SetErrorInfo under COMINTEROP --- src/coreclr/inc/ex.h | 6 ++++++ src/coreclr/utilcode/ex.cpp | 4 ++++ src/coreclr/vm/clrex.cpp | 14 ++------------ src/coreclr/vm/clrex.h | 17 +++++++++++++++++ 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/coreclr/inc/ex.h b/src/coreclr/inc/ex.h index 50949d62f01384..a5f0e37d2da939 100644 --- a/src/coreclr/inc/ex.h +++ b/src/coreclr/inc/ex.h @@ -192,8 +192,10 @@ class Exception virtual BOOL IsDomainBound() {return m_innerException!=NULL && m_innerException->IsDomainBound();} ; virtual HRESULT GetHR() = 0; virtual void GetMessage(SString &s); +#ifdef FEATURE_COMINTEROP virtual IErrorInfo *GetErrorInfo() { LIMITED_METHOD_CONTRACT; return NULL; } virtual HRESULT SetErrorInfo() { LIMITED_METHOD_CONTRACT; return S_OK; } +#endif void SetInnerException(Exception * pInnerException) { LIMITED_METHOD_CONTRACT; m_innerException = pInnerException; } // Dynamic type query for catchers @@ -488,7 +490,9 @@ class SEHException : public Exception // Virtual overrides HRESULT GetHR(); +#ifdef FEATURE_COMINTEROP IErrorInfo *GetErrorInfo(); +#endif void GetMessage(SString &result); protected: @@ -533,7 +537,9 @@ class DelegatingException : public Exception // Virtual overrides virtual BOOL IsDomainBound() {return Exception::IsDomainBound() ||(m_delegatedException!=NULL && m_delegatedException->IsDomainBound());} ; HRESULT GetHR(); +#ifdef FEATURE_COMINTEROP IErrorInfo *GetErrorInfo(); +#endif void GetMessage(SString &result); virtual Exception *Clone(); diff --git a/src/coreclr/utilcode/ex.cpp b/src/coreclr/utilcode/ex.cpp index adee9ba55618ca..c50195751079ee 100644 --- a/src/coreclr/utilcode/ex.cpp +++ b/src/coreclr/utilcode/ex.cpp @@ -811,11 +811,13 @@ HRESULT SEHException::GetHR() return m_exception.ExceptionCode; } +#ifdef FEATURE_COMINTEROP IErrorInfo *SEHException::GetErrorInfo() { LIMITED_METHOD_CONTRACT; return NULL; } +#endif void SEHException::GetMessage(SString &string) { @@ -896,6 +898,7 @@ HRESULT DelegatingException::GetHR() } // HRESULT DelegatingException::GetHR() +#ifdef FEATURE_COMINTEROP //------------------------------------------------------------------------------ IErrorInfo *DelegatingException::GetErrorInfo() { @@ -909,6 +912,7 @@ IErrorInfo *DelegatingException::GetErrorInfo() return pDelegate ? pDelegate->GetErrorInfo() : NULL; } // IErrorInfo *DelegatingException::GetErrorInfo() +#endif //------------------------------------------------------------------------------ void DelegatingException::GetMessage(SString &result) diff --git a/src/coreclr/vm/clrex.cpp b/src/coreclr/vm/clrex.cpp index 7b68ac1dcba82e..7ebdac6385a500 100644 --- a/src/coreclr/vm/clrex.cpp +++ b/src/coreclr/vm/clrex.cpp @@ -366,18 +366,6 @@ IErrorInfo *CLRException::GetErrorInfo() // return the IErrorInfo we got... return pErrorInfo; } -#else // FEATURE_COMINTEROP -IErrorInfo *CLRException::GetErrorInfo() -{ - LIMITED_METHOD_CONTRACT; - return NULL; -} -HRESULT CLRException::SetErrorInfo() -{ - LIMITED_METHOD_CONTRACT; - - return S_OK; - } #endif // FEATURE_COMINTEROP void CLRException::GetMessage(SString &result) @@ -938,12 +926,14 @@ HRESULT EEException::GetHR() return EEException::GetHRFromKind(m_kind); } +#ifdef FEATURE_COMINTEROP IErrorInfo *EEException::GetErrorInfo() { LIMITED_METHOD_CONTRACT; return NULL; } +#endif BOOL EEException::GetThrowableMessage(SString &result) { diff --git a/src/coreclr/vm/clrex.h b/src/coreclr/vm/clrex.h index 586798f397fab3..752de941a187cf 100644 --- a/src/coreclr/vm/clrex.h +++ b/src/coreclr/vm/clrex.h @@ -129,8 +129,10 @@ class CLRException : public Exception } HRESULT GetHR(); +#ifdef FEATURE_COMINTEROP IErrorInfo *GetErrorInfo(); HRESULT SetErrorInfo(); +#endif void GetMessage(SString &result); @@ -222,7 +224,9 @@ class EEException : public CLRException // Virtual overrides HRESULT GetHR(); +#ifdef FEATURE_COMINTEROP IErrorInfo *GetErrorInfo(); +#endif void GetMessage(SString &result); OBJECTREF CreateThrowable(); @@ -842,6 +846,7 @@ LONG CLRNoCatchHandler(EXCEPTION_POINTERS* pExceptionInfo, PVOID pv); // // Thus, the scoped use of FAULT_NOT_FATAL macro. #undef EX_CATCH_HRESULT +#ifdef FEATURE_COMINTEROP #define EX_CATCH_HRESULT(_hr) \ EX_CATCH \ { \ @@ -857,6 +862,18 @@ LONG CLRNoCatchHandler(EXCEPTION_POINTERS* pExceptionInfo, PVOID pv); _ASSERTE(FAILED(_hr)); \ } \ EX_END_CATCH(SwallowAllExceptions) +#else // FEATURE_COMINTEROP +#define EX_CATCH_HRESULT(_hr) \ + EX_CATCH \ + { \ + (_hr) = GET_EXCEPTION()->GetHR(); \ + { \ + FAULT_NOT_FATAL(); \ + } \ + _ASSERTE(FAILED(_hr)); \ + } \ + EX_END_CATCH(SwallowAllExceptions) +#endif // FEATURE_COMINTEROP #endif // !DACCESS_COMPILE From 782cacdf984040cb21f8d041a8b77bb2f264a6eb Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 15 Jun 2024 16:10:37 +0800 Subject: [PATCH 2/9] Guard more IErrorInfo usage --- src/coreclr/inc/ex.h | 2 ++ src/coreclr/vm/clrex.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/coreclr/inc/ex.h b/src/coreclr/inc/ex.h index a5f0e37d2da939..bfbc3f5cbe20d8 100644 --- a/src/coreclr/inc/ex.h +++ b/src/coreclr/inc/ex.h @@ -434,8 +434,10 @@ class COMException : public HRException { friend bool DebugIsEECxxExceptionPointer(void* pv); +#ifdef FEATURE_COMINTEROP private: IErrorInfo *m_pErrorInfo; +#endif public: COMException(); diff --git a/src/coreclr/vm/clrex.cpp b/src/coreclr/vm/clrex.cpp index 7ebdac6385a500..0f09c2b5dff012 100644 --- a/src/coreclr/vm/clrex.cpp +++ b/src/coreclr/vm/clrex.cpp @@ -686,6 +686,7 @@ OBJECTREF CLRException::GetThrowableFromException(Exception *pException) } else { +#ifdef FEATURE_COMINTEROP SafeComHolder pErrInfo(pException->GetErrorInfo()); if (pErrInfo != NULL) @@ -693,6 +694,7 @@ OBJECTREF CLRException::GetThrowableFromException(Exception *pException) GetExceptionForHR(hr, pErrInfo, &oRetVal); } else +#endif { SString message; pException->GetMessage(message); From c50c0e14ada417877c3d395915e87f79d0282e07 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 15 Jun 2024 16:23:00 +0800 Subject: [PATCH 3/9] Guard GetExceptionForHR usage --- src/coreclr/vm/excep.cpp | 19 ++++++++++++++----- src/coreclr/vm/excep.h | 2 ++ src/coreclr/vm/marshalnative.cpp | 6 +++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/coreclr/vm/excep.cpp b/src/coreclr/vm/excep.cpp index c29505dc1a1774..320f39f254ab65 100644 --- a/src/coreclr/vm/excep.cpp +++ b/src/coreclr/vm/excep.cpp @@ -2989,7 +2989,6 @@ void FreeExceptionData(ExceptionData *pedata) if (pedata->bstrHelpFile) SysFreeString(pedata->bstrHelpFile); } -#endif // FEATURE_COMINTEROP void GetExceptionForHR(HRESULT hr, IErrorInfo* pErrInfo, OBJECTREF* pProtectedThrowable) { @@ -3005,7 +3004,6 @@ void GetExceptionForHR(HRESULT hr, IErrorInfo* pErrInfo, OBJECTREF* pProtectedTh // Initialize *pProtectedThrowable = NULL; -#if defined(FEATURE_COMINTEROP) if (pErrInfo != NULL) { // If this represents a managed object... @@ -3039,7 +3037,6 @@ void GetExceptionForHR(HRESULT hr, IErrorInfo* pErrInfo, OBJECTREF* pProtectedTh (*pProtectedThrowable) = ex.GetThrowable(); } } -#endif // defined(FEATURE_COMINTEROP) // If we made it here and we don't have an exception object, we didn't have a valid IErrorInfo // so we'll create an exception based solely on the hresult. @@ -3062,14 +3059,26 @@ void GetExceptionForHR(HRESULT hr, OBJECTREF* pProtectedThrowable) // Get an IErrorInfo if one is available. IErrorInfo *pErrInfo = NULL; -#ifdef FEATURE_COMINTEROP if (SafeGetErrorInfo(&pErrInfo) != S_OK) pErrInfo = NULL; -#endif // FEATURE_COMINTEROP GetExceptionForHR(hr, pErrInfo, pProtectedThrowable); } +#else +void GetExceptionForHR(HRESULT hr, OBJECTREF* pProtectedThrowable) +{ + CONTRACTL + { + THROWS; + GC_TRIGGERS; // because of IErrorInfo + MODE_ANY; + } + CONTRACTL_END; + EEMessageException ex(hr); + (*pProtectedThrowable) = ex.GetThrowable(); +} +#endif // FEATURE_COMINTEROP // // Maps a Win32 fault to a COM+ Exception enumeration code diff --git a/src/coreclr/vm/excep.h b/src/coreclr/vm/excep.h index 8e8ddacabe6b72..e8e8cd580df528 100644 --- a/src/coreclr/vm/excep.h +++ b/src/coreclr/vm/excep.h @@ -359,7 +359,9 @@ void ExceptionPreserveStackTrace(OBJECTREF throwable); // Create an exception object for an HRESULT //========================================================================== +#ifdef FEATURE_COMINTEROP void GetExceptionForHR(HRESULT hr, IErrorInfo* pErrInfo, OBJECTREF* pProtectedThrowable); +#endif void GetExceptionForHR(HRESULT hr, OBJECTREF* pProtectedThrowable); HRESULT GetHRFromThrowable(OBJECTREF throwable); diff --git a/src/coreclr/vm/marshalnative.cpp b/src/coreclr/vm/marshalnative.cpp index a71ec7d00c49b0..8b20efe4a3f6e5 100644 --- a/src/coreclr/vm/marshalnative.cpp +++ b/src/coreclr/vm/marshalnative.cpp @@ -438,9 +438,9 @@ extern "C" void QCALLTYPE MarshalNative_GetExceptionForHR(INT32 errorCode, LPVOI BEGIN_QCALL; +#ifdef FEATURE_COMINTEROP // Retrieve the IErrorInfo to use. IErrorInfo* pErrorInfo = (IErrorInfo*)errorInfo; -#ifdef FEATURE_COMINTEROP if (pErrorInfo == (IErrorInfo*)(-1)) { pErrorInfo = NULL; @@ -456,7 +456,11 @@ extern "C" void QCALLTYPE MarshalNative_GetExceptionForHR(INT32 errorCode, LPVOI OBJECTREF exceptObj = NULL; GCPROTECT_BEGIN(exceptObj); +#ifdef FEATURE_COMINTEROP ::GetExceptionForHR(errorCode, pErrorInfo, &exceptObj); +#else + ::GetExceptionForHR(errorCode, &exceptObj); +#endif // FEATURE_COMINTEROP retVal.Set(exceptObj); GCPROTECT_END(); From 938bfa4a92dea58b6401bf976e5a929f4e9db261 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 15 Jun 2024 16:36:08 +0800 Subject: [PATCH 4/9] Guard RealCOMPlusThrowHR --- src/coreclr/vm/excep.cpp | 19 ++++++++++++++----- src/coreclr/vm/excep.h | 2 ++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/coreclr/vm/excep.cpp b/src/coreclr/vm/excep.cpp index 320f39f254ab65..47eabfcae46563 100644 --- a/src/coreclr/vm/excep.cpp +++ b/src/coreclr/vm/excep.cpp @@ -11211,6 +11211,7 @@ VOID DECLSPEC_NORETURN RealCOMPlusThrowNonLocalized(RuntimeExceptionKind reKind, //========================================================================== // Throw a runtime exception based on an HResult //========================================================================== +#ifdef FEATURE_COMINTEROP VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr, IErrorInfo* pErrInfo, Exception * pInnerException) { CONTRACTL @@ -11233,7 +11234,6 @@ VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr, IErrorInfo* pErrInfo, Exce //_ASSERTE((hr != COR_E_EXECUTIONENGINE) || // !"ExecutionEngineException shouldn't be thrown. Use EEPolicy to failfast or a better exception. The caller of this function should modify their code."); -#ifdef FEATURE_COMINTEROP // check for complus created IErrorInfo pointers if (pErrInfo != NULL) { @@ -11247,9 +11247,7 @@ VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr, IErrorInfo* pErrInfo, Exce GCPROTECT_END (); } } -#endif // FEATURE_COMINTEROP - _ASSERTE((pErrInfo == NULL) || !"pErrInfo should always be null when FEATURE_COMINTEROP is disabled."); if (pInnerException == NULL) { EX_THROW(EEMessageException, (hr)); @@ -11281,8 +11279,6 @@ VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr) RealCOMPlusThrowHR(hr, (IErrorInfo*)NULL); } - -#ifdef FEATURE_COMINTEROP VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr, tagGetErrorInfo) { CONTRACTL @@ -11302,6 +11298,19 @@ VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr, tagGetErrorInfo) // Throw the exception. RealCOMPlusThrowHR(hr, pErrInfo); } +#else // FEATURE_COMINTEROP +VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr) +{ + CONTRACTL + { + THROWS; + DISABLED(GC_NOTRIGGER); // Must sanitize first pass handling to enable this + MODE_ANY; + } + CONTRACTL_END; + + EX_THROW(EEMessageException, (hr)); +} #endif // FEATURE_COMINTEROP diff --git a/src/coreclr/vm/excep.h b/src/coreclr/vm/excep.h index e8e8cd580df528..a380edd585f351 100644 --- a/src/coreclr/vm/excep.h +++ b/src/coreclr/vm/excep.h @@ -286,7 +286,9 @@ VOID DECLSPEC_NORETURN RealCOMPlusThrow(RuntimeExceptionKind reKind, UINT resID // passed as the first substitution string (%1). //========================================================================== +#ifdef FEATURE_COMINTEROP VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr, IErrorInfo* pErrInfo, Exception * pInnerException = NULL); +#endif VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr); VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr, UINT resID, LPCWSTR wszArg1 = NULL, LPCWSTR wszArg2 = NULL, LPCWSTR wszArg3 = NULL, LPCWSTR wszArg4 = NULL, LPCWSTR wszArg5 = NULL, From 6700f23f76e62916a69b67ac831d3aa0505bb115 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 15 Jun 2024 16:39:12 +0800 Subject: [PATCH 5/9] Delete dummy oaild.h --- src/coreclr/pal/inc/rt/oaidl.h | 18 ------------------ src/coreclr/pal/inc/rt/ole2.h | 1 - src/coreclr/pal/inc/rt/oleauto.h | 1 - src/coreclr/pal/prebuilt/inc/metahost.h | 1 - 4 files changed, 21 deletions(-) delete mode 100644 src/coreclr/pal/inc/rt/oaidl.h diff --git a/src/coreclr/pal/inc/rt/oaidl.h b/src/coreclr/pal/inc/rt/oaidl.h deleted file mode 100644 index ed7491c5840e1d..00000000000000 --- a/src/coreclr/pal/inc/rt/oaidl.h +++ /dev/null @@ -1,18 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// - -// -// =========================================================================== -// File: oaidl.h -// -// =========================================================================== - -#ifndef __OAIDL_H__ -#define __OAIDL_H__ - -// Pointer to IErrorInfo is still used in non-Windows code -// Prevent accidentally using its member -struct IErrorInfo; - -#endif //__OAIDL_H__ diff --git a/src/coreclr/pal/inc/rt/ole2.h b/src/coreclr/pal/inc/rt/ole2.h index f51d41e04b057f..260e051b43fcab 100644 --- a/src/coreclr/pal/inc/rt/ole2.h +++ b/src/coreclr/pal/inc/rt/ole2.h @@ -7,5 +7,4 @@ #include "objidl.h" #include "servprov.h" -#include "oaidl.h" diff --git a/src/coreclr/pal/inc/rt/oleauto.h b/src/coreclr/pal/inc/rt/oleauto.h index 15db2c3912e9a7..663faf6be54d24 100644 --- a/src/coreclr/pal/inc/rt/oleauto.h +++ b/src/coreclr/pal/inc/rt/oleauto.h @@ -11,7 +11,6 @@ #ifndef _OLEAUTO_H_ #define _OLEAUTO_H_ -#include "oaidl.h" #ifndef BEGIN_INTERFACE #define BEGIN_INTERFACE diff --git a/src/coreclr/pal/prebuilt/inc/metahost.h b/src/coreclr/pal/prebuilt/inc/metahost.h index e35cb6e140679f..e0fc0fc0680373 100644 --- a/src/coreclr/pal/prebuilt/inc/metahost.h +++ b/src/coreclr/pal/prebuilt/inc/metahost.h @@ -82,7 +82,6 @@ typedef interface ICLRRuntimeInfo ICLRRuntimeInfo; /* header files for imported files */ #include "unknwn.h" -#include "oaidl.h" #include "ocidl.h" #include "mscoree.h" From dfcbd57d5d7e2eead70a97ddb48c92f2ed55405c Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 15 Jun 2024 17:08:54 +0800 Subject: [PATCH 6/9] Fix m_pErrorInfo initialization --- src/coreclr/inc/ex.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/coreclr/inc/ex.h b/src/coreclr/inc/ex.h index bfbc3f5cbe20d8..4391808f9ab2c4 100644 --- a/src/coreclr/inc/ex.h +++ b/src/coreclr/inc/ex.h @@ -1298,15 +1298,19 @@ inline HRMsgException::HRMsgException(HRESULT hr, SString const &s) } inline COMException::COMException() - : HRException(), - m_pErrorInfo(NULL) + : HRException() +#ifdef FEATURE_COMINTEROP + , m_pErrorInfo(NULL) +#endif { WRAPPER_NO_CONTRACT; } inline COMException::COMException(HRESULT hr) - : HRException(hr), - m_pErrorInfo(NULL) + : HRException(hr) +#ifdef FEATURE_COMINTEROP + , m_pErrorInfo(NULL) +#endif { LIMITED_METHOD_CONTRACT; } From 5a000ebd20b06b88a5d27a1976731b98f7705565 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 24 Jun 2024 12:58:49 +0800 Subject: [PATCH 7/9] Apply suggestions from code review Co-authored-by: Aaron Robinson --- src/coreclr/inc/ex.h | 12 ++++++------ src/coreclr/utilcode/ex.cpp | 4 ++-- src/coreclr/vm/clrex.cpp | 4 ++-- src/coreclr/vm/clrex.h | 7 ++----- src/coreclr/vm/excep.h | 4 ++-- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/coreclr/inc/ex.h b/src/coreclr/inc/ex.h index 4391808f9ab2c4..9a0cad2b210226 100644 --- a/src/coreclr/inc/ex.h +++ b/src/coreclr/inc/ex.h @@ -195,7 +195,7 @@ class Exception #ifdef FEATURE_COMINTEROP virtual IErrorInfo *GetErrorInfo() { LIMITED_METHOD_CONTRACT; return NULL; } virtual HRESULT SetErrorInfo() { LIMITED_METHOD_CONTRACT; return S_OK; } -#endif +#endif // FEATURE_COMINTEROP void SetInnerException(Exception * pInnerException) { LIMITED_METHOD_CONTRACT; m_innerException = pInnerException; } // Dynamic type query for catchers @@ -437,7 +437,7 @@ class COMException : public HRException #ifdef FEATURE_COMINTEROP private: IErrorInfo *m_pErrorInfo; -#endif +#endif // FEATURE_COMINTEROP public: COMException(); @@ -494,7 +494,7 @@ class SEHException : public Exception HRESULT GetHR(); #ifdef FEATURE_COMINTEROP IErrorInfo *GetErrorInfo(); -#endif +#endif // FEATURE_COMINTEROP void GetMessage(SString &result); protected: @@ -541,7 +541,7 @@ class DelegatingException : public Exception HRESULT GetHR(); #ifdef FEATURE_COMINTEROP IErrorInfo *GetErrorInfo(); -#endif +#endif // FEATURE_COMINTEROP void GetMessage(SString &result); virtual Exception *Clone(); @@ -1301,7 +1301,7 @@ inline COMException::COMException() : HRException() #ifdef FEATURE_COMINTEROP , m_pErrorInfo(NULL) -#endif +#endif // FEATURE_COMINTEROP { WRAPPER_NO_CONTRACT; } @@ -1310,7 +1310,7 @@ inline COMException::COMException(HRESULT hr) : HRException(hr) #ifdef FEATURE_COMINTEROP , m_pErrorInfo(NULL) -#endif +#endif // FEATURE_COMINTEROP { LIMITED_METHOD_CONTRACT; } diff --git a/src/coreclr/utilcode/ex.cpp b/src/coreclr/utilcode/ex.cpp index c50195751079ee..8197e4f0ef72cb 100644 --- a/src/coreclr/utilcode/ex.cpp +++ b/src/coreclr/utilcode/ex.cpp @@ -817,7 +817,7 @@ IErrorInfo *SEHException::GetErrorInfo() LIMITED_METHOD_CONTRACT; return NULL; } -#endif +#endif // FEATURE_COMINTEROP void SEHException::GetMessage(SString &string) { @@ -912,7 +912,7 @@ IErrorInfo *DelegatingException::GetErrorInfo() return pDelegate ? pDelegate->GetErrorInfo() : NULL; } // IErrorInfo *DelegatingException::GetErrorInfo() -#endif +#endif // FEATURE_COMINTEROP //------------------------------------------------------------------------------ void DelegatingException::GetMessage(SString &result) diff --git a/src/coreclr/vm/clrex.cpp b/src/coreclr/vm/clrex.cpp index 0f09c2b5dff012..947f5eeb992f17 100644 --- a/src/coreclr/vm/clrex.cpp +++ b/src/coreclr/vm/clrex.cpp @@ -694,7 +694,7 @@ OBJECTREF CLRException::GetThrowableFromException(Exception *pException) GetExceptionForHR(hr, pErrInfo, &oRetVal); } else -#endif +#endif // FEATURE_COMINTEROP { SString message; pException->GetMessage(message); @@ -935,7 +935,7 @@ IErrorInfo *EEException::GetErrorInfo() return NULL; } -#endif +#endif // FEATURE_COMINTEROP BOOL EEException::GetThrowableMessage(SString &result) { diff --git a/src/coreclr/vm/clrex.h b/src/coreclr/vm/clrex.h index 752de941a187cf..2426ac7401c80d 100644 --- a/src/coreclr/vm/clrex.h +++ b/src/coreclr/vm/clrex.h @@ -132,7 +132,7 @@ class CLRException : public Exception #ifdef FEATURE_COMINTEROP IErrorInfo *GetErrorInfo(); HRESULT SetErrorInfo(); -#endif +#endif // FEATURE_COMINTEROP void GetMessage(SString &result); @@ -226,7 +226,7 @@ class EEException : public CLRException HRESULT GetHR(); #ifdef FEATURE_COMINTEROP IErrorInfo *GetErrorInfo(); -#endif +#endif // FEATURE_COMINTEROP void GetMessage(SString &result); OBJECTREF CreateThrowable(); @@ -867,9 +867,6 @@ LONG CLRNoCatchHandler(EXCEPTION_POINTERS* pExceptionInfo, PVOID pv); EX_CATCH \ { \ (_hr) = GET_EXCEPTION()->GetHR(); \ - { \ - FAULT_NOT_FATAL(); \ - } \ _ASSERTE(FAILED(_hr)); \ } \ EX_END_CATCH(SwallowAllExceptions) diff --git a/src/coreclr/vm/excep.h b/src/coreclr/vm/excep.h index a380edd585f351..210677250b0700 100644 --- a/src/coreclr/vm/excep.h +++ b/src/coreclr/vm/excep.h @@ -288,7 +288,7 @@ VOID DECLSPEC_NORETURN RealCOMPlusThrow(RuntimeExceptionKind reKind, UINT resID #ifdef FEATURE_COMINTEROP VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr, IErrorInfo* pErrInfo, Exception * pInnerException = NULL); -#endif +#endif // FEATURE_COMINTEROP VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr); VOID DECLSPEC_NORETURN RealCOMPlusThrowHR(HRESULT hr, UINT resID, LPCWSTR wszArg1 = NULL, LPCWSTR wszArg2 = NULL, LPCWSTR wszArg3 = NULL, LPCWSTR wszArg4 = NULL, LPCWSTR wszArg5 = NULL, @@ -363,7 +363,7 @@ void ExceptionPreserveStackTrace(OBJECTREF throwable); #ifdef FEATURE_COMINTEROP void GetExceptionForHR(HRESULT hr, IErrorInfo* pErrInfo, OBJECTREF* pProtectedThrowable); -#endif +#endif // FEATURE_COMINTEROP void GetExceptionForHR(HRESULT hr, OBJECTREF* pProtectedThrowable); HRESULT GetHRFromThrowable(OBJECTREF throwable); From ef99f9b43f9b94bf1f62b7bf623bb477688e5da9 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 24 Jun 2024 13:16:58 +0800 Subject: [PATCH 8/9] Update comment in GetExceptionForHR --- src/coreclr/vm/excep.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/vm/excep.cpp b/src/coreclr/vm/excep.cpp index 47eabfcae46563..66d2313908e020 100644 --- a/src/coreclr/vm/excep.cpp +++ b/src/coreclr/vm/excep.cpp @@ -3070,7 +3070,7 @@ void GetExceptionForHR(HRESULT hr, OBJECTREF* pProtectedThrowable) CONTRACTL { THROWS; - GC_TRIGGERS; // because of IErrorInfo + GC_TRIGGERS; // be consistent with COM interop enabled MODE_ANY; } CONTRACTL_END; From 1279a357a604397eab136e4cf388a1c6770bddad Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 27 Jun 2024 02:22:10 +0800 Subject: [PATCH 9/9] Update contract --- src/coreclr/vm/excep.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreclr/vm/excep.cpp b/src/coreclr/vm/excep.cpp index 66d2313908e020..45bc9715d95e54 100644 --- a/src/coreclr/vm/excep.cpp +++ b/src/coreclr/vm/excep.cpp @@ -3053,7 +3053,7 @@ void GetExceptionForHR(HRESULT hr, OBJECTREF* pProtectedThrowable) { THROWS; GC_TRIGGERS; // because of IErrorInfo - MODE_ANY; + MODE_COOPERATIVE; } CONTRACTL_END; @@ -3069,9 +3069,9 @@ void GetExceptionForHR(HRESULT hr, OBJECTREF* pProtectedThrowable) { CONTRACTL { - THROWS; - GC_TRIGGERS; // be consistent with COM interop enabled - MODE_ANY; + GC_TRIGGERS; + NOTHROW; + MODE_COOPERATIVE; } CONTRACTL_END;