Debian Codegraph @

testsuite/libffi.closures/cls_pointer.c

raw
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 CHECK((unsigned int)(uintptr_t) a1 == 0x12345678);
20 CHECK((unsigned int)(uintptr_t) a2 == 0x89abcdef);
21 CHECK((unsigned int)(uintptr_t) result == 0x9be02467);
22
23 return result;
24 }
25
26 static void
27 cls_pointer_gn(ffi_cif* cif __UNUSED__, void* resp,
28 void** args, void* userdata __UNUSED__)
29 {
30 void* a1 = *(void**)(args[0]);
31 void* a2 = *(void**)(args[1]);
32
33 *(void**)resp = cls_pointer_fn(a1, a2);
34 }
35
36 int main (void)
37 {
38 ffi_cif cif;
39 void *code;
40 ffi_closure* pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
41 void* args[3];
42 /* ffi_type cls_pointer_type; */
43 ffi_type* arg_types[3];
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", (unsigned int) res);
68 /* { dg-output "\nres: 0x9be02467" } */
69
70 CHECK(ffi_prep_closure_loc(pcl, &cif, cls_pointer_gn, NULL, code) == FFI_OK);
71
72 res = (ffi_arg)(uintptr_t)((void*(*)(void*, void*))(code))(arg1, arg2);
73 /* { dg-output "\n0x12345678 0x89abcdef: 0x9be02467" } */
74 printf("res: 0x%08x\n", (unsigned int) res);
75 /* { dg-output "\nres: 0x9be02467" } */
76 CHECK(res == 0x9be02467);
77
78 exit(0);
79 }