From 43be45a82b139703294f6d346a6e7c009e0ab481 Mon Sep 17 00:00:00 2001
From: Anipik <anirudhagnihotry098@gmail.com>
Date: Wed, 17 Jun 2020 23:18:48 -0700
Subject: [PATCH 1/4] moving coMarshal type down

---
 .../src/Resources/Strings.resx                       |  3 +++
 .../src/System.Private.CoreLib.Shared.projitems      |  5 +++++
 .../src/System/Runtime/InteropServices/IMarshal.cs   |  0
 .../InteropServices/StandardOleMarshalObject.cs      |  0
 .../src/Resources/Strings.resx                       |  3 ---
 .../src/System.Runtime.InteropServices.csproj        | 12 +-----------
 6 files changed, 9 insertions(+), 14 deletions(-)
 rename src/libraries/{System.Runtime.InteropServices => System.Private.CoreLib}/src/System/Runtime/InteropServices/IMarshal.cs (100%)
 rename src/libraries/{System.Runtime.InteropServices => System.Private.CoreLib}/src/System/Runtime/InteropServices/StandardOleMarshalObject.cs (100%)

diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
index c1ec9b8ca192af..671183f4096f24 100644
--- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
+++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
@@ -3223,6 +3223,9 @@
   <data name="RuntimeWrappedException" xml:space="preserve">
     <value>An object that does not derive from System.Exception has been wrapped in a RuntimeWrappedException.</value>
   </data>
+  <data name="StandardOleMarshalObjectGetMarshalerFailed" xml:space="preserve">
+    <value>Failed to get marshaler for IID {0}.</value>
+  </data>
   <data name="Security_CannotReadFileData" xml:space="preserve">
     <value>The time zone ID '{0}' was found on the local computer, but the application does not have permission to read the file.</value>
   </data>
diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
index e0f887b270d05e..2b3fdd99ffbf9e 100644
--- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
+++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
@@ -1527,6 +1527,9 @@
     <Compile Include="$(CommonPath)Interop\Windows\Ole32\Interop.CoCreateGuid.cs">
       <Link>Common\Interop\Windows\Ole32\Interop.CoCreateGuid.cs</Link>
     </Compile>
+    <Compile Include="$(CommonPath)\Interop\Windows\Ole32\Interop.CoGetStandardMarshal.cs">
+      <Link>Common\Interop\Windows\Ole32\Interop.CoGetStandardMarshal.cs</Link>
+    </Compile>
     <Compile Include="$(CommonPath)Interop\Windows\Secur32\Interop.GetUserNameExW.cs">
       <Link>Common\Interop\Windows\Secur32\Interop.GetUserNameExW.cs</Link>
     </Compile>
@@ -1582,7 +1585,9 @@
     <Compile Include="$(MSBuildThisFileDirectory)System\PasteArguments.Windows.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Loader\LibraryNameVariation.Windows.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\MemoryFailPoint.Windows.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\IMarshal.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\Marshal.Windows.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\StandardOleMarshalObject.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Versioning\VersioningHelper.Windows.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Security\SecureString.Windows.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Thread.Windows.cs" />
diff --git a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/IMarshal.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/IMarshal.cs
similarity index 100%
rename from src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/IMarshal.cs
rename to src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/IMarshal.cs
diff --git a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/StandardOleMarshalObject.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StandardOleMarshalObject.cs
similarity index 100%
rename from src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/StandardOleMarshalObject.cs
rename to src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StandardOleMarshalObject.cs
diff --git a/src/libraries/System.Runtime.InteropServices/src/Resources/Strings.resx b/src/libraries/System.Runtime.InteropServices/src/Resources/Strings.resx
index e6f882c8df8f82..b65b6b5d5b1a2b 100644
--- a/src/libraries/System.Runtime.InteropServices/src/Resources/Strings.resx
+++ b/src/libraries/System.Runtime.InteropServices/src/Resources/Strings.resx
@@ -75,7 +75,4 @@
   <data name="InvalidOperation_NoDispIdAttribute" xml:space="preserve">
     <value>Event invocation for COM objects requires event to be attributed with DispIdAttribute.</value>
   </data>
-  <data name="StandardOleMarshalObjectGetMarshalerFailed" xml:space="preserve">
-    <value>Failed to get marshaler for IID {0}.</value>
-  </data>
 </root>
\ No newline at end of file
diff --git a/src/libraries/System.Runtime.InteropServices/src/System.Runtime.InteropServices.csproj b/src/libraries/System.Runtime.InteropServices/src/System.Runtime.InteropServices.csproj
index b41eb248fd65ca..6559e175b3ed02 100644
--- a/src/libraries/System.Runtime.InteropServices/src/System.Runtime.InteropServices.csproj
+++ b/src/libraries/System.Runtime.InteropServices/src/System.Runtime.InteropServices.csproj
@@ -3,17 +3,10 @@
     <AssemblyName>System.Runtime.InteropServices</AssemblyName>
     <OutputType>Library</OutputType>
     <IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
