Skip to content

Commit 51c74a4

Browse files
committed
Always load EX(opline) into the current frame in JIT when observers are enabled
Fixes #13772.
1 parent 50fe64c commit 51c74a4

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

ext/opcache/jit/zend_jit_arm64.dasc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9338,7 +9338,7 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
93389338
}
93399339

93409340
if (call_num_args <= func->op_array.num_args) {
9341-
if (!trace || (trace->op == ZEND_JIT_TRACE_END
9341+
if (!trace || ZEND_OBSERVER_ENABLED || (trace->op == ZEND_JIT_TRACE_END
93429342
&& trace->stop == ZEND_JIT_TRACE_STOP_INTERPRETER)) {
93439343
uint32_t num_args;
93449344

@@ -9389,7 +9389,7 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
93899389
}
93909390
}
93919391
} else {
9392-
if (!trace || (trace->op == ZEND_JIT_TRACE_END
9392+
if (!trace || ZEND_OBSERVER_ENABLED || (trace->op == ZEND_JIT_TRACE_END
93939393
&& trace->stop == ZEND_JIT_TRACE_STOP_INTERPRETER)) {
93949394
if (func && zend_accel_in_shm(func->op_array.opcodes)) {
93959395
| LOAD_IP_ADDR (func->op_array.opcodes)

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10074,7 +10074,7 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
1007410074
}
1007510075

1007610076
if (call_num_args <= func->op_array.num_args) {
10077-
if (!trace || (trace->op == ZEND_JIT_TRACE_END
10077+
if (!trace || ZEND_OBSERVER_ENABLED || (trace->op == ZEND_JIT_TRACE_END
1007810078
&& trace->stop == ZEND_JIT_TRACE_STOP_INTERPRETER)) {
1007910079
uint32_t num_args;
1008010080

@@ -10129,7 +10129,7 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
1012910129
}
1013010130
}
1013110131
} else {
10132-
if (!trace || (trace->op == ZEND_JIT_TRACE_END
10132+
if (!trace || ZEND_OBSERVER_ENABLED || (trace->op == ZEND_JIT_TRACE_END
1013310133
&& trace->stop == ZEND_JIT_TRACE_STOP_INTERPRETER)) {
1013410134
if (func && zend_accel_in_shm(func->op_array.opcodes)) {
1013510135
| LOAD_IP_ADDR (func->op_array.opcodes)

ext/opcache/tests/jit/gh13772.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
EX(opline) is correctly set for nested JIT user code calls
3+
--EXTENSIONS--
4+
opcache
5+
zend_test
6+
--INI--
7+
opcache.enable=1
8+
opcache.enable_cli=1
9+
zend_test.observer.enabled=1
10+
zend_test.observer.observe_all=1
11+
zend_test.observer.show_output=0
12+
--FILE--
13+
<?php
14+
15+
function Ack($m, $n) {
16+
if ($m == 0) return $n+1;
17+
if ($n == 0) return Ack($m-1, 1);
18+
return Ack($m - 1, Ack($m, ($n - 1)));
19+
}
20+
21+
var_dump(Ack(3, 3));
22+
23+
?>
24+
--EXPECT--
25+
int(61)
26+

ext/zend_test/observer.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ static void observer_show_opcode(zend_execute_data *execute_data)
6969

7070
static void observer_begin(zend_execute_data *execute_data)
7171
{
72+
ZEND_ASSERT(!ZEND_USER_CODE(EX(func)->type) ||
73+
(EX(opline) >= EX(func)->op_array.opcodes && EX(opline) < EX(func)->op_array.opcodes + EX(func)->op_array.last));
74+
7275
if (!ZT_G(observer_show_output)) {
7376
return;
7477
}

0 commit comments

Comments
 (0)