[Mono-dev] Registering internal calls at runtime
mboisse at noesisinnovation.net
Mon Jul 12 19:05:19 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:
This last approach gives us a bunch of important features:
1) Late binding to dynamic libraries implementing managed classes in C
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" <robertj at gmx.net>
Sent: Monday, July 12, 2010 5:35 PM
To: <mono-devel-list at lists.ximian.com>
Subject: Re: [Mono-dev] 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
>> 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
>> aren't known at compile time of the embedding unmanaged code (ie
>> and therefore registrations can't be made before the call to
>> 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
> Mono-devel-list at lists.ximian.com
More information about the Mono-devel-list