| 1 |
/* Area: ffi_call, closure_call |
| 2 |
Purpose: Check pointer arguments. |
| 3 |
Limitations: none. |
| 4 |
PR: none. |
| 5 |
Originator: Blake Chaffin 6/6/2007 */ |
| 6 |
|
| 7 |
/* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */ |
| 8 |
#include "ffitest.h" |
| 9 |
|
| 10 |
void* cls_pointer_fn(void* a1, void* a2) |
| 11 |
{ |
| 12 |
void* result = (void*)((intptr_t)a1 + (intptr_t)a2); |
| 13 |
|
| 14 |
printf("0x%08x 0x%08x: 0x%08x\n", |
| 15 |
(unsigned int)(uintptr_t) a1, |
| 16 |
(unsigned int)(uintptr_t) a2, |
| 17 |
(unsigned int)(uintptr_t) result); |
| 18 |
|
| 19 |
return result; |
| 20 |
} |
| 21 |
|
| 22 |
static void |
| 23 |
cls_pointer_gn(ffi_cif* cif __UNUSED__, void* resp, |
| 24 |
void** args, void* userdata __UNUSED__) |
| 25 |
{ |
| 26 |
void* a1 = *(void**)(args[0]); |
| 27 |
void* a2 = *(void**)(args[1]); |
| 28 |
|
| 29 |
*(void**)resp = cls_pointer_fn(a1, a2); |
| 30 |
} |
| 31 |
|
| 32 |
int main (void) |
| 33 |
{ |
| 34 |
ffi_cif cif; |
| 35 |
void *code; |
| 36 |
ffi_closure* pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); |
| 37 |
void* args[3]; |
| 38 |
/* ffi_type cls_pointer_type; */ |
| 39 |
ffi_type* arg_types[3]; |
| 40 |
|
| 41 |
/* cls_pointer_type.size = sizeof(void*); |
| 42 |
cls_pointer_type.alignment = 0; |
| 43 |
cls_pointer_type.type = FFI_TYPE_POINTER; |
| 44 |
cls_pointer_type.elements = NULL;*/ |
| 45 |
|
| 46 |
void* arg1 = (void*)0x12345678; |
| 47 |
void* arg2 = (void*)0x89abcdef; |
| 48 |
ffi_arg res = 0; |
| 49 |
|
| 50 |
arg_types[0] = &ffi_type_pointer; |
| 51 |
arg_types[1] = &ffi_type_pointer; |
| 52 |
arg_types[2] = NULL; |
| 53 |
|
| 54 |
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_pointer, |
| 55 |
arg_types) == FFI_OK); |
| 56 |
|
| 57 |
args[0] = &arg1; |
| 58 |
args[1] = &arg2; |
| 59 |
args[2] = NULL; |
| 60 |
|
| 61 |
ffi_call(&cif, FFI_FN(cls_pointer_fn), &res, args); |
| 62 |
/* { dg-output "0x12345678 0x89abcdef: 0x9be02467" } */ |
| 63 |
printf("res: 0x%08x\n", (unsigned int) res); |
| 64 |
/* { dg-output "\nres: 0x9be02467" } */ |
| 65 |
|
| 66 |
CHECK(ffi_prep_closure_loc(pcl, &cif, cls_pointer_gn, NULL, code) == FFI_OK); |
| 67 |
|
| 68 |
res = (ffi_arg)(uintptr_t)((void*(*)(void*, void*))(code))(arg1, arg2); |
| 69 |
/* { dg-output "\n0x12345678 0x89abcdef: 0x9be02467" } */ |
| 70 |
printf("res: 0x%08x\n", (unsigned int) res); |
| 71 |
/* { dg-output "\nres: 0x9be02467" } */ |
| 72 |
|
| 73 |
exit(0); |
| 74 |
} |