Skip to content

Commit 3190062

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Tracing JIT: Fixed possible endless loop when escape from ZEND_CALL_TOP frame
2 parents ca87130 + 60203d5 commit 3190062

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

ext/opcache/jit/zend_jit_arm64.dasc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3089,7 +3089,7 @@ static int zend_jit_trace_link_to_root(dasm_State **Dst, zend_jit_trace_info *t,
30893089
return 1;
30903090
}
30913091

3092-
static int zend_jit_trace_return(dasm_State **Dst, bool original_handler)
3092+
static int zend_jit_trace_return(dasm_State **Dst, bool original_handler, const zend_op *opline)
30933093
{
30943094
if (zend_jit_vm_kind == ZEND_VM_KIND_HYBRID) {
30953095
| ADD_HYBRID_SPAD
@@ -3124,7 +3124,15 @@ static int zend_jit_trace_return(dasm_State **Dst, bool original_handler)
31243124
}
31253125
| ldp FP, RX, T2 // retore FP and IP
31263126
| ldp x29, x30, [sp], # NR_SPAD // stack alignment
3127-
| mov RETVALx, #2 // ZEND_VM_LEAVE
3127+
if (!original_handler || !opline ||
3128+
(opline->opcode != ZEND_RETURN
3129+
&& opline->opcode != ZEND_RETURN_BY_REF
3130+
&& opline->opcode != ZEND_GENERATOR_RETURN
3131+
&& opline->opcode != ZEND_GENERATOR_CREATE
3132+
&& opline->opcode != ZEND_YIELD
3133+
&& opline->opcode != ZEND_YIELD_FROM)) {
3134+
| mov RETVALx, #2 // ZEND_VM_LEAVE
3135+
}
31283136
| ret
31293137
}
31303138
return 1;

ext/opcache/jit/zend_jit_trace.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6698,10 +6698,10 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
66986698
}
66996699
zend_jit_trace_link_to_root(&dasm_state, &zend_jit_traces[t->link], timeout_exit_addr);
67006700
} else {
6701-
zend_jit_trace_return(&dasm_state, 0);
6701+
zend_jit_trace_return(&dasm_state, 0, NULL);
67026702
}
67036703
} else if (p->stop == ZEND_JIT_TRACE_STOP_RETURN) {
6704-
zend_jit_trace_return(&dasm_state, 0);
6704+
zend_jit_trace_return(&dasm_state, 0, NULL);
67056705
} else {
67066706
// TODO: not implemented ???
67076707
ZEND_ASSERT(0 && p->stop);
@@ -6847,7 +6847,7 @@ static const void *zend_jit_trace_exit_to_vm(uint32_t trace_num, uint32_t exit_n
68476847
zend_jit_set_ip_ex(&dasm_state, opline, original_handler);
68486848
}
68496849

6850-
zend_jit_trace_return(&dasm_state, original_handler);
6850+
zend_jit_trace_return(&dasm_state, original_handler, opline);
68516851

68526852
handler = dasm_link_and_encode(&dasm_state, NULL, NULL, NULL, NULL, name, ZEND_JIT_TRACE_NUM, SP_ADJ_JIT, SP_ADJ_NONE);
68536853

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3433,7 +3433,7 @@ static int zend_jit_trace_link_to_root(dasm_State **Dst, zend_jit_trace_info *t,
34333433
return 1;
34343434
}
34353435

3436-
static int zend_jit_trace_return(dasm_State **Dst, bool original_handler)
3436+
static int zend_jit_trace_return(dasm_State **Dst, bool original_handler, const zend_op *opline)
34373437
{
34383438
#if 0
34393439
| jmp ->trace_escape
@@ -3469,7 +3469,15 @@ static int zend_jit_trace_return(dasm_State **Dst, bool original_handler)
34693469
| mov FP, aword T2 // restore FP
34703470
| mov RX, aword T3 // restore IP
34713471
| add r4, NR_SPAD // stack alignment
3472-
| mov r0, 2 // ZEND_VM_LEAVE
3472+
if (!original_handler || !opline ||
3473+
(opline->opcode != ZEND_RETURN
3474+
&& opline->opcode != ZEND_RETURN_BY_REF
3475+
&& opline->opcode != ZEND_GENERATOR_RETURN
3476+
&& opline->opcode != ZEND_GENERATOR_CREATE
3477+
&& opline->opcode != ZEND_YIELD
3478+
&& opline->opcode != ZEND_YIELD_FROM)) {
3479+
| mov r0, 2 // ZEND_VM_LEAVE
3480+
}
34733481
| ret
34743482
}
34753483
#endif

0 commit comments

Comments
 (0)