Commit f3a9726b773 for nodejs
commit f3a9726b773e768afcc13308521528bf8badfc8c
Author: Node.js GitHub Bot <github-bot@iojs.org>
Date: Wed Dec 2 10:35:50 2026 -0500
deps: update libffi to 3.8.2
PR-URL: https://github.com/nodejs/node/pull/67859
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
diff --git a/deps/libffi/ChangeLog b/deps/libffi/ChangeLog
index 133b18134c5..cd2e62c16b5 100644
--- a/deps/libffi/ChangeLog
+++ b/deps/libffi/ChangeLog
@@ -1,3 +1,748 @@
+commit ddd2fe13ee32da9b41fbcc68e03bf2854b25d1c5
+Merge: 110d9e64 4deda119
+Author: Anthony Green <green@moxielogic.com>
+Date: Wed Nov 25 14:31:56 2026 -0500
+
+ Merge pull request #1087 from libffi/release/3.8.2
+
+ Release 3.8.2
+
+commit 4deda119c1870459ec03f7feeb196a2da26dcf33
+Author: Anthony Green <green@moxielogic.com>
+Date: Wed Nov 25 13:14:34 2026 -0500
+
+ Release 3.8.2
+
+ Bump the version from 3.8.1 to 3.8.2 and finalize the changelog:
+
+ * configure.ac: AC_INIT 3.8.1 -> 3.8.2 (propagates to FFI_VERSION,
+ libffi.pc, and the manual's @value{VERSION}).
+ * libtool-version: 13:1:5 -> 13:2:5. The source changed but no exported
+ interface was added, removed, or changed since 3.8.1, so only revision
+ is incremented.
+ * doc/version.texi, README.md: set the version and the release date,
+ and add the LoongArch void-return fix (#1083) to the changelog.
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit 110d9e646f12b64e72ba24a0f253611512075180
+Merge: 943fb441 f9652a35
+Author: Anthony Green <green@moxielogic.com>
+Date: Wed Nov 25 12:43:44 2026 -0500
+
+ Merge pull request #1083 from setarcos/loongarch_fix
+
+ loongarch: ignore return buffer for void calls
+
+commit 943fb441f1bf95b11bafa62168d3516dc888fb18
+Merge: de7afe7a f843ad14
+Author: Anthony Green <green@moxielogic.com>
+Date: Wed Nov 25 12:43:34 2026 -0500
+
+ Merge pull request #1086 from libffi/fix/win64-reject-vectors
+
+ ABI and argument-handling fixes for 3.8.2
+
+commit f843ad14f8574f58d2c75e4ac072a19bbf6195c8
+Author: Anthony Green <green@moxielogic.com>
+Date: Wed Nov 25 12:06:43 2026 -0500
+
+ testsuite: use named fields, not arrays, in cls_struct_float_psave.c
+
+ libffi describes a struct of float fields and a struct holding a float
+ array the same way, but the SPARC64 ABI passes float arrays inside
+ structs in integer registers and named float fields in FP registers.
+ The test's float[2]/[4]/[8] structs therefore reached the closure from a
+ GCC caller in registers libffi did not read, and the test failed in the
+ sparc64 QEMU CI job. Named fields keep the test's ppc64 case (the same
+ homogeneous aggregates) and are passed the same way by GCC and libffi
+ on SPARC64.
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit 3e6faa9769ebbef1a6c8dcfede73b0deb7a57b2d
+Author: Anthony Green <green@moxielogic.com>
+Date: Wed Nov 25 11:49:50 2026 -0500
+
+ SPARC64: fix the FP word mask for struct arguments in closures
+
+ ffi_closure_sparc_inner_v9 drops the FP-register words of a small struct
+ argument that lie beyond the 16 argument slots, using
+ (0xffff00 >> argn) & 0xff00. The mask has one bit per 4-byte word and a
+ slot is two words, so the shift should be two bits per slot: from slot 9
+ on, words that were in FP registers were taken from the integer save area
+ instead. A struct { double } in slot 15 got its low half from there, so
+ the handler saw 700.00026 for 700.
+
+ Allow the words below 2 * (16 - argn).
+
+ Found by cls_struct_double_spill.c (-O2), which failed in the sparc64
+ QEMU CI job; with this change the full suite passes locally with Ubuntu's
+ sparc64 cross GCC 13 under qemu-sparc64, apart from the C++ unwind tests
+ that need a cross g++.
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit 09d804edc86b400f3be5a714af0ffb2b242c7c07
+Author: Anthony Green <green@moxielogic.com>
+Date: Wed Nov 25 11:22:23 2026 -0500
+
+ testsuite: use __builtin_alloca in the over-aligned struct tests
+
+ MinGW has no <alloca.h> either, so struct_overaligned.c and
+ cls_struct_overaligned.c failed to compile in the Windows gcc and clang
+ CI jobs. Use __builtin_alloca, as raw_call.c does.
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit bcf248a2c4ee634429c6c583919a876499387380
+Author: Anthony Green <green@moxielogic.com>
+Date: Wed Nov 25 11:17:39 2026 -0500
+
+ SPARC64: keep SPARC_FLAG_FP_ARGS when ffi_call discards the result
+
+ ffi_prep_args_v9 replaced the whole flags word with SPARC_RET_VOID when
+ rvalue was NULL, which also cleared SPARC_FLAG_FP_ARGS, so ffi_call_v9
+ did not load the FP argument registers. A struct with a floating-point
+ member passed to a void function (or any function whose result is
+ discarded) then reached the callee with stale FP registers: for
+ f (struct { void *p; double d; }) the callee read d as 0. Clear only the
+ return-type bits.
+
+ Found by struct_layout_order.c, which failed in the sparc64 QEMU CI job;
+ checked locally with Ubuntu's sparc64 cross GCC 13 under qemu-sparc64.
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit 7c98cec4df4a5ab582ed146ced651e4d6e82fc68
+Author: Anthony Green <green@moxielogic.com>
+Date: Wed Nov 25 11:17:39 2026 -0500
+
+ testsuite: skip the over-aligned struct tests under MSVC
+
+ MSVC has no <alloca.h> and no __attribute__ ((aligned)), and refuses
+ over-aligned by-value parameters (C2719), so struct_overaligned.c and
+ cls_struct_overaligned.c failed to compile in the Visual C++ CI jobs.
+ Build them as an empty main there.
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit 9f6ba53bf6bf653c89052065f94f39015fa60295
+Author: Anthony Green <green@moxielogic.com>
+Date: Wed Nov 25 10:34:53 2026 -0500
+
+ README: tighten the TBD changelog entries
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit 79a25e87078ebd064e8747d29c9a9d3ca96236ac
+Author: Anthony Green <green@moxielogic.com>
+Date: Wed Nov 25 10:33:22 2026 -0500
+
+ README: correct the size-limit wording and the MIPS N32/N64 closure note
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit 023aa571d9bf597f856a3c0eb1cf8487cea1badd
+Author: Anthony Green <green@moxielogic.com>
+Date: Wed Nov 25 08:58:47 2026 -0500
+
+ AIX: recompute struct alignment from the members on every layout pass
+
+ aix_adjust_aggregate_sizes recomputes the size of a struct and of copies
+ of its nested aggregates, but took their alignment from what was stored
+ in the type. On AIX a struct whose first member is a double is 8-aligned
+ as an outermost type or a first member and 4-aligned as a later member,
+ and laying it out as an outermost argument stored the 8 in the caller's
+ shared ffi_type. After ffi_prep_cif for f (struct inner), with
+ struct inner { double d; }, every later layout of
+ struct outer { void *tag; struct inner in; } placed in at offset 8 and
+ grew outer from 12 to 16 bytes, also under cifs prepared earlier.
+ ffi_call then copied more argument bytes than the frame it had sized
+ (overwriting the saved registers and return address of ffi_call_AIX with
+ enough struct arguments) or shifted every later argument by a word.
+
+ Compute the alignment from the members on every pass, as the size
+ already is, and test the first member through its adjusted copy instead
+ of the shared type. The outermost/first-member 8-byte rule and the tail
+ padding from #805 are unchanged.
+
+ There is no AIX toolchain or emulator here. Checked by extracting
+ aix_adjust_aggregate_sizes into a native harness with 32-bit AIX type
+ sizes and replaying the report's sequence (outer is 16 bytes after it
+ before, 12 after; struct inner alone still gets alignment 8), and by
+ compiling ffi_darwin.c with clang for powerpc-ibm-aix and
+ powerpc64-ibm-aix. New test struct_layout_order.c prepares the same
+ three signatures, checks the sizes against sizeof and makes both calls;
+ it passes on x86-64 and would catch this on AIX.
+
+ Reported as ANT-2026-H865DG8Z.
+
+ Advisory: GHSA-f45x-cg8q-3q9w
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit d1b892a5ea01308dbcc3dbe0f665c8097f3bc56f
+Author: Anthony Green <green@moxielogic.com>
+Date: Wed Nov 25 08:57:02 2026 -0500
+
+ SPARC: allocate the scratch result for a NULL rvalue in ffi_call
+
+ ffi_call with rvalue == NULL for a function whose struct result is
+ returned in memory has to give the callee somewhere to write it.
+ ffi_call_int enlarged the frame by the result size and ffi_prep_args_v9
+ pointed the callee at argp + cif->bytes, but argp is 176 bytes above the
+ frame start (the window save area and ffi_call_v9's outgoing area) while
+ cif->bytes counts from the frame start. So the buffer ended 176 bytes
+ above ffi_call_v9's frame, inside ffi_call_int's: for a result of 49
+ bytes or more the callee overwrote the slots ffi_call_int's %fp and %i7
+ are reloaded from, and once that register window had been spilled,
+ ffi_call returned to an address taken from the discarded struct. The
+ 32-bit port computed its scratch the same way.
+
+ Allocate the scratch in ffi_call_int with alloca and pass it down as
+ rvalue, in both ports, so nothing depends on the frame layout of
+ v8.S/v9.S; ffi_prep_args_v8/v9 then only see a NULL rvalue when the
+ result can be ignored. (The report's second patch; its first corrects
+ the offset instead.)
+
+ New test struct_ret_discard.c discards a 128-byte struct result twice,
+ from a callee that recurses deeply enough to spill the callers' register
+ windows, then makes the same call into a real buffer. Under
+ qemu-sparc64 (clang, freestanding build of prep_cif.c, types.c, ffi64.c
+ and v9.S) it traps before and passes after. The 32-bit half is
+ compile-checked only.
+
+ Reported as ANT-2026-CVMECQB8.
+
+ Advisory: GHSA-v569-599f-q4hr
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit 392ab444ab760b7ddd07de96f2f6491f25553f04
+Author: Anthony Green <green@moxielogic.com>
+Date: Wed Nov 25 08:47:50 2026 -0500
+
+ Refuse signatures too large for libffi's counters and size fields
+
+ Three ways to get FFI_OK for a signature that libffi then cannot
+ represent, each ending in a stack overwrite in ffi_call:
+
+ * Struct layout summed member sizes without a bound, so a struct
+ described with large members got a wrapped size (2^64 - 80, or a
+ small one). On x86-64, ffi_call with rvalue == NULL then built its
+ argument block over ffi_call_int's frame and called an address taken
+ from an argument. (ANT-2026-QUVCPVJU)
+ * By-value arguments totalling 4 GiB wrapped the 32-bit cif->bytes to
+ 0, and ffi_call copied them over its own frame. (ANT-2026-VK76FMFX)
+ * More than INT_MAX arguments overflowed the int counters of the
+ x86-64 ports, with heap and stack overflows. (ANT-2026-KYDPZ7H5)
+
+ From the scan's patches: bound aggregate and vector sizes during layout
+ (FFI_MAX_TYPE_SIZE, also in the CRIS copy); refuse a cif->bytes the
+ field cannot hold in the generic loop and in the x86, x86-64, Win64 and
+ aarch64 sizing; make the x86-64 and Win64 argument counters unsigned and
+ their struct-copy sizes size_t; and give build_plan no plan for an
+ argument count its 32-bit move fields cannot describe.
+
+ The scan's own reports note that s390, Alpha, PA64 and the PowerPC ports
+ size the argument area themselves and stay open with those changes
+ alone. So ffi_prep_cif_core (and the CRIS copy) now also refuses, before
+ any port sees the signature, more than FFI_MAX_NARGS arguments, an
+ argument list whose sizes, each rounded to 16, exceed FFI_MAX_ARG_BYTES
+ (256 MiB), and a return type larger than that. No call can use an
+ argument area anywhere near that size, since it has to fit on a thread's
+ stack.
+
+ Also fix the Win64 vector check added earlier, which compared its now
+ size_t counter against (int) cif->nargs.
+
+ New test err_bad_size.c covers a wrapping struct, a 1 GiB argument and
+ result, two arguments that are each allowed but together too large, and
+ 2^31 arguments through ffi_prep_cif and ffi_prep_cif_var, without
+ allocating any of it. It aborts against a library without these checks.
+ Full suites: x86-64 2700 passes, i386 4328 and arm64 (qemu) 1858, no
+ failures.
+
+ Reported as ANT-2026-QUVCPVJU, ANT-2026-VK76FMFX and ANT-2026-KYDPZ7H5.
+
+ Advisory: GHSA-qpm4-52vm-3xff
+ Advisory: GHSA-j4q2-5r23-67rj
+ Advisory: GHSA-76jh-g582-v8x4
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit 1902f6fff7b45f889e7bf5ea023aca6930e6f545
+Author: Anthony Green <green@moxielogic.com>
+Date: Wed Nov 25 07:55:34 2026 -0500
+
+ MIPS N32/N64: handle complex values that only partly fit in the FP registers
+
+ A named complex value goes in FP argument registers only if all of it
+ fits; otherwise GCC passes it like a struct. Three places got the
+ boundary wrong:
+
+ * ffi_prep_args expanded a float _Complex in the register part to two
+ slots without checking that two were left. One starting in the
+ eighth slot stored its imaginary part past the argument area,
+ stepped over the only address where the write pointer wraps to the
+ stack part, and every later argument went into ffi_call_N32's own
+ frame (the call target was replaced by an argument value). Expand
+ only when two slots remain; otherwise copy it into the one slot as
+ a struct, as for a stack argument. ffi_closure_mips_inner_N32 reads
+ such a value from the GPR slot (argn >= 7, not >= 8).
+ (ANT-2026-6ZMMPRMP)
+
+ * A _Complex double in the eighth slot is passed in a7 and on the
+ stack, but the closure read both halves from the FP save area, the
+ second from one past its end. Read it from the saved GPRs, which
+ the incoming stack arguments follow.
+
+ * A _Complex long double at the seventh slot pair has its real part in
+ $f18/$f19 and its imaginary part on the stack (GCC 12, checked with
+ -S). The closure read both from the FP save area. Rebuild it from
+ the two places.
+
+ New test complex_last_reg.c passes a float, double and long double
+ _Complex that start in the last register slots they can use, followed by
+ six more arguments, through ffi_call and a closure. Under qemu with
+ Debian bookworm GCC 12 it fails before and passes after on N32 and N64;
+ cls_complex_psave.c, which failed on both before, now passes.
+ complex_regs_double.c passes too, so its mips64 xfail goes (libffi
+ #1071; complex_regs_float, complex_regs_longdouble and
+ cls_struct_fp_return keep theirs). call.exp, closure.exp and
+ complex.exp then pass on N64; on N32 only plan.c, cls_pointer_stack.c
+ and complex_int_small.c (-O2) fail, as they did before.
+
+ Reported as ANT-2026-6ZMMPRMP.
+
+ Advisory: GHSA-p8w7-v539-c775
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit 7a962d7878ae76315e8ecc5070f5231a68c19a66
+Author: Anthony Green <green@moxielogic.com>
+Date: Wed Nov 25 07:55:34 2026 -0500
+
+ MIPS O32: give ffi_closure_O32 a 16-byte result slot
+
+ ffi_closure_O32 passed the handler a two-word v0/v1 slot as rvalue.
+ ffi_closure_mips_inner_O32 redirected float/double/long double complex
+ results, and every complex result under soft float, to the FP argument
+ save area, but a hard-float _Complex long long or _Complex unsigned long
+ long kept the 8-byte slot: the handler's 16-byte store ran over the
+ saved $gp and $s0, and the epilogue handed that $s0 back to the native
+ caller. A plain *(_Complex long long *) ret = value is enough.
+
+ Grow the frame by two words so the slot at V0_OFF2 is four words, load
+ the result registers from it for every return type (v0/v1/a0/a1 for
+ integer complex, $f0/$f2 for FP complex), and drop the redirections.
+ That also stops a _Complex double result, stored before the handler
+ reads its arguments, from overwriting leading float/double arguments,
+ which shared the FP save area. ffi_go_closure_O32 uses the same frame.
+
+ New test cls_complex_int.c: ffi_call and closures returning _Complex int
+ and, after a leading double, _Complex long long. On MIPS O32 (Debian
+ bookworm GCC 12 -mabi=32 under qemu) it fails before and passes after;
+ call.exp, closure.exp and complex.exp then fail only the C++ unwindtest
+ builds, as before.
+
+ Reported as ANT-2026-ZUY08AZM.
+
+ Advisory: GHSA-xh8m-x7vg-ww5m
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit e7aded59c39935363eeb5cae88895f6bb51c24e0
+Author: Anthony Green <green@moxielogic.com>
+Date: Wed Nov 25 06:33:09 2026 -0500
+
+ README: cite the advisory for each TBD changelog entry
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit 6b114fcb19df432df713a0c3f8e8ad950c025904
+Author: Anthony Green <green@moxielogic.com>
+Date: Wed Nov 25 06:18:55 2026 -0500
+
+ i386: give a struct argument 16-byte alignment only for an aligned member
+
+ Follow-up to "Pass by-value aggregates aligned beyond the stack alignment
+ correctly", which missed 32-bit x86. ffi_call_int and ffi_closure_inner
+ gave any struct whose alignment is 16 or more a 16-byte-aligned stack
+ slot. GCC (ix86_function_arg_boundary) does that only when some member
+ is of a type that needs 16, such as an SSE vector or Darwin's long
+ double; alignment on the structure type itself, from an attribute or set
+ by the caller, and alignment only from an attribute on a member, are
+ ignored. Checked with GCC 14 on i386: structs aligned to 32 and 128 by
+ type, and one with an _Alignas (16) member, are all placed at 4-byte
+ alignment. libffi inserted padding the callee did not expect, so
+ struct_overaligned.c and cls_struct_overaligned.c failed on i386.
+
+ Use the alignment of the members, at any depth, instead. Darwin's
+ structs containing long double keep their 16-byte alignment.
+
+ On i386 (Debian trixie GCC 14) both tests pass after, and the full suite
+ has 4316 passes and no failures.
+
+ Advisory: GHSA-rwpw-56v4-44r3
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit 52380773550967f87821818199276801bfe1999d
+Author: Anthony Green <green@moxielogic.com>
+Date: Wed Nov 25 06:18:55 2026 -0500
+
+ i386: fix three raw-API bugs in ffi_raw_call and ffi_prep_raw_closure_loc
+
+ * ffi_raw_call aligned its argument block with
+ alloca (... + 15) & ~16, which clears bit 4 instead of rounding up.
+ At half of all stack positions the block, and the call_frame after
+ it, began 16 bytes below the memory alloca reserved, so the call into
+ ffi_call_i386 pushed its return address over the fourth argument word
+ (or over frame->flags when there are no stack arguments), and with a
+ 4-byte-aligned stack memcpy's own return address was overwritten
+ with the first argument word. Round up with FFI_ALIGN, as 79d1509c
+ intended. (ANT-2026-XSEPCMVK)
+
+ * The register-argument loop of ffi_raw_call advanced AVALUE, an
+ ffi_raw pointer, by Z bytes as if it were a char pointer, so
+ thiscall and fastcall raw calls skipped three words after each
+ register argument. Step by bytes.
+
+ * The raw closure entry points give the handler a 16-byte temporary as
+ RET and do not use the hidden return pointer, but
+ ffi_prep_raw_closure_loc accepted cifs whose result is returned in
+ memory; a handler storing such a struct overwrote the saved %ebx and
+ the return address. Refuse X86_RET_STRUCTPOP and X86_RET_STRUCTARG
+ with FFI_BAD_TYPEDEF, as is already done for unsupported argument
+ types. These results never worked on this path. (ANT-2026-9KYPNLY7)
+
+ New tests: raw_call.c calls ffi_raw_call with eight ints from two stack
+ depths, in every ABI call.exp runs; closure_raw_struct.c requires a raw
+ closure returning a 48-byte struct either to be refused or to return it
+ intact. Both are skipped when the raw API is configured out. On i386
+ (Debian trixie GCC 14) raw_call.c fails before in all four ABIs and
+ closure_raw_struct.c fails before; both pass after.
+
+ Advisory: GHSA-qgq7-fxgw-wrp4
+ Advisory: GHSA-64xf-g9qc-vf93
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit 7ca91a47173aaf57b8233e96eaaebbe821cdd672
+Author: Anthony Green <green@moxielogic.com>
+Date: Wed Nov 25 05:31:18 2026 -0500
+
+ powerpc64 ELFv2: do not quadword-align float/double/IBM long double aggregates
+
+ With FFI_LINUX_STRUCT_ALIGN, libffi aligned every by-value struct to its
+ own alignment in the parameter area before classifying it. A struct of
+ only IBM long double (or _Complex long double) members has alignment 16,
+ so it was moved to an even doubleword, but GCC and clang apply the
+ quadword rule only to aggregates that are not homogeneous floating-point
+ aggregates. GCC 14 on ppc64le confirms it: for
+ f (long, struct { long double v[3]; }, const char *) the callee reads
+ the pointer from r10, while for struct { long double x; long y; } it
+ reads r9. Every argument after such a struct was one doubleword off:
+ ffi_call left the callee's next register unwritten, and a closure read
+ later arguments from the next slot. When the compiler's layout fits in
+ eight doublewords the miscount also set FLAG_ARG_NEEDS_PSAVE, so
+ ffi_closure_LINUX64 stored r3-r10 into the caller's frame.
+
+ Classify first and skip the alignment for ELFv2 homogeneous aggregates of
+ float, double and IBM long double, in all three places the rule is
+ written (cif sizing, ffi_prep_args64, ffi_closure_helper_LINUX64).
+ IEEE128 aggregates go in vector registers and keep it.
+
+ ffi_closure_helper_LINUX64 also rebuilt a homogeneous aggregate in place
+ in the FPR or parameter save array, which is only doubleword aligned, and
+ passed that address to the handler. For a 16-byte-aligned IBM long
+ double aggregate a GCC -O0 handler masks the address to 16 when copying
+ it and reads the wrong bytes. Rebuild a misaligned one in aligned stack
+ memory instead.
+
+ The new test cls_struct_longdouble_hfa.c passes (long, struct { long
+ double a, b; }, long) through ffi_call and a closure, and calls a
+ closure taking (long, long, long, that struct, long), which fits in
+ eight doublewords, from a function with no parameter save area. On
+ ppc64le (Debian trixie GCC 14 under qemu) it fails before at -O0 and
+ -O2 and passes after; the full suite has 1800 passes and no failures,
+ and with -mabi=ieeelongdouble it is 1800 passes before and after.
+
+ Reported as ANT-2026-LS1WY3V7.
+
+ Advisory: GHSA-34hv-975q-7p7w
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit 471daadb290e76b77c9f3d34593b87e946b701f1
+Author: Anthony Green <green@moxielogic.com>
+Date: Wed Nov 25 04:01:07 2026 -0500
+
+ README: shorten the over-alignment changelog entry
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit c0b91a34cfbf22b0c77c0e2cbd0725807f5e6b8d
+Author: Anthony Green <green@moxielogic.com>
+Date: Wed Nov 25 03:51:15 2026 -0500
+
+ Static trampolines: make the temporary code-table file immutable
+
+ When ffi_tramp_get_libffi() cannot reopen the object that holds the
+ trampoline code table (no /proc, an unreadable or deleted file, an inode
+ mismatch), ffi_tramp_get_temp_file() copies the table into a file from
+ open_temp_exec_file() and keeps that read-write descriptor for the life
+ of the process, because each further table is mapped from it. Every
+ code table is a MAP_PRIVATE mapping the process never writes, so it
+ shares the file's page cache: a write to the file appears in all of
+ them. fork() hands the descriptor to children, so a child that has
+ dropped to another uid could pwrite() its own code behind every closure
+ of its parent (and of siblings forked later), to run with the parent's
+ privileges at the next callback.
+
+ Once the table has been written, before the first mapping:
+
+ * memfd: create it with MFD_ALLOW_SEALING and add F_SEAL_WRITE,
+ F_SEAL_GROW, F_SEAL_SHRINK and F_SEAL_SEAL.
+ * otherwise: fchmod the file to 0400 and replace the descriptor with a
+ read-only, close-on-exec one opened through /proc/self/fd/N. The
+ fchmod matters: a memfd is mode 0777, so without it a child under
+ another uid could reopen /proc/self/fd/N for writing. This also
+ retires the non-close-on-exec mkstemp() descriptor.
+
+ If neither works, the temp-file fallback fails and static trampolines
+ are reported unsupported, as on any other mapping failure.
+
+ Checked in a Debian container as root, with a parent whose executable is
+ unlinked before its first closure (so the fallback is used) and a forked
+ worker at uid 65534 that tries both pwrite() on every inherited unlinked
+ file and a read-write reopen of /proc/self/fd/N. Before: the parent's
+ closure returns the worker's 0x1337 with a memfd and with an O_TMPFILE
+ file. After: it returns 42 with a sealed memfd, an unsealable memfd and
+ an O_TMPFILE file. With the temp-file path forced for every closure,
+ the full suite passes (2670) in each of those three configurations.
+
+ Reported as ANT-2026-FSNDWSWJ.
+
+ Advisory: GHSA-7qx4-vhpx-x6qm
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit 50d221bafa7d179101c582da32ac6cb8b270f5c0
+Author: Anthony Green <green@moxielogic.com>
+Date: Tue Nov 24 20:50:44 2026 -0500
+
+ RISC-V, LoongArch: one-float struct takes the integer convention once FPRs run out
+
+ The psABI passes a struct that flattens to a single float or double like
+ a lone floating-point scalar: in an FP argument register if one is free,
+ otherwise by the integer convention (next GPR, then the stack). The
+ one-field branch of struct_passed_as_elements() set as_elements without
+ looking at cb->used_float, unlike the two-field branch and the scalar
+ path, so marshal_atom() stored such a struct to fa[8], fa[9], ... of the
+ eight-entry register image: over the integer argument registers a[], then
+ the frame words, then past the alloca block into ffi_call_int's own
+ frame. With a pointer, eight doubles and a struct { double }, the callee
+ received the struct's bits as the pointer. Closures read the same
+ out-of-range slots through unmarshal(), so a handler got the caller's
+ saved registers and return address instead of its stack arguments.
+
+ Add the cb->used_float < NARGREG check to that branch in both copies.
+
+ New tests struct_double_spill.c (call) and cls_struct_double_spill.c
+ (closure; structs of one double and of one float after eight doubles).
+ riscv64 (Debian trixie GCC 14 under qemu): both fail before and pass
+ after; the full suite then has 1788 passes and no failures. LoongArch
+ (clang, freestanding, under qemu-loongarch64): the call test faults and
+ the closure test aborts before, both pass after.
+
+ Reported as ANT-2026-HDYD8KG6.
+
+ Advisory: GHSA-2xrh-7r9c-rwmf
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit d0ea91db79752daf513ef806030dc89412869ada
+Author: Anthony Green <green@moxielogic.com>
+Date: Tue Nov 24 19:13:37 2026 -0500
+
+ powerpc64 ELFv2: set FLAG_ARG_NEEDS_PSAVE only when an argument is in memory
+
+ Under ELFv2 a caller allocates a parameter save area only if some
+ argument is passed in memory. ffi_prep_cif_linux64_core sets
+ FLAG_ARG_NEEDS_PSAVE, which tells ffi_closure_LINUX64 that the area
+ exists, from one register class alone: as soon as floating-point values
+ outnumber the 13 FPRs (scalars, homogeneous aggregates, _Complex), and
+ for a floating-point _Complex as soon as the doubleword count passes
+ eight. Neither means anything is in memory: a floating-point value is
+ there only when it finds no FPR and also lies beyond the eighth
+ doubleword. Structs of floats pack two per doubleword, so their excess
+ elements still go in GPRs; complex halves in FPRs only shadow their
+ doublewords.
+
+ When the flag was wrong the closure entry stored r3-r10 into 64 bytes of
+ a caller frame that has no save area. With
+ (struct float4, unsigned long, struct float8, struct float2) the store
+ of r5 replaced the caller's saved LR with the unsigned long argument.
+
+ Require both conditions at the four fparg_count tests, and move the
+ _Complex intarg_count test into the integer-element branch. ffi_prep_args64
+ and ffi_closure_helper_LINUX64 already place and read the excess elements
+ in the GPR image; ffi_call only uses the flag to size cif->bytes, which
+ shrinks for the affected signatures.
+
+ New tests cls_struct_float_psave.c and cls_complex_psave.c call such a
+ closure from a function that makes no other call. On ppc64le (Debian
+ trixie GCC 14 under qemu) both fail before and pass after; the full
+ suite then has 1786 passes and no failures.
+
+ Reported as ANT-2026-H5SC3C6W.
+
+ Advisory: GHSA-p8c7-j6j7-h7vg
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit 4f06cb2534cf8682c5c4b604a557fb8bab8cf9be
+Author: Anthony Green <green@moxielogic.com>
+Date: Tue Nov 24 14:15:12 2026 -0500
+
+ Pass by-value aggregates aligned beyond the stack alignment correctly
+
+ ffi_prep_cif sizes the outgoing argument area by aligning offsets from 0,
+ but several back ends placed each argument by aligning its address, in
+ an area only as aligned as the stack. For an aggregate whose (caller-
+ set) alignment exceeds that, ffi_call inserted padding that was never
+ reserved: the copy ran past the area into ffi_call's own frame, and the
+ callee read the argument from somewhere else. On x86-64 at alignment
+ 128 the overwritten words include the saved fn pointer.
+
+ * x86-64: start the stack argument area on the largest argument
+ alignment, as a compiled caller does, so address and offset rounding
+ agree. The closure reader now places arguments by offset from the
+ start of the incoming area, since not every caller over-aligns it.
+ * AArch64: round the address of each by-reference struct copy, not its
+ offset, and reserve the extra slack for alignments above 16. A
+ large struct after an over-aligned one was copied below the slab.
+ * ARM: GCC ignores alignment on the aggregate type itself and uses the
+ largest member alignment, at most 8 (checked against GCC 14 armhf);
+ do the same for aggregates aligned above 8.
+ * MIPS: cap the alignment at two slots (8 on O32, 16 on N32/N64), and
+ align the argument's offset rather than its address: on N32/N64 the
+ register slots are moved to the end of the area, so the two disagree
+ when the area holds an odd number of slots. The O32 and N32 closure
+ decoders follow the same rule.
+ * m88k: cap the alignment at 8 in ffi_prep_args and its closure twin.
+ Syntax-checked only; no m88k toolchain was available.
+
+ New tests struct_overaligned.c (call) and cls_struct_overaligned.c
+ (closure) pass a 128-byte-aligned struct at every stack position modulo
+ its alignment. Under qemu (Debian gcc) the call test fails before and
+ passes after on x86-64 (native), arm64, armhf, MIPS O32, N32 and N64;
+ the closure test fails before on armhf and all three MIPS ABIs and
+ passes after. call.exp and closure.exp otherwise give the same results
+ before and after on every target; the MIPS N32 and O32 failures that
+ remain (plan.c, cls_pointer_stack.c, C++ unwindtest builds) predate this.
+
+ Reported as ANT-2026-HFUPZPUU.
+
+ Advisory: GHSA-rwpw-56v4-44r3
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit 70d2a529ae6bd076e5bfed8d82f86f9937862773
+Author: Anthony Green <green@moxielogic.com>
+Date: Tue Nov 24 11:57:53 2026 -0500
+
+ aarch64: reserve 16 bytes per by-reference struct in the argument slab
+
+ ffi_call_int fills one slab of cif->bytes from both ends: copies of
+ non-HFA composites larger than 16 bytes grow down from the top, and
+ stack arguments (including the spilled pointers to those copies) grow
+ up from the bottom. Nothing checks that the two meet, so cif->bytes
+ must cover both. a2ef91c7 added 8 bytes per such composite for the
+ pointer, but not the alignment padding the split causes: the pointer
+ can leave the NSAA at an odd doubleword so a following 16-byte-aligned
+ argument (__int128, long double) pads by 8, and a 16-byte-aligned copy
+ below an odd-doubleword next_struct_area pads by another 8.
+
+ With (struct { __int128 key, value; }, __int128) x 13 followed by one
+ more struct, cif->bytes is 768 but the call needs 808; the last copy
+ overwrites the spilled pointer to the 13th struct with its own first
+ 8 bytes, and the callee reads that struct through an address taken
+ from the argument data.
+
+ Charge 16 per composite: each padding source costs at most 8, since no
+ AArch64 alignment exceeds 16. An instrumented ffi_call_int under
+ qemu-aarch64 found 56 overlaps in 2M random signatures with +8 and none
+ in 50M with +16. Closures only use cif->bytes to seed next_struct_area,
+ so the larger value is harmless there.
+
+ Add many_large_structs_i128.c, which faults on aarch64 (qemu) without
+ the fix and passes with it.
+
+ Reported as ANT-2026-BTYOL2JW.
+
+ Advisory: GHSA-wc36-xxj4-cxh5
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit 0b08ce2aa2fd70fb284f8ae0984454f99805b511
+Author: Anthony Green <green@moxielogic.com>
+Date: Tue Nov 24 09:32:40 2026 -0500
+
+ Reject vector types in the Win64 and CRIS ffi_prep_cif paths
+
+ The generic vector rejection in ffi_prep_cif_core is compiled only when
+ FFI_TARGET_HAS_VECTOR_TYPE is undefined. Two backends slip past it:
+
+ * x86-64 (non-Windows): ffitarget.h defines the macro for the SysV
+ backend, which compiles the check out for every ABI. The Win64
+ backend built into the same library (FFI_WIN64, FFI_GNUW64,
+ FFI_EFI64) has no vector support, yet ffi_prep_cif_machdep_efi64
+ returned FFI_OK with cif->flags = FFI_TYPE_VECTOR. A closure
+ returning a vector of 64 bytes or more then wrote past the 16-byte
+ result scratch in ffi_closure_win64 and overwrote its return
+ address; ffi_call aborted. Introduced in 3.8.0 (93b274cec912).
+
+ * CRIS: the port replaces ffi_prep_cif_core and its copy never got
+ the vector check (b6b8be54), nor the FFI_TYPE_COMPLEX abort. A
+ closure's vector result overflowed the 8-byte llret slot.
+
+ Make ffi_type_contains_vector a hidden non-static helper, declared in
+ ffi_common.h, and call it from the Win64 ffi_prep_cif_machdep (under
+ FFI_TARGET_HAS_VECTOR_TYPE, so native Windows builds are unchanged) and
+ from the CRIS ffi_prep_cif_core, which also gains the complex check.
+ Nested-in-struct vectors are rejected too, as the manual documents.
+ Update the win64.S/win64_intel.S comments that named ffi_prep_cif_core
+ as the only gate.
+
+ Tests: vector_validate.c asserts FFI_BAD_TYPEDEF under FFI_WIN64 and
+ FFI_GNUW64 (aborts without the fix). The new libffi.call test
+ err_vector_unsupported.c runs on every port and checks the rejection
+ where FFI_TARGET_HAS_VECTOR_TYPE is undefined; libffi.vector is skipped
+ on those ports, which is how the CRIS gap went unnoticed. The CRIS
+ change is syntax-checked only; no CRIS toolchain was available.
+
+ Reported as ANT-2026-TPIJU9MR.
+
+ Advisory: GHSA-v9rw-6cxm-q6rf
+ Advisory: GHSA-j9pv-w354-7fg2
+
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
+
+commit f9652a3535d0c83159175b472405c5c9ea6fb969
+Author: Pluto Yang <yangyj.ee@gmail.com>
+Date: Thu Nov 19 21:32:42 2026 +0800
+
+ loongarch: ignore return buffer for void calls
+
+ ffi_type_void has size 1, so a non-NULL rvalue made ffi_call() copy one
+ byte of the return register into the caller's buffer. Skip unmarshalling
+ for VOID, as the RISC-V port already does; without this,
+ testsuite/libffi.call/return_void.c fails on loongarch64.
+
commit de7afe7aa9e8ab7ac36429428a7222caae1e7988
Merge: 63cfe02c 8d6f5bf5
Author: Anthony Green <green@moxielogic.com>
diff --git a/deps/libffi/README.md b/deps/libffi/README.md
index efc73d71566..1e164be349b 100644
--- a/deps/libffi/README.md
+++ b/deps/libffi/README.md
@@ -1,5 +1,5 @@
-libffi-3.8.1 was released on November 14, 2026.
+libffi-3.8.2 was released on November 25, 2026.
What is libffi?
@@ -201,6 +201,40 @@ History
See the git log for details at http://github.com/libffi/libffi.
+ 3.8.2 November-25-2026
+ x86-64: reject vector types under the Win64 ABIs on non-Windows
+ builds, as documented (GHSA-v9rw-6cxm-q6rf).
+ CRIS: reject vector types (GHSA-j9pv-w354-7fg2).
+ aarch64: reserve enough stack for large by-value structs mixed
+ with 16-byte-aligned arguments (GHSA-wc36-xxj4-cxh5).
+ Pass by-value aggregates aligned beyond the stack alignment
+ correctly on x86-64, i386, ARM, MIPS, m88k and AArch64
+ (GHSA-rwpw-56v4-44r3).
+ powerpc64 ELFv2: fix closures overwriting the caller's frame
+ with float structs and _Complex arguments
+ (GHSA-p8c7-j6j7-h7vg), and stop padding IBM long double
+ aggregates (GHSA-34hv-975q-7p7w).
+ RISC-V, LoongArch: fix one-float structs passed after the FP
+ argument registers run out (GHSA-2xrh-7r9c-rwmf).
+ Static trampolines: make the temporary code-table file
+ immutable, so a forked child cannot rewrite its parent's
+ closures (GHSA-7qx4-vhpx-x6qm).
+ i386: fix ffi_raw_call argument placement and refuse raw
+ closures with in-memory results (GHSA-qgq7-fxgw-wrp4,
+ GHSA-64xf-g9qc-vf93).
+ MIPS: fix O32 closures returning _Complex long long
+ (GHSA-xh8m-x7vg-ww5m) and N32/N64 complex arguments at the
+ end of the argument registers (GHSA-p8w7-v539-c775).
+ Refuse oversized signatures instead of truncating them
+ (GHSA-qpm4-52vm-3xff, GHSA-j4q2-5r23-67rj,
+ GHSA-76jh-g582-v8x4).
+ SPARC: fix ffi_call with a NULL rvalue for large struct results
+ (GHSA-v569-599f-q4hr).
+ AIX: make struct layout independent of prior ffi_prep_cif calls
+ (GHSA-f45x-cg8q-3q9w).
+ LoongArch: do not write to the result buffer of a void call
+ (#1083).
+
3.8.1 November-14-2026
Improve ABI conformance and test coverage for complex-number
calls, closures, and small aggregates across ARM, x86, PowerPC,
diff --git a/deps/libffi/configure b/deps/libffi/configure
index 321c6400860..371a9a9d71c 100755
--- a/deps/libffi/configure
+++ b/deps/libffi/configure
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.72 for libffi 3.8.1.
+# Generated by GNU Autoconf 2.72 for libffi 3.8.2.
#
# Report bugs to <http://github.com/libffi/libffi/issues>.
#
@@ -614,8 +614,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='libffi'
PACKAGE_TARNAME='libffi'
-PACKAGE_VERSION='3.8.1'
-PACKAGE_STRING='libffi 3.8.1'
+PACKAGE_VERSION='3.8.2'
+PACKAGE_STRING='libffi 3.8.2'
PACKAGE_BUGREPORT='http://github.com/libffi/libffi/issues'
PACKAGE_URL=''
@@ -1414,7 +1414,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-'configure' configures libffi 3.8.1 to adapt to many kinds of systems.
+'configure' configures libffi 3.8.2 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1486,7 +1486,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of libffi 3.8.1:";;
+ short | recursive ) echo "Configuration of libffi 3.8.2:";;
esac
cat <<\_ACEOF
@@ -1625,7 +1625,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-libffi configure 3.8.1
+libffi configure 3.8.2
generated by GNU Autoconf 2.72
Copyright (C) 2023 Free Software Foundation, Inc.
@@ -2274,7 +2274,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by libffi $as_me 3.8.1, which was
+It was created by libffi $as_me 3.8.2, which was
generated by GNU Autoconf 2.72. Invocation command line was
$ $0$ac_configure_args_raw
@@ -3266,10 +3266,10 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
ac_config_headers="$ac_config_headers fficonfig.h"
-FFI_VERSION_STRING="3.8.1"
-ffi_version_major=`echo "3.8.1" | cut -d. -f1`
-ffi_version_minor=`echo "3.8.1" | cut -d. -f2 | sed 's/[^0-9].*//'`
-ffi_version_micro=`echo "3.8.1" | cut -d. -f3 | sed 's/[^0-9].*//'`
+FFI_VERSION_STRING="3.8.2"
+ffi_version_major=`echo "3.8.2" | cut -d. -f1`
+ffi_version_minor=`echo "3.8.2" | cut -d. -f2 | sed 's/[^0-9].*//'`
+ffi_version_micro=`echo "3.8.2" | cut -d. -f3 | sed 's/[^0-9].*//'`
FFI_VERSION_NUMBER=`expr ${ffi_version_major:-0} \* 10000 + ${ffi_version_minor:-0} \* 100 + ${ffi_version_micro:-0}`
@@ -4214,7 +4214,7 @@ fi
# Define the identity of the package.
PACKAGE='libffi'
- VERSION='3.8.1'
+ VERSION='3.8.2'
printf "%s\n" "#define PACKAGE \"$PACKAGE\"" >>confdefs.h
@@ -22472,7 +22472,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
-This file was extended by libffi $as_me 3.8.1, which was
+This file was extended by libffi $as_me 3.8.2, which was
generated by GNU Autoconf 2.72. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -22540,7 +22540,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config='$ac_cs_config_escaped'
ac_cs_version="\\
-libffi config.status 3.8.1
+libffi config.status 3.8.2
configured by $0, generated by GNU Autoconf 2.72,
with options \\"\$ac_cs_config\\"
diff --git a/deps/libffi/configure.ac b/deps/libffi/configure.ac
index 63731dd8eed..2237b054183 100644
--- a/deps/libffi/configure.ac
+++ b/deps/libffi/configure.ac
@@ -2,7 +2,7 @@ dnl Process this with autoconf to create configure
AC_PREREQ([2.68])
-AC_INIT([libffi],[3.8.1],[http://github.com/libffi/libffi/issues])
+AC_INIT([libffi],[3.8.2],[http://github.com/libffi/libffi/issues])
AC_CONFIG_HEADERS([fficonfig.h])
dnl Derive the version macros from AC_INIT so they cannot drift when the
diff --git a/deps/libffi/generate-headers.py b/deps/libffi/generate-headers.py
index b17dadff080..9a4bbc0a70a 100644
--- a/deps/libffi/generate-headers.py
+++ b/deps/libffi/generate-headers.py
@@ -7,8 +7,8 @@ import sys
from pathlib import Path
-LIBFFI_VERSION = '3.8.1'
-LIBFFI_VERSION_NUMBER = '30801'
+LIBFFI_VERSION = '3.8.2'
+LIBFFI_VERSION_NUMBER = '30802'
def normalize_arch(target_arch):
aliases = {
diff --git a/deps/libffi/include/ffi_common.h b/deps/libffi/include/ffi_common.h
index e4ed2287e58..072e480357d 100644
--- a/deps/libffi/include/ffi_common.h
+++ b/deps/libffi/include/ffi_common.h
@@ -119,6 +119,22 @@ void ffi_type_test(ffi_type *a, const char *file, int line);
/* v cast to size_t and aligned down to a multiple of a */
#define FFI_ALIGN_DOWN(v, a) (((size_t) (v)) & -a)
+/* Upper bound on the size of an aggregate laid out by ffi_prep_cif.
+ Summing member sizes must not wrap, and the call code adds the size of
+ the return type to its frame and argument block (an alloca), so the
+ bound leaves headroom for those additions even where size_t is 32
+ bits. No real object comes anywhere near it. */
+#define FFI_MAX_TYPE_SIZE (((size_t) -1) / 4)
+
+/* Upper bounds on a signature, checked by ffi_prep_cif_core before any
+ port sees it. Several ports keep argument counts in an int and the
+ size of the argument area in the 32-bit cif->bytes, and compute that
+ size in ways that can wrap; no call can use an argument area larger
+ than a thread's stack anyway, so refuse signatures far beyond that
+ rather than let any port truncate them. */
+#define FFI_MAX_ARG_BYTES ((size_t) 256 << 20)
+#define FFI_MAX_NARGS (FFI_MAX_ARG_BYTES / 8)
+
/* Perform machine dependent cif processing */
ffi_status ffi_prep_cif_machdep(ffi_cif *cif);
ffi_status ffi_prep_cif_machdep_var(ffi_cif *cif,
@@ -139,6 +155,9 @@ ffi_status ffi_prep_cif_core(ffi_cif *cif,
ffi_type *rtype,
ffi_type **atypes);
+/* Nonzero if TY is, or contains, a vector (SIMD) type. */
+int ffi_type_contains_vector (ffi_type *ty) FFI_HIDDEN;
+
/* Translate a data pointer to a code pointer. Needed for closures on
some targets. */
void *ffi_data_to_code_pointer (void *data) FFI_HIDDEN;
diff --git a/deps/libffi/libtool-version b/deps/libffi/libtool-version
index 5b9d5599953..2d622658ef1 100644
--- a/deps/libffi/libtool-version
+++ b/deps/libffi/libtool-version
@@ -26,4 +26,4 @@
# release, then set age to 0.
#
# CURRENT:REVISION:AGE
-13:1:5
+13:2:5
diff --git a/deps/libffi/src/aarch64/ffi.c b/deps/libffi/src/aarch64/ffi.c
index d950e970e93..8c1e2568546 100644
--- a/deps/libffi/src/aarch64/ffi.c
+++ b/deps/libffi/src/aarch64/ffi.c
@@ -324,13 +324,16 @@ static void *
allocate_and_copy_struct_to_stack (struct arg_state *state, void *stack,
size_t alignment, size_t size, void *value)
{
- size_t dest = state->next_struct_area - size;
+ char *dest = (char *) stack + state->next_struct_area - size;
- /* Round down to the natural alignment of the value. */
- dest = FFI_ALIGN_DOWN (dest, alignment);
- state->next_struct_area = dest;
+ /* Round down to the natural alignment of the value. Round the address,
+ not the offset: the slab is only 16-byte aligned, and the callee may
+ rely on the full alignment of the copy. ffi_prep_cif_machdep reserves
+ what this can skip for alignments above 16. */
+ dest = (char *) FFI_ALIGN_DOWN (dest, alignment);
+ state->next_struct_area = (size_t) (dest - (char *) stack);
- return memcpy ((char *) stack + dest, value, size);
+ return memcpy (dest, value, size);
}
static ffi_arg
@@ -660,16 +663,32 @@ ffi_prep_cif_machdep (ffi_cif *cif)
NSAA, growing up). The generic prep_cif accounting in cif->bytes
only charges the payload copy, not that 8-byte pointer slot, so the
two regions can collide and a later struct copy can overwrite an
- already-spilled pointer with the copied payload bytes. Reserve an
- extra 8 bytes per such argument so the slab is always large enough
- for both. */
+ already-spilled pointer with the copied payload bytes. Nor does it
+ charge the alignment padding that only arises because the payload and
+ the pointer live in different regions: the 8-byte pointer slot can
+ leave the NSAA at an odd doubleword where the generic layout (which
+ placed the payload there instead) did not, so a following 16-byte
+ aligned stack argument (__int128, long double, ...) needs 8 bytes of
+ padding, and a 16-byte aligned payload copied below an odd-doubleword
+ next_struct_area needs another 8. Reserve an extra 16 bytes per such
+ argument so the slab is always large enough for all of it. */
for (i = 0, n = cif->nargs; i < n; i++)
{
ffi_type *ty = cif->arg_types[i];
if (ty->size > 16 && !is_vfp_type (ty))
- bytes += 8;
+ {
+ bytes += 16;
+ /* Rounding the copy's address down to an alignment above the
+ slab's 16 can skip up to alignment - 1 more bytes. */
+ if (ty->alignment > 16)
+ bytes += ty->alignment;
+ }
}
+ /* cif->bytes is an unsigned int: refuse a total it cannot hold. */
+ if (bytes > INT_MAX)
+ return FFI_BAD_TYPEDEF;
+
/* Round the stack up to a multiple of the stack alignment requirement. */
cif->bytes = (unsigned) FFI_ALIGN(bytes, 16);
cif->flags = flags;
diff --git a/deps/libffi/src/arm/ffi.c b/deps/libffi/src/arm/ffi.c
index b4195b33657..97a07f2168d 100644
--- a/deps/libffi/src/arm/ffi.c
+++ b/deps/libffi/src/arm/ffi.c
@@ -81,6 +81,23 @@ ffi_align (ffi_type *ty, void *p)
alignment = 4;
#else
alignment = ty->alignment;
+ /* An aggregate aligned beyond a doubleword can only have got that from
+ the alignment of the type itself (an attribute on the type, or a
+ caller-set alignment), which the AAPCS ignores when passing it: it
+ uses the largest member alignment, and never more than a doubleword.
+ The argument area is only doubleword aligned anyway. */
+ if (alignment > 8)
+ {
+ ffi_type **p;
+
+ alignment = 4;
+ if (ty->elements != NULL)
+ for (p = ty->elements; *p != NULL; p++)
+ if ((*p)->alignment > alignment)
+ alignment = (*p)->alignment;
+ if (alignment > 8)
+ alignment = 8;
+ }
if (alignment < 4)
alignment = 4;
#endif
diff --git a/deps/libffi/src/closures.c b/deps/libffi/src/closures.c
index 5261c789e20..013042a0473 100644
--- a/deps/libffi/src/closures.c
+++ b/deps/libffi/src/closures.c
@@ -618,7 +618,12 @@ static int
open_temp_exec_file_memfd (const char *name)
{
int fd;
+#ifdef MFD_ALLOW_SEALING
+ /* Let ffi_tramp_get_temp_file () seal the file once it has been filled. */
+ fd = memfd_create (name, MFD_CLOEXEC | MFD_ALLOW_SEALING);
+#else
fd = memfd_create (name, MFD_CLOEXEC);
+#endif
return fd;
}
#endif
diff --git a/deps/libffi/src/cris/ffi.c b/deps/libffi/src/cris/ffi.c
index 9011fdec03a..e7401ad8b2d 100644
--- a/deps/libffi/src/cris/ffi.c
+++ b/deps/libffi/src/cris/ffi.c
@@ -29,6 +29,8 @@
#include <ffi.h>
#include <ffi_common.h>
+#include <stdlib.h>
+
#define STACK_ARG_SIZE(x) FFI_ALIGN(x, FFI_SIZEOF_ARG)
static ffi_status
@@ -52,6 +54,8 @@ initialize_aggregate_packed_struct (ffi_type * arg)
FFI_ASSERT (ffi_type_test ((*ptr)));
+ if ((*ptr)->size > FFI_MAX_TYPE_SIZE - arg->size)
+ return FFI_BAD_TYPEDEF;
arg->size += (*ptr)->size;
arg->alignment = (arg->alignment > (*ptr)->alignment) ?
@@ -160,6 +164,7 @@ ffi_prep_cif_core (ffi_cif * cif,
ffi_type * rtype, ffi_type ** atypes)
{
unsigned bytes = 0;
+ size_t arg_bytes = 0;
unsigned int i;
ffi_type **ptr;
@@ -173,13 +178,31 @@ ffi_prep_cif_core (ffi_cif * cif,
cif->nargs = ntotalargs;
cif->rtype = rtype;
+ if (ntotalargs > FFI_MAX_NARGS)
+ return FFI_BAD_TYPEDEF;
+
+#ifndef FFI_TARGET_HAS_VECTOR_TYPE
+ /* Vector (SIMD) types are only marshalled on ports that opt in. */
+ if (ffi_type_contains_vector (rtype))
+ return FFI_BAD_TYPEDEF;
+ for (i = 0; i < ntotalargs; i++)
+ if (ffi_type_contains_vector (atypes[i]))
+ return FFI_BAD_TYPEDEF;
+#endif
+
cif->flags = 0;
if ((cif->rtype->size == 0)
&& (initialize_aggregate_packed_struct (cif->rtype) != FFI_OK))
return FFI_BAD_TYPEDEF;
+#ifndef FFI_TARGET_HAS_COMPLEX_TYPE
+ if (rtype->type == FFI_TYPE_COMPLEX)
+ abort ();
+#endif
FFI_ASSERT_VALID_TYPE (cif->rtype);
+ if (cif->rtype->size > FFI_MAX_ARG_BYTES)
+ return FFI_BAD_TYPEDEF;
for (ptr = cif->arg_types, i = cif->nargs; i > 0; i--, ptr++)
{
@@ -187,8 +210,18 @@ ffi_prep_cif_core (ffi_cif * cif,
&& (initialize_aggregate_packed_struct ((*ptr)) != FFI_OK))
return FFI_BAD_TYPEDEF;
+#ifndef FFI_TARGET_HAS_COMPLEX_TYPE
+ if ((*ptr)->type == FFI_TYPE_COMPLEX)
+ abort ();
+#endif
FFI_ASSERT_VALID_TYPE (*ptr);
+ /* Bound the whole argument list, as ffi_prep_cif_core does. */
+ if ((*ptr)->size > FFI_MAX_ARG_BYTES
+ || FFI_ALIGN ((*ptr)->size, 16) > FFI_MAX_ARG_BYTES - arg_bytes)
+ return FFI_BAD_TYPEDEF;
+ arg_bytes += FFI_ALIGN ((*ptr)->size, 16);
+
if (((*ptr)->alignment - 1) & bytes)
bytes = FFI_ALIGN (bytes, (*ptr)->alignment);
if ((*ptr)->type == FFI_TYPE_STRUCT)
diff --git a/deps/libffi/src/loongarch/ffi.c b/deps/libffi/src/loongarch/ffi.c
index ab0d929f81f..4903458e363 100644
--- a/deps/libffi/src/loongarch/ffi.c
+++ b/deps/libffi/src/loongarch/ffi.c
@@ -137,7 +137,7 @@ struct_passed_as_elements (call_builder *cb, ffi_type *top)
if (num_fields == 1)
{
- if (IS_FLOAT (fields[0]->type))
+ if (IS_FLOAT (fields[0]->type) && cb->used_float < NARGREG)
{
ret.as_elements = 1;
ret.type1 = fields[0]->type;
@@ -507,7 +507,7 @@ ffi_call_int (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue,
ffi_call_asm ((void *) alloc_base, cb.aregs, fn, closure);
cb.used_float = cb.used_integer = 0;
- if (!return_by_ref && rvalue)
+ if (!return_by_ref && rvalue && cif->rtype->type != FFI_TYPE_VOID)
unmarshal (&cb, cif->rtype, 0, rvalue);
}
diff --git a/deps/libffi/src/m88k/ffi.c b/deps/libffi/src/m88k/ffi.c
index 57b344f4b9a..98df0bb8d77 100644
--- a/deps/libffi/src/m88k/ffi.c
+++ b/deps/libffi/src/m88k/ffi.c
@@ -131,10 +131,14 @@ ffi_prep_args (void *stack, extended_cif *ecif)
argp = stackp;
}
- /* Enforce proper stack alignment of 64-bit types */
+ /* Enforce proper stack alignment of 64-bit types. Arguments never
+ get more than doubleword alignment, whatever the alignment of their
+ type: the stack pointer is only aligned to 16 bytes, and cif->bytes
+ only accounts for padding relative to the start of the argument
+ area. */
if (argp == stackp && a > sizeof (int))
{
- stackp = (char *) FFI_ALIGN(stackp, a);
+ stackp = (char *) FFI_ALIGN(stackp, 2 * sizeof (int));
argp = stackp;
}
@@ -317,10 +321,11 @@ ffi_prep_closure_args_OBSD (ffi_cif *cif, void **avalue, unsigned int *regp,
argp = stackp;
}
- /* Enforce proper stack alignment of 64-bit types */
+ /* Enforce proper stack alignment of 64-bit types. This must match
+ ffi_prep_args. */
if (argp == stackp && a > sizeof (int))
{
- stackp = (char *) FFI_ALIGN(stackp, a);
+ stackp = (char *) FFI_ALIGN(stackp, 2 * sizeof (int));
argp = stackp;
}
diff --git a/deps/libffi/src/mips/ffi.c b/deps/libffi/src/mips/ffi.c
index dc5507926a4..0a23a72e695 100644
--- a/deps/libffi/src/mips/ffi.c
+++ b/deps/libffi/src/mips/ffi.c
@@ -67,6 +67,20 @@ if (argp == &stack[bytes]) \
#define FIX_ARGP
#endif
+/* The offset of ARGP in the argument list. On N32/N64, when there are
+ more than eight slots, ffi_prep_args puts the eight register slots at
+ the end of STACK and the stack slots at its start. */
+#ifdef FFI_MIPS_N32
+#define ARG_OFFSET(p) \
+ (bytes > 8 * (int) sizeof(ffi_arg) \
+ ? ((p) >= &stack[bytes - 8 * sizeof(ffi_arg)] \
+ ? (size_t) ((p) - &stack[bytes - 8 * sizeof(ffi_arg)]) \
+ : (size_t) ((p) - stack) + 8 * sizeof(ffi_arg)) \
+ : (size_t) ((p) - stack))
+#else
+#define ARG_OFFSET(p) ((size_t) ((p) - stack))
+#endif
+
/* ffi_prep_args is called by the assembly routine once stack space
has been allocated for the function's arguments */
@@ -134,12 +148,23 @@ static void ffi_prep_args(char *stack,
a = (*p_arg)->alignment;
if (a < sizeof(ffi_arg))
a = sizeof(ffi_arg);
-
- if ((a - 1) & (unsigned long) argp)
- {
- argp = (char *) FFI_ALIGN(argp, a);
- FIX_ARGP;
- }
+ /* No argument is passed at more than two-slot alignment, and the
+ argument area is only that aligned. */
+ if (a > 2 * sizeof(ffi_arg))
+ a = 2 * sizeof(ffi_arg);
+
+ /* Align the argument's offset in the argument list, as the
+ compiler does, not its address: on N32/N64 the register part is
+ moved to the end of the area, so the two need not agree. */
+ {
+ size_t off = ARG_OFFSET (argp);
+
+ if ((a - 1) & off)
+ {
+ argp += FFI_ALIGN(off, a) - off;
+ FIX_ARGP;
+ }
+ }
z = (*p_arg)->size;
if (z <= sizeof(ffi_arg))
@@ -206,9 +231,12 @@ static void ffi_prep_args(char *stack,
/* expand from 4+4 to 8+8 if pass with fpr reg */
/* argp will wind back to stack when we process all of reg args */
/* all var_args passed with gpr, should be expand */
+ /* if only one reg slot is left, gcc passes it in that gpr
+ like a struct of two floats, so don't expand it */
if(!soft_float
&& (*p_arg)->elements[0]->type == FFI_TYPE_FLOAT
&& argp>=argp_f
+ && argp + 2 * z <= &stack[bytes]
&& i < ecif->cif->mips_nfixedargs)
{
*(float *) argp = *(float *)(* p_argv);
@@ -975,7 +1003,9 @@ ffi_prep_closure_loc (ffi_closure *closure,
* registers have been saved, if any.
*
* RVALUE is the location where the function return value will be
- * stored. CLOSURE is the prepared closure to invoke.
+ * stored; it has room for 16 bytes, so that a complex value returned
+ * in up to four GPRs or in $f0/$f2 fits. CLOSURE is the prepared
+ * closure to invoke.
*
* This function should only be called from assembly, which is in
* turn called from a trampoline.
@@ -1008,27 +1038,13 @@ ffi_closure_mips_inner_O32 (ffi_cif *cif,
argn = 1;
seen_int = 1;
}
- if (cif->rtype->type == FFI_TYPE_COMPLEX
- && (cif->rtype->elements[0]->type == FFI_TYPE_FLOAT
- || cif->rtype->elements[0]->type == FFI_TYPE_DOUBLE
- || cif->rtype->elements[0]->type == FFI_TYPE_LONGDOUBLE))
- {
- rvalue = fpr;
- }
- /* With soft float, complex values are returned in up to four GPRs,
- which does not fit into the space for v0 and v1. ffi_closure_O32
- does not use the space for the FP argument registers in that case,
- so return the value there. */
- if (cif->abi == FFI_O32_SOFT_FLOAT && cif->rtype->type == FFI_TYPE_COMPLEX)
- rvalue = fpr;
-
i = 0;
avn = cif->nargs;
arg_types = cif->arg_types;
while (i < avn)
{
- if (arg_types[i]->alignment == 8 && (argn & 0x1))
+ if (arg_types[i]->alignment > sizeof(ffi_arg) && (argn & 0x1))
argn++;
if (i < 2 && !seen_int &&
(arg_types[i]->type == FFI_TYPE_FLOAT ||
@@ -1225,19 +1241,35 @@ ffi_closure_mips_inner_N32 (ffi_cif *cif,
}
else if (arg_types[i]->type == FFI_TYPE_COMPLEX && arg_types[i]->elements[0]->type == FFI_TYPE_DOUBLE)
{
- argp = (argn >= 8 || i >= cif->mips_nfixedargs || soft_float) ? ar + argn : fpr + argn;
+ /* with only one reg slot left it was passed in that gpr and on
+ the stack, which follows the saved gprs */
+ argp = (argn >= 7 || i >= cif->mips_nfixedargs || soft_float) ? ar + argn : fpr + argn;
avaluep[i] = (char *) argp;
}
else if (arg_types[i]->type == FFI_TYPE_COMPLEX && arg_types[i]->elements[0]->type == FFI_TYPE_LONGDOUBLE)
{
/* align long double */
argn += ((argn & 0x1)? 1 : 0);
- argp = (argn >= 8 || i >= cif->mips_nfixedargs || soft_float) ? ar + argn : fpr + argn;
- avaluep[i] = (char *) argp;
+ if (argn == 6 && i < cif->mips_nfixedargs && !soft_float)
+ {
+ /* Only the real part fits in the last FP register pair; the
+ imaginary part is on the stack, which follows the saved
+ gprs. Put the two halves back together. */
+ char *z = alloca (arg_types[i]->size);
+ memcpy (z, fpr + 6, 2 * sizeof (ffi_arg));
+ memcpy (z + 2 * sizeof (ffi_arg), ar + 8, 2 * sizeof (ffi_arg));
+ avaluep[i] = z;
+ }
+ else
+ {
+ argp = (argn >= 8 || i >= cif->mips_nfixedargs || soft_float) ? ar + argn : fpr + argn;
+ avaluep[i] = (char *) argp;
+ }
}
else if (arg_types[i]->type == FFI_TYPE_COMPLEX && arg_types[i]->elements[0]->type == FFI_TYPE_FLOAT)
{
- if (argn >= 8 || i >= cif->mips_nfixedargs || soft_float)
+ /* with only one reg slot left it was passed in that gpr */
+ if (argn >= 7 || i >= cif->mips_nfixedargs || soft_float)
argp = ar + argn;
else
{
@@ -1253,7 +1285,7 @@ ffi_closure_mips_inner_N32 (ffi_cif *cif,
unsigned type = arg_types[i]->type;
if (arg_types[i]->alignment > sizeof(ffi_arg))
- argn = FFI_ALIGN(argn, arg_types[i]->alignment / sizeof(ffi_arg));
+ argn = FFI_ALIGN(argn, 2);
argp = ar + argn;
diff --git a/deps/libffi/src/mips/o32.S b/deps/libffi/src/mips/o32.S
index 5c884a95979..8f11d14e10a 100644
--- a/deps/libffi/src/mips/o32.S
+++ b/deps/libffi/src/mips/o32.S
@@ -275,21 +275,27 @@ $LFE0:
-2 - fp save
-3 - $16 (s0) save
-4 - cprestore
- -5 - return value high (v1)
- -6 - return value low (v0)
- -7 - f14 (le high, be low)
- -8 - f14 (le low, be high)
- -9 - f12 (le high, be low)
- -10 - f12 (le low, be high)
- -11 - Called function a5 save
- -12 - Called function a4 save
- -13 - Called function a3 save
- -14 - Called function a2 save
- -15 - Called function a1 save
- -16 - Called function a0 save, our sp and fp point here
+ -5 - return value, fourth word (a1 / $f2 high)
+ -6 - return value, third word (a0 / $f2 low)
+ -7 - return value high (v1)
+ -8 - return value low (v0)
+ -9 - f14 (le high, be low)
+ -10 - f14 (le low, be high)
+ -11 - f12 (le high, be low)
+ -12 - f12 (le low, be high)
+ -13 - Called function a5 save
+ -14 - Called function a4 save
+ -15 - Called function a3 save
+ -16 - Called function a2 save
+ -17 - Called function a1 save
+ -18 - Called function a0 save, our sp and fp point here
+
+ The return value area is 16 bytes: a complex value is returned
+ in up to four GPRs, or in $f0/$f2, and ffi_closure_mips_inner_O32
+ stores it there in memory order.
*/
-#define SIZEOF_FRAME2 (16 * FFI_SIZEOF_ARG)
+#define SIZEOF_FRAME2 (18 * FFI_SIZEOF_ARG)
#define A3_OFF2 (SIZEOF_FRAME2 + 3 * FFI_SIZEOF_ARG)
#define A2_OFF2 (SIZEOF_FRAME2 + 2 * FFI_SIZEOF_ARG)
#define A1_OFF2 (SIZEOF_FRAME2 + 1 * FFI_SIZEOF_ARG)
@@ -298,14 +304,14 @@ $LFE0:
#define FP_OFF2 (SIZEOF_FRAME2 - 2 * FFI_SIZEOF_ARG)
#define S0_OFF2 (SIZEOF_FRAME2 - 3 * FFI_SIZEOF_ARG)
#define GP_OFF2 (SIZEOF_FRAME2 - 4 * FFI_SIZEOF_ARG)
-#define V1_OFF2 (SIZEOF_FRAME2 - 5 * FFI_SIZEOF_ARG)
-#define V0_OFF2 (SIZEOF_FRAME2 - 6 * FFI_SIZEOF_ARG)
-#define FA_1_1_OFF2 (SIZEOF_FRAME2 - 7 * FFI_SIZEOF_ARG)
-#define FA_1_0_OFF2 (SIZEOF_FRAME2 - 8 * FFI_SIZEOF_ARG)
-#define FA_0_1_OFF2 (SIZEOF_FRAME2 - 9 * FFI_SIZEOF_ARG)
-#define FA_0_0_OFF2 (SIZEOF_FRAME2 - 10 * FFI_SIZEOF_ARG)
-#define CALLED_A5_OFF2 (SIZEOF_FRAME2 - 11 * FFI_SIZEOF_ARG)
-#define CALLED_A4_OFF2 (SIZEOF_FRAME2 - 12 * FFI_SIZEOF_ARG)
+#define V1_OFF2 (SIZEOF_FRAME2 - 7 * FFI_SIZEOF_ARG)
+#define V0_OFF2 (SIZEOF_FRAME2 - 8 * FFI_SIZEOF_ARG)
+#define FA_1_1_OFF2 (SIZEOF_FRAME2 - 9 * FFI_SIZEOF_ARG)
+#define FA_1_0_OFF2 (SIZEOF_FRAME2 - 10 * FFI_SIZEOF_ARG)
+#define FA_0_1_OFF2 (SIZEOF_FRAME2 - 11 * FFI_SIZEOF_ARG)
+#define FA_0_0_OFF2 (SIZEOF_FRAME2 - 12 * FFI_SIZEOF_ARG)
+#define CALLED_A5_OFF2 (SIZEOF_FRAME2 - 13 * FFI_SIZEOF_ARG)
+#define CALLED_A4_OFF2 (SIZEOF_FRAME2 - 14 * FFI_SIZEOF_ARG)
.text
@@ -445,30 +451,29 @@ $do_closure:
li $9, FFI_TYPE_COMPLEX
bne $8, $9, 1f
+ # Load $f0/$f2 for floating-point complex values, then fall
+ # through to 2 to load the GPRs for integer complex values.
+ # Whichever register set the type does not use is call-clobbered.
li $9, 8
- REG_L $2, FA_0_0_OFF2($fp)
+ REG_L $2, V0_OFF2($fp)
mtc1 $2, $f0
- REG_L $2, FA_0_1_OFF2($fp)
+ REG_L $2, V1_OFF2($fp)
mtc1 $2, $f2
- beq $3, $9, closure_done
+ beq $3, $9, 2f
- li $9, 16
- l.d $f0, FA_0_0_OFF2($fp)
- l.d $f2, FA_1_0_OFF2($fp)
- beq $3, $9, closure_done
+ l.d $f0, V0_OFF2($fp)
+ l.d $f2, (V0_OFF2 + 8)($fp)
#endif
- b 1f
2:
- # FFI_O32_SOFT_FLOAT returns complex values in up to four GPRs.
- # ffi_closure_mips_inner_O32 stored them in the space for the
- # FP argument registers.
+ # Integer complex values, and with FFI_O32_SOFT_FLOAT all complex
+ # values, are returned in up to four GPRs.
li $9, FFI_TYPE_COMPLEX
bne $8, $9, 1f
- REG_L $2, FA_0_0_OFF2($fp)
- REG_L $3, FA_0_1_OFF2($fp)
- REG_L $4, FA_1_0_OFF2($fp)
- REG_L $5, FA_1_1_OFF2($fp)
+ REG_L $2, V0_OFF2($fp)
+ REG_L $3, V1_OFF2($fp)
+ REG_L $4, (V0_OFF2 + 8)($fp)
+ REG_L $5, (V0_OFF2 + 12)($fp)
b closure_done
1:
diff --git a/deps/libffi/src/powerpc/ffi_darwin.c b/deps/libffi/src/powerpc/ffi_darwin.c
index 64449c38e15..4a094df9536 100644
--- a/deps/libffi/src/powerpc/ffi_darwin.c
+++ b/deps/libffi/src/powerpc/ffi_darwin.c
@@ -667,6 +667,7 @@ static int
aix_adjust_aggregate_sizes (ffi_type *s, int outer_most_type_or_first_member)
{
int i, nested_first_member=0, final_align, rc=0;
+ int first_member_align=0, member_align=1;
if (s->type != FFI_TYPE_STRUCT)
return 0;
@@ -684,16 +685,26 @@ aix_adjust_aggregate_sizes (ffi_type *s, int outer_most_type_or_first_member)
else
aix_adjust_aggregate_sizes(&p, 0);
align = p.alignment;
+ if (i == 0)
+ first_member_align = align;
if (i != 0 && p.type == FFI_TYPE_DOUBLE)
align = 4;
+ if (align > member_align)
+ member_align = align;
s->size = FFI_ALIGN(s->size, align) + p.size;
}
+ /* Recompute the alignment from the members, as done for the size: S may be
+ a shared type whose stored alignment was raised to 8 below when it was
+ last laid out as an outer-most type or first member, which must not leak
+ into its layout as a later member (or into that of its enclosing type).
+ For the same reason the first member is tested via its adjusted copy. */
+ s->alignment = member_align;
final_align=s->alignment;
if ((s->elements[0]->type == FFI_TYPE_UINT64
|| s->elements[0]->type == FFI_TYPE_SINT64
|| s->elements[0]->type == FFI_TYPE_DOUBLE
- || s->elements[0]->alignment == 8 || nested_first_member)) {
+ || first_member_align == 8 || nested_first_member)) {
final_align = s->alignment > 8 ? s->alignment : 8;
rc=1;
/* still use the adjusted alignment to calculate tail padding, but don't adjust the types alignment if
diff --git a/deps/libffi/src/powerpc/ffi_linux64.c b/deps/libffi/src/powerpc/ffi_linux64.c
index c0ca42cab9a..c85f3656b11 100644
--- a/deps/libffi/src/powerpc/ffi_linux64.c
+++ b/deps/libffi/src/powerpc/ffi_linux64.c
@@ -164,6 +164,32 @@ discover_homogeneous_aggregate (ffi_abi abi,
}
+/* Whether a struct argument is subject to the FFI_LINUX_STRUCT_ALIGN
+ quadword alignment in the parameter save area. ELT is what
+ discover_homogeneous_aggregate returned for it. Under ELFv2 a
+ homogeneous aggregate of float, double or IBM long double occupies
+ the doublewords its members would as separate arguments, so it is
+ only doubleword aligned even though the struct's alignment is 16
+ (IBM long double). IEEE128 aggregates are passed in vector
+ registers and keep the quadword alignment. */
+static int
+struct_align_applies (ffi_abi abi, unsigned int elt)
+{
+ if ((abi & FFI_LINUX_STRUCT_ALIGN) == 0)
+ return 0;
+#if _CALL_ELF == 2
+ if (elt == FFI_TYPE_FLOAT || elt == FFI_TYPE_DOUBLE)
+ return 0;
+#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
+ if (elt == FFI_TYPE_LONGDOUBLE
+ && (abi & FFI_LINUX_LONG_DOUBLE_IEEE128) == 0)
+ return 0;
+#endif
+#endif
+ return 1;
+}
+
+
/* Perform machine dependent cif processing */
static ffi_status
ffi_prep_cif_linux64_core (ffi_cif *cif)
@@ -339,12 +365,18 @@ homogeneous:
case FFI_TYPE_FLOAT:
fparg_count++;
intarg_count++;
- if (fparg_count > NUM_FPR_ARG_REGISTERS64)
+ /* A floating point value that finds no FPR is passed in the GPR
+ for its doubleword if there is one, and only goes to memory
+ (so the caller must allocate a parameter save area) once
+ the doubleword is beyond the eight that map to GPRs. */
+ if (fparg_count > NUM_FPR_ARG_REGISTERS64
+ && intarg_count > NUM_GPR_ARG_REGISTERS64)
flags |= FLAG_ARG_NEEDS_PSAVE;
break;
case FFI_TYPE_STRUCT:
- if ((cif->abi & FFI_LINUX_STRUCT_ALIGN) != 0)
+ elt = discover_homogeneous_aggregate (cif->abi, *ptr, &elnum);
+ if (struct_align_applies (cif->abi, elt))
{
align = (*ptr)->alignment;
if (align > 16)
@@ -354,7 +386,6 @@ homogeneous:
intarg_count = FFI_ALIGN (intarg_count, align);
}
intarg_count += ((*ptr)->size + 7) / 8;
- elt = discover_homogeneous_aggregate (cif->abi, *ptr, &elnum);
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
if (elt == FFI_TYPE_LONGDOUBLE &&
(cif->abi & FFI_LINUX_LONG_DOUBLE_IEEE128) != 0)
@@ -368,8 +399,12 @@ homogeneous:
#endif
if (elt)
{
+ /* Elements that find no FPR are passed in GPRs while the
+ aggregate's doublewords fit in the eight GPRs (two floats
+ per doubleword), and only beyond that in memory. */
fparg_count += elnum;
- if (fparg_count > NUM_FPR_ARG_REGISTERS64)
+ if (fparg_count > NUM_FPR_ARG_REGISTERS64
+ && intarg_count > NUM_GPR_ARG_REGISTERS64)
flags |= FLAG_ARG_NEEDS_PSAVE;
}
else
@@ -416,7 +451,8 @@ homogeneous:
case FFI_TYPE_DOUBLE:
fparg_count += 2;
intarg_count += 2;
- if (fparg_count > NUM_FPR_ARG_REGISTERS64)
+ if (fparg_count > NUM_FPR_ARG_REGISTERS64
+ && intarg_count > NUM_GPR_ARG_REGISTERS64)
flags |= FLAG_ARG_NEEDS_PSAVE;
break;
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
@@ -436,7 +472,8 @@ homogeneous:
consumes a GPR shadow doubleword -- four of each in total. */
fparg_count += 4;
intarg_count += 4;
- if (fparg_count > NUM_FPR_ARG_REGISTERS64)
+ if (fparg_count > NUM_FPR_ARG_REGISTERS64
+ && intarg_count > NUM_GPR_ARG_REGISTERS64)
flags |= FLAG_ARG_NEEDS_PSAVE;
break;
#endif
@@ -447,12 +484,12 @@ homogeneous:
case FFI_TYPE_SINT64: case FFI_TYPE_UINT64:
case FFI_TYPE_POINTER:
intarg_count += 2;
+ if (intarg_count > NUM_GPR_ARG_REGISTERS64)
+ flags |= FLAG_ARG_NEEDS_PSAVE;
break;
default:
return FFI_BAD_TYPEDEF;
}
- if (intarg_count > NUM_GPR_ARG_REGISTERS64)
- flags |= FLAG_ARG_NEEDS_PSAVE;
break;
#endif
@@ -927,7 +964,8 @@ ffi_prep_args64 (extended_cif *ecif, unsigned long *const stack)
#endif
case FFI_TYPE_STRUCT:
- if ((ecif->cif->abi & FFI_LINUX_STRUCT_ALIGN) != 0)
+ elt = discover_homogeneous_aggregate (ecif->cif->abi, *ptr, &elnum);
+ if (struct_align_applies (ecif->cif->abi, elt))
{
align = (*ptr)->alignment;
if (align > 16)
@@ -939,7 +977,6 @@ ffi_prep_args64 (extended_cif *ecif, unsigned long *const stack)
next_arg.ul = rest.ul;
}
}
- elt = discover_homogeneous_aggregate (ecif->cif->abi, *ptr, &elnum);
if (elt)
{
#if _CALL_ELF == 2
@@ -1221,7 +1258,8 @@ ffi_closure_helper_LINUX64 (ffi_cif *cif,
break;
case FFI_TYPE_STRUCT:
- if ((cif->abi & FFI_LINUX_STRUCT_ALIGN) != 0)
+ elt = discover_homogeneous_aggregate (cif->abi, arg_types[i], &elnum);
+ if (struct_align_applies (cif->abi, elt))
{
align = arg_types[i]->alignment;
if (align > 16)
@@ -1229,7 +1267,6 @@ ffi_closure_helper_LINUX64 (ffi_cif *cif,
if (align > 1)
pst = (unsigned long *) FFI_ALIGN ((size_t) pst, align);
}
- elt = discover_homogeneous_aggregate (cif->abi, arg_types[i], &elnum);
if (elt)
{
#if _CALL_ELF == 2
@@ -1262,6 +1299,15 @@ ffi_closure_helper_LINUX64 (ffi_cif *cif,
else
to.v = pst;
+ /* Those arrays are only doubleword aligned, but an aggregate
+ of IBM long double needs 16: rebuild it in aligned memory
+ instead, or the handler reads it from the wrong place. */
+ if (((size_t) to.v & (arg_types[i]->alignment - 1)) != 0)
+ to.v = (void *) FFI_ALIGN (alloca (arg_types[i]->size
+ + arg_types[i]->alignment
+ - 1),
+ arg_types[i]->alignment);
+
avalue[i] = to.v;
from.ul = pst;
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
diff --git a/deps/libffi/src/prep_cif.c b/deps/libffi/src/prep_cif.c
index 8a448ebbf81..9e158627f2a 100644
--- a/deps/libffi/src/prep_cif.c
+++ b/deps/libffi/src/prep_cif.c
@@ -86,12 +86,15 @@ initialize_vector (ffi_type *arg)
count++;
}
- if (UNLIKELY (count < 1 || elem->size == 0))
+ if (UNLIKELY (count < 1 || elem->size == 0
+ || elem->size > FFI_MAX_TYPE_SIZE / count))
return FFI_BAD_TYPEDEF;
total = elem->size * count;
for (p2 = 1; p2 < total; p2 <<= 1)
;
+ if (UNLIKELY (p2 > FFI_MAX_TYPE_SIZE))
+ return FFI_BAD_TYPEDEF;
arg->size = p2;
arg->alignment = p2 < 16 ? p2 : 16;
@@ -129,6 +132,13 @@ static ffi_status initialize_aggregate(ffi_type *arg, size_t *offsets)
FFI_ASSERT_VALID_TYPE(*ptr);
arg->size = FFI_ALIGN(arg->size, (*ptr)->alignment);
+
+ /* Reject a type too large to exist rather than letting the sum
+ wrap or handing the call code a size it cannot allocate. */
+ if (UNLIKELY((*ptr)->size > FFI_MAX_TYPE_SIZE
+ || arg->size > FFI_MAX_TYPE_SIZE - (*ptr)->size))
+ return FFI_BAD_TYPEDEF;
+
if (offsets)
*offsets++ = arg->size;
arg->size += (*ptr)->size;
@@ -155,18 +165,19 @@ static ffi_status initialize_aggregate(ffi_type *arg, size_t *offsets)
arg->alignment = FFI_AGGREGATE_ALIGNMENT;
#endif
- if (arg->size == 0)
+ if (arg->size == 0 || arg->size > FFI_MAX_TYPE_SIZE)
return FFI_BAD_TYPEDEF;
else
return FFI_OK;
}
-#ifndef FFI_TARGET_HAS_VECTOR_TYPE
/* Recursively test whether TY is, or contains, a vector (SIMD) type. Ports
that do not define FFI_TARGET_HAS_VECTOR_TYPE cannot marshal vectors, so
ffi_prep_cif_core rejects any signature that mentions one (directly or
- nested inside a struct) with FFI_BAD_TYPEDEF rather than aborting. */
-static int
+ nested inside a struct) with FFI_BAD_TYPEDEF rather than aborting. Ports
+ that define it but also build a backend without vector support (x86-64's
+ ffiw64.c) call this from that backend's ffi_prep_cif_machdep. */
+int FFI_HIDDEN
ffi_type_contains_vector (ffi_type *ty)
{
ffi_type **p;
@@ -181,7 +192,6 @@ ffi_type_contains_vector (ffi_type *ty)
return 1;
return 0;
}
-#endif /* !FFI_TARGET_HAS_VECTOR_TYPE */
#ifndef __CRIS__
/* The CRIS ABI specifies structure elements to have byte
@@ -205,6 +215,7 @@ ffi_status FFI_HIDDEN ffi_prep_cif_core(ffi_cif *cif, ffi_abi abi,
ffi_type *rtype, ffi_type **atypes)
{
unsigned bytes = 0;
+ size_t arg_bytes = 0;
unsigned int i;
ffi_type **ptr;
@@ -220,6 +231,9 @@ ffi_status FFI_HIDDEN ffi_prep_cif_core(ffi_cif *cif, ffi_abi abi,
cif->nargs = ntotalargs;
cif->rtype = rtype;
+ if (ntotalargs > FFI_MAX_NARGS)
+ return FFI_BAD_TYPEDEF;
+
#ifndef FFI_TARGET_HAS_VECTOR_TYPE
/* Vector (SIMD) types are only marshalled on ports that opt in. */
if (ffi_type_contains_vector (rtype))
@@ -248,6 +262,8 @@ ffi_status FFI_HIDDEN ffi_prep_cif_core(ffi_cif *cif, ffi_abi abi,
#endif
/* Perform a sanity check on the return type */
FFI_ASSERT_VALID_TYPE(cif->rtype);
+ if (cif->rtype->size > FFI_MAX_ARG_BYTES)
+ return FFI_BAD_TYPEDEF;
/* x86, x86-64 and s390 stack space allocation is handled in prep_machdep. */
#if !defined FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
@@ -280,6 +296,12 @@ ffi_status FFI_HIDDEN ffi_prep_cif_core(ffi_cif *cif, ffi_abi abi,
check after the initialization. */
FFI_ASSERT_VALID_TYPE(*ptr);
+ /* Bound the whole argument list, whatever the port does with it. */
+ if ((*ptr)->size > FFI_MAX_ARG_BYTES
+ || FFI_ALIGN ((*ptr)->size, 16) > FFI_MAX_ARG_BYTES - arg_bytes)
+ return FFI_BAD_TYPEDEF;
+ arg_bytes += FFI_ALIGN ((*ptr)->size, 16);
+
#if !defined FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
{
/* Add any padding if necessary */
@@ -300,6 +322,10 @@ ffi_status FFI_HIDDEN ffi_prep_cif_core(ffi_cif *cif, ffi_abi abi,
bytes = 6*4;
#endif
+ /* cif->bytes is an unsigned int: refuse a total it cannot hold
+ rather than let ffi_call allocate the truncated size. */
+ if (bytes > INT_MAX || (*ptr)->size > INT_MAX - bytes)
+ return FFI_BAD_TYPEDEF;
bytes += (unsigned int)STACK_ARG_SIZE((*ptr)->size);
}
#endif
diff --git a/deps/libffi/src/riscv/ffi.c b/deps/libffi/src/riscv/ffi.c
index 53c41db60a6..becc23fc972 100644
--- a/deps/libffi/src/riscv/ffi.c
+++ b/deps/libffi/src/riscv/ffi.c
@@ -119,7 +119,7 @@ static float_struct_info struct_passed_as_elements(call_builder *cb, ffi_type *t
int num_fields = flatten_struct(top, fields, fields + 3) - fields;
if (num_fields == 1) {
- if (IS_FLOAT(fields[0]->type)) {
+ if (IS_FLOAT(fields[0]->type) && cb->used_float < NARGREG) {
ret.as_elements = 1;
ret.type1 = fields[0]->type;
}
diff --git a/deps/libffi/src/sparc/ffi.c b/deps/libffi/src/sparc/ffi.c
index bcda1ff2219..26169692ad4 100644
--- a/deps/libffi/src/sparc/ffi.c
+++ b/deps/libffi/src/sparc/ffi.c
@@ -188,18 +188,9 @@ ffi_prep_args_v8(ffi_cif *cif, unsigned long *argp, void *rvalue, void **avalue)
if (rvalue == NULL)
{
- if ((flags & SPARC_FLAG_RET_MASK) == SPARC_RET_STRUCT)
- {
- /* Since we pass the pointer to the callee, we need a value.
- We allowed for this space in ffi_call, before ffi_call_v8
- alloca'd the space. */
- rvalue = (char *)argp + cif->bytes;
- }
- else
- {
- /* Otherwise, we can ignore the return value. */
- flags = SPARC_RET_VOID;
- }
+ /* ffi_call supplied scratch space if the callee needs a pointer
+ to the return value; otherwise we can ignore it. */
+ flags = SPARC_RET_VOID;
}
/* This could only really be done when we are returning a structure.
@@ -296,7 +287,7 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
got to pass the return value to the callee. Otherwise ignore it. */
if (rvalue == NULL
&& (cif->flags & SPARC_FLAG_RET_MASK) == SPARC_RET_STRUCT)
- bytes += FFI_ALIGN (cif->rtype->size, 8);
+ rvalue = alloca (cif->rtype->size);
/* If we have any structure arguments, make a copy so we are passing
by value. The pointer array is cloned first: the caller owns avalue[]
diff --git a/deps/libffi/src/sparc/ffi64.c b/deps/libffi/src/sparc/ffi64.c
index 80cad660460..737c6f89667 100644
--- a/deps/libffi/src/sparc/ffi64.c
+++ b/deps/libffi/src/sparc/ffi64.c
@@ -342,18 +342,11 @@ ffi_prep_args_v9(ffi_cif *cif, unsigned long *argp, void *rvalue, void **avalue)
if (rvalue == NULL)
{
- if (flags & SPARC_FLAG_RET_IN_MEM)
- {
- /* Since we pass the pointer to the callee, we need a value.
- We allowed for this space in ffi_call, before ffi_call_v8
- alloca'd the space. */
- rvalue = (char *)argp + cif->bytes;
- }
- else
- {
- /* Otherwise, we can ignore the return value. */
- flags = SPARC_RET_VOID;
- }
+ /* ffi_call supplied scratch space if the callee needs a pointer
+ to the return value; otherwise we can ignore it. Keep the other
+ flags: SPARC_FLAG_FP_ARGS says whether to load the FP argument
+ registers. */
+ flags = (flags & ~SPARC_FLAG_RET_MASK) | SPARC_RET_VOID;
}
#ifdef USING_PURIFY
@@ -451,8 +444,10 @@ ffi_call_int(ffi_cif *cif, void (*fn)(void), void *rvalue,
FFI_ASSERT (cif->abi == FFI_V9);
+ /* If we've not got a return value, we need to create one if we've
+ got to pass the return value to the callee. Otherwise ignore it. */
if (rvalue == NULL && (cif->flags & SPARC_FLAG_RET_IN_MEM))
- bytes += FFI_ALIGN (cif->rtype->size, 16);
+ rvalue = alloca (cif->rtype->size);
/* If we have any large structure arguments, make a copy so we are passing
by value. The pointer array is cloned first: the caller owns avalue[]
@@ -604,7 +599,11 @@ ffi_closure_sparc_inner_v9(ffi_cif *cif,
if (named && argn < 16)
{
int size_mask = ffi_struct_float_mask (ty, 0);
- int argn_mask = (0xffff00 >> argn) & 0xff00;
+ /* The mask has one bit per 4-byte word of the struct, and
+ word I is in argument slot ARGN + I / 2; only slots below
+ 16 have FP registers. */
+ int nwords = 2 * (16 - argn);
+ int argn_mask = (nwords >= 8 ? 0xff : (1 << nwords) - 1) << 8;
/* Eliminate fp registers off the end. */
size_mask = (size_mask & 0xff) | (size_mask & argn_mask);
diff --git a/deps/libffi/src/tramp.c b/deps/libffi/src/tramp.c
index 5b2b2cfd36b..9203ff04c21 100644
--- a/deps/libffi/src/tramp.c
+++ b/deps/libffi/src/tramp.c
@@ -306,6 +306,47 @@ ffi_tramp_get_libffi (void)
#if defined (__linux__) || defined (__CYGWIN__)
+/*
+ * Every trampoline code table is a private mapping of tramp_globals.fd, so a
+ * write to the file shows up in all of them. The temporary file is opened
+ * read-write and the descriptor survives fork (), so once the code table has
+ * been written, make the file immutable: seal it (memfd) or else make it
+ * read-only for everyone but its owner and replace the descriptor with a
+ * read-only one.
+ */
+static int
+ffi_tramp_seal_temp_file (void)
+{
+ char path[64];
+ int fd;
+ int open_flags = O_RDONLY;
+
+#ifdef F_ADD_SEALS
+ if (fcntl (tramp_globals.fd, F_ADD_SEALS,
+ F_SEAL_WRITE | F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL) == 0)
+ return 1;
+#endif
+
+#ifdef O_CLOEXEC
+ open_flags |= O_CLOEXEC;
+#endif
+
+ /* A read-only descriptor alone is not enough: a child under another uid
+ could reopen /proc/self/fd/N for writing, and a memfd is mode 0777.
+ Take away write permission first. */
+ if (fchmod (tramp_globals.fd, S_IRUSR) != 0)
+ return 0;
+
+ snprintf (path, sizeof (path), "/proc/self/fd/%d", tramp_globals.fd);
+ fd = open (path, open_flags);
+ if (fd == -1)
+ return 0;
+
+ close (tramp_globals.fd);
+ tramp_globals.fd = fd;
+ return 1;
+}
+
static int
ffi_tramp_get_temp_file (void)
{
@@ -315,11 +356,13 @@ ffi_tramp_get_temp_file (void)
tramp_globals.fd = open_temp_exec_file ();
/*
- * Write the trampoline code table into the temporary file and allocate a
- * trampoline table to make sure that the temporary file can be mapped.
+ * Write the trampoline code table into the temporary file, make the file
+ * read-only and allocate a trampoline table to make sure that the temporary
+ * file can be mapped.
*/
count = write(tramp_globals.fd, tramp_globals.text, tramp_globals.map_size);
- if (count >=0 && (size_t)count == tramp_globals.map_size && tramp_table_alloc ())
+ if (count >=0 && (size_t)count == tramp_globals.map_size
+ && ffi_tramp_seal_temp_file () && tramp_table_alloc ())
return 1;
close (tramp_globals.fd);
diff --git a/deps/libffi/src/x86/ffi.c b/deps/libffi/src/x86/ffi.c
index f2beecf5398..aa816733f20 100644
--- a/deps/libffi/src/x86/ffi.c
+++ b/deps/libffi/src/x86/ffi.c
@@ -190,6 +190,10 @@ ffi_prep_cif_machdep(ffi_cif *cif)
else
#endif
bytes = FFI_ALIGN (bytes, t->alignment);
+ /* cif->bytes is an unsigned int: refuse a total it cannot hold
+ rather than let ffi_call allocate the truncated size. */
+ if (bytes > INT_MAX || t->size > INT_MAX - bytes)
+ return FFI_BAD_TYPEDEF;
bytes += FFI_ALIGN (t->size, FFI_SIZEOF_ARG);
}
cif->bytes = bytes;
@@ -273,6 +277,25 @@ extern void FFI_DECLARE_FASTCALL ffi_call_i386(struct call_frame *, char *) FFI_
/* n.b. ffi_call_unix64 will steal the alloca'd `stack` variable here for use
_as its own stack_ - so we need to compile this function without ASAN */
FFI_ASAN_NO_SANITIZE
+/* Whether a structure argument is passed at 16-byte alignment: GCC does
+ that only when some member, at any depth, is of a type that needs 16
+ (an SSE vector, or long double on Darwin). Alignment on the structure
+ type itself, from an attribute or set by the caller, is ignored. */
+static int
+struct_has_aligned_member (ffi_type *ty)
+{
+ ffi_type **p;
+
+ if (ty->elements == NULL)
+ return 0;
+ for (p = ty->elements; *p != NULL; p++)
+ if ((*p)->type == FFI_TYPE_STRUCT
+ ? struct_has_aligned_member (*p)
+ : (*p)->alignment >= 16)
+ return 1;
+ return 0;
+}
+
static void
ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
void **avalue, void *closure)
@@ -380,13 +403,15 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
narg_reg = 2;
/* Alignment rules for arguments are quite complex. Vectors and
- structures with 16 byte alignment get it. Note that long double
- on Darwin does have 16 byte alignment, and does not get this
- alignment if passed directly; a structure with a long double
- inside, however, would get 16 byte alignment. Since libffi does
- not support vectors, we need non concern ourselves with other
- cases. */
- if (t == FFI_TYPE_STRUCT && ty->alignment >= 16)
+ structures containing a 16-byte-aligned member get it. Note that
+ long double on Darwin does have 16 byte alignment, and does not
+ get this alignment if passed directly; a structure with a long
+ double inside, however, would get 16 byte alignment. Alignment
+ given to the structure type itself, rather than coming from a
+ member, does not count (see struct_has_aligned_member). Since
+ libffi does not support vectors, we need non concern ourselves
+ with other cases. */
+ if (t == FFI_TYPE_STRUCT && struct_has_aligned_member (ty))
align = 16;
if (dir < 0)
@@ -516,7 +541,7 @@ ffi_closure_inner (struct closure_frame *frame, char *stack)
size_t align = FFI_SIZEOF_ARG;
/* See the comment in ffi_call_int. */
- if (t == FFI_TYPE_STRUCT && ty->alignment >= 16)
+ if (t == FFI_TYPE_STRUCT && struct_has_aligned_member (ty))
align = 16;
/* Issue 434: For thiscall and fastcall, if the parameter passed
@@ -709,6 +734,17 @@ ffi_prep_raw_closure_loc (ffi_raw_closure *closure,
return FFI_BAD_TYPEDEF;
}
+ /* Likewise for results returned in memory. The raw closure entry
+ points only provide a 16-byte temporary for the result and do not
+ handle the hidden return pointer, so a handler storing a larger
+ struct there would overrun the frame. */
+ switch (cif->flags)
+ {
+ case X86_RET_STRUCTPOP:
+ case X86_RET_STRUCTARG:
+ return FFI_BAD_TYPEDEF;
+ }
+
switch (cif->abi)
{
case FFI_THISCALL:
@@ -794,7 +830,7 @@ ffi_raw_call(ffi_cif *cif, void (*fn)(void), void *rvalue, ffi_raw *avalue)
bytes = STACK_ALIGN (cif->bytes);
argp = stack =
- (void *)((uintptr_t)alloca(bytes + sizeof(*frame) + rsize + 15) & ~16);
+ (void *) FFI_ALIGN (alloca (bytes + sizeof(*frame) + rsize + 15), 16);
frame = (struct call_frame *)(stack + bytes);
if (rsize)
rvalue = frame + 1;
@@ -841,7 +877,8 @@ ffi_raw_call(ffi_cif *cif, void (*fn)(void), void *rvalue, ffi_raw *avalue)
z = FFI_ALIGN (z, FFI_SIZEOF_ARG);
argp += z;
}
- avalue += z;
+ /* Z is in bytes; AVALUE points to ffi_raw. */
+ avalue = (ffi_raw *) ((char *) avalue + z);
bytes -= z;
}
if (i < n)
diff --git a/deps/libffi/src/x86/ffi64.c b/deps/libffi/src/x86/ffi64.c
index 6bb2b9639c7..2fec6f7bac8 100644
--- a/deps/libffi/src/x86/ffi64.c
+++ b/deps/libffi/src/x86/ffi64.c
@@ -487,8 +487,8 @@ ffi_prep_cif_machdep_efi64(ffi_cif *cif);
ffi_status FFI_HIDDEN
ffi_prep_cif_machdep (ffi_cif *cif)
{
- int gprcount, ssecount, i, avn, ngpr, nsse;
- unsigned flags;
+ int gprcount, ssecount, ngpr, nsse;
+ unsigned i, avn, flags;
enum x86_64_reg_class classes[MAX_CLASSES];
size_t bytes, n, rtype_size;
ffi_type *rtype;
@@ -671,6 +671,10 @@ ffi_prep_cif_machdep (ffi_cif *cif)
align = 8;
bytes = FFI_ALIGN (bytes, align);
+ /* cif->bytes is an unsigned int: refuse a total it cannot hold
+ rather than let ffi_call allocate the truncated size. */
+ if (bytes > INT_MAX || cif->arg_types[i]->size > INT_MAX - bytes)
+ return FFI_BAD_TYPEDEF;
bytes += cif->arg_types[i]->size;
}
else
@@ -682,8 +686,14 @@ ffi_prep_cif_machdep (ffi_cif *cif)
if (ssecount)
flags |= UNIX64_FLAG_XMM_ARGS;
+ /* cif->bytes is unsigned: refuse an argument area it cannot describe
+ rather than truncating it and making the call with a short stack. */
+ bytes = FFI_ALIGN (bytes, 8);
+ if (bytes > UINT_MAX)
+ return FFI_BAD_TYPEDEF;
+
cif->flags = flags;
- cif->bytes = (unsigned) FFI_ALIGN (bytes, 8);
+ cif->bytes = (unsigned) bytes;
return FFI_OK;
}
@@ -698,8 +708,10 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
enum x86_64_reg_class classes[MAX_CLASSES];
char *stack, *argp;
ffi_type **arg_types;
- int gprcount, ssecount, ngpr, nsse, i, avn, flags;
+ int gprcount, ssecount, ngpr, nsse, flags;
+ unsigned i, avn;
struct register_args *reg_args;
+ size_t stack_align;
/* Can't call 32-bit mode from 64-bit mode. */
FFI_ASSERT (cif->abi == FFI_UNIX64);
@@ -718,8 +730,22 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
arg_types = cif->arg_types;
avn = cif->nargs;
- /* Allocate the space for the arguments, plus 4 words of temp space. */
- stack = alloca (sizeof (struct register_args) + cif->bytes + 4*8);
+ /* ffi_prep_cif_machdep sized the stack argument area by aligning
+ offsets into it, but the arguments are placed (and found by the
+ callee) by aligning addresses. The two only agree if the area
+ starts on a multiple of the largest argument alignment, as it does
+ in a compiled caller; alloca promises no more than 16 bytes. */
+ stack_align = 16;
+ for (i = 0; i < avn; ++i)
+ if (arg_types[i]->alignment > stack_align)
+ stack_align = arg_types[i]->alignment;
+
+ /* Allocate the space for the arguments, plus 4 words of temp space,
+ plus the slack needed to align the stack argument area. */
+ stack = alloca (sizeof (struct register_args) + cif->bytes + 4*8
+ + (stack_align - 16));
+ stack += -(uintptr_t) (stack + sizeof (struct register_args))
+ & (stack_align - 1);
reg_args = (struct register_args *) stack;
argp = stack + sizeof (struct register_args);
@@ -927,8 +953,15 @@ build_plan (ffi_cif *cif)
#endif
}
+ /* The move list is described by 32-bit fields (nmoves, dst_off,
+ alloc_bytes), and 2 * avn + 1 must not wrap below: a signature with
+ more arguments than that fits gets no plan and the caller falls back
+ to ffi_call. */
+ if (avn > ((UINT_MAX - sizeof (ffi_plan)) / sizeof (ffi_move) - 1) / 2)
+ return NULL;
+
/* One self-contained allocation: header + moves, released with plain free(). */
- nbytes = sizeof (ffi_plan) + sizeof (ffi_move) * (2 * avn + 1);
+ nbytes = sizeof (ffi_plan) + sizeof (ffi_move) * (2 * (size_t) avn + 1);
plan = malloc (nbytes);
if (plan == NULL)
return NULL;
@@ -1178,8 +1211,8 @@ ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
{
ffi_type **arg_types = cif->arg_types;
void **avalue_copy = NULL;
- int i, nargs = cif->nargs;
- const int max_reg_struct_size = cif->abi == FFI_GNUW64 ? 8 : 16;
+ unsigned i, nargs = cif->nargs;
+ const size_t max_reg_struct_size = cif->abi == FFI_GNUW64 ? 8 : 16;
/* If we have any large structure arguments, make a copy so we are passing
by value. The pointer array is cloned first: the caller owns avalue[]
@@ -1187,7 +1220,7 @@ ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
for (i = 0; i < nargs; i++)
{
ffi_type *at = arg_types[i];
- int size = at->size;
+ size_t size = at->size;
if (at->type == FFI_TYPE_STRUCT && size > max_reg_struct_size)
{
char *argcopy = alloca (size);
@@ -1324,6 +1357,7 @@ ffi_closure_unix64_inner(ffi_cif *cif,
long i, avn;
int gprcount, ssecount, ngpr, nsse;
int flags;
+ size_t argoff = 0;
avn = cif->nargs;
flags = cif->flags;
@@ -1358,10 +1392,12 @@ ffi_closure_unix64_inner(ffi_cif *cif,
if (align < 8)
align = 8;
- /* Pass this argument in memory. */
- argp = (void *) FFI_ALIGN (argp, align);
- avalue[i] = argp;
- argp += arg_types[i]->size;
+ /* Pass this argument in memory. Its position is an aligned
+ offset from the start of the argument area; not every
+ caller aligns the area itself to more than 16 bytes. */
+ argoff = FFI_ALIGN (argoff, align);
+ avalue[i] = argp + argoff;
+ argoff += arg_types[i]->size;
}
/* If the argument is in a single register, or two consecutive
integer registers, then we can use that address directly. */
diff --git a/deps/libffi/src/x86/ffiw64.c b/deps/libffi/src/x86/ffiw64.c
index f8db4e0d962..5431f1c2bbd 100644
--- a/deps/libffi/src/x86/ffiw64.c
+++ b/deps/libffi/src/x86/ffiw64.c
@@ -54,7 +54,8 @@ extern void ffi_call_win64 (void *stack, struct win64_call_frame *,
ffi_status FFI_HIDDEN
EFI64(ffi_prep_cif_machdep)(ffi_cif *cif)
{
- int flags, n;
+ int flags;
+ size_t n;
switch (cif->abi)
{
@@ -65,6 +66,16 @@ EFI64(ffi_prep_cif_machdep)(ffi_cif *cif)
return FFI_BAD_ABI;
}
+#ifdef FFI_TARGET_HAS_VECTOR_TYPE
+ /* This backend does not marshal vectors. When it is built alongside
+ ffi64.c, ffi_prep_cif_core lets them through, so reject them here. */
+ if (ffi_type_contains_vector (cif->rtype))
+ return FFI_BAD_TYPEDEF;
+ for (n = 0; n < cif->nargs; n++)
+ if (ffi_type_contains_vector (cif->arg_types[n]))
+ return FFI_BAD_TYPEDEF;
+#endif
+
flags = cif->rtype->type;
switch (flags)
{
@@ -100,11 +111,17 @@ EFI64(ffi_prep_cif_machdep)(ffi_cif *cif)
/* Each argument either fits in a register, an 8 byte slot, or is
passed by reference with the pointer in the 8 byte slot. */
+ if (cif->nargs > INT_MAX / 8 - 1)
+ return FFI_BAD_TYPEDEF;
n = cif->nargs;
n += (flags == FFI_TYPE_STRUCT);
if (n < 4)
n = 4;
- cif->bytes = n * 8;
+ /* cif->bytes is unsigned: refuse an argument area it cannot describe
+ rather than truncating it and making the call with a short stack. */
+ if (n > UINT_MAX / 8)
+ return FFI_BAD_TYPEDEF;
+ cif->bytes = (unsigned) (n * 8);
return FFI_OK;
}
@@ -121,13 +138,14 @@ static void
ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
void **avalue, void *closure)
{
- int i, j, n, flags;
+ unsigned i, j, n;
+ int flags;
UINT64 *stack;
size_t rsize;
struct win64_call_frame *frame;
ffi_type **arg_types = cif->arg_types;
void **avalue_copy = NULL;
- int nargs = cif->nargs;
+ unsigned nargs = cif->nargs;
FFI_ASSERT(cif->abi == FFI_GNUW64 || cif->abi == FFI_WIN64);
@@ -138,7 +156,7 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
for (i = 0; i < nargs; i++)
{
ffi_type *at = arg_types[i];
- int size = at->size;
+ size_t size = at->size;
bool needcopy = false;
switch (at->type)
diff --git a/deps/libffi/src/x86/win64.S b/deps/libffi/src/x86/win64.S
index f23a5fa29e8..f47e7eba295 100644
--- a/deps/libffi/src/x86/win64.S
+++ b/deps/libffi/src/x86/win64.S
@@ -151,9 +151,10 @@ E(0b, FFI_TYPE_UINT128)
E(0b, FFI_TYPE_SINT128)
movdqu %xmm0, (%r8)
epilogue
-/* Win64 does not marshal vectors (ffi_prep_cif_core rejects them), but the
- FFI_TYPE_SMALL_STRUCT_* codes are FFI_TYPE_LAST-relative, so this slot must
- exist to keep the table contiguous and the small-struct entries aligned. */
+/* Win64 does not marshal vectors (ffi_prep_cif_core or, when built alongside
+ ffi64.c, ffi_prep_cif_machdep rejects them), but the FFI_TYPE_SMALL_STRUCT_*
+ codes are FFI_TYPE_LAST-relative, so this slot must exist to keep the table
+ contiguous and the small-struct entries aligned. */
E(0b, FFI_TYPE_VECTOR)
call PLT(C(abort))
E(0b, FFI_TYPE_SMALL_STRUCT_1B)
diff --git a/deps/libffi/src/x86/win64_intel.S b/deps/libffi/src/x86/win64_intel.S
index 807f5b3e98f..e801dcd11b4 100644
--- a/deps/libffi/src/x86/win64_intel.S
+++ b/deps/libffi/src/x86/win64_intel.S
@@ -152,9 +152,10 @@ E(0b, FFI_TYPE_UINT128)
E(0b, FFI_TYPE_SINT128)
movdqu xmmword ptr [r8], xmm0
epilogue
-/* Win64 does not marshal vectors (ffi_prep_cif_core rejects them), but the
- FFI_TYPE_SMALL_STRUCT_* codes are FFI_TYPE_LAST-relative, so this slot must
- exist to keep the table contiguous and the small-struct entries aligned. */
+/* Win64 does not marshal vectors (ffi_prep_cif_core or, when built alongside
+ ffi64.c, ffi_prep_cif_machdep rejects them), but the FFI_TYPE_SMALL_STRUCT_*
+ codes are FFI_TYPE_LAST-relative, so this slot must exist to keep the table
+ contiguous and the small-struct entries aligned. */
E(0b, FFI_TYPE_VECTOR)
call PLT(C(abort))
E(0b, FFI_TYPE_SMALL_STRUCT_1B)