[Mono-dev] how does unmanaged callback marshalling work in full aot?

Brian Luczkiewicz brian at sooloos.com
Sat Jul 30 17:51:16 EDT 2011

I just thought of a scheme to do non-static delegate marshalling without
code generation, but it's a little bit goofy.

Allocate a structure that contains two things:

(1) the instance ptr that you want to capture
(2) the function ptr for a compile-time-generated invoker that implements
the desired unmanaged function signature.

Then hand this structure off to unmanaged-land as if it were a function

when you try to execute the function, the kernel will raise a fault. The
runtime can notice that it's in this situation and invoke (2) with (1)
either using another compile time generated function to forward the call, or
(maybe on x86) by rewriting the stack to push the instance pointer + then
jumping to the real function.

There's obviously a cost associated with the fault. There's also a chance
that the specific implementation of iOS's limitations would prohibit this
(the kernel might murder the process before we get a chance to recover).

Anyways, just a thought..

On Fri, Jul 29, 2011 at 5:14 PM, Geoff Norton <grompf at gmail.com> wrote:

> It is disabled in full-aot environments.  Full-aot only supports static
> delegates to be pinvoked, and even then they need to be decorated with a
> special attribute.
> See https://github.com/mono/mono/blob/master/mono/mini/aot-compiler.c around
> line 2793.
> -g
> On 2011-07-29, at 5:03 PM, Brian Luczkiewicz wrote:
> I'm having trouble seeing how an arbitrary delegate can be marshalled into
> an unmanaged function pointer without runtime code generation to capture the
> object pointer.
> Is this functionality disabled in full-aot environments or is it
> accomplished by some mechanism that I'm not considering?
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20110730/a5944051/attachment.html 

More information about the Mono-devel-list mailing list