Fix ABI on 32-bit non-Windows x86: go back to trampoline size 10

The trampoline size is part of the ABI, so it cannot change.  Move the
logic from the stdcall and thiscall trampolines to the functions they
call, to reduce them both to 10 bytes.

This drops the previously added support for raw THISCALL closures on
non-Windows.  (Non-raw THISCALL closures still work.)
This commit is contained in:
Josh Triplett
2014-04-05 17:33:42 -07:00
parent c860a992fe
commit b5fed60194
3 changed files with 67 additions and 35 deletions
+44 -17
View File
@@ -33,8 +33,13 @@
#include <fficonfig.h>
#include <ffi.h>
#define CIF_ABI_OFFSET 0
#define CIF_BYTES_OFFSET 16
#ifdef _MSC_VER
#define CLOSURE_CIF_OFFSET ((FFI_TRAMPOLINE_SIZE + 3) AND NOT 3)
.386
.MODEL FLAT, C
@@ -188,12 +193,12 @@ ca_epilogue:
ret
ffi_call_win32 ENDP
ffi_closure_THISCALL PROC NEAR FORCEFRAME
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 PROC NEAR
;; Insert the register argument on the stack as the first argument
xchg DWORD PTR [esp+4], ecx
xchg DWORD PTR [esp], ecx
push ecx
jmp ffi_closure_STDCALL
ffi_closure_THISCALL ENDP
ffi_closure_SYSV PROC NEAR FORCEFRAME
@@ -464,8 +469,18 @@ cd_retlongdouble:
jmp cd_epilogue
cd_epilogue:
;; Epilogue code is autogenerated.
ret
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
jmp edx
ffi_closure_STDCALL ENDP
_TEXT ENDS
@@ -473,6 +488,8 @@ END
#else
#define CLOSURE_CIF_OFFSET ((FFI_TRAMPOLINE_SIZE + 3) & ~3)
#if defined(SYMBOL_UNDERSCORE)
#define USCORE_SYMBOL(x) _##x
#else
@@ -657,13 +674,11 @@ FFI_HIDDEN(ffi_closure_THISCALL)
.def _ffi_closure_THISCALL; .scl 2; .type 32; .endef
#endif
USCORE_SYMBOL(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
/* Insert the register argument on the stack as the first argument */
xchg %ecx, 4(%esp)
xchg %ecx, (%esp)
push %ecx
jmp .ffi_closure_STDCALL_internal
.LFE1:
# This assumes we are using gas.
@@ -685,7 +700,6 @@ USCORE_SYMBOL(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 */
@@ -811,6 +825,8 @@ USCORE_SYMBOL(ffi_closure_SYSV):
#define RAW_CLOSURE_FUN_OFFSET (RAW_CLOSURE_CIF_OFFSET + 4)
#define RAW_CLOSURE_USER_DATA_OFFSET (RAW_CLOSURE_FUN_OFFSET + 4)
#define CIF_FLAGS_OFFSET 20
#ifdef X86_WIN32
.balign 16
FFI_HIDDEN(ffi_closure_raw_THISCALL)
.globl USCORE_SYMBOL(ffi_closure_raw_THISCALL)
@@ -827,6 +843,8 @@ USCORE_SYMBOL(ffi_closure_raw_THISCALL):
movl %edx, 12(%esp) /* user_data */
leal 12(%ebp), %edx /* __builtin_dwarf_cfa () */
jmp .stubraw
#endif /* X86_WIN32 */
# This assumes we are using gas.
.balign 16
#if defined(X86_WIN32)
@@ -958,6 +976,7 @@ FFI_HIDDEN(ffi_closure_STDCALL)
.def _ffi_closure_STDCALL; .scl 2; .type 32; .endef
#endif
USCORE_SYMBOL(ffi_closure_STDCALL):
.ffi_closure_STDCALL_internal:
.LFB5:
pushl %ebp
.LCFI9:
@@ -1070,7 +1089,15 @@ USCORE_SYMBOL(ffi_closure_STDCALL):
.Lscls_epilogue:
movl %ebp, %esp
popl %ebp
ret
popl %ecx
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
.ffi_closure_STDCALL_end:
.LFE5: