x86: Fix thiscall and fastcall stack cleanup behavior (#611) These are meant to use callee clean-up.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
diff --git a/src/x86/ffi.c b/src/x86/ffi.c
index 26dbc05..24431c1 100644
--- a/src/x86/ffi.c
+++ b/src/x86/ffi.c
@@ -538,10 +538,17 @@ ffi_closure_inner (struct closure_frame *frame, char *stack)
frame->fun (cif, rvalue, avalue, frame->user_data);
- if (cabi == FFI_STDCALL)
- return flags + (cif->bytes << X86_RET_POP_SHIFT);
- else
- return flags;
+ switch (cabi)
+ {
+ case FFI_STDCALL:
+ return flags | (cif->bytes << X86_RET_POP_SHIFT);
+ case FFI_THISCALL:
+ case FFI_FASTCALL:
+ return flags | ((cif->bytes - (narg_reg * FFI_SIZEOF_ARG))
+ << X86_RET_POP_SHIFT);
+ default:
+ return flags;
+ }
}
ffi_status
@@ -558,12 +565,12 @@ ffi_prep_closure_loc (ffi_closure* closure,
switch (cif->abi)
{
case FFI_SYSV:
- case FFI_THISCALL:
- case FFI_FASTCALL:
case FFI_MS_CDECL:
dest = ffi_closure_i386;
break;
case FFI_STDCALL:
+ case FFI_THISCALL:
+ case FFI_FASTCALL:
case FFI_PASCAL:
dest = ffi_closure_STDCALL;
break;