From: Jan Kotas Date: Fri, 26 Aug 2016 01:14:28 +0000 (-0700) Subject: Make GetHRForException to return e.HResult on non-Windows platforms (dotnet/coreclr... X-Git-Tag: submit/tizen/20210909.063632~11030^2~9564 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=440a189fb2afbf35967843c8ba07a787cf51fb96;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Make GetHRForException to return e.HResult on non-Windows platforms (dotnet/coreclr#6929) Fixes https://github.com/dotnet/corefx/issues/11144 Commit migrated from https://github.com/dotnet/coreclr/commit/9caa82a7b334836b474a89188f2ffb0def582785 --- diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs b/src/coreclr/src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs index 5e6e782..86e8830 100644 --- a/src/coreclr/src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs +++ b/src/coreclr/src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs @@ -1148,24 +1148,6 @@ namespace System.Runtime.InteropServices //==================================================================== - // Converts the CLR exception to an HRESULT. This function also sets - // up an IErrorInfo for the exception. - //==================================================================== - [System.Security.SecurityCritical] // auto-generated_required - [MethodImplAttribute(MethodImplOptions.InternalCall)] - public static extern int GetHRForException(Exception e); - - //==================================================================== - // Converts the CLR exception to an HRESULT. This function also sets - // up an IErrorInfo for the exception. - // This function is only used in WinRT and converts ObjectDisposedException - // to RO_E_CLOSED - //==================================================================== - [System.Security.SecurityCritical] // auto-generated_required - [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static extern int GetHRForException_WinRT(Exception e); - - //==================================================================== // This method is intended for compiler code generators rather // than applications. //==================================================================== @@ -1336,6 +1318,24 @@ namespace System.Runtime.InteropServices #if FEATURE_COMINTEROP + //==================================================================== + // Converts the CLR exception to an HRESULT. This function also sets + // up an IErrorInfo for the exception. + //==================================================================== + [System.Security.SecurityCritical] // auto-generated_required + [MethodImplAttribute(MethodImplOptions.InternalCall)] + public static extern int GetHRForException(Exception e); + + //==================================================================== + // Converts the CLR exception to an HRESULT. This function also sets + // up an IErrorInfo for the exception. + // This function is only used in WinRT and converts ObjectDisposedException + // to RO_E_CLOSED + //==================================================================== + [System.Security.SecurityCritical] // auto-generated_required + [MethodImplAttribute(MethodImplOptions.InternalCall)] + internal static extern int GetHRForException_WinRT(Exception e); + internal static readonly Guid ManagedNameGuid = new Guid("{0F21F359-AB84-41E8-9A78-36D110E6D2F9}"); //==================================================================== diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/InteropServices/NonPortable.cs b/src/coreclr/src/mscorlib/src/System/Runtime/InteropServices/NonPortable.cs index 130a48a..408f56c 100644 --- a/src/coreclr/src/mscorlib/src/System/Runtime/InteropServices/NonPortable.cs +++ b/src/coreclr/src/mscorlib/src/System/Runtime/InteropServices/NonPortable.cs @@ -5,9 +5,15 @@ // Dummy implementations of non-portable interop methods that just throw PlatformNotSupportedException namespace System.Runtime.InteropServices -{ +{ public static partial class Marshal { + [System.Security.SecurityCritical] + public static int GetHRForException(Exception e) + { + return (e != null) ? e.HResult : 0; + } + [System.Security.SecurityCriticalAttribute] public static int AddRef(System.IntPtr pUnk) { diff --git a/src/coreclr/src/vm/ecalllist.h b/src/coreclr/src/vm/ecalllist.h index 5992b29..c693acd 100644 --- a/src/coreclr/src/vm/ecalllist.h +++ b/src/coreclr/src/vm/ecalllist.h @@ -1600,11 +1600,11 @@ FCFuncStart(gInteropMarshalFuncs) FCFuncElement("StructureToPtr", MarshalNative::StructureToPtr) FCFuncElement("ThrowExceptionForHRInternal", MarshalNative::ThrowExceptionForHR) FCFuncElement("GetExceptionForHRInternal", MarshalNative::GetExceptionForHR) - FCFuncElement("GetHRForException", MarshalNative::GetHRForException) - FCFuncElement("GetHRForException_WinRT", MarshalNative::GetHRForException_WinRT) FCFuncElement("GetDelegateForFunctionPointerInternal", MarshalNative::GetDelegateForFunctionPointerInternal) FCFuncElement("GetFunctionPointerForDelegateInternal", MarshalNative::GetFunctionPointerForDelegateInternal) #ifdef FEATURE_COMINTEROP + FCFuncElement("GetHRForException", MarshalNative::GetHRForException) + FCFuncElement("GetHRForException_WinRT", MarshalNative::GetHRForException_WinRT) FCFuncElement("GetRawIUnknownForComObjectNoAddRef", MarshalNative::GetRawIUnknownForComObjectNoAddRef) FCFuncElement("IsComObject", MarshalNative::IsComObject) FCFuncElement("GetObjectForIUnknown", MarshalNative::GetObjectForIUnknown)