Skip to content

Commit

Permalink
JIT: Partially fix handling of exceptions thrown in interrupt handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed Nov 11, 2021
1 parent fa0b84a commit 5380b41
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions ext/opcache/jit/zend_jit_disasm_x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ static int zend_jit_disasm_init(void)
REGISTER_HELPER(zval_jit_update_constant_ex);
#endif
REGISTER_HELPER(zend_jit_free_trampoline_helper);
REGISTER_HELPER(zend_jit_exception_in_interrupt_handler_helper);
#undef REGISTER_HELPER

#ifndef _WIN32
Expand Down
17 changes: 17 additions & 0 deletions ext/opcache/jit/zend_jit_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -2719,3 +2719,20 @@ static void ZEND_FASTCALL zend_jit_free_trampoline_helper(zend_function *func)
zend_string_release_ex(func->common.function_name, 0);
zend_free_trampoline(func);
}

static void ZEND_FASTCALL zend_jit_exception_in_interrupt_handler_helper(void)
{
if (EG(exception)) {
/* We have to UNDEF result, because ZEND_HANDLE_EXCEPTION is going to free it */
const zend_op *throw_op = EG(opline_before_exception);

if (throw_op
&& throw_op->result_type & (IS_TMP_VAR|IS_VAR)
&& throw_op->opcode != ZEND_ADD_ARRAY_ELEMENT
&& throw_op->opcode != ZEND_ADD_ARRAY_UNPACK
&& throw_op->opcode != ZEND_ROPE_INIT
&& throw_op->opcode != ZEND_ROPE_ADD) {
ZVAL_UNDEF(ZEND_CALL_VAR(EG(current_execute_data), throw_op->result.var));
}
}
}
4 changes: 4 additions & 0 deletions ext/opcache/jit/zend_jit_x86.dasc
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,10 @@ static int zend_jit_interrupt_handler_stub(dasm_State **Dst)
| mov aword A1, FP
| EXT_CALL zend_interrupt_function, r0
|.endif
| MEM_OP2_1_ZTS cmp, aword, executor_globals, exception, 0, r0
| je >1
| EXT_CALL zend_jit_exception_in_interrupt_handler_helper, r0
|1:
| //ZEND_VM_ENTER();
| //execute_data = EG(current_execute_data);
| MEM_OP2_2_ZTS mov, FP, aword, executor_globals, current_execute_data, r0
Expand Down

0 comments on commit 5380b41

Please sign in to comment.