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>
Date:   Sat Nov 14 08:15:07 2026 -0500

    Merge pull request #1082 from libffi/release/3.8.1
    
    Release 3.8.1

commit 8d6f5bf587f642c53b62bde916d7ec60da925cf3
Author: Anthony Green <green@moxielogic.com>
Date:   Sat Nov 14 08:10:58 2026 -0500

    Release 3.8.1
    
    Bump the version from 3.8.0 to 3.8.1 and finalize the changelog:
    
      * configure.ac: AC_INIT 3.8.0 -> 3.8.1 (propagates to FFI_VERSION,
        libffi.pc, and the manual's @value{VERSION}).
      * libtool-version: 13:0:5 -> 13:1:5.  The source changed but no exported
        interface was added, removed, or changed since 3.8.0, so only revision
        is incremented.
      * doc/version.texi, README.md: set the version and the release date.
    
    Also fix three latent release-tooling bugs that "make distcheck" exposes
    (plain "make dist" hides them because it does not make the source tree
    read-only or verify a clean distclean):
    
      * Makefile.am dist-hook rewrote $(distdir)/README.md, which automake had
        already copied read-only, so the redirect failed with "Permission
        denied".  Remove it first.
      * configure.ac: the X86_64 unwind-section test linked conftest without
        -o, leaving an a.out that distcleancheck flagged.  Link to a conftest
        file and clean up.
      * Makefile.am: add the generated libffi.map (and libffi.map-sun) to
        DISTCLEANFILES so distclean removes them.
    
    make distcheck now passes end to end: builds from the tarball, runs the
    full testsuite, installs, uninstalls, and distcleans with nothing left.
    
    Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

commit 63cfe02cc95a0ad97a38586bb5aaf87fcc7e69b4
Merge: fd2cdac5 f3dd79a0
Author: Anthony Green <green@moxielogic.com>
Date:   Sat Nov 14 07:34:25 2026 -0500

    Merge pull request #1081 from libffi/testsuite/dist-missing-tests
    
    testsuite: add new tests to EXTRA_DIST so they ship in the release

commit f3dd79a0662142fca361835ebabea06727c634eb
Author: Anthony Green <green@moxielogic.com>
Date:   Sat Nov 14 07:22:22 2026 -0500

    testsuite: add the new tests to EXTRA_DIST so they ship in the release
    
    The dejagnu .exp drivers glob *.c at run time, so these tests ran in-tree,
    but testsuite/Makefile.am's EXTRA_DIST is a hand-maintained list and `make
    dist` ships only what it names.  The tests added this cycle were missing, so
    a `make check` from the release tarball would silently skip them -- dropping
    the regression coverage for several of the security fixes:
    
      libffi.call/closure_raw.c                 (GHSA-w6j9-w53f-2857)
      libffi.closures/closure_int128.c          (GHSA-wf8m-qr3x-cch4)
      libffi.closures/closure_mmap_failure.c    (#1055)
      libffi.closures/closure_trampoline_table.c (GHSA-23hx-9rxv-9qfp)
      libffi.vector/vector_unsupported_abi.c    (GHSA-5pc3-hr6f-q3mm)
    
    Also add libffi.configure/libdir.sh (the --libdir test run from CI) so it
    ships too.
    
    Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

commit fd2cdac5e82b6c357775ff968ff58149f8f44245
Merge: 297a80c4 852244d3
Author: Anthony Green <green@moxielogic.com>
Date:   Sat Nov 14 07:19:30 2026 -0500

    Merge pull request #1080 from libffi/readme/tighten-tbd
    
    README: tighten the TBD changelog and fold in the security fixes

commit 852244d378e908d846439a7a02d2b33c8b00a965
Author: Anthony Green <green@moxielogic.com>
Date:   Sat Nov 14 07:18:18 2026 -0500

    README: tighten the TBD changelog and fold in the security fixes
    
    Group the pending changes by architecture and theme instead of a flat
    list plus a separate "Security fixes" block, so related entries (including
    the six advisories) sit together.  Drop the CWE codes and the long
    mechanism descriptions -- the referenced issues and advisories carry that
    detail -- while keeping every #issue and GHSA reference.
    
    Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

commit 297a80c4b02ef00010e985675c4c34dbc7bb2181
Merge: 21a49087 46203c53
Author: Anthony Green <green@moxielogic.com>
Date:   Sat Nov 14 07:12:43 2026 -0500

    Merge pull request #1079 from libffi/ci/green-emscripten-pytest
    
    ci(emscripten): get the browser test job green (pytest 9.x + closure_mmap_failure)

commit 46203c534e0a5d57729d838cc59d42103dd7cf62
Author: Anthony Green <green@moxielogic.com>
Date:   Sat Nov 14 06:21:33 2026 -0500

    testsuite: guard closure_mmap_failure for non-glibc harnesses
    
    The Emscripten browser harness (testsuite/emscripten/build-tests.sh) compiles
    every testcase and ignores the dg-do "target x86_64-*-linux-gnu*" directive.
    closure_mmap_failure interposes mmap via dlsym(RTLD_NEXT, "mmap"), which aborts
    on wasm:
    
      Aborted(Assertion failed: Tried to dlsym() from an unopened handle: -1)
    
    (188 passed, 1 failed in the browser run.)  Guard the body on __GLIBC__ so it
    is a no-op wherever the RTLD_NEXT mmap-interposition technique isn't available;
    ffitest.h pulls in <stdlib.h>, so __GLIBC__ is defined on the x86_64-linux-gnu
    dejagnu runs that actually exercise this test, leaving them unchanged.
    
    Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

commit 4abb340542b4a7f6af328bf5e8c16d2bd631b30e
Author: Anthony Green <green@moxielogic.com>
Date:   Sat Nov 14 06:08:19 2026 -0500

    ci(emscripten): bump pytest-pyodide 0.59.2 -> 0.59.4 for pytest 9.x
    
    The browser `test` job crashed during pytest collection:
    
      INTERNALERROR> AttributeError: 'FixtureManager' object has no
      attribute '_arg2fixturedefs'
    
    pytest-pyodide 0.59.2's set_runtime_fixture_params() reads the private
    pytest internal `_fixturemanager._arg2fixturedefs`, which pytest removed.
    The workflow installs an unpinned pytest (currently 9.2.0), so collection
    aborted before any test ran.  (It was masked until now because the build
    job failed first; fixing closure_raw.c let the test job finally run.)
    
    0.59.4 handles this with a version shim (uses getfixturedefs() on
    pytest >= 9.2), so just bump the pin.  Pinning pytest down instead is a
    dead end: pytest-asyncio 1.5.0 (a pytest-pyodide dep) requires pytest>=8.4,
    which already lacks _arg2fixturedefs.
    
    Verified locally that collection of testsuite/emscripten/test_libffi.py
    succeeds with pytest 9.2.0 + pytest-pyodide 0.59.4 (the crash is gone);
    the browser run itself is validated by CI.
    
    Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

commit 21a490876ea8046f544fbbf93a594ccf63685e9a
Merge: 997aee20 6aff44d2
Author: Anthony Green <green@moxielogic.com>
Date:   Sat Nov 14 05:41:38 2026 -0500

    Merge pull request #1078 from libffi/ci/green-emscripten-raw
    
    testsuite: guard closure_raw on !FFI_NO_RAW_API (fix Emscripten CI)

commit 6aff44d25cc7ba8ed4d3a1f64a7e931544545a41
Author: Anthony Green <green@moxielogic.com>
Date:   Sat Nov 14 05:18:38 2026 -0500

    testsuite: guard closure_raw on !FFI_NO_RAW_API (fix Emscripten CI)
    
    The Emscripten build configures libffi with --disable-raw-api, which sets
    FFI_NO_RAW_API and compiles raw_api.c (and the native raw entries) to
    nothing -- so ffi_prep_raw_closure_loc is absent from the wasm library.
    closure_raw.c referenced it unconditionally under only #if FFI_CLOSURES, so
    every wasm target failed to link:
    
      wasm-ld: error: undefined symbol: ffi_prep_raw_closure_loc
    
    Match raw_api.c's own guard: compile the raw-closure test only when
    FFI_CLOSURES && !FFI_NO_RAW_API, falling back to the no-op main otherwise.
    ffitest.h already includes fficonfig.h, so FFI_NO_RAW_API is visible to the
    test.  No change on targets where the raw API is enabled.
    
    Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

commit 997aee20b30d93c4526473d66fec6a37168f550a
Merge: 4098fd38 7632e27b
Author: Anthony Green <green@moxielogic.com>
Date:   Sat Nov 14 00:41:50 2026 -0500

    Merge pull request #1077 from libffi/ci/green-android-macos
    
    ci: xfail x86_64 Android ld-struct return; drop dead macos-14 runner

commit 7632e27b5894c78b0511a4aef8ef0cf0c325880c
Author: Anthony Green <green@moxielogic.com>
Date:   Fri Nov 13 22:06:45 2026 -0500

    ci: xfail x86_64 Android ld-struct return; drop dead macos-14 runner
    
    Two independent CI-green fixes:
    
    testsuite: cls_struct_ld_return.c fails only on x86_64-pc-linux-android
    (NDK clang, static, run natively), while x86_64-pc-linux-gnu passes the
    identical test.  The generic x86-64 struct-return path is therefore sound;
    the Android-specific divergence (possibly a binary128 vs 80-bit long double
    difference feeding classify_argument) is unconfirmed and can't be reproduced
    without the NDK.  xfail it on x86_64-*-linux-android* and track the real fix
    in libffi #1076 rather than guess at ffi64.c and risk the cases that pass.
    
    build.yml: the macos-14 runners (both compiler jobs and the Rosetta job that
    pins macos-14) have been lost on every recent run -- scheduled, then killed
    ~2 min in with no steps, conclusion "cancelled" -- while macos-15 runs fine.
    Drop macos-14 from the matrix and move the Rosetta x86_64 job to macos-15,
    which is also Apple Silicon and supports Rosetta 2, so x86_64 macOS coverage
    is preserved.
    
    Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

commit 4098fd38a167f492e0f9c774298f6754c8ec20d1
Merge: 89a976d5 24c817af
Author: Anthony Green <green@moxielogic.com>
Date:   Fri Nov 13 19:38:54 2026 -0500

    Merge pull request #1075 from libffi/ci/green-android-win32
    
    CI: make dist PDF best-effort (Android) and xfail closure_raw on i686 MSVC

commit 24c817af9aac5e1fb286ce7219d2e08ffd38c113
Author: Anthony Green <green@moxielogic.com>
Date:   Fri Nov 13 19:38:36 2026 -0500

    testsuite: xfail closure_raw on i686 MSVC (libffi #1074)
    
    The raw-API closure test passes everywhere except 32-bit MSVC
    (i686-pc-cygwin), where it compiles but fails at execution in the i386
    native raw-closure path.  It passes on Windows 64-bit gcc/clang and all
    Linux/macOS targets, and the GHSA-w6j9 change there is static-trampoline
    gated (off on Windows), so this is a pre-existing gap the new test
    exposed.  xfail it on i686-pc-cygwin, tracked by issue #1074.
    
    Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

commit 9967918609a581dad639b388e03b6d5679e7340b
Author: Anthony Green <green@moxielogic.com>
Date:   Fri Nov 13 19:38:36 2026 -0500

    build: make the dist-hook PDF manual truly best-effort
    
    The previous guard checked for texi2pdf, but texi2pdf ships with texinfo
    even when no TeX engine is installed (e.g. the Android CI container), so
    'make pdf' still ran texi2dvi --pdf and failed 'make dist'.  Attempt the
    PDF build and copy, and if any part fails, skip it with a message; the
    .info manual is still shipped and release builds (with texlive) still get
    the PDF.  Verified: 'make dist' with the TeX engine forced to fail still
    succeeds.
