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

Blittability check doesn't account for generic structs #90828

Closed
jtschuster opened this issue Aug 18, 2023 · 1 comment · Fixed by #90836
Closed

Blittability check doesn't account for generic structs #90828

jtschuster opened this issue Aug 18, 2023 · 1 comment · Fixed by #90836

Comments

@jtschuster
Copy link
Member

jtschuster commented Aug 18, 2023

MarshallingRequired check does not have a case for generic value types and will report them as requiring marshalling at runtime and throw an invalid program exception.

A minimal repro is below:

public static unsafe class Program
{
    public static unsafe void Main()
    {
        unsafe {
            void* m = (void*)(delegate* unmanaged[MemberFunction]<void*, MyStruct<nint>, int, int> )&ABI_Method;
            var i = ((delegate* unmanaged[MemberFunction]<MyStruct<int>, int, int>)m)(new MyStruct<int>(), 1);
        }
    }
    [global::System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(global::System.Runtime.CompilerServices.CallConvMemberFunction) })]
    internal static int ABI_Method(void* __this_native, MyStruct<nint> __p_native, int size)
    { return 0;}

}

struct MyStruct<T> where T: unmanaged {}
@ghost
Copy link

ghost commented Aug 18, 2023

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

Issue Details

MarshallingRequired check does not have a case for generic value types and will report them as requiring marshalling at runtime and throw an invalid program exception.

A minimal repro is below:

public static unsafe class Program
{
    public static unsafe void Main()
    {
        unsafe {
            void* m = (void*)(delegate* unmanaged[MemberFunction]<void*, MyStruct<nint>, int, int> )&ABI_Method;
            var i = ((delegate* unmanaged[MemberFunction]<MyStruct<int>, int, int>)m)(new MyStruct<int>(), 1);
        }
    }
    [global::System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(global::System.Runtime.CompilerServices.CallConvMemberFunction) })]
    internal static int ABI_Method(void* __this_native, MyStruct<nint> __p_native, int size)
    { return 0;}

}

struct MyStruct<T> where T: unmanaged {}
Author: jtschuster
Assignees: jtschuster
Labels:

area-System.Runtime.InteropServices

Milestone: 9.0.0

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Aug 18, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Sep 1, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Oct 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant