How to fool ABI on x86_64 and push parameters on stack

First of all there doesn’t seem to be any good way of doing this. But if you really need it, you can use this information (from ABI reference):

If the class is MEMORY, pass the argument on the stack.

If the size of an object is larger than four eightbytes, or it contains unaligned fields, it has class MEMORY.

The thing I can use here is if it contains unaligned fields. So I can make a struct with unaligned fields and a union so I can access my data “easily”:

[c]#pragma pack(push)
#pragma pack(1)
typedef struct fool_abi_struct {
char a;
short b;
char c;
} fool_abi_t;
#pragma pack(pop)
typedef union nonabi_union {
fool_abi_t nabi;
long long d;
} nabi_t;[/c]

You have to typecast a little but that’s ok:

[c]
#define NABI_PARAM (nabi_t)(long long)

int func(nabi_t a) {
printf("%llxn", a.d);
return 0;
}

void callfunc()
{
func(NABI_PARAM 0x123456);
}
[/c]

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s