-    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <Nullable>enable</Nullable>
-    <TargetFrameworks>$(NetCoreAppCurrent)-Windows_NT;$(NetCoreAppCurrent)-Unix</TargetFrameworks>
+    <TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
   </PropertyGroup>
   <ItemGroup>
-    <Compile Include="$(CommonPath)System\HResults.cs"
-             Link="Common\System\HResults.cs" />
-    <Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs"
-             Link="Common\Interop\Interop.Libraries.cs" />
-    <Compile Include="$(CommonPath)Interop\Windows\Ole32\Interop.CoGetStandardMarshal.cs"
-             Link="Common\Interop\Windows\Ole32\Interop.CoGetStandardMarshal.cs" />
     <Compile Include="System\Runtime\CompilerServices\IDispatchConstantAttribute.cs" />
     <Compile Include="System\Runtime\CompilerServices\IUnknownConstantAttribute.cs" />
     <Compile Include="System\Runtime\InteropServices\ComTypes\ADVF.cs" />
@@ -39,14 +32,12 @@
     <Compile Include="System\Runtime\InteropServices\HandleCollector.cs" />
     <Compile Include="System\Runtime\InteropServices\IDispatchImplAttribute.cs" />
     <Compile Include="System\Runtime\InteropServices\IDispatchImplType.cs" />
-    <Compile Include="System\Runtime\InteropServices\IMarshal.cs" />
     <Compile Include="System\Runtime\InteropServices\ImportedFromTypeLibAttribute.cs" />
     <Compile Include="System\Runtime\InteropServices\ManagedToNativeComInteropStubAttribute.cs" />
     <Compile Include="System\Runtime\InteropServices\PrimaryInteropAssemblyAttribute.cs" />
     <Compile Include="System\Runtime\InteropServices\RegistrationClassContext.cs" />
     <Compile Include="System\Runtime\InteropServices\RegistrationConnectionType.cs" />
     <Compile Include="System\Runtime\InteropServices\RuntimeEnvironment.cs" />
-    <Compile Include="System\Runtime\InteropServices\StandardOleMarshalObject.cs" />
     <Compile Include="System\Runtime\InteropServices\SetWin32ContextInIDispatchAttribute.cs" />
     <Compile Include="System\Runtime\InteropServices\TypeLibFuncAttribute.cs" />
     <Compile Include="System\Runtime\InteropServices\TypeLibFuncFlags.cs" />
@@ -60,6 +51,5 @@
   </ItemGroup>
   <ItemGroup>
     <ReferenceFromRuntime Include="System.Private.CoreLib" />
-    <ProjectReference Include="..\..\System.Runtime.Extensions\src\System.Runtime.Extensions.csproj" />
   </ItemGroup>
 </Project>
\ No newline at end of file

From f351dd4d025a53ed342391f365543275f0914095 Mon Sep 17 00:00:00 2001
From: Anipik <anirudhagnihotry098@gmail.com>
Date: Wed, 17 Jun 2020 23:49:32 -0700
Subject: [PATCH 2/4] add unix implementation

---
 .../System.Private.CoreLib.Shared.projitems   |  5 ++-
 .../StandardOleMarshalObject.Unix.cs          | 43 +++++++++++++++++++
 ...cs => StandardOleMarshalObject.Windows.cs} |  0
 3 files changed, 46 insertions(+), 2 deletions(-)
 create mode 100644 src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StandardOleMarshalObject.Unix.cs
 rename src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/{StandardOleMarshalObject.cs => StandardOleMarshalObject.Windows.cs} (100%)

diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
index 2b3fdd99ffbf9e..d9c25f17664ee3 100644
--- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
+++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
@@ -747,6 +747,7 @@
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ICustomMarshaler.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ICustomQueryInterface.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\IDynamicInterfaceCastable.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\IMarshal.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\InAttribute.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\InterfaceTypeAttribute.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\InvalidComObjectException.cs" />
@@ -1585,9 +1586,8 @@
     <Compile Include="$(MSBuildThisFileDirectory)System\PasteArguments.Windows.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Loader\LibraryNameVariation.Windows.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\MemoryFailPoint.Windows.cs" />
-    <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\IMarshal.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\Marshal.Windows.cs" />
-    <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\StandardOleMarshalObject.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\StandardOleMarshalObject.Windows.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Versioning\VersioningHelper.Windows.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Security\SecureString.Windows.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Thread.Windows.cs" />
@@ -1799,6 +1799,7 @@
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Loader\LibraryNameVariation.Unix.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\MemoryFailPoint.Unix.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\Marshal.Unix.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\StandardOleMarshalObject.Unix.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Versioning\VersioningHelper.Unix.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Security\SecureString.Unix.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Thread.Unix.cs" />
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StandardOleMarshalObject.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StandardOleMarshalObject.Unix.cs
new file mode 100644
index 00000000000000..3d3c2eac42f486
--- /dev/null
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StandardOleMarshalObject.Unix.cs
@@ -0,0 +1,43 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Runtime.InteropServices
+{
+    public class StandardOleMarshalObject : MarshalByRefObject, IMarshal
+    {
+        protected StandardOleMarshalObject()
+        {
+        }
+
+        int IMarshal.GetUnmarshalClass(ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out Guid pCid)
+        {
+            return HResults.E_NOTIMPL;
+        }
+
+        unsafe int IMarshal.GetMarshalSizeMax(ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out int pSize)
+        {
+            return HResults.E_NOTIMPL;
+        }
+
+        unsafe int IMarshal.MarshalInterface(IntPtr pStm, ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags)
+        {
+            return HResults.E_NOTIMPL;
+        }
+
+        int IMarshal.UnmarshalInterface(IntPtr pStm, ref Guid riid, out IntPtr ppv)
+        {
+            return HResults.E_NOTIMPL;
+        }
+
+        int IMarshal.ReleaseMarshalData(IntPtr pStm)
+        {
+            return HResults.E_NOTIMPL;
+        }
+
+        int IMarshal.DisconnectObject(int dwReserved)
+        {
+            return HResults.E_NOTIMPL;
+        }
+    }
+}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StandardOleMarshalObject.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StandardOleMarshalObject.Windows.cs
similarity index 100%
rename from src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StandardOleMarshalObject.cs
rename to src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StandardOleMarshalObject.Windows.cs

From 2b0206bbc946ada81116020fb914820ec87f5088 Mon Sep 17 00:00:00 2001
From: Anipik <anirudhagnihotry098@gmail.com>
Date: Thu, 18 Jun 2020 00:14:18 -0700
Subject: [PATCH 3/4] setting default value for out params in unix

---
 .../Runtime/InteropServices/StandardOleMarshalObject.Unix.cs   | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StandardOleMarshalObject.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StandardOleMarshalObject.Unix.cs
index 3d3c2eac42f486..a18a7c88beda23 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StandardOleMarshalObject.Unix.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StandardOleMarshalObject.Unix.cs
@@ -12,11 +12,13 @@ protected StandardOleMarshalObject()
 
         int IMarshal.GetUnmarshalClass(ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out Guid pCid)
         {
+            pCid = Guid.Empty;
             return HResults.E_NOTIMPL;
         }
 
         unsafe int IMarshal.GetMarshalSizeMax(ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out int pSize)
         {
+            pSize = -1;
             return HResults.E_NOTIMPL;
         }
 
@@ -27,6 +29,7 @@ unsafe int IMarshal.MarshalInterface(IntPtr pStm, ref Guid riid, IntPtr pv, int
 
         int IMarshal.UnmarshalInterface(IntPtr pStm, ref Guid riid, out IntPtr ppv)
         {
+            ppv = IntPtr.Zero;
             return HResults.E_NOTIMPL;
         }
 

From dab33fb6185ec2f7bfb629bb3dd01fc2144e0a8d Mon Sep 17 00:00:00 2001
From: Anipik <anirudhagnihotry098@gmail.com>
Date: Thu, 18 Jun 2020 10:04:30 -0700
Subject: [PATCH 4/4] remove unsafe

---
 .../Runtime/InteropServices/StandardOleMarshalObject.Unix.cs  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StandardOleMarshalObject.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StandardOleMarshalObject.Unix.cs
index a18a7c88beda23..9d03839d45aebd 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StandardOleMarshalObject.Unix.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StandardOleMarshalObject.Unix.cs
@@ -16,13 +16,13 @@ int IMarshal.GetUnmarshalClass(ref Guid riid, IntPtr pv, int dwDestContext, IntP
             return HResults.E_NOTIMPL;
         }
 
-        unsafe int IMarshal.GetMarshalSizeMax(ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out int pSize)
+        int IMarshal.GetMarshalSizeMax(ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags, out int pSize)
         {
             pSize = -1;
             return HResults.E_NOTIMPL;
         }
 
-        unsafe int IMarshal.MarshalInterface(IntPtr pStm, ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags)
+        int IMarshal.MarshalInterface(IntPtr pStm, ref Guid riid, IntPtr pv, int dwDestContext, IntPtr pvDestContext, int mshlflags)
         {
             return HResults.E_NOTIMPL;
         }
