Skip to content

Commit d21881f

Browse files
authored
Fix x86/ffi64 calls with 6 gp and some sse registers (libffi#848)
* Fix x86/ffi64 calls with 6 gp and some sse registers * Add test demonstating issue when mixing gp and sse registers
1 parent 8a0d029 commit d21881f

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

src/x86/ffi64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
651651
break;
652652
default:
653653
reg_args->gpr[gprcount] = 0;
654-
memcpy (&reg_args->gpr[gprcount], a, size);
654+
memcpy (&reg_args->gpr[gprcount], a, sizeof(UINT64));
655655
}
656656
gprcount++;
657657
break;
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/* Area: ffi_call
2+
Purpose: Demonstrate structures with integers corrupting earlier floats
3+
Limitations: none.
4+
PR: #848
5+
Originator: kellda */
6+
7+
/* { dg-do run } */
8+
#include "ffitest.h"
9+
10+
typedef struct
11+
{
12+
unsigned long i;
13+
float f;
14+
} test_structure_int_float;
15+
16+
static float ABI_ATTR struct_int_float(test_structure_int_float ts1,
17+
test_structure_int_float ts2,
18+
test_structure_int_float ts3,
19+
test_structure_int_float ts4,
20+
test_structure_int_float ts5,
21+
test_structure_int_float ts6)
22+
{
23+
return ts1.f;
24+
}
25+
26+
int main (void)
27+
{
28+
ffi_cif cif;
29+
ffi_type *args[MAX_ARGS];
30+
void *values[MAX_ARGS];
31+
ffi_type ts_type;
32+
ffi_type *ts_type_elements[3];
33+
float rfloat;
34+
35+
test_structure_int_float ts_arg[6];
36+
37+
ts_type.size = 0;
38+
ts_type.alignment = 0;
39+
ts_type.type = FFI_TYPE_STRUCT;
40+
ts_type.elements = ts_type_elements;
41+
ts_type_elements[0] = &ffi_type_ulong;
42+
ts_type_elements[1] = &ffi_type_float;
43+
ts_type_elements[2] = NULL;
44+
45+
args[0] = &ts_type;
46+
values[0] = &ts_arg[0];
47+
args[1] = &ts_type;
48+
values[1] = &ts_arg[1];
49+
args[2] = &ts_type;
50+
values[2] = &ts_arg[2];
51+
args[3] = &ts_type;
52+
values[3] = &ts_arg[3];
53+
args[4] = &ts_type;
54+
values[4] = &ts_arg[4];
55+
args[5] = &ts_type;
56+
values[5] = &ts_arg[5];
57+
58+
/* Initialize the cif */
59+
CHECK(ffi_prep_cif(&cif, ABI_NUM, 6, &ffi_type_float, args) == FFI_OK);
60+
61+
ts_arg[0].i = 1;
62+
ts_arg[0].f = 1.11f;
63+
ts_arg[1].i = 2;
64+
ts_arg[1].f = 2.22f;
65+
ts_arg[2].i = 3;
66+
ts_arg[2].f = 3.33f;
67+
ts_arg[3].i = 4;
68+
ts_arg[3].f = 4.44f;
69+
ts_arg[4].i = 5;
70+
ts_arg[4].f = 5.55f;
71+
ts_arg[5].i = 6;
72+
ts_arg[5].f = 6.66f;
73+
74+
printf ("%g\n", ts_arg[0].f);
75+
printf ("%g\n", ts_arg[1].f);
76+
printf ("%g\n", ts_arg[2].f);
77+
printf ("%g\n", ts_arg[3].f);
78+
printf ("%g\n", ts_arg[4].f);
79+
printf ("%g\n", ts_arg[5].f);
80+
81+
ffi_call(&cif, FFI_FN(struct_int_float), &rfloat, values);
82+
83+
printf ("%g\n", rfloat);
84+
85+
CHECK(rfloat == 1.11f);
86+
87+
exit(0);
88+
}

0 commit comments

Comments
 (0)