Skip to content

Commit e96f980

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: JIT: Partially fix handling of exceptions thrown in interrupt handlers
2 parents 47435d6 + efba3b6 commit e96f980

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

ext/opcache/jit/zend_jit_arm64.dasc

+4
Original file line numberDiff line numberDiff line change
@@ -1778,6 +1778,10 @@ static int zend_jit_interrupt_handler_stub(dasm_State **Dst)
17781778
| //zend_interrupt_function(execute_data);
17791779
| mov CARG1, FP
17801780
| EXT_CALL zend_interrupt_function, TMP1
1781+
| MEM_LOAD_64_ZTS ldr, REG0, executor_globals, exception, TMP1
1782+
| cbz REG0, >1
1783+
| EXT_CALL zend_jit_exception_in_interrupt_handler_helper, TMP1
1784+
|1:
17811785
| //ZEND_VM_ENTER();
17821786
| //execute_data = EG(current_execute_data);
17831787
| MEM_LOAD_64_ZTS ldr, FP, executor_globals, current_execute_data, TMP1

ext/opcache/jit/zend_jit_disasm.c

+1
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ static int zend_jit_disasm_init(void)
700700
REGISTER_HELPER(zval_jit_update_constant_ex);
701701
#endif
702702
REGISTER_HELPER(zend_jit_free_trampoline_helper);
703+
REGISTER_HELPER(zend_jit_exception_in_interrupt_handler_helper);
703704
#undef REGISTER_HELPER
704705

705706
#ifndef _WIN32

ext/opcache/jit/zend_jit_helpers.c

+17
Original file line numberDiff line numberDiff line change
@@ -2545,6 +2545,23 @@ static void ZEND_FASTCALL zend_jit_free_trampoline_helper(zend_function *func)
25452545
zend_free_trampoline(func);
25462546
}
25472547

2548+
static void ZEND_FASTCALL zend_jit_exception_in_interrupt_handler_helper(void)
2549+
{
2550+
if (EG(exception)) {
2551+
/* We have to UNDEF result, because ZEND_HANDLE_EXCEPTION is going to free it */
2552+
const zend_op *throw_op = EG(opline_before_exception);
2553+
2554+
if (throw_op
2555+
&& throw_op->result_type & (IS_TMP_VAR|IS_VAR)
2556+
&& throw_op->opcode != ZEND_ADD_ARRAY_ELEMENT
2557+
&& throw_op->opcode != ZEND_ADD_ARRAY_UNPACK
2558+
&& throw_op->opcode != ZEND_ROPE_INIT
2559+
&& throw_op->opcode != ZEND_ROPE_ADD) {
2560+
ZVAL_UNDEF(ZEND_CALL_VAR(EG(current_execute_data), throw_op->result.var));
2561+
}
2562+
}
2563+
}
2564+
25482565
static zend_string* ZEND_FASTCALL zend_jit_rope_end(zend_string **rope, uint32_t count)
25492566
{
25502567
zend_string *ret;

ext/opcache/jit/zend_jit_x86.dasc

+4
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,10 @@ static int zend_jit_interrupt_handler_stub(dasm_State **Dst)
17151715
| mov aword A1, FP
17161716
| EXT_CALL zend_interrupt_function, r0
17171717
|.endif
1718+
| MEM_CMP_ZTS aword, executor_globals, exception, 0, r0
1719+
| je >1
1720+
| EXT_CALL zend_jit_exception_in_interrupt_handler_helper, r0
1721+
|1:
17181722
| //ZEND_VM_ENTER();
17191723
| //execute_data = EG(current_execute_data);
17201724
| MEM_LOAD_ZTS FP, aword, executor_globals, current_execute_data, r0

0 commit comments

Comments
 (0)