Skip to content

Commit e5fe419

Browse files
committed
Add zend_vm_stack_init_ex, add the page_size arg to ZEND_VM_STACK_PAGE_ALIGNED_SIZE.
1 parent 388c31e commit e5fe419

File tree

2 files changed

+73
-65
lines changed

2 files changed

+73
-65
lines changed

Zend/zend_execute.c

Lines changed: 72 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
/*
22
+----------------------------------------------------------------------+
3-
| Zend Engine |
3+
| Zend Engine |
44
+----------------------------------------------------------------------+
55
| Copyright (c) 1998-2018 Zend Technologies Ltd. (http://www.zend.com) |
66
+----------------------------------------------------------------------+
7-
| This source file is subject to version 2.00 of the Zend license, |
8-
| that is bundled with this package in the file LICENSE, and is |
9-
| available through the world-wide-web at the following url: |
10-
| http://www.zend.com/license/2_00.txt. |
7+
| This source file is subject to version 2.00 of the Zend license, |
8+
| that is bundled with this package in the file LICENSE, and is |
9+
| available through the world-wide-web at the following url: |
10+
| http://www.zend.com/license/2_00.txt. |
1111
| If you did not receive a copy of the Zend license and are unable to |
12-
| obtain it through the world-wide-web, please send a note to |
13-
| license@zend.com so we can mail you a copy immediately. |
12+
| obtain it through the world-wide-web, please send a note to |
13+
| license@zend.com so we can mail you a copy immediately. |
1414
+----------------------------------------------------------------------+
15-
| Authors: Andi Gutmans <andi@php.net> |
16-
| Zeev Suraski <zeev@php.net> |
17-
| Dmitry Stogov <dmitry@php.net> |
15+
| Authors: Andi Gutmans <andi@php.net> |
16+
| Zeev Suraski <zeev@php.net> |
17+
| Dmitry Stogov <dmitry@php.net> |
1818
+----------------------------------------------------------------------+
1919
*/
2020

@@ -63,25 +63,25 @@
6363
# pragma GCC diagnostic ignored "-Wvolatile-register-var"
6464
register zend_execute_data* volatile execute_data __asm__(ZEND_VM_FP_GLOBAL_REG);
6565
# pragma GCC diagnostic warning "-Wvolatile-register-var"
66-
# define EXECUTE_DATA_D void
66+
# define EXECUTE_DATA_D void
6767
# define EXECUTE_DATA_C
6868
# define EXECUTE_DATA_DC
6969
# define EXECUTE_DATA_CC
7070
# define NO_EXECUTE_DATA_CC
71-
# define OPLINE_D void
71+
# define OPLINE_D void
7272
# define OPLINE_C
7373
# define OPLINE_DC
7474
# define OPLINE_CC
7575
#else
76-
# define EXECUTE_DATA_D zend_execute_data* execute_data
77-
# define EXECUTE_DATA_C execute_data
78-
# define EXECUTE_DATA_DC , EXECUTE_DATA_D
79-
# define EXECUTE_DATA_CC , EXECUTE_DATA_C
76+
# define EXECUTE_DATA_D zend_execute_data* execute_data
77+
# define EXECUTE_DATA_C execute_data
78+
# define EXECUTE_DATA_DC , EXECUTE_DATA_D
79+
# define EXECUTE_DATA_CC , EXECUTE_DATA_C
8080
# define NO_EXECUTE_DATA_CC , NULL
81-
# define OPLINE_D const zend_op* opline
82-
# define OPLINE_C opline
83-
# define OPLINE_DC , OPLINE_D
84-
# define OPLINE_CC , OPLINE_C
81+
# define OPLINE_D const zend_op* opline
82+
# define OPLINE_C opline
83+
# define OPLINE_DC , OPLINE_D
84+
# define OPLINE_CC , OPLINE_C
8585
#endif
8686

8787
#if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
@@ -92,10 +92,10 @@
9292
#endif
9393

9494
#define _CONST_CODE 0
95-
#define _TMP_CODE 1
96-
#define _VAR_CODE 2
95+
#define _TMP_CODE 1
96+
#define _VAR_CODE 2
9797
#define _UNUSED_CODE 3
98-
#define _CV_CODE 4
98+
#define _CV_CODE 4
9999

100100
typedef int (ZEND_FASTCALL *incdec_t)(zval *);
101101

@@ -117,18 +117,18 @@ static ZEND_FUNCTION(pass)
117117
}
118118

