Skip to content

Commit 60203d5

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

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
@@ -6697,10 +6697,10 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
66976697
}
66986698
zend_jit_trace_link_to_root(&dasm_state, &zend_jit_traces[t->link], timeout_exit_addr);
66996699
} else {
6700-
zend_jit_trace_return(&dasm_state, 0);
6700+
zend_jit_trace_return(&dasm_state, 0, NULL);
67016701
}
67026702
} else if (p->stop == ZEND_JIT_TRACE_STOP_RETURN) {
6703-
zend_jit_trace_return(&dasm_state, 0);
6703+
zend_jit_trace_return(&dasm_state, 0, NULL);
67046704
} else {
67056705
// TODO: not implemented ???
67066706
ZEND_ASSERT(0 && p->stop);
@@ -6846,7 +6846,7 @@ static const void *zend_jit_trace_exit_to_vm(uint32_t trace_num, uint32_t exit_n
68466846
zend_jit_set_ip_ex(&dasm_state, opline, original_handler);
68476847
}
68486848

6849-
zend_jit_trace_return(&dasm_state, original_handler);
6849+
zend_jit_trace_return(&dasm_state, original_handler, opline);
68506850

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

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)