-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Q: How to use UnmanagedCallersOnlyAttribute? #37930
Comments
I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label. |
@hypeartist The Another way to use this attribute is via the low level hosting APIs - This attribute is really a low level building block for tooling or providing symmetry for C# function pointers. |
So this attribute itself doesn't create native export and you need to go extra mile if you need one? Is it safe to use C# function pointers feature to get a pointer to C# method and manually pass that pointer to native code (using pinvoke or something)? What's the difference compared to Marshal.GetFunctionPointerForDelegate? |
Correct. It is an attribute that indicates to the JIT that this function will only be called from a non-managed context and therefore you should add that transition logic.
Yes. That is exactly the intent - the function itself and subsequently the pointer can only be dispatched to in an unmanaged way. Note that the
Mostly performance and an allocation. Using |
Is there any info on how to use that new attribute?
All I have found is:
runtime/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/UnmanagedCallersOnlyAttribute.cs
Line 8 in f185bd5
I have tried to apply it to some static POD method of a class library but what next? It doesn't show up in exports (used some third-party tools to check) and also I can't obtain its address having dll's handle via
GetProcAddress
.Thanks in advance for any clarification.
PS: using .NET 5 Preview 7
The text was updated successfully, but these errors were encountered: