Returning structs by value on different platforms.
On x86-32, we distinguish between "small structs" and "large structs".
On Linux, NetBSD and Solaris, all structs are large structs. On Mac OS X, Windows, FreeBSD and OpenBSD, all structs are small structs except those that satisfy one of the following:
complex float
valueSmall structs are returned in EAX:EDX, with the first 4 bytes in EAX and the second 4 bytes in EDX. If the
struct is smaller than 4 bytes in size, EDX is undefined.
Large structs are handled as follows. The struct-returning function actually has a hidden first parameter which must be a pointer to a memory area large enough to store the returned struct. This memory area must be supplied by the caller. The EAX and EDX registers are unused in this case.
If the struct-returning function uses the stdcall calling convention (Windows only), then it behaves exactly like a void-returning function with an extra first parameter. However, on non-Windows platforms where the C calling convention is used, the struct-returning function returns with the stack pointer incremented by 4 bytes. So after calling such a function, if you care about the value of ESP, you must decrement ESP by 4 bytes, by pushing a dummy value, for instance.
This revision created on Tue, 21 Jul 2009 00:29:08 by slava