Skip to content

fix php#25837: FFI: struct with an enum field passed by value is described to libffi with a void element - #25844

Open
DPDmancul wants to merge 1 commit into
php:PHP-8.4from
DPDmancul:fix/25837-ffi-array-in-struct
Open

DPDmancul wants to merge 1 commit into
php:PHP-8.4from
DPDmancul:fix/25837-ffi-array-in-struct

Conversation

@DPDmancul

Copy link
Copy Markdown
Contributor

Solves #25837

@DPDmancul
DPDmancul requested a review from dstogov as a code owner November 27, 2026 16:52
@DPDmancul
DPDmancul force-pushed the fix/25837-ffi-array-in-struct branch from 0d4d260 to 00962c8 Compare November 27, 2026 16:53
@DPDmancul

Copy link
Copy Markdown
Contributor Author

The test on Windows fails, but I think it is not an issue of this PR.

In fact, running this test program with released php 8.4

<?php
$ffi = FFI::cdef(<<<EOF
    typedef struct {
        uint8_t a, b, c;
    } test;

    typedef struct {
        uint8_t (*read_a)(test x, uint8_t last);
    } functions;
    EOF,
);
$f = $ffi->new('functions');
$f->read_a = fn ($x, $last) => $x->a;

$s = $ffi->new('test');
$s->a = 1;
$s->b = 2;
$s->c = 3;

var_dump(($f->read_a)($s, 4));

works on Linux

$ php test.php 
int(1)
but crashes on Windows
$ wine php.exe test.php 
0024:fixme:bcrypt:BCryptGenRandom ignoring selected algorithm
wine: Unhandled page fault on read access to 0000000000030201 at address 00006FFFFEA346D8 (thread 0024), starting debugger...
WineDbg attached to pid 0020
0124:fixme:dbghelp:elf_search_auxv can't find symbol in module
Unhandled exception: page fault on read access to 0x0000000000030201 in 64-bit code (0x006ffffea346d8).
0124:fixme:dbghelp:elf_search_auxv can't find symbol in module
Register dump:
 rip:00006ffffea346d8 rsp:0000780c197ebce0 rbp:00007ffffe15f800 eflags:00010206 (  R- --  I   - -P- )
 rax:0000000000000002 rbx:00007ffffec010a8 rcx:00006ffffea346d8 rdx:00006ffffea54020
 rsi:0000000000030201 rdi:00007ffffec132c0  r8:0000000000000000  r9:00006ffffea30000 r10:00007ffffec5d348
 r11:0000780c197ebf38 r12:0000000000000000 r13:00007ffffec75720 r14:00007ffffec75480 r15:00007ffffec03118
Stack dump:
0x00780c197ebce0:  00007ffffec132a0 00007ffffe15f800
0x00780c197ebcf0:  0000000000030201 00007ffffec132c0
0x00780c197ebd00:  00007ffffec75720 00007ffffec13250
0x00780c197ebd10:  0000780c197ebfb0 00007ffffec03118
0x00780c197ebd20:  00007ffffec8c338 00006ffffd87133a
0x00780c197ebd30:  00007ffffec132a0 00007ffffec7c340
0x00780c197ebd40:  0000000000000002 00006ffffd834af9
0x00780c197ebd50:  00007ffffec132c0 00006ffffd8349fd
0x00780c197ebd60:  00006ffffe088c20 0000000000000000
0x00780c197ebd70:  0000000000000000 00006ffffd853419
0x00780c197ebd80:  00007ffffec907b0 00007ffffec13250
0x00780c197ebd90:  0000000000000000 00007ffffec8c338
Backtrace:
=>0 0x006ffffea346d8 in php_ffi (+0x46d8) (0x007ffffe15f800)
  1 0x006ffffd87133a in php8 (+0x5133a) (0x007ffffec7c340)
  2 0x006ffffd853419 in php8 (+0x33419) (0000000000000000)
  3 0x006ffffdbc8f82 in php8 (+0x3a8f82) (0000000000000000)
  4 0x006ffffd847e5a in php8 (+0x27e5a) (0000000000000000)
  5 0x006ffffd847b8e in php8 (+0x27b8e) (0x00780c197ebfb1)
  6 0x006ffffea33227 in php_ffi (+0x3227) (0x00780c197ec060)
  7 0x006ffffea4daac in php_ffi (+0x1daac) (0x00780c197ec110)
  8 0x006ffffea4e0c6 in php_ffi (+0x1e0c6) (0x00780c197ec1c0)
  9 0x006ffffea4df81 in php_ffi (+0x1df81) (0x00780c197ec1c0)
  10 0x006ffffea4d960 in php_ffi (+0x1d960) (0x00780c197ec210)
  11 0x006ffffea38b44 in php_ffi (+0x8b44) (0x00780c197ec320)
  12 0x006ffffd830ff3 in php8 (+0x10ff3) (0x000000ffffffff)
  13 0x006ffffd853419 in php8 (+0x33419) (0000000000000000)
  14 0x006ffffdbc8f82 in php8 (+0x3a8f82) (0000000000000000)
  15 0x006ffffd826366 in php8 (+0x6366) (0000000000000000)
  16 0x006ffffd824904 in php8 (+0x4904) (0000000000000000)
  17 0x006ffffd8239b4 in php8 (+0x39b4) (0x00780c197ed5c0)
  18 0x00000140002a9b in php (+0x2a9b) (0x00780c197ef270)
  19 0x00000140003672 in php (+0x3672) (0x00780c197efe30)
  20 0x0000014000c718 in php (+0xc718) (0000000000000000)
  21 0x006fffffec1469 in kernel32 (+0x11469) (0000000000000000)
  22 0x006ffffff40d2b in ntdll (+0x10d2b) (0000000000000000)
0x006ffffea346d8 php_ffi+0x46d8: movzbl (%rsi), %eax
Modules:
Module  Address                                 Debug info      Name (61 modules)
PE             140000000-       140033000       --none--        php
PE          6ffffd6d0000-    6ffffd6ee000       Deferred        vcruntime140
PE-Wine     6ffffd700000-    6ffffd71c000       Deferred        bcrypt
PE-Wine     6ffffd730000-    6ffffd809000       Deferred        crypt32
PE          6ffffd820000-    6ffffe342000       --none--        php8
PE-Wine     6ffffe500000-    6ffffe50d000       Deferred        nsi
PE-Wine     6ffffe520000-    6ffffe537000       Deferred        dnsapi
PE-Wine     6ffffe550000-    6ffffe57f000       Deferred        iphlpapi
PE-Wine     6ffffe620000-    6ffffe640000       Deferred        imm32
PE          6ffffea30000-    6ffffea5e000       --none--        php_ffi
PE-Wine     6ffffea70000-    6ffffea89000       Deferred        shcore
PE-Wine     6ffffeaa0000-    6ffffeaf2000       Deferred        shlwapi
PE-Wine     6ffffeb10000-    6fffff44b000       Deferred        shell32
PE-Wine     6fffff460000-    6fffff47c000       Deferred        coml2
PE-Wine     6fffff490000-    6fffff49d000       Deferred        cryptbase
PE-Wine     6fffff4b0000-    6fffff53b000       Deferred        rpcrt4
PE-Wine     6fffff550000-    6fffff58a000       Deferred        win32u
PE-Wine     6fffff5a0000-    6fffff76d000       Deferred        user32
PE-Wine     6fffff780000-    6fffff804000       Deferred        gdi32
PE-Wine     6fffff820000-    6fffff873000       Deferred        combase
PE-Wine     6fffff890000-    6fffff94f000       Deferred        ole32
PE-Wine     6fffff960000-    6fffff988000       Deferred        ws2_32
PE-Wine     6fffff9a0000-    6fffffa7d000       Deferred        ucrtbase
PE-Wine     6fffffa90000-    6fffffab2000       Deferred        sechost
PE-Wine     6fffffad0000-    6fffffb7a000       Deferred        msvcrt
PE-Wine     6fffffb90000-    6fffffbd1000       Deferred        advapi32
PE-Wine     6fffffbf0000-    6fffffe97000       Deferred        kernelbase
PE-Wine     6fffffeb0000-    6ffffff18000       COFF            kernel32
PE-Wine     6ffffff30000-    6ffffffe9000       COFF            ntdll
ELF         780c14818000-    780c1481f000       Deferred        crypt32.so
ELF         780c14897000-    780c148c7000       Deferred        libexpat.so.1
ELF         780c148c7000-    780c14919000       Deferred        libfontconfig.so.1
ELF         780c14919000-    780c14a00000       Deferred        libfreetype.so.6
ELF         780c14a00000-    780c14c45000       Deferred        win32u.so
ELF         780c14c6b000-    780c14c8e000       Deferred        libbrotlicommon.so.1
ELF         780c14c8e000-    780c14d86000       Deferred        libm.so.6
ELF         780c14d86000-    780c14e30000       Deferred        libgmp.so.10
ELF         780c14e30000-    780c1501d000       Deferred        libunistring.so.5
ELF         780c1501d000-    780c15200000       Deferred        libp11-kit.so.0
ELF         780c15200000-    780c15471000       Deferred        libgnutls.so.30
ELF         780c1547d000-    780c1549c000       Deferred        libz.so.1
ELF         780c1549c000-    780c154d9000       Deferred        libpng16.so.16
ELF         780c154d9000-    780c154ee000       Deferred        libbz2.so.1
ELF         780c154ee000-    780c15503000       Deferred        libffi.so.8
ELF         780c15503000-    780c1555b000       Deferred        libnettle.so.8
ELF         780c1555b000-    780c155a8000       Deferred        libhogweed.so.6
ELF         780c155a8000-    780c155bf000       Deferred        libtasn1.so.6
ELF         780c155bf000-    780c155f0000       Deferred        libidn2.so.0
ELF         780c19cf1000-    780c19d00000       Deferred        libbrotlidec.so.1
ELF         780c19e00000-    780c1a009000       Deferred        libc.so.6
ELF         780c1a00e000-    780c1a013000       Deferred        libdl.so.2
ELF         780c1a013000-    780c1a021000       Deferred        bcrypt.so
ELF         780c1a021000-    780c1a029000       Deferred        ws2_32.so
ELF         780c1a029000-    780c1a03b000       Deferred        libresolv.so.2
ELF         780c1a03b000-    780c1a041000       Deferred        dnsapi.so
ELF         780c1a041000-    780c1a046000       Deferred        libpthread.so.0
ELF         780c1a046000-    780c1a078000       Deferred        liblzma.so.5
ELF         780c1a078000-    780c1a095000       Deferred        libunwind.so.8
ELF         780c1a095000-    780c1a162000       Export          ntdll.so
ELF         780c1a168000-    780c1a1a3000       Deferred        ld-linux-x86-64.so.2
ELF         780c1a1a3000-    780c1a1a9000       Deferred        <wine-loader>
Threads:
process  tid      prio    name (all IDs are in hex)
00000020 (D) Z:\home\dpd-\phptest\php.exe
        00000024    0 <==
        00000128    0
00000038 services.exe
        0000003c    0
        00000040    0     wine_rpcrt4_server
        0000004c    0     wine_rpcrt4_io
        00000050    0     wine_threadpool_worker
        00000078    0     wine_rpcrt4_io
        00000090    0     wine_rpcrt4_io
        000000a8    0     wine_rpcrt4_io
        000000d8    0     wine_rpcrt4_io
        000000e4    0     wine_threadpool_worker
        000000f0    0
        000000fc    0     wine_rpcrt4_io
00000044 winedevice.exe
        00000048    0
        00000054    0
        00000058    0     wine_sechost_service
        0000005c    0
        00000060    0
        00000064    0
        0000009c    0     wine_nsi_notification
00000068 plugplay.exe
        0000006c    0
        0000007c    0
        00000080    0     wine_sechost_service
        00000084    0     wine_rpcrt4_server
        000000c4    0     wine_rpcrt4_io
        000000c8    0     wine_threadpool_worker
00000070 explorer.exe
        00000074    0
        000000cc    0
        000000d0    0     wine_explorer_display_settings_restorer
        000000d4    0     wine_rpcrt4_server
00000088 svchost.exe
        0000008c    0
        00000094    0
        00000098    0     wine_sechost_service
000000a0 winedevice.exe
        000000a4    0
        000000ac    0
        000000b0    0     wine_sechost_service
        000000b4    0
        000000b8    0
        000000bc    0
        000000c0    0
        000000dc    0
        000000e8    0
        000000ec    0
000000f4 rpcss.exe
        000000f8    0
        00000100    0
        00000104    0     wine_sechost_service
        00000108    0     wine_rpcrt4_server
        0000010c    0     wine_rpcrt4_server
        00000110    0     wine_rpcrt4_io
        00000114    0     wine_threadpool_worker
00000118 conhost.exe
        0000011c    0
System information:
    Wine build: wine-11.0
    Platform: x86_64 (guest: i386)
    Version: Windows 10
    Host system: Linux
    Host version: 6.18.57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant