[NativeAOT] How can I implement dynamic internal calls(or Qcall) in my custom NativeAOT runtime? #111143
Replies: 1 comment 1 reply
-
Have you forked this repository and modified the runtime to have a new internal calls or qcalls? Or are you trying to statically linking to a library that is not defined in dotnet/runtime? The second is more common and documented, so I'll answer it first. Generating direct calls for P/InvokesSee this article. Rather than allowing the .NET Runtime to lazily load shared libraries (.DLLs) when using P/Invoke, you can have the native linker either dynamically or statically link the final executable against native libraries. Defining a new internal call in a custom NativeAOT runtimeThis is only something you should do if you are forking this repository (dotnet/runtime) in order to add a new .NET runtime feature. It is much easier to use the method defined in the previous section, if possible. I'll use an existing internal call, FCIMPL2(FC_BOOL_RET, RhRegisterGcCallout, GcRestrictedCalloutKind eKind, void * pCallout)
{
// ...
}
FCIMPLEND In the C# side, you use the [MethodImplAttribute(MethodImplOptions.InternalCall)]
[RuntimeImport(RuntimeLibrary, "RhRegisterGcCallout")]
internal static extern bool RhRegisterGcCallout(GcRestrictedCalloutKind eKind, IntPtr pCalloutMethod); ( Note that while the Important note: if you are doing nothing in your internal call the blocks for any amount of time, you should use a QCALL instead. This will ensure that the garbage collector can suspend threads in a timely manner. See |
Beta Was this translation helpful? Give feedback.
-
I'm trying to implement Mono's add_internal_call API and the invocation of internal calls. I'm confused about how NativeAOT achieves internal call invocation. My idea is to modify the ILC's ILEmitter, similar to TypeSystemThrowingILEmitter, to generate native method calls. However, emitting IL is a bit difficult for me. Does anyone have any good suggestions?
Beta Was this translation helpful? Give feedback.
All reactions