Skip to content

Commit

Permalink
Fix libffi 3.2.1 on 64-bit
Browse files Browse the repository at this point in the history
libffi was broken on 64-bit, any c function returning a struct > 8 bytes and not a multiple of 16 will cause a segfault. This is because between 3.1 and 3.2 somebody changed (size != 1 || size != 2 || size != 4 || size != 8) into (size & (1 | 2 | 4 | 8) == 0), which is not the same.
  • Loading branch information
Furniel committed Jul 26, 2018
1 parent 545c888 commit 679f68d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
50 changes: 50 additions & 0 deletions patches/libffi/fix_return_size.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
--- src/libffi-3.2.1/src/x86/ffi.c.orig 2016-07-20 21:24:49.000771900 +0100
+++ src/libffi-3.2.1/src/x86/ffi.c 2016-07-20 21:25:09.918786700 +0100
@@ -65,7 +65,8 @@
if ((ecif->cif->flags == FFI_TYPE_STRUCT
|| ecif->cif->flags == FFI_TYPE_MS_STRUCT)
#ifdef X86_WIN64
- && ((ecif->cif->rtype->size & (1 | 2 | 4 | 8)) == 0)
+ && (ecif->cif->rtype->size != 1 && ecif->cif->rtype->size != 2
+ && ecif->cif->rtype->size != 4 && ecif->cif->rtype->size != 8)
#endif
)
{
@@ -108,7 +109,7 @@
#ifdef X86_WIN64
if (z > FFI_SIZEOF_ARG
|| ((*p_arg)->type == FFI_TYPE_STRUCT
- && (z & (1 | 2 | 4 | 8)) == 0)
+ && (z != 1 && z != 2 && z != 4 && z != 8))
#if FFI_TYPE_DOUBLE != FFI_TYPE_LONGDOUBLE
|| ((*p_arg)->type == FFI_TYPE_LONGDOUBLE)
#endif
@@ -360,7 +361,8 @@
#ifdef X86_WIN64
if (rvalue == NULL
&& cif->flags == FFI_TYPE_STRUCT
- && ((cif->rtype->size & (1 | 2 | 4 | 8)) == 0))
+ && cif->rtype->size != 1 && cif->rtype->size != 2
+ && cif->rtype->size != 4 && cif->rtype->size != 8)
{
ecif.rvalue = alloca((cif->rtype->size + 0xF) & ~0xF);
}
@@ -545,7 +547,8 @@
if ((cif->flags == FFI_TYPE_STRUCT
|| cif->flags == FFI_TYPE_MS_STRUCT)
#ifdef X86_WIN64
- && ((cif->rtype->size & (1 | 2 | 4 | 8)) == 0)
+ && ((cif->rtype->size != 1 && cif->rtype->size != 2
+ && cif->rtype->size != 4 && cif->rtype->size != 8))
#endif
)
{
@@ -608,7 +611,7 @@
#ifdef X86_WIN64
if (z > FFI_SIZEOF_ARG
|| ((*p_arg)->type == FFI_TYPE_STRUCT
- && (z & (1 | 2 | 4 | 8)) == 0)
+ && (z != 1 && z != 2 && z != 4 && z != 8))
#if FFI_TYPE_DOUBLE != FFI_TYPE_LONGDOUBLE
|| ((*p_arg)->type == FFI_TYPE_LONGDOUBLE)
#endif
4 changes: 3 additions & 1 deletion scripts/libffi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ PKG_PRIORITY=extra

#

PKG_PATCHES=()
PKG_PATCHES=(
libffi/fix_return_size.patch
)

#

Expand Down

0 comments on commit 679f68d

Please sign in to comment.