[Mono-dev] Method for common marshaling between calls in/out of mono?

Robert Jordan robertj at gmx.net
Mon Mar 20 11:00:56 UTC 2017


On 19.03.2017 23:02, Chase wrote:
> I may have missed what I'm looking for in the documentation, please let me
> know if I have.  If not I'd like to hear from someone familiar with the code
> base on how difficult of an undertaking this might be for me to attempt to
> add to the project.

The boxing of structs on thunk signatures is performed on purpose.
By the time the thunks were designed, there was no straightforward
way to mirror a managed struct declaration in C/C++ because of
unexpected alignment issues.

The canonical sample was

struct PointF {
	float x;
	float y;
}

whose fields got aligned at 8 bytes boundaries by Mono, while GCC
has aligned them at 4 bytes (i386 ABI).

Years later the alignment issue was removed, but the thunk APIs
remained unchanged for obvious reasons (compatibility).
This can be fixed, but it requires some decent knowledge
of Mono's runtime.

Another issue is returning structs from methods. This is usually
not compatible across CPUs and ABIs. Internal calls are avoiding
such signatures, and are returning values as an "out" argument
instead.

As there is no fix for this (AFAIK), thunks can't return unboxed
structs. mono_runtime_invoke doesn't either.

Robert




More information about the Mono-devel-list mailing list