Skip to content

Commit 2167986

Browse files
committed
Preallocate space for Win64 shadow args
Otherwise "fixed_call_stack" doesn't make sense
1 parent 986dfd4 commit 2167986

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

ext/opcache/jit/zend_jit_ir.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
(1<<(16+6)) | (1<<(16+7)) | (1<<(16+8)) | (1<<(16+9)) | (1<<(16+10)) | \
4040
(1<<(16+11)) | (1<<(16+12)) | (1<<(16+13)) | (1<<(16+14)) | (1<<(16+15)))
4141
*/
42+
# define IR_SHADOW_ARGS 32
4243
# else
4344
# define IR_REGSET_PRESERVED ((1<<3) | (1<<5) | (1<<12) | (1<<13) | (1<<14) | (1<<15)) /* all preserved registers */
4445
# endif
@@ -2709,7 +2710,11 @@ static void zend_jit_init_ctx(zend_jit_ctx *jit, uint32_t flags)
27092710
// jit->ctx.fixed_save_regset &= 0xffff; // TODO: don't save FP registers ???
27102711
//#endif
27112712
}
2713+
#ifdef _WIN64
2714+
jit->ctx.fixed_call_stack_size = 16 + IR_SHADOW_ARGS;
2715+
#else
27122716
jit->ctx.fixed_call_stack_size = 16;
2717+
#endif
27132718
} else {
27142719
#ifdef ZEND_VM_HYBRID_JIT_RED_ZONE_SIZE
27152720
jit->ctx.fixed_stack_red_zone = ZEND_VM_HYBRID_JIT_RED_ZONE_SIZE;
@@ -8978,7 +8983,11 @@ static int zend_jit_init_method_call(zend_jit_ctx *jit,
89788983
// JIT: alloca(sizeof(void*));
89798984
this_ref2 = ir_ALLOCA(ir_CONST_ADDR(0x10));
89808985
} else {
8986+
#ifdef _WIN64
8987+
this_ref2 = ir_HARD_COPY_A(jit_ADD_OFFSET(jit, ir_RLOAD_A(IR_REG_SP), IR_SHADOW_ARGS));
8988+
#else
89818989
this_ref2 = ir_HARD_COPY_A(ir_RLOAD_A(IR_REG_SP));
8990+
#endif
89828991
}
89838992
ir_STORE(this_ref2, this_ref);
89848993

@@ -8994,10 +9003,17 @@ static int zend_jit_init_method_call(zend_jit_ctx *jit,
89949003
this_ref2);
89959004
}
89969005

8997-
this_ref2 = ir_LOAD_A(ir_RLOAD_A(IR_REG_SP));
9006+
89989007
if (!jit->ctx.fixed_call_stack_size) {
9008+
this_ref2 = ir_LOAD_A(ir_RLOAD_A(IR_REG_SP));
89999009
// JIT: revert alloca
90009010
ir_AFREE(ir_CONST_ADDR(0x10));
9011+
} else {
9012+
#ifdef _WIN64
9013+
this_ref2 = ir_LOAD_A(jit_ADD_OFFSET(jit, ir_RLOAD_A(IR_REG_SP), IR_SHADOW_ARGS));
9014+
#else
9015+
this_ref2 = ir_LOAD_A(ir_RLOAD_A(IR_REG_SP));
9016+
#endif
90019017
}
90029018

90039019
ir_GUARD(ref2, jit_STUB_ADDR(jit, jit_stub_exception_handler));
@@ -10257,7 +10273,11 @@ static int zend_jit_do_fcall(zend_jit_ctx *jit, const zend_op *opline, const zen
1025710273
// JIT: alloca(sizeof(void*));
1025810274
ptr = ir_ALLOCA(ir_CONST_ADDR(sizeof(zval)));
1025910275
} else {
10276+
#ifdef _WIN64
10277+
ptr = ir_HARD_COPY_A(jit_ADD_OFFSET(jit, ir_RLOAD_A(IR_REG_SP), IR_SHADOW_ARGS));
10278+
#else
1026010279
ptr = ir_HARD_COPY_A(ir_RLOAD_A(IR_REG_SP));
10280+
#endif
1026110281
}
1026210282
res_addr = ZEND_ADDR_REF_ZVAL(ptr);
1026310283
}
@@ -10385,7 +10405,16 @@ static int zend_jit_do_fcall(zend_jit_ctx *jit, const zend_op *opline, const zen
1038510405
func_info |= MAY_BE_NULL;
1038610406

1038710407
if (func_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_REF)) {
10388-
ir_ref sp = ir_RLOAD_A(IR_REG_SP);
10408+
ir_ref sp;
10409+
if (!jit->ctx.fixed_call_stack_size) {
10410+
sp = ir_RLOAD_A(IR_REG_SP);
10411+
} else {
10412+
#ifdef _WIN32
10413+
sp = jit_ADD_OFFSET(jit, ir_RLOAD_A(IR_REG_SP), IR_SHADOW_ARGS);
10414+
#else
10415+
sp = ir_RLOAD_A(IR_REG_SP);
10416+
#endif
10417+
}
1038910418
res_addr = ZEND_ADDR_REF_ZVAL(sp);
1039010419
jit_ZVAL_PTR_DTOR(jit, res_addr, func_info, 1, opline);
1039110420
}

0 commit comments

Comments
 (0)