Moves CriticalHandle to shared location
authorMarek Safar <marek.safar@gmail.com>
Sun, 30 Dec 2018 22:29:35 +0000 (23:29 +0100)
committerJan Kotas <jkotas@microsoft.com>
Mon, 31 Dec 2018 08:55:37 +0000 (22:55 -1000)
Commit migrated from https://github.com/dotnet/coreclr/commit/e4959bbc9127d4635a7f38e9aa9dd4a74d0e2703

src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CriticalHandle.CoreCLR.cs [new file with mode: 0644]
src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/CriticalHandle.cs [moved from src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CriticalHandle.cs with 93% similarity]

index a141c52..6f69bca 100644 (file)
     <Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\ComTypes\ITypeInfo2.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\ComTypes\ITypeLib.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\ComTypes\ITypeLib2.cs" />
-    <Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\CriticalHandle.cs" />
+    <Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\CriticalHandle.CoreCLR.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\CurrencyWrapper.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\ErrorWrapper.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\Expando\IExpando.cs" />
diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CriticalHandle.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CriticalHandle.CoreCLR.cs
new file mode 100644 (file)
index 0000000..8c4dfee
--- /dev/null
@@ -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
index 2c26181..9a84597 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\CallingConvention.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\CharSet.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ComVisibleAttribute.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\CriticalHandle.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\DefaultCharSetAttribute.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\DefaultDllImportSearchPathsAttribute.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\DllImportAttribute.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;