Skip to content

Commit

Permalink
JIT: Fix register clobbering
Browse files Browse the repository at this point in the history
Fixes oss-fuzz #41621
  • Loading branch information
dstogov committed Dec 3, 2021
1 parent c4ee668 commit 2515e78
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
13 changes: 10 additions & 3 deletions ext/opcache/jit/zend_jit_x86.dasc
Original file line number Diff line number Diff line change
Expand Up @@ -5000,9 +5000,6 @@ static int zend_jit_long_math_helper(dasm_State **Dst,

if (opcode == ZEND_MOD) {
result_reg = ZREG_RAX;
if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RAX) {
| mov aword T1, r0 // save
}
} else if (Z_MODE(res_addr) == IS_REG) {
if ((opline->opcode == ZEND_SL || opline->opcode == ZEND_SR)
&& opline->op2_type != IS_CONST) {
Expand Down Expand Up @@ -5127,6 +5124,11 @@ static int zend_jit_long_math_helper(dasm_State **Dst,
| GET_ZVAL_LVAL result_reg, op1_addr
| LONG_MATH ZEND_BW_AND, result_reg, tmp_addr
} else {
if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RAX) {
| mov aword T1, r0 // save
} else if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RCX) {
| mov aword T1, Ra(ZREG_RCX) // save
}
result_reg = ZREG_RDX;
if (op2_lval == -1) {
| xor Ra(result_reg), Ra(result_reg)
Expand All @@ -5142,6 +5144,8 @@ static int zend_jit_long_math_helper(dasm_State **Dst,
}
if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RAX) {
| mov r0, aword T1 // restore
} else if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RCX) {
| mov Ra(ZREG_RCX), aword T1 // restore
}
}
} else {
Expand Down Expand Up @@ -5183,6 +5187,9 @@ static int zend_jit_long_math_helper(dasm_State **Dst,
|.code
}

if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RAX) {
| mov aword T1, r0 // save
}
result_reg = ZREG_RDX;
| GET_ZVAL_LVAL ZREG_RAX, op1_addr
|.if X64
Expand Down
26 changes: 26 additions & 0 deletions ext/opcache/tests/jit/mod_005.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
JIT MOD: 005
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.file_update_protection=0
opcache.jit_buffer_size=1M
opcache.protect_memory=1
--FILE--
<?php
class Test{
public $prop = 32;
}

function test2($test) {
$test->prop %= 3;
return $test;
}

var_dump(test2(new Test));
?>
--EXPECT--
object(Test)#1 (1) {
["prop"]=>
int(2)
}

0 comments on commit 2515e78

Please sign in to comment.