-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Custom internal calls in .NET Core hosting #11941
Comments
Would the calli proposal in the csharp "Compiler Intrinsics" https://github.com/dotnet/csharplang/blob/master/proposals/intrinsics.md#calli fit this need? (Though I don't know if that's the latest variant) /cc @jaredpar |
@benaadams Unfortunately, I haven't tested it myself, but someone has: |
Behaviour should be improved in coreclr dotnet/coreclr#13756 |
(Hopefully I'm not completely wrong with this reply, this is what I've figured our from looking at the CLR source code.) One issue I can see is that all the internal calls inside the runtime have to do a few things to remain safe, i.e. look at It has to play nice with the GC ( I assume that all of this is taken care of, in the generated stubs, when using For a bit more info see Calling from managed to native code, Is your code GC-safe? and PInvokes |
We currently use P/Invoke to call into things like MKL and the overhead does show up in backtraces. We only pass unsafe pointers to unmanaged
then we'd be extremely happy! |
I think the proper way to address this is to add attribute to annotate PInvoke methods that always take less than microsecond and that do not do other problematic actions like taking locks that can deadlock with GC. The runtime would recognize this attribute and skip the full PInvoke transition for these. More details in dotnet/coreclr#22383 (comment) |
Thanks for your information @benaadams. I did a simple test and Interestingly, |
Not that I recommend this for your code, if you're satisfied with the performance ... but you can use On x64 the managed calling convention is the native x64 calling convention, and on Windows x86 I believe it is You can read more about this in |
I honestly don't know why delegates retrieved by |
The difference between
The delegate has an extra indirection in it. This indirection costs extra instructions.
If you consider doing something like this, make sure that the unmanaged code that you are calling meets all constrains listed in the doc. |
What I actually need is to call function pointers provided by unmanaged code at runtime, which can not be retrieved by |
Why can’t you use calli with the unmanaged calling convention? That will solve your problem without having to worry about the constraints and GC delaying of using a managed calling convention. |
You said you don't recommend this? |
|
As an experiment I tested Results still in https://github.com/dotnet/coreclr/issues/22320#issuecomment-466736048 |
@NextTurn I don't see any current action here so am closing this. Please file a new issue if there is some action that is being suggested or asked about. Thank you. |
P/Invoke is not so efficient as internal calls when working with frequent native code calls, for instance, game scripting runtime.
Internal calls in CoreCLR are hard coded in
ecalllist.h
and limited tomscorlib.dll
scope. While Mono provides amono_add_internal_call
API which became the first choice of Unity and CRYENGINE.Will you provide an API to register custom internal calls?
The text was updated successfully, but these errors were encountered: