[Mono-list] Internalcall

Jason Whittington jasonw@develop.com
Fri, 28 Dec 2001 11:35:39 -0700


Internalcall methods are ones where the body is generated by the runtime,
typically because they represents some intrinsic capability of the runtime
itself.  Sort of like P/Invoke in reverse - rather than calling out to
unmanaged
code it's a method that has to be linked to a method implemented by the
runtime
itself.

Thread.StartInternal is the classic instance in my mind,
there's no reasonable way to start a thread from pure managed code -
the runtime has to do whatever makes sense for the platform.  If you look
at the mono source for Thread
(/mcs/class/corlib/System.Threading/Thread.cs)
you'll see that Start_internal is marked as
[MethodImpl(MethodImplOptions.InternalCall)]
and has no body.

So the runtime itself has to have a priori knowledge of
internalcall methods and know how to implement them.  I always
imagined (but haven't proved) that the runtime has more or less
a dictionary so that when JITting it sees the flag and finds the
matching function and links it up internally.  There is no way
to actually attach any kind of *body* to an internalcall method
(you'll notice that all internalcall methods you find have empty
bodies) so I think the "dictionary" approach may be the only
way to do it.

Jason