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

[mono] Implement support for UnmanagedCallersOnlyAttribute #38209

Closed
lambdageek opened this issue Jun 22, 2020 · 4 comments
Closed

[mono] Implement support for UnmanagedCallersOnlyAttribute #38209

lambdageek opened this issue Jun 22, 2020 · 4 comments
Assignees
Labels
area-Codegen-meta-mono runtime-mono specific to the Mono runtime
Milestone

Comments

@lambdageek
Copy link
Member

The UnmanagedCallersOnlyAttribute is part of the C# FunctionPointers proposal, specifically it's applied to methods that will be called from native code only #32462 (but note that the calling convention part will be changing #37612)

Implementation note: the presence of the attribute means that ldftn should return a pointer to a native-to-managed wrapper.

@lambdageek lambdageek added area-Codegen-meta-mono runtime-mono specific to the Mono runtime labels Jun 22, 2020
@lambdageek lambdageek added this to the 5.0.0 milestone Jun 22, 2020
@ghost
Copy link

ghost commented Jun 22, 2020

Tagging subscribers to this area: @lewurm
Notify danmosemsft if you want to be subscribed.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Jun 22, 2020
@lambdageek lambdageek removed the untriaged New issue has not been triaged by the area owner label Jun 22, 2020
@lambdageek
Copy link
Member Author

A related issue is to correctly parse the new "Unmanaged" (0x09) metadata calling convention. That's subject of #38480

@lambdageek lambdageek self-assigned this Jun 26, 2020
@lambdageek
Copy link
Member Author

lambdageek commented Jun 27, 2020

Update actually this case will be a runtime exception. In CoreCLR since the UnmanagedCallersOnly check is done in the method itself (not at the ldftn site), it's hard for them to do the checking around a P/Invoke. Mono will follow CoreCLR behavior.


Another implementation note: if the function is actually already a native function we should get a pointer to it without a wrapper.

[UnamangedCallersOnly]
[DllImport("SomeLib", EntryPoint="foo")]
public static extern void foo ();

In this case ldftn foo should still be a pointer to foo, not to a managed-to-native wrapper.

@lambdageek
Copy link
Member Author

Implemented by #38728

@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Codegen-meta-mono runtime-mono specific to the Mono runtime
Projects
None yet
Development

No branches or pull requests

2 participants