summaryrefslogtreecommitdiff
path: root/libffi/src
diff options
context:
space:
mode:
authorktietz <ktietz@138bc75d-0d04-0410-961f-82ee72b054a4>2012-02-08 21:35:19 +0000
committerktietz <ktietz@138bc75d-0d04-0410-961f-82ee72b054a4>2012-02-08 21:35:19 +0000
commite5fbea4091e302e6d696c978eea3abc231b17adf (patch)
tree04eccef5248b2631ad4b9a46a6f2bc4f49b8cd64 /libffi/src
parentf19ce63be8c51cb72c08d1b83bb23fac0c82cb82 (diff)
downloadgcc-e5fbea4091e302e6d696c978eea3abc231b17adf.tar.gz
* src/prep_cif.c (ffi_prep_cif): Allow for X86_WIN32
also FFI_THISCALL. * src/x86/ffi.c (ffi_closure_THISCALL): Add prototype. (FFI_INIT_TRAMPOLINE_THISCALL): New trampoline code. (ffi_prep_closure_loc): Add FFI_THISCALL support. * src/x86/ffitarget.h (FFI_TRAMPOLINE_SIZE): Adjust size. * src/x86/win32.S (ffi_closure_THISCALL): New closure code for thiscall-calling convention. * testsuite/libffi.call/closure_thiscall.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@184021 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libffi/src')
-rw-r--r--libffi/src/prep_cif.c5
-rw-r--r--libffi/src/x86/ffi.c36
-rw-r--r--libffi/src/x86/ffitarget.h2
-rw-r--r--libffi/src/x86/win32.S25
4 files changed, 67 insertions, 1 deletions
diff --git a/libffi/src/prep_cif.c b/libffi/src/prep_cif.c
index c1c3b9a6c86..e0a0c68cac5 100644
--- a/libffi/src/prep_cif.c
+++ b/libffi/src/prep_cif.c
@@ -93,7 +93,12 @@ ffi_status ffi_prep_cif(ffi_cif *cif, ffi_abi abi, unsigned int nargs,
ffi_type **ptr;
FFI_ASSERT(cif != NULL);
+#ifndef X86_WIN32
FFI_ASSERT((abi > FFI_FIRST_ABI) && (abi <= FFI_DEFAULT_ABI));
+#else
+ FFI_ASSERT(abi > FFI_FIRST_ABI && abi <= FFI_DEFAULT_ABI
+ || abi == FFI_THISCALL);
+#endif
cif->abi = abi;
cif->arg_types = atypes;
diff --git a/libffi/src/x86/ffi.c b/libffi/src/x86/ffi.c
index bbfd95e5ec1..7c01c57c4db 100644
--- a/libffi/src/x86/ffi.c
+++ b/libffi/src/x86/ffi.c
@@ -449,6 +449,8 @@ void FFI_HIDDEN ffi_closure_raw_SYSV (ffi_raw_closure *)
#ifdef X86_WIN32
void FFI_HIDDEN ffi_closure_STDCALL (ffi_closure *)
__attribute__ ((regparm(1)));
+void FFI_HIDDEN ffi_closure_THISCALL (ffi_closure *)
+ __attribute__ ((regparm(1)));
#endif
#ifdef X86_WIN64
void FFI_HIDDEN ffi_closure_win64 (ffi_closure *);
@@ -608,6 +610,33 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue, void **avalue,
*(unsigned int*) &__tramp[6] = __dis; /* jmp __fun */ \
}
+#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] = 0x8324048b; /* mov (%esp), %eax */ \
+ *(unsigned int *) &__tramp[4] = 0x4c890cec; /* sub $12, %esp */ \
+ *(unsigned int *) &__tramp[8] = 0x04890424; /* mov %ecx, 4(%esp) */ \
+ *(unsigned char*) &__tramp[12] = 0x24; /* mov %eax, (%esp) */ \
+ *(unsigned char*) &__tramp[13] = 0xb8; \
+ *(unsigned int *) &__tramp[14] = __size; /* mov __size, %eax */ \
+ *(unsigned int *) &__tramp[18] = 0x08244c8d; /* lea 8(%esp), %ecx */ \
+ *(unsigned int *) &__tramp[22] = 0x4802e8c1; /* shr $2, %eax ; dec %eax */ \
+ *(unsigned short*) &__tramp[26] = 0x0b74; /* jz 1f */ \
+ *(unsigned int *) &__tramp[28] = 0x8908518b; /* 2b: mov 8(%ecx), %edx */ \
+ *(unsigned int *) &__tramp[32] = 0x04c18311; /* mov %edx, (%ecx) ; add $4, %ecx */ \
+ *(unsigned char*) &__tramp[36] = 0x48; /* dec %eax */ \
+ *(unsigned short*) &__tramp[37] = 0xf575; /* jnz 2b ; 1f: */ \
+ *(unsigned char*) &__tramp[39] = 0xb8; \
+ *(unsigned int*) &__tramp[40] = __ctx; /* movl __ctx, %eax */ \
+ *(unsigned char *) &__tramp[44] = 0xe8; \
+ *(unsigned int*) &__tramp[45] = __dis; /* call __fun */ \
+ *(unsigned char*) &__tramp[49] = 0xc2; /* ret */ \
+ *(unsigned short*) &__tramp[50] = (__size + 8); /* ret (__size + 8) */ \
+ }
+
#define FFI_INIT_TRAMPOLINE_STDCALL(TRAMP,FUN,CTX,SIZE) \
{ unsigned char *__tramp = (unsigned char*)(TRAMP); \
unsigned int __fun = (unsigned int)(FUN); \
@@ -650,6 +679,13 @@ ffi_prep_closure_loc (ffi_closure* closure,
(void*)codeloc);
}
#ifdef X86_WIN32
+ else if (cif->abi == FFI_THISCALL)
+ {
+ FFI_INIT_TRAMPOLINE_THISCALL (&closure->tramp[0],
+ &ffi_closure_THISCALL,
+ (void*)codeloc,
+ cif->bytes);
+ }
else if (cif->abi == FFI_STDCALL)
{
FFI_INIT_TRAMPOLINE_STDCALL (&closure->tramp[0],
diff --git a/libffi/src/x86/ffitarget.h b/libffi/src/x86/ffitarget.h
index 4154762d250..dfecd1b3c6e 100644
--- a/libffi/src/x86/ffitarget.h
+++ b/libffi/src/x86/ffitarget.h
@@ -103,7 +103,7 @@ typedef enum ffi_abi {
#define FFI_NATIVE_RAW_API 0
#else
#ifdef X86_WIN32
-#define FFI_TRAMPOLINE_SIZE 13
+#define FFI_TRAMPOLINE_SIZE 52
#else
#ifdef X86_WIN64
#define FFI_TRAMPOLINE_SIZE 29
diff --git a/libffi/src/x86/win32.S b/libffi/src/x86/win32.S
index e472d623c06..e5c93ecf7b9 100644
--- a/libffi/src/x86/win32.S
+++ b/libffi/src/x86/win32.S
@@ -170,6 +170,16 @@ ca_epilogue:
ret
ffi_call_win32 ENDP
+ffi_closure_THISCALL PROC NEAR FORCEFRAME
+ push ebp
+ mov ebp, esp
+ sub esp, 40
+ lea edx, [ebp -24]
+ mov [ebp - 12], edx /* resp */
+ lea edx, [ebp + 12] /* account for stub return address on stack */
+ jmp stub
+ffi_closure_THISCALL ENDP
+
ffi_closure_SYSV PROC NEAR FORCEFRAME
;; the ffi_closure ctx is passed in eax by the trampoline.
@@ -177,6 +187,7 @@ ffi_closure_SYSV PROC NEAR FORCEFRAME
lea edx, [ebp - 24]
mov [ebp - 12], edx ;; resp
lea edx, [ebp + 8]
+stub:
mov [esp + 8], edx ;; args
lea edx, [ebp - 12]
mov [esp + 4], edx ;; &resp
@@ -573,6 +584,19 @@ _ffi_call_win32:
popl %ebp
ret
.ffi_call_win32_end:
+ .balign 16
+ .globl _ffi_closure_THISCALL
+#ifndef __OS2__
+ .def _ffi_closure_THISCALL; .scl 2; .type 32; .endef
+#endif
+_ffi_closure_THISCALL:
+ pushl %ebp
+ movl %esp, %ebp
+ subl $40, %esp
+ leal -24(%ebp), %edx
+ movl %edx, -12(%ebp) /* resp */
+ leal 12(%ebp), %edx /* account for stub return address on stack */
+ jmp .stub
.LFE1:
# This assumes we are using gas.
@@ -591,6 +615,7 @@ _ffi_closure_SYSV:
leal -24(%ebp), %edx
movl %edx, -12(%ebp) /* resp */
leal 8(%ebp), %edx
+.stub:
movl %edx, 4(%esp) /* args = __builtin_dwarf_cfa () */
leal -12(%ebp), %edx
movl %edx, (%esp) /* &resp */