From e4959bbc9127d4635a7f38e9aa9dd4a74d0e2703 Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Sun, 30 Dec 2018 23:29:35 +0100 Subject: [PATCH] Moves CriticalHandle to shared location --- .../System.Private.CoreLib.csproj | 2 +- .../shared/System.Private.CoreLib.Shared.projitems | 1 + .../Runtime/InteropServices/CriticalHandle.cs | 17 ++------------- .../InteropServices/CriticalHandle.CoreCLR.cs | 24 ++++++++++++++++++++++ 4 files changed, 28 insertions(+), 16 deletions(-) rename src/System.Private.CoreLib/{src => shared}/System/Runtime/InteropServices/CriticalHandle.cs (93%) create mode 100644 src/System.Private.CoreLib/src/System/Runtime/InteropServices/CriticalHandle.CoreCLR.cs diff --git a/src/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/System.Private.CoreLib/System.Private.CoreLib.csproj index a141c52..6f69bca 100644 --- a/src/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -276,7 +276,7 @@ - + diff --git a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems index 2c26181..9a84597 100644 --- a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems +++ b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems @@ -556,6 +556,7 @@ + diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CriticalHandle.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/CriticalHandle.cs similarity index 93% rename from src/System.Private.CoreLib/src/System/Runtime/InteropServices/CriticalHandle.cs rename to src/System.Private.CoreLib/shared/System/Runtime/InteropServices/CriticalHandle.cs index da7cb3e..acb94c4 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CriticalHandle.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/CriticalHandle.cs @@ -127,7 +127,7 @@ using System.IO; namespace System.Runtime.InteropServices { // This class should not be serializable - it's a handle - public abstract class CriticalHandle : CriticalFinalizerObject, IDisposable + public abstract partial class CriticalHandle : CriticalFinalizerObject, IDisposable { // ! Do not add or rearrange fields as the EE depends on this layout. //------------------------------------------------------------------ @@ -138,7 +138,6 @@ namespace System.Runtime.InteropServices protected CriticalHandle(IntPtr invalidHandleValue) { handle = invalidHandleValue; - _isClosed = false; } ~CriticalHandle() @@ -155,22 +154,10 @@ namespace System.Runtime.InteropServices if (IsInvalid) return; - // Save last error from P/Invoke in case the implementation of - // ReleaseHandle trashes it (important because this ReleaseHandle could - // occur implicitly as part of unmarshaling another P/Invoke). - int lastError = Marshal.GetLastWin32Error(); - - if (!ReleaseHandle()) - FireCustomerDebugProbe(); - - Marshal.SetLastWin32Error(lastError); - + ReleaseHandleCore(); GC.SuppressFinalize(this); } - [MethodImplAttribute(MethodImplOptions.InternalCall)] - private extern void FireCustomerDebugProbe(); - protected void SetHandle(IntPtr handle) { this.handle = handle; diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CriticalHandle.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CriticalHandle.CoreCLR.cs new file mode 100644 index 0000000..8c4dfee --- /dev/null +++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CriticalHandle.CoreCLR.cs @@ -0,0 +1,24 @@ +using System.Runtime.CompilerServices; +using System.Runtime.ConstrainedExecution; + +namespace System.Runtime.InteropServices +{ + public abstract partial class CriticalHandle : CriticalFinalizerObject, IDisposable + { + void ReleaseHandleCore() + { + // Save last error from P/Invoke in case the implementation of + // ReleaseHandle trashes it (important because this ReleaseHandle could + // occur implicitly as part of unmarshaling another P/Invoke). + int lastError = Marshal.GetLastWin32Error(); + + if (!ReleaseHandle()) + FireCustomerDebugProbe(); + + Marshal.SetLastWin32Error(lastError); + } + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private extern void FireCustomerDebugProbe(); + } +} \ No newline at end of file -- 2.7.4