1/* Area: ffi_call, closure_call 2 Purpose: Check passing of multiple unsigned char values. 3 Limitations: none. 4 PR: PR13221. 5 Originator: <andreast@gcc.gnu.org> 20031129 */ 6 7/* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */ 8#include "ffitest.h" 9 10unsigned char test_func_fn(unsigned char a1, unsigned char a2, 11 unsigned char a3, unsigned char a4) 12{ 13 unsigned char result; 14 15 result = a1 + a2 + a3 + a4; 16 17 printf("%d %d %d %d: %d\n", a1, a2, a3, a4, result); 18 19 return result; 20 21} 22 23static void test_func_gn(ffi_cif *cif, void *rval, void **avals, void *data) 24{ 25 unsigned char a1, a2, a3, a4; 26 27 a1 = *(unsigned char *)avals[0]; 28 a2 = *(unsigned char *)avals[1]; 29 a3 = *(unsigned char *)avals[2]; 30 a4 = *(unsigned char *)avals[3]; 31 32 *(ffi_arg *)rval = test_func_fn(a1, a2, a3, a4); 33 34} 35 36typedef unsigned char (*test_type)(unsigned char, unsigned char, 37 unsigned char, unsigned char); 38void test_func(ffi_cif *cif, void *rval, void **avals, void *data) 39{ 40 printf("%d %d %d %d\n", *(unsigned char *)avals[0], 41 *(unsigned char *)avals[1], *(unsigned char *)avals[2], 42 *(unsigned char *)avals[3]); 43} 44int main (void) 45{ 46 ffi_cif cif; 47#ifndef USING_MMAP 48 static ffi_closure cl; 49#endif 50 ffi_closure *pcl; 51 void * args_dbl[5]; 52 ffi_type * cl_arg_types[5]; 53 ffi_arg res_call; 54 unsigned char a, b, c, d, res_closure; 55 56#ifdef USING_MMAP 57 pcl = allocate_mmap (sizeof(ffi_closure)); 58#else 59 pcl = &cl; 60#endif 61 62 a = 1; 63 b = 2; 64 c = 127; 65 d = 125; 66 67 args_dbl[0] = &a; 68 args_dbl[1] = &b; 69 args_dbl[2] = &c; 70 args_dbl[3] = &d; 71 args_dbl[4] = NULL; 72 73 cl_arg_types[0] = &ffi_type_uchar; 74 cl_arg_types[1] = &ffi_type_uchar; 75 cl_arg_types[2] = &ffi_type_uchar; 76 cl_arg_types[3] = &ffi_type_uchar; 77 cl_arg_types[4] = NULL; 78 79 /* Initialize the cif */ 80 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4, 81 &ffi_type_uchar, cl_arg_types) == FFI_OK); 82 83 ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl); 84 /* { dg-output "1 2 127 125: 255" } */ 85 printf("res: %d\n", res_call); 86 /* { dg-output "\nres: 255" } */ 87 88 CHECK(ffi_prep_closure(pcl, &cif, test_func_gn, NULL) == FFI_OK); 89 90 res_closure = (*((test_type)pcl))(1, 2, 127, 125); 91 /* { dg-output "\n1 2 127 125: 255" } */ 92 printf("res: %d\n", res_closure); 93 /* { dg-output "\nres: 255" } */ 94 95 exit(0); 96} 97