This source file includes following definitions.
- BEGIN_EXTERN_C
- zend_vm_stack_push_call_frame_ex
- zend_vm_calc_used_stack
- zend_vm_stack_push_call_frame
- zend_vm_stack_free_extra_args_ex
- zend_vm_stack_free_extra_args
- zend_vm_stack_free_args
- zend_vm_stack_free_call_frame_ex
- zend_vm_stack_free_call_frame
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 #ifndef ZEND_EXECUTE_H
24 #define ZEND_EXECUTE_H
25
26 #include "zend_compile.h"
27 #include "zend_hash.h"
28 #include "zend_operators.h"
29 #include "zend_variables.h"
30
31 BEGIN_EXTERN_C()
32 struct _zend_fcall_info;
33 ZEND_API extern void (*zend_execute_ex)(zend_execute_data *execute_data);
34 ZEND_API extern void (*zend_execute_internal)(zend_execute_data *execute_data, zval *return_value);
35
36 void init_executor(void);
37 void shutdown_executor(void);
38 void shutdown_destructors(void);
39 ZEND_API void zend_init_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value);
40 ZEND_API zend_execute_data *zend_create_generator_execute_data(zend_execute_data *call, zend_op_array *op_array, zval *return_value);
41 ZEND_API void zend_execute(zend_op_array *op_array, zval *return_value);
42 ZEND_API void execute_ex(zend_execute_data *execute_data);
43 ZEND_API void execute_internal(zend_execute_data *execute_data, zval *return_value);
44 ZEND_API zend_class_entry *zend_lookup_class(zend_string *name);
45 ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *key, int use_autoload);
46 ZEND_API zend_class_entry *zend_get_called_scope(zend_execute_data *ex);
47 ZEND_API zend_object *zend_get_this_object(zend_execute_data *ex);
48 ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name);
49 ZEND_API int zend_eval_stringl(char *str, size_t str_len, zval *retval_ptr, char *string_name);
50 ZEND_API int zend_eval_string_ex(char *str, zval *retval_ptr, char *string_name, int handle_exceptions);
51 ZEND_API int zend_eval_stringl_ex(char *str, size_t str_len, zval *retval_ptr, char *string_name, int handle_exceptions);
52
53 ZEND_API void ZEND_FASTCALL zend_check_internal_arg_type(zend_function *zf, uint32_t arg_num, zval *arg);
54 ZEND_API int ZEND_FASTCALL zend_check_arg_type(zend_function *zf, uint32_t arg_num, zval *arg, zval *default_value, void **cache_slot);
55 ZEND_API void ZEND_FASTCALL zend_check_missing_arg(zend_execute_data *execute_data, uint32_t arg_num, void **cache_slot);
56
57 static zend_always_inline zval* zend_assign_to_variable(zval *variable_ptr, zval *value, zend_uchar value_type)
58 {
59 zend_refcounted *ref = NULL;
60
61 if (ZEND_CONST_COND(value_type & (IS_VAR|IS_CV), 1) && Z_ISREF_P(value)) {
62 ref = Z_COUNTED_P(value);
63 value = Z_REFVAL_P(value);
64 }
65
66 do {
67 if (UNEXPECTED(Z_REFCOUNTED_P(variable_ptr))) {
68 zend_refcounted *garbage;
69
70 if (Z_ISREF_P(variable_ptr)) {
71 variable_ptr = Z_REFVAL_P(variable_ptr);
72 if (EXPECTED(!Z_REFCOUNTED_P(variable_ptr))) {
73 break;
74 }
75 }
76 if (Z_TYPE_P(variable_ptr) == IS_OBJECT &&
77 UNEXPECTED(Z_OBJ_HANDLER_P(variable_ptr, set) != NULL)) {
78 Z_OBJ_HANDLER_P(variable_ptr, set)(variable_ptr, value);
79 return variable_ptr;
80 }
81 if (ZEND_CONST_COND(value_type & (IS_VAR|IS_CV), 1) && variable_ptr == value) {
82 return variable_ptr;
83 }
84 garbage = Z_COUNTED_P(variable_ptr);
85 if (--GC_REFCOUNT(garbage) == 0) {
86 ZVAL_COPY_VALUE(variable_ptr, value);
87 if (value_type == IS_CONST) {
88
89 if (UNEXPECTED(Z_OPT_COPYABLE_P(variable_ptr))) {
90 zval_copy_ctor_func(variable_ptr);
91 }
92 } else if (value_type == IS_CV) {
93 if (UNEXPECTED(Z_OPT_REFCOUNTED_P(variable_ptr))) {
94 Z_ADDREF_P(variable_ptr);
95 }
96 } else if (ZEND_CONST_COND(value_type == IS_VAR, 1) && UNEXPECTED(ref)) {
97 if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) {
98 efree_size(ref, sizeof(zend_reference));
99 } else if (Z_OPT_REFCOUNTED_P(variable_ptr)) {
100 Z_ADDREF_P(variable_ptr);
101 }
102 }
103 zval_dtor_func_for_ptr(garbage);
104 return variable_ptr;
105 } else {
106
107 if ((Z_COLLECTABLE_P(variable_ptr)) &&
108 UNEXPECTED(!GC_INFO(garbage))) {
109 gc_possible_root(garbage);
110 }
111 }
112 }
113 } while (0);
114
115 ZVAL_COPY_VALUE(variable_ptr, value);
116 if (value_type == IS_CONST) {
117
118 if (UNEXPECTED(Z_OPT_COPYABLE_P(variable_ptr))) {
119 zval_copy_ctor_func(variable_ptr);
120 }
121 } else if (value_type == IS_CV) {
122 if (UNEXPECTED(Z_OPT_REFCOUNTED_P(variable_ptr))) {
123 Z_ADDREF_P(variable_ptr);
124 }
125 } else if (ZEND_CONST_COND(value_type == IS_VAR, 1) && UNEXPECTED(ref)) {
126 if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) {
127 efree_size(ref, sizeof(zend_reference));
128 } else if (Z_OPT_REFCOUNTED_P(variable_ptr)) {
129 Z_ADDREF_P(variable_ptr);
130 }
131 }
132 return variable_ptr;
133 }
134
135 ZEND_API int zval_update_constant(zval *pp, zend_bool inline_change);
136 ZEND_API int zval_update_constant_ex(zval *pp, zend_bool inline_change, zend_class_entry *scope);
137
138
139 struct _zend_vm_stack {
140 zval *top;
141 zval *end;
142 zend_vm_stack prev;
143 };
144
145 #define ZEND_VM_STACK_HEADER_SLOTS \
146 ((ZEND_MM_ALIGNED_SIZE(sizeof(struct _zend_vm_stack)) + ZEND_MM_ALIGNED_SIZE(sizeof(zval)) - 1) / ZEND_MM_ALIGNED_SIZE(sizeof(zval)))
147
148 #define ZEND_VM_STACK_ELEMETS(stack) \
149 (((zval*)(stack)) + ZEND_VM_STACK_HEADER_SLOTS)
150
151
152
153
154
155
156
157
158 #if ZEND_DEBUG
159 # define ZEND_ASSERT_VM_STACK(stack) ZEND_ASSERT(stack->top > (zval *) stack && stack->end > (zval *) stack && stack->top <= stack->end)
160 # define ZEND_ASSERT_VM_STACK_GLOBAL ZEND_ASSERT(EG(vm_stack_top) > (zval *) EG(vm_stack) && EG(vm_stack_end) > (zval *) EG(vm_stack) && EG(vm_stack_top) <= EG(vm_stack_end))
161 #else
162 # define ZEND_ASSERT_VM_STACK(stack)
163 # define ZEND_ASSERT_VM_STACK_GLOBAL
164 #endif
165
166 ZEND_API void zend_vm_stack_init(void);
167 ZEND_API void zend_vm_stack_destroy(void);
168 ZEND_API void* zend_vm_stack_extend(size_t size);
169
170 static zend_always_inline zend_execute_data *zend_vm_stack_push_call_frame_ex(uint32_t used_stack, uint32_t call_info, zend_function *func, uint32_t num_args, zend_class_entry *called_scope, zend_object *object)
171 {
172 zend_execute_data *call = (zend_execute_data*)EG(vm_stack_top);
173
174 ZEND_ASSERT_VM_STACK_GLOBAL;
175
176 if (UNEXPECTED(used_stack > (size_t)(((char*)EG(vm_stack_end)) - (char*)call))) {
177 call = (zend_execute_data*)zend_vm_stack_extend(used_stack);
178 ZEND_SET_CALL_INFO(call, call_info | ZEND_CALL_ALLOCATED);
179 } else {
180 EG(vm_stack_top) = (zval*)((char*)call + used_stack);
181 ZEND_SET_CALL_INFO(call, call_info);
182 }
183
184 ZEND_ASSERT_VM_STACK_GLOBAL;
185
186 call->func = func;
187 Z_OBJ(call->This) = object;
188 ZEND_CALL_NUM_ARGS(call) = num_args;
189 call->called_scope = called_scope;
190 return call;
191 }
192
193 static zend_always_inline uint32_t zend_vm_calc_used_stack(uint32_t num_args, zend_function *func)
194 {
195 uint32_t used_stack = ZEND_CALL_FRAME_SLOT + num_args;
196
197 if (EXPECTED(ZEND_USER_CODE(func->type))) {
198 used_stack += func->op_array.last_var + func->op_array.T - MIN(func->op_array.num_args, num_args);
199 }
200 return used_stack * sizeof(zval);
201 }
202
203 static zend_always_inline zend_execute_data *zend_vm_stack_push_call_frame(uint32_t call_info, zend_function *func, uint32_t num_args, zend_class_entry *called_scope, zend_object *object)
204 {
205 uint32_t used_stack = zend_vm_calc_used_stack(num_args, func);
206
207 return zend_vm_stack_push_call_frame_ex(used_stack, call_info,
208 func, num_args, called_scope, object);
209 }
210
211 static zend_always_inline void zend_vm_stack_free_extra_args_ex(uint32_t call_info, zend_execute_data *call)
212 {
213 if (UNEXPECTED(call_info & ZEND_CALL_FREE_EXTRA_ARGS)) {
214 zval *end = ZEND_CALL_VAR_NUM(call, call->func->op_array.last_var + call->func->op_array.T);
215 zval *p = end + (ZEND_CALL_NUM_ARGS(call) - call->func->op_array.num_args);
216 do {
217 p--;
218 if (Z_REFCOUNTED_P(p)) {
219 if (!Z_DELREF_P(p)) {
220 zend_refcounted *r = Z_COUNTED_P(p);
221 ZVAL_NULL(p);
222 zval_dtor_func_for_ptr(r);
223 } else {
224 GC_ZVAL_CHECK_POSSIBLE_ROOT(p);
225 }
226 }
227 } while (p != end);
228 }
229 }
230
231 static zend_always_inline void zend_vm_stack_free_extra_args(zend_execute_data *call)
232 {
233 zend_vm_stack_free_extra_args_ex(ZEND_CALL_INFO(call), call);
234 }
235
236 static zend_always_inline void zend_vm_stack_free_args(zend_execute_data *call)
237 {
238 uint32_t num_args = ZEND_CALL_NUM_ARGS(call);
239
240 if (EXPECTED(num_args > 0)) {
241 zval *end = ZEND_CALL_ARG(call, 1);
242 zval *p = end + num_args;
243
244 do {
245 p--;
246 if (Z_REFCOUNTED_P(p)) {
247 if (!Z_DELREF_P(p)) {
248 zend_refcounted *r = Z_COUNTED_P(p);
249 ZVAL_NULL(p);
250 zval_dtor_func_for_ptr(r);
251 }
252 }
253 } while (p != end);
254 }
255 }
256
257 static zend_always_inline void zend_vm_stack_free_call_frame_ex(uint32_t call_info, zend_execute_data *call)
258 {
259 ZEND_ASSERT_VM_STACK_GLOBAL;
260
261 if (UNEXPECTED(call_info & ZEND_CALL_ALLOCATED)) {
262 zend_vm_stack p = EG(vm_stack);
263
264 zend_vm_stack prev = p->prev;
265
266 EG(vm_stack_top) = prev->top;
267 EG(vm_stack_end) = prev->end;
268 EG(vm_stack) = prev;
269 efree(p);
270
271 } else {
272 EG(vm_stack_top) = (zval*)call;
273 }
274
275 ZEND_ASSERT_VM_STACK_GLOBAL;
276 }
277
278 static zend_always_inline void zend_vm_stack_free_call_frame(zend_execute_data *call)
279 {
280 zend_vm_stack_free_call_frame_ex(ZEND_CALL_INFO(call), call);
281 }
282
283
284 ZEND_API const char *get_active_class_name(const char **space);
285 ZEND_API const char *get_active_function_name(void);
286 ZEND_API const char *zend_get_executed_filename(void);
287 ZEND_API zend_string *zend_get_executed_filename_ex(void);
288 ZEND_API uint zend_get_executed_lineno(void);
289 ZEND_API zend_bool zend_is_executing(void);
290
291 ZEND_API void zend_set_timeout(zend_long seconds, int reset_signals);
292 ZEND_API void zend_unset_timeout(void);
293 ZEND_API void zend_timeout(int dummy);
294 ZEND_API zend_class_entry *zend_fetch_class(zend_string *class_name, int fetch_type);
295 ZEND_API zend_class_entry *zend_fetch_class_by_name(zend_string *class_name, const zval *key, int fetch_type);
296 void zend_verify_abstract_class(zend_class_entry *ce);
297
298 ZEND_API void zend_fetch_dimension_by_zval(zval *result, zval *container, zval *dim);
299
300 ZEND_API zval* zend_get_compiled_variable_value(const zend_execute_data *execute_data_ptr, uint32_t var);
301
302 #define ZEND_USER_OPCODE_CONTINUE 0
303 #define ZEND_USER_OPCODE_RETURN 1
304 #define ZEND_USER_OPCODE_DISPATCH 2
305 #define ZEND_USER_OPCODE_ENTER 3
306 #define ZEND_USER_OPCODE_LEAVE 4
307
308 #define ZEND_USER_OPCODE_DISPATCH_TO 0x100
309
310 ZEND_API int zend_set_user_opcode_handler(zend_uchar opcode, user_opcode_handler_t handler);
311 ZEND_API user_opcode_handler_t zend_get_user_opcode_handler(zend_uchar opcode);
312
313
314 typedef zval* zend_free_op;
315
316 ZEND_API zval *zend_get_zval_ptr(int op_type, const znode_op *node, const zend_execute_data *execute_data, zend_free_op *should_free, int type);
317
318 ZEND_API void zend_clean_and_cache_symbol_table(zend_array *symbol_table);
319 void zend_free_compiled_variables(zend_execute_data *execute_data);
320 void zend_cleanup_unfinished_execution(zend_execute_data *execute_data, uint32_t op_num, uint32_t catch_op_num);
321
322 #define CACHE_ADDR(num) \
323 ((void**)((char*)EX_RUN_TIME_CACHE() + (num)))
324
325 #define CACHED_PTR(num) \
326 ((void**)((char*)EX_RUN_TIME_CACHE() + (num)))[0]
327
328 #define CACHE_PTR(num, ptr) do { \
329 ((void**)((char*)EX_RUN_TIME_CACHE() + (num)))[0] = (ptr); \
330 } while (0)
331
332 #define CACHED_POLYMORPHIC_PTR(num, ce) \
333 (EXPECTED(((void**)((char*)EX_RUN_TIME_CACHE() + (num)))[0] == (void*)(ce)) ? \
334 ((void**)((char*)EX_RUN_TIME_CACHE() + (num)))[1] : \
335 NULL)
336
337 #define CACHE_POLYMORPHIC_PTR(num, ce, ptr) do { \
338 void **slot = (void**)((char*)EX_RUN_TIME_CACHE() + (num)); \
339 slot[0] = (ce); \
340 slot[1] = (ptr); \
341 } while (0)
342
343 #define CACHED_PTR_EX(slot) \
344 (slot)[0]
345
346 #define CACHE_PTR_EX(slot, ptr) do { \
347 (slot)[0] = (ptr); \
348 } while (0)
349
350 #define CACHED_POLYMORPHIC_PTR_EX(slot, ce) \
351 (EXPECTED((slot)[0] == (ce)) ? (slot)[1] : NULL)
352
353 #define CACHE_POLYMORPHIC_PTR_EX(slot, ce, ptr) do { \
354 (slot)[0] = (ce); \
355 (slot)[1] = (ptr); \
356 } while (0)
357
358 #define SKIP_EXT_OPLINE(opline) do { \
359 while (UNEXPECTED((opline)->opcode >= ZEND_EXT_STMT \
360 && (opline)->opcode <= ZEND_TICKS)) { \
361 (opline)--; \
362 } \
363 } while (0)
364
365 END_EXTERN_C()
366
367 #endif
368
369
370
371
372
373
374
375