Skip to content

Bootstrap: gethostname() VM path — libc gethostname(2) without host PHP (phpc_gethostname.c) #5022

Closed

Description

@PurHur

Category

bootstrap · stdlib

Problem

gethostname() VM path calls VmHost::gethostname() which delegates to host Zend PHP \gethostname(). For self-host / AOT (#1492), the VM must not depend on Zend for this syscall.

JIT/AOT already use __compiler_gethostname from lib/AOT/runtime/phpc_gethostname.c (#3465); VM execute path is the gap.

php-src reference

Repro

On a host without PHP gethostname() (or under bootstrap policy that forbids host calls):

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r "var_dump(gethostname());"'

Today VM always routes through VmHost → \gethostname(). Bootstrap inventory includes ext/standard/gethostname.php — native VM should call the same C helper as JIT.

Compare JIT path (already native):

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && ./vendor/bin/phpunit test/compliance/GethostnameJITTest.php -v'

Scope (this repo)

Area Path
VM ext/standard/gethostname.php, ext/standard/VmHost.php — call __compiler_gethostname or shared wrapper
Runtime link Reuse phpc_gethostname.c in VM native bridge (same as #3465)
Tests Extend test/unit/GethostnameBuiltinTest.php — no host gethostname mock

Done when

  • bin/vm.php -r "echo gethostname();" returns a non-empty string using libc only (no \gethostname() in VM execute path).
  • JIT/AOT behavior unchanged; make bootstrap-inventory.php --check still green for gethostname.php.

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 3, 2026
  2. PurHur commented on Jun 8, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — starting this run (#5022: VmHost gethostname via libc FFI, no host \gethostname() delegation).

  3. PurHur commented on Jun 8, 2026

    @PurHur
    OwnerAuthor

    Merged via #7716.

    Change: VmHost::gethostname() routes through libc gethostname(2) via FFI (256-byte buffer, same failure semantics as JitGethostname). Removed host Zend @\gethostname() delegation on the VM execute path.

    C runtime: no new C; phpc_gethostname.c already absent — VM now aligns with existing JIT/AOT libc path.

    Verification (green):

    • php bin/vm.php -r "var_dump(gethostname());" → non-empty hostname string
    • vendor/bin/phpunit --filter "GethostnameBuiltinTest|VmHostTest|GethostnameVMTest|GethostnameJITTest" → OK (6 tests)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-0:FoundationPhase 0 – foundation & DevExphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions