Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crossgenning of sparse COM interface types on non-Windows and add test #40404

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/coreclr/src/zap/zapimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
}

//-----------------------------------------------------------------------------
Expand Down
18 changes: 18 additions & 0 deletions src/tests/Interop/COM/NETClients/VtableGap/App.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity
type="win32"
name="NetPrimitivesClient"
version="1.0.0.0" />

<dependency>
<dependentAssembly>
<!-- RegFree COM -->
<assemblyIdentity
type="win32"
name="COMNativeServer.X"
version="1.0.0.0"/>
</dependentAssembly>
</dependency>

</assembly>
45 changes: 45 additions & 0 deletions src/tests/Interop/COM/NETClients/VtableGap/ErrorTests.cs
Original file line number Diff line number Diff line change
@@ -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
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
{
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);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<ApplicationManifest>App.manifest</ApplicationManifest>
<!-- ilasm round-trip testing blocked on ILAsm supporting embedding resources. See https://github.com/dotnet/runtime/issues/11412 -->
<IlasmRoundTripIncompatible>true</IlasmRoundTripIncompatible>
<!-- This test would require the runincontext.exe to include App.manifest describing the COM interfaces -->
<UnloadabilityIncompatible>true</UnloadabilityIncompatible>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="ErrorTests.cs" />
<Compile Include="../../ServerContracts/Server.CoClasses.cs" />
<Compile Include="../../ServerContracts/Server.Contracts.cs" />
<Compile Include="../../ServerContracts/ServerGuids.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Condition="'$(TargetsWindows)' == 'true'" Include="../../NativeServer/CMakeLists.txt" />
<ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
</ItemGroup>
</Project>
48 changes: 48 additions & 0 deletions src/tests/Interop/COM/NETClients/VtableGap/Program.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
10 changes: 10 additions & 0 deletions src/tests/Interop/COM/ServerContracts/Server.Contracts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@ public interface IErrorMarshalTesting
HResult Return_As_HResult_Struct(int hresultToReturn);
}

[ComImport]
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
[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,
Expand Down