• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /macosx-10.10.1/pyobjc-45/2.6/pyobjc/pyobjc-core/libffi-src/tests/testsuite/libffi.call/
1/* Area:		ffi_call, closure_call
2   Purpose:		Check pointer arguments across multiple hideous stack frames.
3   Limitations:	none.
4   PR:			none.
5   Originator:	Blake Chaffin 6/7/2007	*/
6
7/* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
8#include "ffitest.h"
9
10static	long dummyVar;
11
12long dummy_func(
13	long double a1, char b1,
14	long double a2, char b2,
15	long double a3, char b3,
16	long double a4, char b4)
17{
18	return a1 + b1 + a2 + b2 + a3 + b3 + a4 + b4;
19}
20
21void* cls_pointer_fn2(void* a1, void* a2)
22{
23	long double	trample1	= (long)a1 + (long)a2;
24	char		trample2	= ((char*)&a1)[0] + ((char*)&a2)[0];
25	long double	trample3	= (long)trample1 + (long)a1;
26	char		trample4	= trample2 + ((char*)&a1)[1];
27	long double	trample5	= (long)trample3 + (long)a2;
28	char		trample6	= trample4 + ((char*)&a2)[1];
29	long double	trample7	= (long)trample5 + (long)trample1;
30	char		trample8	= trample6 + trample2;
31
32	dummyVar	= dummy_func(trample1, trample2, trample3, trample4,
33		trample5, trample6, trample7, trample8);
34
35	void*	result	= (void*)((long)a1 + (long)a2);
36
37	printf("0x%08x 0x%08x: 0x%08x\n", a1, a2, result);
38
39	return result;
40}
41
42void* cls_pointer_fn1(void* a1, void* a2)
43{
44	long double	trample1	= (long)a1 + (long)a2;
45	char		trample2	= ((char*)&a1)[0] + ((char*)&a2)[0];
46	long double	trample3	= (long)trample1 + (long)a1;
47	char		trample4	= trample2 + ((char*)&a1)[1];
48	long double	trample5	= (long)trample3 + (long)a2;
49	char		trample6	= trample4 + ((char*)&a2)[1];
50	long double	trample7	= (long)trample5 + (long)trample1;
51	char		trample8	= trample6 + trample2;
52
53	dummyVar	= dummy_func(trample1, trample2, trample3, trample4,
54		trample5, trample6, trample7, trample8);
55
56	void*	result	= (void*)((long)a1 + (long)a2);
57
58	printf("0x%08x 0x%08x: 0x%08x\n", a1, a2, result);
59
60	result	= cls_pointer_fn2(result, a1);
61
62	return result;
63}
64
65static void
66cls_pointer_gn(ffi_cif* cif, void* resp, void** args, void* userdata)
67{
68	void*	a1	= *(void**)(args[0]);
69	void*	a2	= *(void**)(args[1]);
70
71	long double	trample1	= (long)a1 + (long)a2;
72	char		trample2	= ((char*)&a1)[0] + ((char*)&a2)[0];
73	long double	trample3	= (long)trample1 + (long)a1;
74	char		trample4	= trample2 + ((char*)&a1)[1];
75	long double	trample5	= (long)trample3 + (long)a2;
76	char		trample6	= trample4 + ((char*)&a2)[1];
77	long double	trample7	= (long)trample5 + (long)trample1;
78	char		trample8	= trample6 + trample2;
79
80	dummyVar	= dummy_func(trample1, trample2, trample3, trample4,
81		trample5, trample6, trample7, trample8);
82
83	*(void**)resp = cls_pointer_fn1(a1, a2);
84}
85
86int main (void)
87{
88	ffi_cif	cif;
89#ifndef USING_MMAP
90	static ffi_closure	cl;
91#endif
92	ffi_closure*	pcl;
93	void*			args[3];
94//	ffi_type		cls_pointer_type;
95	ffi_type*		arg_types[3];
96
97#ifdef USING_MMAP
98	pcl = allocate_mmap(sizeof(ffi_closure));
99#else
100	pcl = &cl;
101#endif
102
103/*	cls_pointer_type.size = sizeof(void*);
104	cls_pointer_type.alignment = 0;
105	cls_pointer_type.type = FFI_TYPE_POINTER;
106	cls_pointer_type.elements = NULL;*/
107
108	void*	arg1	= (void*)0x01234567;
109	void*	arg2	= (void*)0x89abcdef;
110	ffi_arg	res		= 0;
111
112	arg_types[0] = &ffi_type_pointer;
113	arg_types[1] = &ffi_type_pointer;
114	arg_types[2] = NULL;
115
116	CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_pointer,
117		arg_types) == FFI_OK);
118
119	args[0] = &arg1;
120	args[1] = &arg2;
121	args[2] = NULL;
122
123	printf("\n");
124	ffi_call(&cif, FFI_FN(cls_pointer_fn1), &res, args);
125
126	printf("res: 0x%08x\n", res);
127	// { dg-output "\n0x01234567 0x89abcdef: 0x8acf1356" }
128	// { dg-output "\n0x8acf1356 0x01234567: 0x8bf258bd" }
129	// { dg-output "\nres: 0x8bf258bd" }
130
131	CHECK(ffi_prep_closure(pcl, &cif, cls_pointer_gn, NULL) == FFI_OK);
132
133	res = (ffi_arg)((void*(*)(void*, void*))(pcl))(arg1, arg2);
134
135	printf("res: 0x%08x\n", res);
136	// { dg-output "\n0x01234567 0x89abcdef: 0x8acf1356" }
137	// { dg-output "\n0x8acf1356 0x01234567: 0x8bf258bd" }
138	// { dg-output "\nres: 0x8bf258bd" }
139
140	exit(0);
141}
142