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.
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
diff --git a/src/x86/ffi.c b/src/x86/ffi.c
index bcfc153..64b19ec 100644
--- a/src/x86/ffi.c
+++ b/src/x86/ffi.c
@@ -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],
diff --git a/src/x86/win32.S b/src/x86/win32.S
index 0a655c4..699ea46 100644
--- a/src/x86/win32.S
+++ b/src/x86/win32.S
@@ -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:
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index acd15c5..da10465 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -35,14 +35,14 @@ libffi.call/cls_align_longdouble_split2.c libffi.call/return_dbl2.c \
libffi.call/return_fl3.c libffi.call/stret_medium.c \
libffi.call/nested_struct6.c libffi.call/closure_fn3.c \
libffi.call/float3.c libffi.call/many2.c \
-libffi.call/closure_stdcall.c libffi.call/cls_align_uint16.c \
+libffi.call/closure_simple.c libffi.call/cls_align_uint16.c \
libffi.call/cls_9byte1.c libffi.call/closure_fn6.c \
libffi.call/cls_double_va.c libffi.call/cls_align_pointer.c \
libffi.call/cls_align_longdouble.c libffi.call/closure_fn2.c \
libffi.call/cls_sshort.c \
libffi.call/nested_struct.c libffi.call/cls_20byte.c \
libffi.call/cls_longdouble.c libffi.call/cls_multi_uchar.c \
-libffi.call/return_uc.c libffi.call/closure_thiscall.c \
+libffi.call/return_uc.c \
libffi.call/cls_18byte.c libffi.call/cls_8byte.c \
libffi.call/promotion.c \
libffi.call/return_dbl.c libffi.call/cls_24byte.c \
diff --git a/testsuite/libffi.call/closure_simple.c b/testsuite/libffi.call/closure_simple.c
new file mode 100644
index 0000000..5a4e728
--- /dev/null
+++ b/testsuite/libffi.call/closure_simple.c
@@ -0,0 +1,55 @@
+/* Area: closure_call
+ Purpose: Check simple closure handling with all ABIs
+ Limitations: none.
+ PR: none.
+ Originator: <twalljava@dev.java.net> */
+
+/* { dg-do run } */
+#include "ffitest.h"
+
+static void
+closure_test(ffi_cif* cif __UNUSED__, void* resp, void** args, void* userdata)
+{
+ *(ffi_arg*)resp =
+ (int)*(int *)args[0] + (int)(*(int *)args[1])
+ + (int)(*(int *)args[2]) + (int)(*(int *)args[3])
+ + (int)(intptr_t)userdata;
+
+ printf("%d %d %d %d: %d\n",
+ (int)*(int *)args[0], (int)(*(int *)args[1]),
+ (int)(*(int *)args[2]), (int)(*(int *)args[3]),
+ (int)*(ffi_arg *)resp);
+
+}
+
+typedef int (ABI_ATTR *closure_test_type0)(int, int, int, int);
+
+int main (void)
+{
+ ffi_cif cif;
+ void *code;
+ ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
+ ffi_type * cl_arg_types[17];
+ int res;
+
+ cl_arg_types[0] = &ffi_type_uint;
+ cl_arg_types[1] = &ffi_type_uint;
+ cl_arg_types[2] = &ffi_type_uint;
+ cl_arg_types[3] = &ffi_type_uint;
+ cl_arg_types[4] = NULL;
+
+ /* Initialize the cif */
+ CHECK(ffi_prep_cif(&cif, ABI_NUM, 4,
+ &ffi_type_sint, cl_arg_types) == FFI_OK);
+
+ CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test,
+ (void *) 3 /* userdata */, code) == FFI_OK);
+
+ res = (*(closure_test_type0)code)(0, 1, 2, 3);
+ /* { dg-output "0 1 2 3: 9" } */
+
+ printf("res: %d\n",res);
+ /* { dg-output "\nres: 9" } */
+
+ exit(0);
+}
diff --git a/testsuite/libffi.call/closure_stdcall.c b/testsuite/libffi.call/closure_stdcall.c
deleted file mode 100644
index fd1e4b0..0000000
--- a/testsuite/libffi.call/closure_stdcall.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Area: closure_call (stdcall convention)
- Purpose: Check handling when caller expects stdcall callee
- Limitations: none.
- PR: none.
- Originator: <twalljava@dev.java.net> */
-
-/* { dg-do run { target i?86-*-* } } */
-#include "ffitest.h"
-
-static void
-closure_test_stdcall(ffi_cif* cif __UNUSED__, void* resp, void** args,
- void* userdata)
-{
- *(ffi_arg*)resp =
- (int)*(int *)args[0] + (int)(*(int *)args[1])
- + (int)(*(int *)args[2]) + (int)(*(int *)args[3])
- + (int)(intptr_t)userdata;
-
- printf("%d %d %d %d: %d\n",
- (int)*(int *)args[0], (int)(*(int *)args[1]),
- (int)(*(int *)args[2]), (int)(*(int *)args[3]),
- (int)*(ffi_arg *)resp);
-
-}
-
-typedef int (__STDCALL__ *closure_test_type0)(int, int, int, int);
-
-int main (void)
-{
- ffi_cif cif;
- void *code;
- ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
- ffi_type * cl_arg_types[17];
- int res;
-
- cl_arg_types[0] = &ffi_type_uint;
- cl_arg_types[1] = &ffi_type_uint;
- cl_arg_types[2] = &ffi_type_uint;
- cl_arg_types[3] = &ffi_type_uint;
- cl_arg_types[4] = NULL;
-
- /* Initialize the cif */
- CHECK(ffi_prep_cif(&cif, FFI_STDCALL, 4,
- &ffi_type_sint, cl_arg_types) == FFI_OK);
-
- CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test_stdcall,
- (void *) 3 /* userdata */, code) == FFI_OK);
-
- res = (*(closure_test_type0)code)(0, 1, 2, 3);
- /* { dg-output "0 1 2 3: 9" } */
-
- printf("res: %d\n",res);
- /* { dg-output "\nres: 9" } */
-
- exit(0);
-}
diff --git a/testsuite/libffi.call/closure_thiscall.c b/testsuite/libffi.call/closure_thiscall.c
deleted file mode 100644
index 8f7d2fa..0000000
--- a/testsuite/libffi.call/closure_thiscall.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Area: closure_call (thiscall convention)
- Purpose: Check handling when caller expects thiscall callee
- Limitations: none.
- PR: none.
- Originator: <ktietz@redhat.com> */
-
-/* { dg-do run { target i?86-*-* } } */
-#include "ffitest.h"
-
-static void
-closure_test_thiscall(ffi_cif* cif __UNUSED__, void* resp, void** args,
- void* userdata)
-{
- *(ffi_arg*)resp =
- (int)*(int *)args[0] + (int)(*(int *)args[1])
- + (int)(*(int *)args[2]) + (int)(*(int *)args[3])
- + (int)(intptr_t)userdata;
-
- printf("%d %d %d %d: %d\n",
- (int)*(int *)args[0], (int)(*(int *)args[1]),
- (int)(*(int *)args[2]), (int)(*(int *)args[3]),
- (int)*(ffi_arg *)resp);
-
-}
-
-typedef int (__THISCALL__ *closure_test_type0)(int, int, int, int);
-
-int main (void)
-{
- ffi_cif cif;
- void *code;
- ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
- ffi_type * cl_arg_types[17];
- int res;
-
- cl_arg_types[0] = &ffi_type_uint;
- cl_arg_types[1] = &ffi_type_uint;
- cl_arg_types[2] = &ffi_type_uint;
- cl_arg_types[3] = &ffi_type_uint;
- cl_arg_types[4] = NULL;
-
- /* Initialize the cif */
- CHECK(ffi_prep_cif(&cif, FFI_THISCALL, 4,
- &ffi_type_sint, cl_arg_types) == FFI_OK);
-
- CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test_thiscall,
- (void *) 3 /* userdata */, code) == FFI_OK);
-
- res = (*(closure_test_type0)code)(0, 1, 2, 3);
- /* { dg-output "0 1 2 3: 9" } */
-
- printf("res: %d\n",res);
- /* { dg-output "\nres: 9" } */
-
- exit(0);
-}