Skip to content

Invoking an unmanaged fastcall function pointer under x86 Windows fails at runtime #113851

Open
@frabert

Description

@frabert

Description

Exporting a function using UnmanagedCallersOnly and the Fastcall calling convention will work, but calling ((delegate* unmanaged[Fastcall]<int, int>)somePtr)(someArg) will fail with

System.TypeLoadException
  HResult=0x80131522
  Message=Unsupported unmanaged calling convention.

Reproduction Steps

unsafe
{
    int x = ((delegate* unmanaged[Fastcall]<int, int>)IntPtr.Zero)(0);
}

Expected behavior

The function pointer should be called.

Actual behavior

The call fails due to the Fastcall calling convention being unimplemented.

Regression?

Unlikely that this was implemented before and removed afterwards.

Known Workarounds

No response

Configuration

Windows x86

Technically I'm running from a CoreCLR embedded in an application, but it should not matter in this scenario.

Other information

COMPlusThrow(kTypeLoadException, IDS_INVALID_PINVOKE_CALLCONV);

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-x86area-Interop-coreclrin-prThere is an active PR which will close this issue when it is merged

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions