Skip to content

Commit 6bac907

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Backport fix for GH-9011 (#17052)
2 parents e50cf7a + 9d4f5f0 commit 6bac907

File tree

2 files changed

+77
-14
lines changed

2 files changed

+77
-14
lines changed

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9274,19 +9274,11 @@ static int zend_jit_init_fcall_guard(dasm_State **Dst, uint32_t level, const zen
92749274
int32_t exit_point;
92759275
const void *exit_addr;
92769276

9277-
if (func->type == ZEND_INTERNAL_FUNCTION) {
9278-
#ifdef ZEND_WIN32
9279-
// TODO: ASLR may cause different addresses in different workers ???
9280-
return 0;
9281-
#endif
9282-
} else if (func->type == ZEND_USER_FUNCTION) {
9277+
if (func->type == ZEND_USER_FUNCTION) {
92839278
if (!zend_accel_in_shm(func->op_array.opcodes)) {
92849279
/* op_array and op_array->opcodes are not persistent. We can't link. */
92859280
return 0;
92869281
}
9287-
} else {
9288-
ZEND_UNREACHABLE();
9289-
return 0;
92909282
}
92919283

92929284
exit_point = zend_jit_trace_get_exit_point(to_opline, ZEND_JIT_EXIT_POLYMORPHISM);
@@ -9320,6 +9312,22 @@ static int zend_jit_init_fcall_guard(dasm_State **Dst, uint32_t level, const zen
93209312
| cmp aword [r1 + offsetof(zend_op_array, opcodes)], opcodes
93219313
| .endif
93229314
| jne &exit_addr
9315+
#ifdef _WIN32
9316+
} else if (func->type == ZEND_INTERNAL_FUNCTION) {
9317+
const zif_handler handler = func->internal_function.handler;
9318+
9319+
| .if X64
9320+
|| if (!IS_SIGNED_32BIT(handler)) {
9321+
| mov64 r2, ((ptrdiff_t)handler)
9322+
| cmp aword [r1 + offsetof(zend_internal_function, handler)], r2
9323+
|| } else {
9324+
| cmp aword [r1 + offsetof(zend_internal_function, handler)], handler
9325+
|| }
9326+
| .else
9327+
| cmp aword [r1 + offsetof(zend_internal_function, handler)], handler
9328+
| .endif
9329+
| jne &exit_addr
9330+
#endif
93239331
} else {
93249332
| .if X64
93259333
|| if (!IS_SIGNED_32BIT(func)) {
@@ -9466,6 +9474,22 @@ static int zend_jit_init_fcall(dasm_State **Dst, const zend_op *opline, uint32_t
94669474
| cmp aword [r0 + offsetof(zend_op_array, opcodes)], opcodes
94679475
| .endif
94689476
| jz >3
9477+
#ifdef _WIN32
9478+
} else if (func->type == ZEND_INTERNAL_FUNCTION) {
9479+
const zif_handler handler = func->internal_function.handler;
9480+
9481+
| .if X64
9482+
|| if (!IS_SIGNED_32BIT(handler)) {
9483+
| mov64 r1, ((ptrdiff_t)handler)
9484+
| cmp aword [r0 + offsetof(zend_internal_function, handler)], r1
9485+
|| } else {
9486+
| cmp aword [r0 + offsetof(zend_internal_function, handler)], handler
9487+
|| }
9488+
| .else
9489+
| cmp aword [r0 + offsetof(zend_internal_function, handler)], handler
9490+
| .endif
9491+
| jz >3
9492+
#endif
94699493
} else {
94709494
| .if X64
94719495
|| if (!IS_SIGNED_32BIT(func)) {
@@ -9652,11 +9676,7 @@ static int zend_jit_init_method_call(dasm_State **Dst,
96529676
if ((!func || zend_jit_may_be_modified(func, op_array))
96539677
&& trace
96549678
&& trace->op == ZEND_JIT_TRACE_INIT_CALL
9655-
&& trace->func
9656-
#ifdef _WIN32
9657-
&& trace->func->type != ZEND_INTERNAL_FUNCTION
9658-
#endif
9659-
) {
9679+
&& trace->func) {
96609680
int32_t exit_point;
96619681
const void *exit_addr;
96629682

@@ -9685,6 +9705,22 @@ static int zend_jit_init_method_call(dasm_State **Dst,
96859705
| cmp aword [r0 + offsetof(zend_op_array, opcodes)], opcodes
96869706
| .endif
96879707
| jne &exit_addr
9708+
#ifdef _WIN32
9709+
} else if (func->type == ZEND_INTERNAL_FUNCTION) {
9710+
const zif_handler handler = func->internal_function.handler;
9711+
9712+
| .if X64
9713+
|| if (!IS_SIGNED_32BIT(handler)) {
9714+
| mov64 r1, ((ptrdiff_t)handler)
9715+
| cmp aword [r0 + offsetof(zend_internal_function, handler)], r1
9716+
|| } else {
9717+
| cmp aword [r0 + offsetof(zend_internal_function, handler)], handler
9718+
|| }
9719+
| .else
9720+
| cmp aword [r0 + offsetof(zend_internal_function, handler)], handler
9721+
| .endif
9722+
| jne &exit_addr
9723+
#endif
96889724
} else {
96899725
| .if X64
96909726
|| if (!IS_SIGNED_32BIT(func)) {

ext/opcache/tests/jit/gh9011.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
GH-9011: Assertion failure with tracing JIT
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
--FILE--
8+
<?php
9+
$foo = [];
10+
$foo[] = new \Exception(); /* Native interface implemented Native instance */
11+
$foo[] = new class () implements \Stringable /* Native interface implemented User instance */
12+
{
13+
public function __toString(): string
14+
{
15+
return "bar";
16+
}
17+
};
18+
19+
foreach ($foo as $baz) {
20+
for ($i = 0; $i < 64; $i++) {
21+
$baz->__toString();
22+
}
23+
}
24+
?>
25+
DONE
26+
--EXPECT--
27+
DONE

0 commit comments

Comments
 (0)