Skip to content

Commit 29c8c1e

Browse files
committed
Tracing JIT: Fixed possible endless loop when escape from ZEND_CALL_TOP frame
1 parent 3e9b53f commit 29c8c1e

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

ext/opcache/jit/zend_jit_trace.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6382,10 +6382,10 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
63826382
}
63836383
zend_jit_trace_link_to_root(&dasm_state, &zend_jit_traces[t->link], timeout_exit_addr);
63846384
} else {
6385-
zend_jit_trace_return(&dasm_state, 0);
6385+
zend_jit_trace_return(&dasm_state, 0, NULL);
63866386
}
63876387
} else if (p->stop == ZEND_JIT_TRACE_STOP_RETURN) {
6388-
zend_jit_trace_return(&dasm_state, 0);
6388+
zend_jit_trace_return(&dasm_state, 0, NULL);
63896389
} else {
63906390
// TODO: not implemented ???
63916391
ZEND_ASSERT(0 && p->stop);
@@ -6525,7 +6525,7 @@ static const void *zend_jit_trace_exit_to_vm(uint32_t trace_num, uint32_t exit_n
65256525
zend_jit_set_ip_ex(&dasm_state, opline, original_handler);
65266526
}
65276527

6528-
zend_jit_trace_return(&dasm_state, original_handler);
6528+
zend_jit_trace_return(&dasm_state, original_handler, opline);
65296529

65306530
handler = dasm_link_and_encode(&dasm_state, NULL, NULL, NULL, NULL, name, ZEND_JIT_TRACE_NUM);
65316531

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3420,7 +3420,7 @@ static int zend_jit_trace_link_to_root(dasm_State **Dst, zend_jit_trace_info *t,
34203420
return 1;
34213421
}
34223422

3423-
static int zend_jit_trace_return(dasm_State **Dst, zend_bool original_handler)
3423+
static int zend_jit_trace_return(dasm_State **Dst, zend_bool original_handler, const zend_op *opline)
34243424
{
34253425
#if 0
34263426
| jmp ->trace_escape
@@ -3456,7 +3456,15 @@ static int zend_jit_trace_return(dasm_State **Dst, zend_bool original_handler)
34563456
| mov FP, aword T2 // restore FP
34573457
| mov RX, aword T3 // restore IP
34583458
| add r4, NR_SPAD // stack alignment
3459-
| mov r0, 2 // ZEND_VM_LEAVE
3459+
if (!original_handler || !opline ||
3460+
(opline->opcode != ZEND_RETURN
3461+
&& opline->opcode != ZEND_RETURN_BY_REF
3462+
&& opline->opcode != ZEND_GENERATOR_RETURN
3463+
&& opline->opcode != ZEND_GENERATOR_CREATE
3464+
&& opline->opcode != ZEND_YIELD
3465+
&& opline->opcode != ZEND_YIELD_FROM)) {
3466+
| mov r0, 2 // ZEND_VM_LEAVE
3467+
}
34603468
| ret
34613469
}
34623470
#endif

0 commit comments

Comments
 (0)