Skip to content

Conversation

@elinor-fung
Copy link
Member

@elinor-fung elinor-fung commented May 17, 2021

Fixes #51156

  • Add UnmanagedCallConvAttribute
  • Use UnmanagedCallConv if the calling convention is not specified or specified as winapi on pinvokeimpl metadata
    • Also used for suppressing GC transition, since CallConvSuppressGCTransition can be specified
    • Check attribute in mono - cc @CoffeeFlux @lambdageek
    • Check attribute in crossgen2 - cc @trylek
  • Add tests
  • Not handled in crossgen
    • Similar to UnmanagedCallersOnly - since we don't include the support to read a type array, make crossgen bail if the method is marked UnmanagedCallConv

This does not implement checking of UnmanagedCallConv for delegates.

cc @AaronRobinsonMSFT @jkoritzinsky

@ghost
Copy link

ghost commented May 17, 2021

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@elinor-fung elinor-fung force-pushed the unmanagedCallConv branch 2 times, most recently from 58d494e to 26651ea Compare May 17, 2021 23:50
@jkotas
Copy link
Member

jkotas commented May 18, 2021

This also does not implement checking of UnmanagedCallConv for delegates

I would not bother with implementing the advanced calling conventions for delegates. I think we should make everybody who needs to do interop with function pointers to use function pointers.

@elinor-fung elinor-fung marked this pull request as ready for review May 18, 2021 18:26
Copy link
Member

@lambdageek lambdageek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if the mono code could avoid managed allocation to decode the custom attribute. That would make it usable for AOT compilation. If that turns out not to work, we should still take the code, disabled, and do a follow-up fix to mono_reflection_create_custom_attr_data_args_noalloc to make it work.

@AaronRobinsonMSFT
Copy link
Member

I would not bother with implementing the advanced calling conventions for delegates.

I am okay with this also. I would like to see us error out though if it is set on a Delegate - unless someone can argue it being a no-op is more appropriate.

@jkotas
Copy link
Member

jkotas commented May 18, 2021

I would like to see us error out though if it is set on a Delegate

If you try to use this on a Delegate, the compiler will produce an error thanks to AttributeTargets.Method.

Copy link
Member

@lambdageek lambdageek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mono bits lgtm

@elinor-fung
Copy link
Member Author

All the tests passed - failure was from uploading results (azure.devops.exceptions.AzureDevOpsClientRequestError: Operation returned an invalid status code of 503)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extensible Calling Conventions for native callee functions

5 participants