From 9f0d843bcb98c4946d5cca09c0ed6bf1fc138202 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 5 Aug 2020 12:04:14 -0700 Subject: [PATCH 1/3] Fix crossgenning vtable gap members on non-Windows and add a test for vtable gap members. --- src/coreclr/src/zap/zapimage.cpp | 4 -- .../COM/NETClients/VtableGap/App.manifest | 18 +++++++ .../COM/NETClients/VtableGap/ErrorTests.cs | 45 +++++++++++++++++ .../VtableGap/NETClientVtableGap.csproj | 21 ++++++++ .../COM/NETClients/VtableGap/Program.cs | 48 +++++++++++++++++++ .../COM/ServerContracts/Server.Contracts.cs | 10 ++++ 6 files changed, 142 insertions(+), 4 deletions(-) create mode 100644 src/tests/Interop/COM/NETClients/VtableGap/App.manifest create mode 100644 src/tests/Interop/COM/NETClients/VtableGap/ErrorTests.cs create mode 100644 src/tests/Interop/COM/NETClients/VtableGap/NETClientVtableGap.csproj create mode 100644 src/tests/Interop/COM/NETClients/VtableGap/Program.cs diff --git a/src/coreclr/src/zap/zapimage.cpp b/src/coreclr/src/zap/zapimage.cpp index bcd02a3b2c429..36aec0b1f193c 100644 --- a/src/coreclr/src/zap/zapimage.cpp +++ b/src/coreclr/src/zap/zapimage.cpp @@ -1894,7 +1894,6 @@ void ZapImage::TryCompileMethodStub(LPVOID pContext, CORINFO_METHOD_HANDLE hStub //----------------------------------------------------------------------------- BOOL ZapImage::IsVTableGapMethod(mdMethodDef md) { -#ifdef FEATURE_COMINTEROP HRESULT hr; DWORD dwAttributes; @@ -1916,9 +1915,6 @@ BOOL ZapImage::IsVTableGapMethod(mdMethodDef md) // If we make it to here we have a vtable gap method. return TRUE; -#else - return FALSE; -#endif // FEATURE_COMINTEROP } //----------------------------------------------------------------------------- diff --git a/src/tests/Interop/COM/NETClients/VtableGap/App.manifest b/src/tests/Interop/COM/NETClients/VtableGap/App.manifest new file mode 100644 index 0000000000000..6bd83fd63f7ce --- /dev/null +++ b/src/tests/Interop/COM/NETClients/VtableGap/App.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + diff --git a/src/tests/Interop/COM/NETClients/VtableGap/ErrorTests.cs b/src/tests/Interop/COM/NETClients/VtableGap/ErrorTests.cs new file mode 100644 index 0000000000000..02eba3fc68ec6 --- /dev/null +++ b/src/tests/Interop/COM/NETClients/VtableGap/ErrorTests.cs @@ -0,0 +1,45 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace NetClient +{ + using System; + using System.Runtime.InteropServices; + using TestLibrary; + + class ErrorTests + { + private readonly Server.Contract.IErrorMarshalTesting_VtableGap server; + public ErrorTests() + { + this.server = (Server.Contract.IErrorMarshalTesting_VtableGap)new Server.Contract.Servers.ErrorMarshalTestingClass(); + } + + public void Run() + { + this.VerifyReturnHResult(); + } + + private void VerifyReturnHResult() + { + Console.WriteLine($"Verify preserved function signature"); + + var hrs = new[] + { + unchecked((int)0x80004001), + unchecked((int)0x80004003), + unchecked((int)0x80070005), + unchecked((int)0x80070057), + unchecked((int)0x8000ffff), + -1, + 1, + 2 + }; + + foreach (var hr in hrs) + { + Assert.AreEqual(hr, this.server.Return_As_HResult_Struct(hr).hr); + } + } + } +} diff --git a/src/tests/Interop/COM/NETClients/VtableGap/NETClientVtableGap.csproj b/src/tests/Interop/COM/NETClients/VtableGap/NETClientVtableGap.csproj new file mode 100644 index 0000000000000..6bc32e6340403 --- /dev/null +++ b/src/tests/Interop/COM/NETClients/VtableGap/NETClientVtableGap.csproj @@ -0,0 +1,21 @@ + + + Exe + App.manifest + + true + + true + + + + + + + + + + + + + diff --git a/src/tests/Interop/COM/NETClients/VtableGap/Program.cs b/src/tests/Interop/COM/NETClients/VtableGap/Program.cs new file mode 100644 index 0000000000000..6b94cf53f390a --- /dev/null +++ b/src/tests/Interop/COM/NETClients/VtableGap/Program.cs @@ -0,0 +1,48 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace NetClient +{ + using System; + using System.Threading; + using System.Runtime.InteropServices; + using TestLibrary; + + class Program + { + static int Main(string[] doNotUse) + { + // RegFree COM is not supported on Windows Nano + if (TestLibrary.Utilities.IsWindowsNanoServer) + { + return 100; + } + + // COM is not supported off Windows. + // However, we want to test non-Windows crossgen on vtable gap members + // so we still build and run this test on non-Windows so the crossgen test + // runs exercise that path. + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return 100; + } + + try + { + RunTests(); + } + catch (Exception e) + { + Console.WriteLine($"Test Failure: {e}"); + return 101; + } + + return 100; + } + + private static void RunTests() + { + new ErrorTests().Run(); + } + } +} diff --git a/src/tests/Interop/COM/ServerContracts/Server.Contracts.cs b/src/tests/Interop/COM/ServerContracts/Server.Contracts.cs index 2a0de065f4fc7..5e7cab578b7fa 100644 --- a/src/tests/Interop/COM/ServerContracts/Server.Contracts.cs +++ b/src/tests/Interop/COM/ServerContracts/Server.Contracts.cs @@ -203,6 +203,16 @@ public interface IErrorMarshalTesting HResult Return_As_HResult_Struct(int hresultToReturn); } + [ComImport] + [Guid("592386A5-6837-444D-9DE3-250815D18556")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface IErrorMarshalTesting_VtableGap + { + void _VtblGap1_2(); + [PreserveSig] + HResult Return_As_HResult_Struct(int hresultToReturn); + } + public enum IDispatchTesting_Exception { Disp, From bd1c66b2de689c0ee8352abef77cdb4f3ab35879 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 5 Aug 2020 12:38:58 -0700 Subject: [PATCH 2/3] Test as part of the typeequivalence test suite instead of as part of the COM test suite. --- .../COM/NETClients/VtableGap/App.manifest | 18 ------- .../COM/NETClients/VtableGap/ErrorTests.cs | 45 ----------------- .../VtableGap/NETClientVtableGap.csproj | 21 -------- .../COM/NETClients/VtableGap/Program.cs | 48 ------------------- .../contracts/TypeContracts.csproj | 2 - .../typeequivalence/impl/TypeImpl.csproj | 2 - .../typeequivalence/simple/Simple.cs | 4 ++ .../typeequivalence/simple/Simple.csproj | 2 - 8 files changed, 4 insertions(+), 138 deletions(-) delete mode 100644 src/tests/Interop/COM/NETClients/VtableGap/App.manifest delete mode 100644 src/tests/Interop/COM/NETClients/VtableGap/ErrorTests.cs delete mode 100644 src/tests/Interop/COM/NETClients/VtableGap/NETClientVtableGap.csproj delete mode 100644 src/tests/Interop/COM/NETClients/VtableGap/Program.cs diff --git a/src/tests/Interop/COM/NETClients/VtableGap/App.manifest b/src/tests/Interop/COM/NETClients/VtableGap/App.manifest deleted file mode 100644 index 6bd83fd63f7ce..0000000000000 --- a/src/tests/Interop/COM/NETClients/VtableGap/App.manifest +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - diff --git a/src/tests/Interop/COM/NETClients/VtableGap/ErrorTests.cs b/src/tests/Interop/COM/NETClients/VtableGap/ErrorTests.cs deleted file mode 100644 index 02eba3fc68ec6..0000000000000 --- a/src/tests/Interop/COM/NETClients/VtableGap/ErrorTests.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace NetClient -{ - using System; - using System.Runtime.InteropServices; - using TestLibrary; - - class ErrorTests - { - private readonly Server.Contract.IErrorMarshalTesting_VtableGap server; - public ErrorTests() - { - this.server = (Server.Contract.IErrorMarshalTesting_VtableGap)new Server.Contract.Servers.ErrorMarshalTestingClass(); - } - - public void Run() - { - this.VerifyReturnHResult(); - } - - private void VerifyReturnHResult() - { - Console.WriteLine($"Verify preserved function signature"); - - var hrs = new[] - { - unchecked((int)0x80004001), - unchecked((int)0x80004003), - unchecked((int)0x80070005), - unchecked((int)0x80070057), - unchecked((int)0x8000ffff), - -1, - 1, - 2 - }; - - foreach (var hr in hrs) - { - Assert.AreEqual(hr, this.server.Return_As_HResult_Struct(hr).hr); - } - } - } -} diff --git a/src/tests/Interop/COM/NETClients/VtableGap/NETClientVtableGap.csproj b/src/tests/Interop/COM/NETClients/VtableGap/NETClientVtableGap.csproj deleted file mode 100644 index 6bc32e6340403..0000000000000 --- a/src/tests/Interop/COM/NETClients/VtableGap/NETClientVtableGap.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - Exe - App.manifest - - true - - true - - - - - - - - - - - - - diff --git a/src/tests/Interop/COM/NETClients/VtableGap/Program.cs b/src/tests/Interop/COM/NETClients/VtableGap/Program.cs deleted file mode 100644 index 6b94cf53f390a..0000000000000 --- a/src/tests/Interop/COM/NETClients/VtableGap/Program.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace NetClient -{ - using System; - using System.Threading; - using System.Runtime.InteropServices; - using TestLibrary; - - class Program - { - static int Main(string[] doNotUse) - { - // RegFree COM is not supported on Windows Nano - if (TestLibrary.Utilities.IsWindowsNanoServer) - { - return 100; - } - - // COM is not supported off Windows. - // However, we want to test non-Windows crossgen on vtable gap members - // so we still build and run this test on non-Windows so the crossgen test - // runs exercise that path. - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - return 100; - } - - try - { - RunTests(); - } - catch (Exception e) - { - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - - return 100; - } - - private static void RunTests() - { - new ErrorTests().Run(); - } - } -} diff --git a/src/tests/baseservices/typeequivalence/contracts/TypeContracts.csproj b/src/tests/baseservices/typeequivalence/contracts/TypeContracts.csproj index ce626dfdd026c..306758e5a5b85 100644 --- a/src/tests/baseservices/typeequivalence/contracts/TypeContracts.csproj +++ b/src/tests/baseservices/typeequivalence/contracts/TypeContracts.csproj @@ -1,8 +1,6 @@ Library - - true diff --git a/src/tests/baseservices/typeequivalence/impl/TypeImpl.csproj b/src/tests/baseservices/typeequivalence/impl/TypeImpl.csproj index 4c64a59beda10..b916b70076098 100644 --- a/src/tests/baseservices/typeequivalence/impl/TypeImpl.csproj +++ b/src/tests/baseservices/typeequivalence/impl/TypeImpl.csproj @@ -1,8 +1,6 @@ Library - - true diff --git a/src/tests/baseservices/typeequivalence/simple/Simple.cs b/src/tests/baseservices/typeequivalence/simple/Simple.cs index 4454281731a4d..ac543f11dd706 100644 --- a/src/tests/baseservices/typeequivalence/simple/Simple.cs +++ b/src/tests/baseservices/typeequivalence/simple/Simple.cs @@ -151,6 +151,10 @@ private static void CallSparseInterface() public static int Main(string[] noArgs) { + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return 100; + } try { InterfaceTypesFromDifferentAssembliesAreEquivalent(); diff --git a/src/tests/baseservices/typeequivalence/simple/Simple.csproj b/src/tests/baseservices/typeequivalence/simple/Simple.csproj index e53815c61324c..028b3cc152efd 100644 --- a/src/tests/baseservices/typeequivalence/simple/Simple.csproj +++ b/src/tests/baseservices/typeequivalence/simple/Simple.csproj @@ -1,8 +1,6 @@ Exe - - true From e421329c9710b8b38346446e9c997371a10854d3 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 5 Aug 2020 12:46:27 -0700 Subject: [PATCH 3/3] PR feedback --- .../Interop/COM/ServerContracts/Server.Contracts.cs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/tests/Interop/COM/ServerContracts/Server.Contracts.cs b/src/tests/Interop/COM/ServerContracts/Server.Contracts.cs index 5e7cab578b7fa..2a0de065f4fc7 100644 --- a/src/tests/Interop/COM/ServerContracts/Server.Contracts.cs +++ b/src/tests/Interop/COM/ServerContracts/Server.Contracts.cs @@ -203,16 +203,6 @@ public interface IErrorMarshalTesting HResult Return_As_HResult_Struct(int hresultToReturn); } - [ComImport] - [Guid("592386A5-6837-444D-9DE3-250815D18556")] - [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] - public interface IErrorMarshalTesting_VtableGap - { - void _VtblGap1_2(); - [PreserveSig] - HResult Return_As_HResult_Struct(int hresultToReturn); - } - public enum IDispatchTesting_Exception { Disp,