ยปCore Development>Code coverage>Modules/_ctypes/libffi/testsuite/libffi.call/closure_thiscall.c

Python code coverage for Modules/_ctypes/libffi/testsuite/libffi.call/closure_thiscall.c

#countcontent
1n/a/* Area: closure_call (thiscall convention)
2n/a Purpose: Check handling when caller expects thiscall callee
3n/a Limitations: none.
4n/a PR: none.
5n/a Originator: <ktietz@redhat.com> */
6n/a
7n/a/* { dg-do run { target i?86-*-cygwin* i?86-*-mingw* } } */
8n/a#include "ffitest.h"
9n/a
10n/astatic void
11n/aclosure_test_thiscall(ffi_cif* cif __UNUSED__, void* resp, void** args,
12n/a void* userdata)
13n/a{
14n/a *(ffi_arg*)resp =
15n/a (int)*(int *)args[0] + (int)(*(int *)args[1])
16n/a + (int)(*(int *)args[2]) + (int)(*(int *)args[3])
17n/a + (int)(intptr_t)userdata;
18n/a
19n/a printf("%d %d %d %d: %d\n",
20n/a (int)*(int *)args[0], (int)(*(int *)args[1]),
21n/a (int)(*(int *)args[2]), (int)(*(int *)args[3]),
22n/a (int)*(ffi_arg *)resp);
23n/a
24n/a}
25n/a
26n/atypedef int (__thiscall *closure_test_type0)(int, int, int, int);
27n/a
28n/aint main (void)
29n/a{
30n/a ffi_cif cif;
31n/a void *code;
32n/a ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
33n/a ffi_type * cl_arg_types[17];
34n/a int res;
35n/a void* sp_pre;
36n/a void* sp_post;
37n/a char buf[1024];
38n/a
39n/a cl_arg_types[0] = &ffi_type_uint;
40n/a cl_arg_types[1] = &ffi_type_uint;
41n/a cl_arg_types[2] = &ffi_type_uint;
42n/a cl_arg_types[3] = &ffi_type_uint;
43n/a cl_arg_types[4] = NULL;
44n/a
45n/a /* Initialize the cif */
46n/a CHECK(ffi_prep_cif(&cif, FFI_THISCALL, 4,
47n/a &ffi_type_sint, cl_arg_types) == FFI_OK);
48n/a
49n/a CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test_thiscall,
50n/a (void *) 3 /* userdata */, code) == FFI_OK);
51n/a
52n/a#ifdef _MSC_VER
53n/a __asm { mov sp_pre, esp }
54n/a#else
55n/a asm volatile (" movl %%esp,%0" : "=g" (sp_pre));
56n/a#endif
57n/a res = (*(closure_test_type0)code)(0, 1, 2, 3);
58n/a#ifdef _MSC_VER
59n/a __asm { mov sp_post, esp }
60n/a#else
61n/a asm volatile (" movl %%esp,%0" : "=g" (sp_post));
62n/a#endif
63n/a /* { dg-output "0 1 2 3: 9" } */
64n/a
65n/a printf("res: %d\n",res);
66n/a /* { dg-output "\nres: 9" } */
67n/a
68n/a sprintf(buf, "mismatch: pre=%p vs post=%p", sp_pre, sp_post);
69n/a printf("stack pointer %s\n", (sp_pre == sp_post ? "match" : buf));
70n/a /* { dg-output "\nstack pointer match" } */
71n/a exit(0);
72n/a}