Skip to content

Commit 7c69d4b

Browse files
committed
Fix GH-21368 crash: use jit->current_op_array in escape_if_undef
#21368 dispatched to orig_handler via exit_info->op_array. That pointer is set at parent-trace compile time from JIT_G(current_frame)->func, and can become stale by the time a side trace compiles for that exit, producing an access violation in zend_jit_escape_if_undef on long-lived IIS+FastCGI workers. Use jit->current_op_array instead. On the crash path (zend_jit_compile_side_trace -> zend_jit_trace), zend_jit_trace_start sets it to trace_buffer->op_array, which is freshly captured for the current compilation and avoids the parent's potentially stale reference. On the zend_jit_trace_exit_to_vm path, zend_jit_deoptimizer_start leaves current_op_array unset, so set it from exit_info->op_array there. The gh21267 tests still pass.
1 parent 391ec27 commit 7c69d4b

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

ext/opcache/jit/zend_jit_ir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8068,7 +8068,7 @@ static int zend_jit_defined(zend_jit_ctx *jit, const zend_op *opline, uint8_t sm
80688068
return 1;
80698069
}
80708070

8071-
static int zend_jit_escape_if_undef(zend_jit_ctx *jit, int var, uint32_t flags, const zend_op *opline, const zend_op_array *op_array, int8_t reg)
8071+
static int zend_jit_escape_if_undef(zend_jit_ctx *jit, int var, uint32_t flags, const zend_op *opline, int8_t reg)
80728072
{
80738073
zend_jit_addr reg_addr = ZEND_ADDR_REF_ZVAL(zend_jit_deopt_rload(jit, IR_ADDR, reg));
80748074
ir_ref if_def = ir_IF(jit_Z_TYPE(jit, reg_addr));
@@ -8094,7 +8094,7 @@ static int zend_jit_escape_if_undef(zend_jit_ctx *jit, int var, uint32_t flags,
80948094

80958095
/* We can't use trace_escape() because opcode handler may be overridden by JIT */
80968096
zend_jit_op_array_trace_extension *jit_extension =
8097-
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(op_array);
8097+
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(jit->current_op_array);
80988098
size_t offset = jit_extension->offset;
80998099
ir_ref ref = ir_CONST_ADDR(ZEND_OP_TRACE_INFO((opline - 1), offset)->orig_handler);
81008100
if (GCC_GLOBAL_REGS) {

ext/opcache/jit/zend_jit_trace.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3603,7 +3603,7 @@ static int zend_jit_trace_deoptimization(
36033603

36043604
ZEND_ASSERT(STACK_FLAGS(parent_stack, check2) == ZREG_ZVAL_COPY);
36053605
ZEND_ASSERT(reg != ZREG_NONE);
3606-
if (!zend_jit_escape_if_undef(jit, check2, flags, opline, exit_info->op_array, reg)) {
3606+
if (!zend_jit_escape_if_undef(jit, check2, flags, opline, reg)) {
36073607
return 0;
36083608
}
36093609
if (!zend_jit_restore_zval(jit, EX_NUM_TO_VAR(check2), reg)) {
@@ -7374,6 +7374,8 @@ static const void *zend_jit_trace_exit_to_vm(uint32_t trace_num, uint32_t exit_n
73747374
zend_jit_traces[trace_num].stack_map + zend_jit_traces[trace_num].exit_info[exit_num].stack_offset :
73757375
NULL;
73767376

7377+
ctx.current_op_array = zend_jit_traces[trace_num].exit_info[exit_num].op_array;
7378+
73777379
if (!zend_jit_trace_deoptimization(&ctx,
73787380
&zend_jit_traces[trace_num].exit_info[exit_num],
73797381
stack, stack_size, NULL, NULL,

0 commit comments

Comments
 (0)