| 1 |
/* Area: closure_call |
| 2 |
Purpose: Check multiple values passing from different type. |
| 3 |
Also, exceed the limit of gpr and fpr registers on PowerPC |
| 4 |
Darwin. |
| 5 |
Limitations: none. |
| 6 |
PR: none. |
| 7 |
Originator: <[email protected]> 20030828 */ |
| 8 |
|
| 9 |
|
| 10 |
#include "ffitest.h" |
| 11 |
|
| 12 |
static void |
| 13 |
closure_loc_test_fn0(ffi_cif* cif __UNUSED__, void* resp, void** args, |
| 14 |
void* userdata) |
| 15 |
{ |
| 16 |
*(ffi_arg*)resp = |
| 17 |
(int)*(unsigned long long *)args[0] + (int)(*(int *)args[1]) + |
| 18 |
(int)(*(unsigned long long *)args[2]) + (int)*(int *)args[3] + |
| 19 |
(int)(*(signed short *)args[4]) + |
| 20 |
(int)(*(unsigned long long *)args[5]) + |
| 21 |
(int)*(int *)args[6] + (int)(*(int *)args[7]) + |
| 22 |
(int)(*(double *)args[8]) + (int)*(int *)args[9] + |
| 23 |
(int)(*(int *)args[10]) + (int)(*(float *)args[11]) + |
| 24 |
(int)*(int *)args[12] + (int)(*(int *)args[13]) + |
| 25 |
(int)(*(int *)args[14]) + *(int *)args[15] + (intptr_t)userdata; |
| 26 |
|
| 27 |
printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d: %d\n", |
| 28 |
(int)*(unsigned long long *)args[0], (int)(*(int *)args[1]), |
| 29 |
(int)(*(unsigned long long *)args[2]), |
| 30 |
(int)*(int *)args[3], (int)(*(signed short *)args[4]), |
| 31 |
(int)(*(unsigned long long *)args[5]), |
| 32 |
(int)*(int *)args[6], (int)(*(int *)args[7]), |
| 33 |
(int)(*(double *)args[8]), (int)*(int *)args[9], |
| 34 |
(int)(*(int *)args[10]), (int)(*(float *)args[11]), |
| 35 |
(int)*(int *)args[12], (int)(*(int *)args[13]), |
| 36 |
(int)(*(int *)args[14]),*(int *)args[15], |
| 37 |
(int)(intptr_t)userdata, (int)*(ffi_arg *)resp); |
| 38 |
|
| 39 |
} |
| 40 |
|
| 41 |
typedef int (*closure_loc_test_type0)(unsigned long long, int, unsigned long long, |
| 42 |
int, signed short, unsigned long long, int, |
| 43 |
int, double, int, int, float, int, int, |
| 44 |
int, int); |
| 45 |
|
| 46 |
int main (void) |
| 47 |
{ |
| 48 |
ffi_cif cif; |
| 49 |
ffi_closure *pcl; |
| 50 |
ffi_type * cl_arg_types[17]; |
| 51 |
int res; |
| 52 |
void *codeloc; |
| 53 |
|
| 54 |
cl_arg_types[0] = &ffi_type_uint64; |
| 55 |
cl_arg_types[1] = &ffi_type_sint; |
| 56 |
cl_arg_types[2] = &ffi_type_uint64; |
| 57 |
cl_arg_types[3] = &ffi_type_sint; |
| 58 |
cl_arg_types[4] = &ffi_type_sshort; |
| 59 |
cl_arg_types[5] = &ffi_type_uint64; |
| 60 |
cl_arg_types[6] = &ffi_type_sint; |
| 61 |
cl_arg_types[7] = &ffi_type_sint; |
| 62 |
cl_arg_types[8] = &ffi_type_double; |
| 63 |
cl_arg_types[9] = &ffi_type_sint; |
| 64 |
cl_arg_types[10] = &ffi_type_sint; |
| 65 |
cl_arg_types[11] = &ffi_type_float; |
| 66 |
cl_arg_types[12] = &ffi_type_sint; |
| 67 |
cl_arg_types[13] = &ffi_type_sint; |
| 68 |
cl_arg_types[14] = &ffi_type_sint; |
| 69 |
cl_arg_types[15] = &ffi_type_sint; |
| 70 |
cl_arg_types[16] = NULL; |
| 71 |
|
| 72 |
/* Initialize the cif */ |
| 73 |
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 16, |
| 74 |
&ffi_type_sint, cl_arg_types) == FFI_OK); |
| 75 |
|
| 76 |
pcl = ffi_closure_alloc(sizeof(ffi_closure), &codeloc); |
| 77 |
CHECK(pcl != NULL); |
| 78 |
CHECK(codeloc != NULL); |
| 79 |
|
| 80 |
CHECK(ffi_prep_closure_loc(pcl, &cif, closure_loc_test_fn0, |
| 81 |
(void *) 3 /* userdata */, codeloc) == FFI_OK); |
| 82 |
|
| 83 |
#if !defined(FFI_EXEC_STATIC_TRAMP) && !defined(__EMSCRIPTEN__) |
| 84 |
/* With static trampolines, the codeloc does not point to closure */ |
| 85 |
CHECK(memcmp(pcl, FFI_CL(codeloc), sizeof(*pcl)) == 0); |
| 86 |
#endif |
| 87 |
|
| 88 |
res = (*((closure_loc_test_type0)codeloc)) |
| 89 |
(1LL, 2, 3LL, 4, 127, 429LL, 7, 8, 9.5, 10, 11, 12, 13, |
| 90 |
19, 21, 1); |
| 91 |
/* { dg-output "1 2 3 4 127 429 7 8 9 10 11 12 13 19 21 1 3: 680" } */ |
| 92 |
printf("res: %d\n",res); |
| 93 |
/* { dg-output "\nres: 680" } */ |
| 94 |
CHECK(res == 680); |
| 95 |
exit(0); |
| 96 |
} |