119119
ZEND_API const zend_internal_function zend_pass_function = {
120-
ZEND_INTERNAL_FUNCTION, /* type */
121-
{0, 0, 0}, /* arg_flags */
122-
0, /* fn_flags */
123-
NULL, /* name */
124-
NULL, /* scope */
125-
NULL, /* prototype */
126-
0, /* num_args */
127-
0, /* required_num_args */
128-
NULL, /* arg_info */
129-
ZEND_FN(pass), /* handler */
130-
NULL, /* module */
131-
{NULL,NULL,NULL,NULL} /* reserved */
120+
ZEND_INTERNAL_FUNCTION, /* type */
121+
{0, 0, 0}, /* arg_flags */
122+
0, /* fn_flags */
123+
NULL, /* name */
124+
NULL, /* scope */
125+
NULL, /* prototype */
126+
0, /* num_args */
127+
0, /* required_num_args */
128+
NULL, /* arg_info */
129+
ZEND_FN(pass), /* handler */
130+
NULL, /* module */
131+
{NULL,NULL,NULL,NULL} /* reserved */
132132
};
133133

134134
#undef zval_ptr_dtor
@@ -168,9 +168,9 @@ ZEND_API const zend_internal_function zend_pass_function = {
168168

169169
#define ZEND_VM_STACK_PAGE_SLOTS (16 * 1024) /* should be a power of 2 */
170170

171-
#define ZEND_VM_STACK_PAGE_ALIGNED_SIZE(size) \
171+
#define ZEND_VM_STACK_PAGE_ALIGNED_SIZE(size, page_size) \
172172
(((size) + ZEND_VM_STACK_HEADER_SLOTS * sizeof(zval) \
173-
+ (EG(vm_stack_page_size) - 1)) & ~(EG(vm_stack_page_size) - 1))
173+
+ ((page_size) - 1)) & ~((page_size) - 1))
174174

