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 mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */ 8#include "ffitest.h" 9 10void* cls_pointer_fn(void* a1, void* a2) 11{ 12 void* result = (void*)((long)a1 + (long)a2); 13 14 printf("0x%08x 0x%08x: 0x%08x\n", a1, a2, result); 15 16 return result; 17} 18 19static void 20cls_pointer_gn(ffi_cif* cif, void* resp, void** args, void* userdata) 21{ 22 void* a1 = *(void**)(args[0]); 23 void* a2 = *(void**)(args[1]); 24 25 *(void**)resp = cls_pointer_fn(a1, a2); 26} 27 28int main (void) 29{ 30 ffi_cif cif; 31#ifndef USING_MMAP 32 static ffi_closure cl; 33#endif 34 ffi_closure* pcl; 35 void* args[3]; 36// ffi_type cls_pointer_type; 37 ffi_type* arg_types[3]; 38 39#ifdef USING_MMAP 40 pcl = allocate_mmap(sizeof(ffi_closure)); 41#else 42 pcl = &cl; 43#endif 44 45/* cls_pointer_type.size = sizeof(void*); 46 cls_pointer_type.alignment = 0; 47 cls_pointer_type.type = FFI_TYPE_POINTER; 48 cls_pointer_type.elements = NULL;*/ 49 50 void* arg1 = (void*)0x12345678; 51 void* arg2 = (void*)0x89abcdef; 52 ffi_arg res = 0; 53 54 arg_types[0] = &ffi_type_pointer; 55 arg_types[1] = &ffi_type_pointer; 56 arg_types[2] = NULL; 57 58 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_pointer, 59 arg_types) == FFI_OK); 60 61 args[0] = &arg1; 62 args[1] = &arg2; 63 args[2] = NULL; 64 65 ffi_call(&cif, FFI_FN(cls_pointer_fn), &res, args); 66 /* { dg-output "0x12345678 0x89abcdef: 0x9be02467" } */ 67 printf("res: 0x%08x\n", res); 68 /* { dg-output "\nres: 0x9be02467" } */ 69 70 CHECK(ffi_prep_closure(pcl, &cif, cls_pointer_gn, NULL) == FFI_OK); 71 72 res = (ffi_arg)((void*(*)(void*, void*))(pcl))(arg1, arg2); 73 /* { dg-output "\n0x12345678 0x89abcdef: 0x9be02467" } */ 74 printf("res: 0x%08x\n", res); 75 /* { dg-output "\nres: 0x9be02467" } */ 76 77 exit(0); 78} 79