This is the mail archive of the
libffi-discuss@sourceware.org
mailing list for the libffi project.
Re: [patch libffi]: Add thiscall-closure support for fixing regression PR/51500
- From: Uros Bizjak <ubizjak at gmail dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Kai Tietz <ktietz70 at googlemail dot com>, libffi-discuss at sourceware dot org, Anthony Green <green at redhat dot com>, Andrew Haley <aph at redhat dot com>
- Date: Tue, 31 Jan 2012 09:45:36 +0100
- Subject: Re: [patch libffi]: Add thiscall-closure support for fixing regression PR/51500
Hello!
> this patch adds missing support of the X86_WIN32 calling-convention
> for thiscall-closures. ?As thiscall-convention can be only used in C++
> for class-member calls, the assumption that first argument gets passed
> in register is always valid. ?As it is either the "this" pointer, or
> the structure-aggregate-return-pointer.
> This patch is necessary to fix on gcc's trunk the PR 51500 completely.
> +#define FFI_INIT_TRAMPOLINE_THISCALL(TRAMP,FUN,CTX,SIZE) \
> +{ unsigned char *__tramp = (unsigned char*)(TRAMP); \
> + ? unsigned int ?__fun = (unsigned int)(FUN); \
> + ? unsigned int ?__ctx = (unsigned int)(CTX); \
> + ? unsigned int ?__dis = __fun - (__ctx + 22); ?\
> + ? unsigned short __size = (unsigned short)(SIZE); \
> + ? *(unsigned int *) &__tramp[0] = 0x8924048b; /* mov (%esp), %eax */ \
> + ? *(unsigned int *) &__tramp[4] = 0xec83240c; /* mov %ecx, (%esp) */ \
> + ? *(unsigned int *) &__tramp[8] = 0x24048904; /* sub $4,(%esp) */ \
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?/* mov %eax, (%esp) */ \
> + ? *(unsigned char*) &__tramp[12] = 0xb8; \
> + ? *(unsigned int*) ?&__tramp[13] = __ctx; /* movl __ctx, %eax */ \
> + ? *(unsigned char *) ?&__tramp[17] = 0xe8; \
> + ? *(unsigned int*) ?&__tramp[18] = __dis; /* call __fun ?*/ \
> + ? *(unsigned char*) ?&__tramp[22] = 0xc2; /* ret ?*/ \
> + ? *(unsigned short*) ?&__tramp[23] = __size; /* ret __size ?*/ \
> + }
This code violate 16byte stack alignment assumption at call.
Uros.