175175
static zend_always_inline zend_vm_stack zend_vm_stack_new_page(size_t size, zend_vm_stack prev) {
176176
zend_vm_stack page = (zend_vm_stack)emalloc(size);
@@ -183,8 +183,15 @@ static zend_always_inline zend_vm_stack zend_vm_stack_new_page(size_t size, zend
183183

184184
ZEND_API void zend_vm_stack_init(void)
185185
{
186-
EG(vm_stack_page_size) = ZEND_VM_STACK_PAGE_SLOTS * sizeof(zval);
187-
EG(vm_stack) = zend_vm_stack_new_page(EG(vm_stack_page_size), NULL);
186+
zend_vm_stack_init_ex(ZEND_VM_STACK_PAGE_SLOTS * sizeof(zval));
187+
}
188+
189+
ZEND_API void zend_vm_stack_init_ex(size_t page_size)
190+
{
191+
/* page_size must be a power of 2 */
192+
ZEND_ASSERT(page_size > 0 && (page_size & (page_size - 1)) == 0);
193+
EG(vm_stack_page_size) = page_size;
194+
EG(vm_stack) = zend_vm_stack_new_page(page_size, NULL);
188195
EG(vm_stack_top) = EG(vm_stack)->top;
189196
EG(vm_stack_end) = EG(vm_stack)->end;
190197
}
@@ -209,7 +216,7 @@ ZEND_API void* zend_vm_stack_extend(size_t size)
209216
stack->top = EG(vm_stack_top);
210217
EG(vm_stack) = stack = zend_vm_stack_new_page(
211218
EXPECTED(size < EG(vm_stack_page_size) - (ZEND_VM_STACK_HEADER_SLOTS * sizeof(zval))) ?
212-
EG(vm_stack_page_size) : ZEND_VM_STACK_PAGE_ALIGNED_SIZE(size),
219+
EG(vm_stack_page_size) : ZEND_VM_STACK_PAGE_ALIGNED_SIZE(size, EG(vm_stack_page_size)),
213220
stack);
214221
ptr = stack->top;
215222
EG(vm_stack_top) = (void*)(((char*)ptr) + size);
@@ -1731,7 +1738,7 @@ static zend_never_inline zval* ZEND_FASTCALL zend_fetch_dimension_address_inner_
17311738

17321739
static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *container, zval *dim, int dim_type, int type EXECUTE_DATA_DC)
17331740
{
1734-
zval *retval;
1741+
zval *retval;
17351742

17361743
if (EXPECTED(Z_TYPE_P(container) == IS_ARRAY)) {
17371744
try_array:
@@ -2090,7 +2097,7 @@ static zend_never_inline int ZEND_FASTCALL zend_isempty_dim_slow(zval *container
20902097
static zend_always_inline void zend_fetch_property_address(zval *result, zval *container, uint32_t container_op_type, zval *prop_ptr, uint32_t prop_op_type, void **cache_slot, int type OPLINE_DC)
20912098
{
20922099
zval *ptr;
2093-
if (container_op_type != IS_UNUSED && UNEXPECTED(Z_TYPE_P(container) != IS_OBJECT)) {
2100+
if (container_op_type != IS_UNUSED && UNEXPECTED(Z_TYPE_P(container) != IS_OBJECT)) {
20942101
do {
20952102
if (Z_ISREF_P(container)) {
20962103
container = Z_REFVAL_P(container);
@@ -2108,7 +2115,7 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
21082115
} while (0);
21092116
}
21102117
if (prop_op_type == IS_CONST &&
2111-
EXPECTED(Z_OBJCE_P(container) == CACHED_PTR_EX(cache_slot))) {
2118+
EXPECTED(Z_OBJCE_P(container) == CACHED_PTR_EX(cache_slot))) {
21122119
uintptr_t prop_offset = (uintptr_t)CACHED_PTR_EX(cache_slot + 1);
21132120
zend_object *zobj = Z_OBJ_P(container);
21142121
zval *retval;
@@ -2281,20 +2288,20 @@ ZEND_API void zend_free_compiled_variables(zend_execute_data *execute_data) /* {
22812288
* Stack Frame Layout (the whole stack frame is allocated at once)
22822289
* ==================
22832290
*
2284-
* +========================================+
2285-
* EG(current_execute_data) -> | zend_execute_data |
2286-
* +----------------------------------------+
2287-
* EX_CV_NUM(0) ---------> | VAR[0] = ARG[1] |
2288-
* | ... |
2289-
* | VAR[op_array->num_args-1] = ARG[N] |
2290-
* | ... |
2291-
* | VAR[op_array->last_var-1] |
2292-
* | VAR[op_array->last_var] = TMP[0] |
2293-
* | ... |
2294-
* | VAR[op_array->last_var+op_array->T-1] |
2295-
* | ARG[N+1] (extra_args) |
2296-
* | ... |
2297-
* +----------------------------------------+
2291+
* +========================================+
2292+
* EG(current_execute_data) -> | zend_execute_data |
2293+
* +----------------------------------------+
2294+
* EX_CV_NUM(0) ---------> | VAR[0] = ARG[1] |
2295+
* | ... |
2296+
* | VAR[op_array->num_args-1] = ARG[N] |
2297+
* | ... |
2298+
* | VAR[op_array->last_var-1] |
2299+
* | VAR[op_array->last_var] = TMP[0] |
2300+
* | ... |
2301+
* | VAR[op_array->last_var+op_array->T-1] |
2302+
* | ARG[N+1] (extra_args) |
2303+
* | ... |
2304+
* +----------------------------------------+
22982305
*/
22992306

23002307
static zend_never_inline void zend_copy_extra_args(EXECUTE_DATA_D)
@@ -2487,7 +2494,7 @@ ZEND_API void zend_init_func_execute_data(zend_execute_data *ex, zend_op_array *
24872494
i_init_func_execute_data(op_array, return_value, 1 EXECUTE_DATA_CC);
24882495

24892496
#if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
2490-
EX(opline) = opline;
2497+
EX(opline) = opline;
24912498
opline = orig_opline;
24922499
execute_data = orig_execute_data;
24932500
#endif
@@ -2777,14 +2784,14 @@ ZEND_API void zend_cleanup_unfinished_execution(zend_execute_data *execute_data,
27772784

27782785
static void zend_swap_operands(zend_op *op) /* {{{ */
27792786
{
2780-
znode_op tmp;
2787+
znode_op tmp;
27812788
zend_uchar tmp_type;
27822789

2783-
tmp = op->op1;
2784-
tmp_type = op->op1_type;
2785-
op->op1 = op->op2;
2790+
tmp = op->op1;
2791+
tmp_type = op->op1_type;
2792+
op->op1 = op->op2;
27862793
op->op1_type = op->op2_type;
2787-
op->op2 = tmp;
2794+
op->op2 = tmp;
27882795
op->op2_type = tmp_type;
27892796
}
27902797
/* }}} */
@@ -2875,7 +2882,7 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_object(zval *
28752882
uint32_t call_info = ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC;
28762883

28772884
if (EXPECTED(Z_OBJ_HANDLER_P(function, get_closure)) &&
2878-
EXPECTED(Z_OBJ_HANDLER_P(function, get_closure)(function, &called_scope, &fbc, &object) == SUCCESS)) {
2885+
EXPECTED(Z_OBJ_HANDLER_P(function, get_closure)(function, &called_scope, &fbc, &object) == SUCCESS)) {
28792886

28802887
if (fbc->common.fn_flags & ZEND_ACC_CLOSURE) {
28812888
/* Delay closure destruction until its invocation */
@@ -3180,7 +3187,7 @@ static zend_always_inline int _zend_quick_get_constant(
31803187
if (zv) {
31813188
c = (zend_constant*)Z_PTR_P(zv);
31823189
} else {
3183-
key++;
3190+
key++;
31843191
zv = zend_hash_find_ex(EG(zend_constants), Z_STR_P(key), 1);
31853192
if (zv && (ZEND_CONSTANT_FLAGS((zend_constant*)Z_PTR_P(zv)) & CONST_CS) == 0) {
31863193
c = (zend_constant*)Z_PTR_P(zv);

Zend/zend_execute.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ struct _zend_vm_stack {
168168
#endif
169169

170170
ZEND_API void zend_vm_stack_init(void);
171+
ZEND_API void zend_vm_stack_init_ex(size_t page_size);
171172
ZEND_API void zend_vm_stack_destroy(void);
172173
ZEND_API void* zend_vm_stack_extend(size_t size);
173174

0 commit comments

Comments
 (0)