Skip to content

Commit 7484b8f

Browse files
committed
Preallocate zval for unused result of internal function on CPU stack
1 parent a868780 commit 7484b8f

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
|.define FCARG2a, CARG2
4141
|.define FCARG1d, CARG1d
4242
|.define FCARG2d, CARG2d
43-
|.define SPAD, 0x08 // padding for CPU stack alignment
43+
|.define SPAD, 0x58 // padding for CPU stack alignment
4444
|.define NR_SPAD, 0x58 // padding for CPU stack alignment
4545
|.define T3, [r4+0x50] // Used to store old value of IP
4646
|.define T2, [r4+0x48] // Used to store old value of FP
@@ -68,10 +68,10 @@
6868
|.define FCARG2a, CARG2
6969
|.define FCARG1d, CARG1d
7070
|.define FCARG2d, CARG2d
71-
|.define SPAD, 0x08 // padding for CPU stack alignment
72-
|.define NR_SPAD, 0x18 // padding for CPU stack alignment
73-
|.define T3, [r4+0x10] // Used to store old value of IP (CALL VM only)
74-
|.define T2, [r4+0x08] // Used to store old value of FP (CALL VM only)
71+
|.define SPAD, 0x18 // padding for CPU stack alignment
72+
|.define NR_SPAD, 0x28 // padding for CPU stack alignment
73+
|.define T3, [r4+0x20] // Used to store old value of IP (CALL VM only)
74+
|.define T2, [r4+0x18] // Used to store old value of FP (CALL VM only)
7575
|.define T1, [r4]
7676
|.else
7777
|.define FP, esi
@@ -82,15 +82,21 @@
8282
|.define FCARG2a, edx
8383
|.define FCARG1d, ecx
8484
|.define FCARG2d, edx
85-
|.define SPAD, 12 // padding for CPU stack alignment
86-
|.define NR_SPAD, 12 // padding for CPU stack alignment
87-
|.define T3, [r4+0x10] // Used to store old value of IP (CALL VM only)
88-
|.define T2, [r4+0x08] // Used to store old value of FP (CALL VM only)
85+
|.define SPAD, 0x1c // padding for CPU stack alignment
86+
|.define NR_SPAD, 0x1c // padding for CPU stack alignment
87+
|.define T3, [r4+0x18] // Used to store old value of IP (CALL VM only)
88+
|.define T2, [r4+0x14] // Used to store old value of FP (CALL VM only)
8989
|.define T1, [r4]
9090
|.endif
9191

9292
|.define HYBRID_SPAD, 16 // padding for stack alignment
9393

94+
#ifdef _WIN64
95+
# define TMP_ZVAL_OFFSET 0x20
96+
#else
97+
# define TMP_ZVAL_OFFSET 0
98+
#endif
99+
94100
#define DASM_ALIGNMENT 16
95101

96102
/* According to x86 and x86_64 ABI, CPU stack has to be 16 byte aligned to
@@ -8730,13 +8736,8 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
87308736
if (RETURN_VALUE_USED(opline)) {
87318737
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->result.var);
87328738
} else {
8733-
#ifdef _WIN64
8734-
/* Reuse reserved arguments stack */
8735-
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_R4, 0x20);
8736-
#else
87378739
/* CPU stack allocated temporary zval */
8738-
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_R4, 8);
8739-
#endif
8740+
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_R4, TMP_ZVAL_OFFSET);
87408741
}
87418742

87428743
if ((opline-1)->opcode == ZEND_SEND_UNPACK || (opline-1)->opcode == ZEND_SEND_ARRAY ||
@@ -9161,12 +9162,6 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
91619162
}
91629163
}
91639164

9164-
if (!RETURN_VALUE_USED(opline)) {
9165-
|.if not(X64WIN)
9166-
| sub r4, 16 /* alloca() */
9167-
|.endif
9168-
}
9169-
91709165
| // ZVAL_NULL(EX_VAR(opline->result.var));
91719166
| LOAD_ZVAL_ADDR FCARG2a, res_addr
91729167
| SET_Z_TYPE_INFO FCARG2a, IS_NULL
@@ -9257,9 +9252,6 @@ static int zend_jit_do_fcall(dasm_State **Dst, const zend_op *opline, const zend
92579252
if (func_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_REF)) {
92589253
| ZVAL_PTR_DTOR res_addr, func_info, 1, 1, opline
92599254
}
9260-
|.if not(X64WIN)
9261-
| add r4, 16 /* revert alloca() */
9262-
|.endif
92639255
}
92649256

92659257
| // if (UNEXPECTED(EG(exception) != NULL)) {

0 commit comments

Comments
 (0)