Support fastcall closures

libffi on 32-bit x86 now supports closures for all supported ABIs.
Thus, rewrite the last remaining duplicated-by-ABI test (closure_stdcall
and closure_thiscall) to use the generic ABI_NUM/ABI_ATTR mechanism.
This commit is contained in:
Josh Triplett
2014-04-20 12:03:25 -07:00
parent 93a24f216b
commit d36952273d
5 changed files with 54 additions and 80 deletions

View File

@@ -448,6 +448,8 @@ void FFI_HIDDEN ffi_closure_STDCALL (ffi_closure *)
__attribute__ ((regparm(1)));
void FFI_HIDDEN ffi_closure_THISCALL (ffi_closure *)
__attribute__ ((regparm(1)));
void FFI_HIDDEN ffi_closure_FASTCALL (ffi_closure *)
__attribute__ ((regparm(1)));
#else
void FFI_HIDDEN ffi_closure_win64 (ffi_closure *);
#endif
@@ -672,6 +674,12 @@ ffi_prep_closure_loc (ffi_closure* closure,
&ffi_closure_SYSV,
(void*)codeloc);
}
else if (cif->abi == FFI_FASTCALL)
{
FFI_INIT_TRAMPOLINE_STDCALL (&closure->tramp[0],
&ffi_closure_FASTCALL,
(void*)codeloc);
}
else if (cif->abi == FFI_THISCALL)
{
FFI_INIT_TRAMPOLINE_STDCALL (&closure->tramp[0],

View File

@@ -472,14 +472,19 @@ cd_epilogue:
mov esp, ebp
pop ebp
pop ecx
mov ecx, DWORD PTR [ecx + (CLOSURE_CIF_OFFSET-10)]
cmp DWORD PTR [ecx + CIF_ABI_OFFSET], 3
mov ecx, DWORD PTR [ecx + CIF_BYTES_OFFSET]
jne cd_not_thiscall
add ecx, 4
cd_not_thiscall:
pop edx
add esp, ecx
mov ecx, DWORD PTR [ecx + (CLOSURE_CIF_OFFSET-10)]
add esp, DWORD PTR [ecx + CIF_BYTES_OFFSET]
mov ecx, DWORD PTR [ecx + CIF_ABI_OFFSET]
cmp ecx, 3
je cd_thiscall
cmp ecx, 4
jne cd_not_fastcall
add esp, 4
cd_thiscall:
add esp, 4
cd_not_fastcall:
jmp edx
ffi_closure_STDCALL ENDP
@@ -679,6 +684,20 @@ USCORE_SYMBOL(ffi_closure_THISCALL):
xchg %ecx, (%esp)
push %ecx
jmp .ffi_closure_STDCALL_internal
.balign 16
FFI_HIDDEN(ffi_closure_FASTCALL)
.globl USCORE_SYMBOL(ffi_closure_FASTCALL)
#if defined(X86_WIN32) && !defined(__OS2__)
.def _ffi_closure_FASTCALL; .scl 2; .type 32; .endef
#endif
USCORE_SYMBOL(ffi_closure_FASTCALL):
/* Insert the register arguments on the stack as the first two arguments */
xchg %edx, 4(%esp)
xchg %ecx, (%esp)
push %edx
push %ecx
jmp .ffi_closure_STDCALL_internal
.LFE1:
# This assumes we are using gas.
@@ -1090,14 +1109,18 @@ USCORE_SYMBOL(ffi_closure_STDCALL):
movl %ebp, %esp
popl %ebp
popl %ecx
popl %edx
movl (CLOSURE_CIF_OFFSET-10)(%ecx), %ecx
cmpl $3, CIF_ABI_OFFSET(%ecx) /* FFI_THISCALL */
movl CIF_BYTES_OFFSET(%ecx), %ecx
jne 1f
addl $4, %ecx
1: popl %edx
addl %ecx, %esp
jmp *%edx
addl CIF_BYTES_OFFSET(%ecx), %esp
movl CIF_ABI_OFFSET(%ecx), %ecx
cmpl $3, %ecx /* FFI_THISCALL */
je 1f
cmpl $4, %ecx /* FFI_FASTCALL */
jne 2f
addl $4, %esp
1: addl $4, %esp
2: jmp *%edx
.ffi_closure_STDCALL_end:
.LFE5: