[Mono-dev] Registering internal calls at runtime
mboisse at noesisinnovation.net
Mon Jul 12 19:02:42 EDT 2010
Thank you Robert, I appreciate your involvement.
Here's our problem: any calls to mono_add_internal_call is ineffective when made from managed code.
Our initial idea was to use P/Invoke to load a dynamic library and run some initialization method in it which would make the appropriate registrations. Based on tests we did, any call which doesn't precede the mono_jit_exec call has no effect.
Which of these assumptions can we make?
Do classes using internal calls have their methods bound to internal methods as soon as their owning assembly is initialized?
Or is the internal method registry is simply completely sealed once mono_jit_exec is running?
I was hoping the binding process was done "on request", only the first time a method is called from managed code (because an exception is thrown only when a call to the unfound internal method is made).
Actually, internal method declarations in the managed code like
would be considerably more powerful if it allowed a module and a method symbol to be supplied directly some way like this:
[MethodImplAttribute(MethodImplOptions.MonoNativeCall, "MyDynamicLibrary.dll", "MyMethod")]
This last approach gives us a bunch of important features:
1) Late binding to dynamic libraries implementing managed classes in C becomes possible.
2) No fancy registration mechanism (as suggested, and yet not totally working / risk free for late binding scenarios) is necessary from the unmanaged code to register methods.
3) Dynamic library loading can be made implicitly (from the explicit dependency embodied by the attribute declaration).
I wish something like that existed to call native code. Please tell me there's a way.
From: Robert Jordan [via Mono]
Sent: Monday, July 12, 2010 5:36 PM
Subject: Re: Registering internal calls at runtime
On 12.07.2010 21:43, MBoisse wrote:
> Has there been any improvements regarding late registrations of internal
> methods at runtime using "mono_add_internal_call"?
> Would it make sense to load and register C functions in a dll from managed
> code, and only then have the assembly referring to them loaded?
> There are many scenarios in which the C functions we need to make calls to
> aren't known at compile time of the embedding unmanaged code (ie mono.exe)
> and therefore registrations can't be made before the call to mono_jit_exec
> is made. However, most often the functions are known at the managed code
> compile time.
> Is P/Invoke still our only option?
You could add an internal call that adds internal calls ;) Problem solved.
Or resort to an internal p/invoke from the runtime itself:
static extern void mono_add_internal_call(string desc, IntPtr ftnptr);
Mono-devel-list mailing list
View message @ http://mono.1490590.n4.nabble.com/Registering-internal-calls-at-runtime-tp1527179p2286774.html
To unsubscribe from Re: Registering internal calls at runtime, click here.
View this message in context: http://mono.1490590.n4.nabble.com/Registering-internal-calls-at-runtime-tp1527179p2286841.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Mono-devel-list