[Mono-dev] Alignment issue when interoperate with native code

Robert Jordan robertj at gmx.net
Sun Jan 30 17:25:46 EST 2011


Christian,

On 30.01.2011 21:56, Christian Krause wrote:
> It would be great if someone could confirm whether my findings are
> correct. ;-) Thank you very much in advance!

Your findings are correct :) Mono is aligning its structs and
classes using GCC's __alignof__ builtin which returns
optimal alignments that do not always match the ABI.
Floats in the x86 ABI are such a notable exception.

Although the marshaller normally takes care of this mismatch,
in your case (unsafe pointers) the struct remains unmarshalled
because it is assumed to be fully blittable.

You can test alignment mismatches of a given type
with these macros:

#define MONO_ALIGN(type) __alignof__(type)
#define ABI_ALIGN(type) offsetof(struct { char c; type x; }, x)

Robert



More information about the Mono-devel-list mailing list