Skip to content

Commit 7ae8adc

Browse files
committed
Fix AArch64 JIT stub handlers pointing at discarded veneers after opcache restart
zend_jit_commit_veneers() replaces zend_jit_stub_handlers[] entries with veneers emitted inside trace code. zend_jit_restart() discards that code but kept the table, so traces compiled after opcache_reset() branched into unrelated code and PHP-FPM workers crashed or hung. Save the table at startup and restore it on restart.
1 parent 6ec6987 commit 7ae8adc

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎ext/opcache/jit/zend_jit.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,11 @@ static bool zend_may_be_dynamic_property(zend_class_entry *ce, zend_string *memb
695695

696696
#include "jit/zend_jit_ir.c"
697697

698+
#if defined(IR_TARGET_AARCH64)
699+
/* Stub addresses as generated at startup. Veneers overwrite zend_jit_stub_handlers[], and they are lost on restart. */
700+
static void *zend_jit_stub_handlers_saved[sizeof(zend_jit_stubs) / sizeof(zend_jit_stubs[0])];
701+
#endif
702+
698703
#if defined(__clang__)
699704
# pragma clang diagnostic pop
700705
#endif
@@ -3726,6 +3731,9 @@ void zend_jit_startup(void *buf, size_t size, bool reattached)
37263731
zend_jit_unprotect();
37273732
/* save JIT buffer pos */
37283733
dasm_ptr[1] = dasm_ptr[0];
3734+
#if defined(IR_TARGET_AARCH64)
3735+
memcpy(zend_jit_stub_handlers_saved, zend_jit_stub_handlers, sizeof(zend_jit_stub_handlers_saved));
3736+
#endif
37293737
zend_jit_protect();
37303738
}
37313739

@@ -3889,6 +3897,11 @@ void zend_jit_restart(void)
38893897

38903898
/* restore JIT buffer pos */
38913899
dasm_ptr[0] = dasm_ptr[1];
3900+
#if defined(IR_TARGET_AARCH64)
3901+
/* Veneers lived in the code that was just discarded */
3902+
memcpy(zend_jit_stub_handlers, zend_jit_stub_handlers_saved, sizeof(zend_jit_stub_handlers_saved));
3903+
memset(zend_jit_stub_handlers + (sizeof(zend_jit_stubs) / sizeof(zend_jit_stubs[0])), 0, sizeof(zend_jit_stub_handlers_saved));
3904+
#endif
38923905

38933906
zend_jit_trace_restart();
38943907

0 commit comments

Comments
 (0)