aboutsummaryrefslogtreecommitdiff
path: root/libffi
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2010-10-01 09:31:49 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2010-10-01 09:31:49 +0200
commit731fc5f040ae78d2bedb8caed5e5f6c15e8071d1 (patch)
treecb68ecf8788e12e49305ed8b8af678fb3921a2e1 /libffi
parent16045c71e76e48153446fe2d4b59c6c1b482e3ac (diff)
downloadgcc-731fc5f040ae78d2bedb8caed5e5f6c15e8071d1.zip
gcc-731fc5f040ae78d2bedb8caed5e5f6c15e8071d1.tar.gz
gcc-731fc5f040ae78d2bedb8caed5e5f6c15e8071d1.tar.bz2
re PR libffi/45677 (Bad stack allocation for ffi function calls on x86-64)
PR libffi/45677 * src/x86/ffi64.c (ffi_prep_cif_machdep): Ensure cif->bytes is a multiple of 8. * testsuite/libffi.call/many2.c: New test. From-SVN: r164829
Diffstat (limited to 'libffi')
-rw-r--r--libffi/ChangeLog7
-rw-r--r--libffi/src/x86/ffi64.c4
-rw-r--r--libffi/testsuite/libffi.call/many2.c54
3 files changed, 63 insertions, 2 deletions
diff --git a/libffi/ChangeLog b/libffi/ChangeLog
index 4ebcb84..02a2b15 100644
--- a/libffi/ChangeLog
+++ b/libffi/ChangeLog
@@ -1,3 +1,10 @@
+2010-10-01 Jakub Jelinek <jakub@redhat.com>
+
+ PR libffi/45677
+ * src/x86/ffi64.c (ffi_prep_cif_machdep): Ensure cif->bytes is
+ a multiple of 8.
+ * testsuite/libffi.call/many2.c: New test.
+
2010-08-20 Mark Wielaard <mjw@redhat.com>
* src/closures.c (open_temp_exec_file_mnt): Check if getmntent_r
diff --git a/libffi/src/x86/ffi64.c b/libffi/src/x86/ffi64.c
index 07a2627..340b8d0 100644
--- a/libffi/src/x86/ffi64.c
+++ b/libffi/src/x86/ffi64.c
@@ -378,7 +378,7 @@ ffi_prep_cif_machdep (ffi_cif *cif)
if (align < 8)
align = 8;
- bytes = ALIGN(bytes, align);
+ bytes = ALIGN (bytes, align);
bytes += cif->arg_types[i]->size;
}
else
@@ -390,7 +390,7 @@ ffi_prep_cif_machdep (ffi_cif *cif)
if (ssecount)
flags |= 1 << 11;
cif->flags = flags;
- cif->bytes = bytes;
+ cif->bytes = ALIGN (bytes, 8);
return FFI_OK;
}
diff --git a/libffi/testsuite/libffi.call/many2.c b/libffi/testsuite/libffi.call/many2.c
new file mode 100644
index 0000000..1077159
--- /dev/null
+++ b/libffi/testsuite/libffi.call/many2.c
@@ -0,0 +1,54 @@
+/* Area: ffi_call
+ Purpose: Check uint8_t arguments.
+ Limitations: none.
+ PR: PR45677.
+ Originator: Dan Witte <dwitte@gmail.com> 20100916 */
+
+/* { dg-do run } */
+
+#include "ffitest.h"
+
+#define NARGS 7
+
+typedef unsigned char u8;
+
+__attribute__((noinline)) uint8_t
+foo (uint8_t a, uint8_t b, uint8_t c, uint8_t d,
+ uint8_t e, uint8_t f, uint8_t g)
+{
+ return a + b + c + d + e + f + g;
+}
+
+uint8_t
+bar (uint8_t a, uint8_t b, uint8_t c, uint8_t d,
+ uint8_t e, uint8_t f, uint8_t g)
+{
+ return foo (a, b, c, d, e, f, g);
+}
+
+int
+main (void)
+{
+ ffi_type *ffitypes[NARGS];
+ int i;
+ ffi_cif cif;
+ ffi_arg result = 0;
+ uint8_t args[NARGS];
+ void *argptrs[NARGS];
+
+ for (i = 0; i < NARGS; ++i)
+ ffitypes[i] = &ffi_type_uint8;
+
+ CHECK (ffi_prep_cif (&cif, FFI_DEFAULT_ABI, NARGS,
+ &ffi_type_uint8, ffitypes) == FFI_OK);
+
+ for (i = 0; i < NARGS; ++i)
+ {
+ args[i] = i;
+ argptrs[i] = &args[i];
+ }
+ ffi_call (&cif, FFI_FN (bar), &result, argptrs);
+
+ CHECK (result == 21);
+ return 0;
+}