1 /*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
5 | Copyright (c) Zend Technologies Ltd. (http://www.zend.com) |
6 +----------------------------------------------------------------------+
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. |
11 | 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. |
14 +----------------------------------------------------------------------+
15 | Authors: Andi Gutmans <andi@php.net> |
16 | Zeev Suraski <zeev@php.net> |
17 | Dmitry Stogov <dmitry@php.net> |
18 +----------------------------------------------------------------------+
19 */
20
21 #ifndef ZEND_EXECUTE_H
22 #define ZEND_EXECUTE_H
23
24 #include "zend_compile.h"
25 #include "zend_hash.h"
26 #include "zend_operators.h"
27 #include "zend_variables.h"
28
29 #include <stdint.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 /* The lc_name may be stack allocated! */
37 ZEND_API extern zend_class_entry *(*zend_autoload)(zend_string *name, zend_string *lc_name);
38
39 void init_executor(void);
40 void shutdown_executor(void);
41 void shutdown_destructors(void);
42 ZEND_API void zend_shutdown_executor_values(bool fast_shutdown);
43
44 ZEND_API void zend_init_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value);
45 ZEND_API void zend_init_func_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value);
46 ZEND_API void zend_init_code_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value);
47 ZEND_API void zend_execute(zend_op_array *op_array, zval *return_value);
48 ZEND_API void execute_ex(zend_execute_data *execute_data);
49 ZEND_API void execute_internal(zend_execute_data *execute_data, zval *return_value);
50 ZEND_API bool zend_is_valid_class_name(zend_string *name);
51 ZEND_API zend_class_entry *zend_lookup_class(zend_string *name);
52 ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, zend_string *lcname, uint32_t flags);
53 ZEND_API zend_class_entry *zend_get_called_scope(zend_execute_data *ex);
54 ZEND_API zend_object *zend_get_this_object(zend_execute_data *ex);
55 ZEND_API zend_result zend_eval_string(const char *str, zval *retval_ptr, const char *string_name);
56 ZEND_API zend_result zend_eval_stringl(const char *str, size_t str_len, zval *retval_ptr, const char *string_name);
57 ZEND_API zend_result zend_eval_string_ex(const char *str, zval *retval_ptr, const char *string_name, bool handle_exceptions);
58 ZEND_API zend_result zend_eval_stringl_ex(const char *str, size_t str_len, zval *retval_ptr, const char *string_name, bool handle_exceptions);
59
60 /* export zend_pass_function to allow comparisons against it */
61 extern ZEND_API const zend_internal_function zend_pass_function;
62
63 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_missing_arg_error(zend_execute_data *execute_data);
64 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_function(const zend_function *fbc);
65 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_false_to_array_deprecated(void);
66 ZEND_COLD void ZEND_FASTCALL zend_param_must_be_ref(const zend_function *func, uint32_t arg_num);
67 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_use_resource_as_offset(const zval *dim);
68
69 ZEND_API bool ZEND_FASTCALL zend_verify_ref_assignable_zval(zend_reference *ref, zval *zv, bool strict);
70
71 typedef enum {
72 ZEND_VERIFY_PROP_ASSIGNABLE_BY_REF_CONTEXT_ASSIGNMENT,
73 ZEND_VERIFY_PROP_ASSIGNABLE_BY_REF_CONTEXT_MAGIC_GET,
74 } zend_verify_prop_assignable_by_ref_context;
75 ZEND_API bool ZEND_FASTCALL zend_verify_prop_assignable_by_ref_ex(const zend_property_info *prop_info, zval *orig_val, bool strict, zend_verify_prop_assignable_by_ref_context context);
76 ZEND_API bool ZEND_FASTCALL zend_verify_prop_assignable_by_ref(const zend_property_info *prop_info, zval *orig_val, bool strict);
77
78 ZEND_API ZEND_COLD void zend_throw_ref_type_error_zval(const zend_property_info *prop, const zval *zv);
79 ZEND_API ZEND_COLD void zend_throw_ref_type_error_type(const zend_property_info *prop1, const zend_property_info *prop2, const zval *zv);
80 ZEND_API ZEND_COLD zval* ZEND_FASTCALL zend_undefined_offset_write(HashTable *ht, zend_long lval);
81 ZEND_API ZEND_COLD zval* ZEND_FASTCALL zend_undefined_index_write(HashTable *ht, zend_string *offset);
82 ZEND_API ZEND_COLD void zend_wrong_string_offset_error(void);
83
84 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_modification_error(const zend_property_info *info);
85 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_indirect_modification_error(const zend_property_info *info);
86
87 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_invalid_class_constant_type_error(uint8_t type);
88
89 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_object_released_while_assigning_to_property_error(const zend_property_info *info);
90
91 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_cannot_add_element(void);
92
93 ZEND_API bool zend_verify_scalar_type_hint(uint32_t type_mask, zval *arg, bool strict, bool is_internal_arg);
94 ZEND_API ZEND_COLD void zend_verify_arg_error(
95 const zend_function *zf, const zend_arg_info *arg_info, uint32_t arg_num, zval *value);
96 ZEND_API ZEND_COLD void zend_verify_return_error(
97 const zend_function *zf, zval *value);
98 ZEND_API ZEND_COLD void zend_verify_never_error(
99 const zend_function *zf);
100 ZEND_API bool zend_verify_ref_array_assignable(zend_reference *ref);
101 ZEND_API bool zend_check_user_type_slow(
102 zend_type *type, zval *arg, zend_reference *ref, void **cache_slot, bool is_return_type);
103
104 #if ZEND_DEBUG
105 ZEND_API bool zend_internal_call_should_throw(zend_function *fbc, zend_execute_data *call);
106 ZEND_API ZEND_COLD void zend_internal_call_arginfo_violation(zend_function *fbc);
107 ZEND_API bool zend_verify_internal_return_type(zend_function *zf, zval *ret);
108 #endif
109
110 #define ZEND_REF_TYPE_SOURCES(ref) \
111 (ref)->sources
112
113 #define ZEND_REF_HAS_TYPE_SOURCES(ref) \
114 (ZEND_REF_TYPE_SOURCES(ref).ptr != NULL)
115
116 #define ZEND_REF_FIRST_SOURCE(ref) \
117 (ZEND_PROPERTY_INFO_SOURCE_IS_LIST((ref)->sources.list) \
118 ? ZEND_PROPERTY_INFO_SOURCE_TO_LIST((ref)->sources.list)->ptr[0] \
119 : (ref)->sources.ptr)
120
121
122 ZEND_API void ZEND_FASTCALL zend_ref_add_type_source(zend_property_info_source_list *source_list, zend_property_info *prop);
123 ZEND_API void ZEND_FASTCALL zend_ref_del_type_source(zend_property_info_source_list *source_list, const zend_property_info *prop);
124
125 ZEND_API zval* zend_assign_to_typed_ref(zval *variable_ptr, zval *value, uint8_t value_type, bool strict);
126 ZEND_API zval* zend_assign_to_typed_ref_ex(zval *variable_ptr, zval *value, uint8_t value_type, bool strict, zend_refcounted **garbage_ptr);
127
zend_copy_to_variable(zval * variable_ptr,zval * value,uint8_t value_type)128 static zend_always_inline void zend_copy_to_variable(zval *variable_ptr, zval *value, uint8_t value_type)
129 {
130 zend_refcounted *ref = NULL;
131
132 if (ZEND_CONST_COND(value_type & (IS_VAR|IS_CV), 1) && Z_ISREF_P(value)) {
133 ref = Z_COUNTED_P(value);
134 value = Z_REFVAL_P(value);
135 }
136
137 ZVAL_COPY_VALUE(variable_ptr, value);
138 if (ZEND_CONST_COND(value_type == IS_CONST, 0)) {
139 if (UNEXPECTED(Z_OPT_REFCOUNTED_P(variable_ptr))) {
140 Z_ADDREF_P(variable_ptr);
141 }
142 } else if (value_type & (IS_CONST|IS_CV)) {
143 if (Z_OPT_REFCOUNTED_P(variable_ptr)) {
144 Z_ADDREF_P(variable_ptr);
145 }
146 } else if (ZEND_CONST_COND(value_type == IS_VAR, 1) && UNEXPECTED(ref)) {
147 if (UNEXPECTED(GC_DELREF(ref) == 0)) {
148 efree_size(ref, sizeof(zend_reference));
149 } else if (Z_OPT_REFCOUNTED_P(variable_ptr)) {
150 Z_ADDREF_P(variable_ptr);
151 }
152 }
153 }
154
zend_assign_to_variable(zval * variable_ptr,zval * value,uint8_t value_type,bool strict)155 static zend_always_inline zval* zend_assign_to_variable(zval *variable_ptr, zval *value, uint8_t value_type, bool strict)
156 {
157 do {
158 if (UNEXPECTED(Z_REFCOUNTED_P(variable_ptr))) {
159 zend_refcounted *garbage;
160
161 if (Z_ISREF_P(variable_ptr)) {
162 if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(Z_REF_P(variable_ptr)))) {
163 return zend_assign_to_typed_ref(variable_ptr, value, value_type, strict);
164 }
165
166 variable_ptr = Z_REFVAL_P(variable_ptr);
167 if (EXPECTED(!Z_REFCOUNTED_P(variable_ptr))) {
168 break;
169 }
170 }
171 garbage = Z_COUNTED_P(variable_ptr);
172 zend_copy_to_variable(variable_ptr, value, value_type);
173 GC_DTOR_NO_REF(garbage);
174 return variable_ptr;
175 }
176 } while (0);
177
178 zend_copy_to_variable(variable_ptr, value, value_type);
179 return variable_ptr;
180 }
181
zend_assign_to_variable_ex(zval * variable_ptr,zval * value,zend_uchar value_type,bool strict,zend_refcounted ** garbage_ptr)182 static zend_always_inline zval* zend_assign_to_variable_ex(zval *variable_ptr, zval *value, zend_uchar value_type, bool strict, zend_refcounted **garbage_ptr)
183 {
184 do {
185 if (UNEXPECTED(Z_REFCOUNTED_P(variable_ptr))) {
186 if (Z_ISREF_P(variable_ptr)) {
187 if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(Z_REF_P(variable_ptr)))) {
188 return zend_assign_to_typed_ref_ex(variable_ptr, value, value_type, strict, garbage_ptr);
189 }
190
191 variable_ptr = Z_REFVAL_P(variable_ptr);
192 if (EXPECTED(!Z_REFCOUNTED_P(variable_ptr))) {
193 break;
194 }
195 }
196 *garbage_ptr = Z_COUNTED_P(variable_ptr);
197 }
198 } while (0);
199
200 zend_copy_to_variable(variable_ptr, value, value_type);
201 return variable_ptr;
202 }
203
204 ZEND_API zend_result ZEND_FASTCALL zval_update_constant(zval *pp);
205 ZEND_API zend_result ZEND_FASTCALL zval_update_constant_ex(zval *pp, zend_class_entry *scope);
206 ZEND_API zend_result ZEND_FASTCALL zval_update_constant_with_ctx(zval *pp, zend_class_entry *scope, zend_ast_evaluate_ctx *ctx);
207
208 /* dedicated Zend executor functions - do not use! */
209 struct _zend_vm_stack {
210 zval *top;
211 zval *end;
212 zend_vm_stack prev;
213 };
214
215 /* Ensure the correct alignment before slots calculation */
216 ZEND_STATIC_ASSERT(ZEND_MM_ALIGNED_SIZE(sizeof(zval)) == sizeof(zval),
217 "zval must be aligned by ZEND_MM_ALIGNMENT");
218 /* A number of call frame slots (zvals) reserved for _zend_vm_stack. */
219 #define ZEND_VM_STACK_HEADER_SLOTS \
220 ((sizeof(struct _zend_vm_stack) + sizeof(zval) - 1) / sizeof(zval))
221
222 #define ZEND_VM_STACK_ELEMENTS(stack) \
223 (((zval*)(stack)) + ZEND_VM_STACK_HEADER_SLOTS)
224
225 /*
226 * In general in RELEASE build ZEND_ASSERT() must be zero-cost, but for some
227 * reason, GCC generated worse code, performing CSE on assertion code and the
228 * following "slow path" and moving memory read operations from slow path into
229 * common header. This made a degradation for the fast path.
230 * The following "#if ZEND_DEBUG" eliminates it.
231 */
232 #if ZEND_DEBUG
233 # define ZEND_ASSERT_VM_STACK(stack) ZEND_ASSERT(stack->top > (zval *) stack && stack->end > (zval *) stack && stack->top <= stack->end)
234 # 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))
235 #else
236 # define ZEND_ASSERT_VM_STACK(stack)
237 # define ZEND_ASSERT_VM_STACK_GLOBAL
238 #endif
239
240 ZEND_API void zend_vm_stack_init(void);
241 ZEND_API void zend_vm_stack_init_ex(size_t page_size);
242 ZEND_API void zend_vm_stack_destroy(void);
243 ZEND_API void* zend_vm_stack_extend(size_t size);
244
zend_vm_stack_new_page(size_t size,zend_vm_stack prev)245 static zend_always_inline zend_vm_stack zend_vm_stack_new_page(size_t size, zend_vm_stack prev) {
246 zend_vm_stack page = (zend_vm_stack)emalloc(size);
247
248 page->top = ZEND_VM_STACK_ELEMENTS(page);
249 page->end = (zval*)((char*)page + size);
250 page->prev = prev;
251 return page;
252 }
253
zend_vm_init_call_frame(zend_execute_data * call,uint32_t call_info,zend_function * func,uint32_t num_args,void * object_or_called_scope)254 static zend_always_inline void zend_vm_init_call_frame(zend_execute_data *call, uint32_t call_info, zend_function *func, uint32_t num_args, void *object_or_called_scope)
255 {
256 ZEND_ASSERT(!func->common.scope || object_or_called_scope);
257 call->func = func;
258 Z_PTR(call->This) = object_or_called_scope;
259 ZEND_CALL_INFO(call) = call_info;
260 ZEND_CALL_NUM_ARGS(call) = num_args;
261 }
262
zend_vm_stack_push_call_frame_ex(uint32_t used_stack,uint32_t call_info,zend_function * func,uint32_t num_args,void * object_or_called_scope)263 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, void *object_or_called_scope)
264 {
265 zend_execute_data *call = (zend_execute_data*)EG(vm_stack_top);
266
267 ZEND_ASSERT_VM_STACK_GLOBAL;
268
269 if (UNEXPECTED(used_stack > (size_t)(((char*)EG(vm_stack_end)) - (char*)call))) {
270 call = (zend_execute_data*)zend_vm_stack_extend(used_stack);
271 ZEND_ASSERT_VM_STACK_GLOBAL;
272 zend_vm_init_call_frame(call, call_info | ZEND_CALL_ALLOCATED, func, num_args, object_or_called_scope);
273 return call;
274 } else {
275 EG(vm_stack_top) = (zval*)((char*)call + used_stack);
276 zend_vm_init_call_frame(call, call_info, func, num_args, object_or_called_scope);
277 return call;
278 }
279 }
280
zend_vm_calc_used_stack(uint32_t num_args,zend_function * func)281 static zend_always_inline uint32_t zend_vm_calc_used_stack(uint32_t num_args, zend_function *func)
282 {
283 uint32_t used_stack = ZEND_CALL_FRAME_SLOT + num_args + func->common.T;
284
285 if (EXPECTED(ZEND_USER_CODE(func->type))) {
286 used_stack += func->op_array.last_var - MIN(func->op_array.num_args, num_args);
287 }
288 return used_stack * sizeof(zval);
289 }
290
zend_vm_stack_push_call_frame(uint32_t call_info,zend_function * func,uint32_t num_args,void * object_or_called_scope)291 static zend_always_inline zend_execute_data *zend_vm_stack_push_call_frame(uint32_t call_info, zend_function *func, uint32_t num_args, void *object_or_called_scope)
292 {
293 uint32_t used_stack = zend_vm_calc_used_stack(num_args, func);
294
295 return zend_vm_stack_push_call_frame_ex(used_stack, call_info,
296 func, num_args, object_or_called_scope);
297 }
298
zend_vm_stack_free_extra_args_ex(uint32_t call_info,zend_execute_data * call)299 static zend_always_inline void zend_vm_stack_free_extra_args_ex(uint32_t call_info, zend_execute_data *call)
300 {
301 if (UNEXPECTED(call_info & ZEND_CALL_FREE_EXTRA_ARGS)) {
302 uint32_t count = ZEND_CALL_NUM_ARGS(call) - call->func->op_array.num_args;
303 zval *p = ZEND_CALL_VAR_NUM(call, call->func->op_array.last_var + call->func->op_array.T);
304 do {
305 i_zval_ptr_dtor(p);
306 p++;
307 } while (--count);
308 }
309 }
310
zend_vm_stack_free_extra_args(zend_execute_data * call)311 static zend_always_inline void zend_vm_stack_free_extra_args(zend_execute_data *call)
312 {
313 zend_vm_stack_free_extra_args_ex(ZEND_CALL_INFO(call), call);
314 }
315
zend_vm_stack_free_args(zend_execute_data * call)316 static zend_always_inline void zend_vm_stack_free_args(zend_execute_data *call)
317 {
318 uint32_t num_args = ZEND_CALL_NUM_ARGS(call);
319
320 if (EXPECTED(num_args > 0)) {
321 zval *p = ZEND_CALL_ARG(call, 1);
322
323 do {
324 zval_ptr_dtor_nogc(p);
325 p++;
326 } while (--num_args);
327 }
328 }
329
zend_vm_stack_free_call_frame_ex(uint32_t call_info,zend_execute_data * call)330 static zend_always_inline void zend_vm_stack_free_call_frame_ex(uint32_t call_info, zend_execute_data *call)
331 {
332 ZEND_ASSERT_VM_STACK_GLOBAL;
333
334 if (UNEXPECTED(call_info & ZEND_CALL_ALLOCATED)) {
335 zend_vm_stack p = EG(vm_stack);
336 zend_vm_stack prev = p->prev;
337
338 ZEND_ASSERT(call == (zend_execute_data*)ZEND_VM_STACK_ELEMENTS(EG(vm_stack)));
339 EG(vm_stack_top) = prev->top;
340 EG(vm_stack_end) = prev->end;
341 EG(vm_stack) = prev;
342 efree(p);
343 } else {
344 EG(vm_stack_top) = (zval*)call;
345 }
346
347 ZEND_ASSERT_VM_STACK_GLOBAL;
348 }
349
zend_vm_stack_free_call_frame(zend_execute_data * call)350 static zend_always_inline void zend_vm_stack_free_call_frame(zend_execute_data *call)
351 {
352 zend_vm_stack_free_call_frame_ex(ZEND_CALL_INFO(call), call);
353 }
354
355 zend_execute_data *zend_vm_stack_copy_call_frame(
356 zend_execute_data *call, uint32_t passed_args, uint32_t additional_args);
357
zend_vm_stack_extend_call_frame(zend_execute_data ** call,uint32_t passed_args,uint32_t additional_args)358 static zend_always_inline void zend_vm_stack_extend_call_frame(
359 zend_execute_data **call, uint32_t passed_args, uint32_t additional_args)
360 {
361 if (EXPECTED((uint32_t)(EG(vm_stack_end) - EG(vm_stack_top)) > additional_args)) {
362 EG(vm_stack_top) += additional_args;
363 } else {
364 *call = zend_vm_stack_copy_call_frame(*call, passed_args, additional_args);
365 }
366 }
367
368 ZEND_API void ZEND_FASTCALL zend_free_extra_named_params(zend_array *extra_named_params);
369
370 /* services */
371 ZEND_API const char *get_active_class_name(const char **space);
372 ZEND_API const char *get_active_function_name(void);
373 ZEND_API const char *get_active_function_arg_name(uint32_t arg_num);
374 ZEND_API const char *get_function_arg_name(const zend_function *func, uint32_t arg_num);
375 ZEND_API zend_string *get_active_function_or_method_name(void);
376 ZEND_API zend_string *get_function_or_method_name(const zend_function *func);
377 ZEND_API const char *zend_get_executed_filename(void);
378 ZEND_API zend_string *zend_get_executed_filename_ex(void);
379 ZEND_API uint32_t zend_get_executed_lineno(void);
380 ZEND_API zend_class_entry *zend_get_executed_scope(void);
381 ZEND_API bool zend_is_executing(void);
382 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_cannot_pass_by_reference(uint32_t arg_num);
383
384 ZEND_API void zend_set_timeout(zend_long seconds, bool reset_signals);
385 ZEND_API void zend_unset_timeout(void);
386 ZEND_API ZEND_NORETURN void ZEND_FASTCALL zend_timeout(void);
387 ZEND_API zend_class_entry *zend_fetch_class(zend_string *class_name, uint32_t fetch_type);
388 ZEND_API zend_class_entry *zend_fetch_class_with_scope(zend_string *class_name, uint32_t fetch_type, zend_class_entry *scope);
389 ZEND_API zend_class_entry *zend_fetch_class_by_name(zend_string *class_name, zend_string *lcname, uint32_t fetch_type);
390
391 ZEND_API zend_function * ZEND_FASTCALL zend_fetch_function(zend_string *name);
392 ZEND_API zend_function * ZEND_FASTCALL zend_fetch_function_str(const char *name, size_t len);
393 ZEND_API void ZEND_FASTCALL zend_init_func_run_time_cache(zend_op_array *op_array);
394
395 ZEND_API void zend_fetch_dimension_const(zval *result, zval *container, zval *dim, int type);
396
397 ZEND_API zval* zend_get_compiled_variable_value(const zend_execute_data *execute_data_ptr, uint32_t var);
398
399 ZEND_API bool zend_gcc_global_regs(void);
400
401 #define ZEND_USER_OPCODE_CONTINUE 0 /* execute next opcode */
402 #define ZEND_USER_OPCODE_RETURN 1 /* exit from executor (return from function) */
403 #define ZEND_USER_OPCODE_DISPATCH 2 /* call original opcode handler */
404 #define ZEND_USER_OPCODE_ENTER 3 /* enter into new op_array without recursion */
405 #define ZEND_USER_OPCODE_LEAVE 4 /* return to calling op_array within the same executor */
406
407 #define ZEND_USER_OPCODE_DISPATCH_TO 0x100 /* call original handler of returned opcode */
408
409 ZEND_API zend_result zend_set_user_opcode_handler(uint8_t opcode, user_opcode_handler_t handler);
410 ZEND_API user_opcode_handler_t zend_get_user_opcode_handler(uint8_t opcode);
411
412 ZEND_API zval *zend_get_zval_ptr(const zend_op *opline, int op_type, const znode_op *node, const zend_execute_data *execute_data);
413
414 ZEND_API void zend_clean_and_cache_symbol_table(zend_array *symbol_table);
415 ZEND_API void ZEND_FASTCALL zend_free_compiled_variables(zend_execute_data *execute_data);
416 ZEND_API void zend_unfinished_calls_gc(zend_execute_data *execute_data, zend_execute_data *call, uint32_t op_num, zend_get_gc_buffer *buf);
417 ZEND_API void zend_cleanup_unfinished_execution(zend_execute_data *execute_data, uint32_t op_num, uint32_t catch_op_num);
418 ZEND_API ZEND_ATTRIBUTE_DEPRECATED HashTable *zend_unfinished_execution_gc(zend_execute_data *execute_data, zend_execute_data *call, zend_get_gc_buffer *gc_buffer);
419 ZEND_API HashTable *zend_unfinished_execution_gc_ex(zend_execute_data *execute_data, zend_execute_data *call, zend_get_gc_buffer *gc_buffer, bool suspended_by_yield);
420
421 zval * ZEND_FASTCALL zend_handle_named_arg(
422 zend_execute_data **call_ptr, zend_string *arg_name,
423 uint32_t *arg_num_ptr, void **cache_slot);
424 ZEND_API zend_result ZEND_FASTCALL zend_handle_undef_args(zend_execute_data *call);
425
426 #define CACHE_ADDR(num) \
427 ((void**)((char*)EX(run_time_cache) + (num)))
428
429 #define CACHED_PTR(num) \
430 ((void**)((char*)EX(run_time_cache) + (num)))[0]
431
432 #define CACHE_PTR(num, ptr) do { \
433 ((void**)((char*)EX(run_time_cache) + (num)))[0] = (ptr); \
434 } while (0)
435
436 #define CACHED_POLYMORPHIC_PTR(num, ce) \
437 (EXPECTED(((void**)((char*)EX(run_time_cache) + (num)))[0] == (void*)(ce)) ? \
438 ((void**)((char*)EX(run_time_cache) + (num)))[1] : \
439 NULL)
440
441 #define CACHE_POLYMORPHIC_PTR(num, ce, ptr) do { \
442 void **slot = (void**)((char*)EX(run_time_cache) + (num)); \
443 slot[0] = (ce); \
444 slot[1] = (ptr); \
445 } while (0)
446
447 #define CACHED_PTR_EX(slot) \
448 (slot)[0]
449
450 #define CACHE_PTR_EX(slot, ptr) do { \
451 (slot)[0] = (ptr); \
452 } while (0)
453
454 #define CACHED_POLYMORPHIC_PTR_EX(slot, ce) \
455 (EXPECTED((slot)[0] == (ce)) ? (slot)[1] : NULL)
456
457 #define CACHE_POLYMORPHIC_PTR_EX(slot, ce, ptr) do { \
458 (slot)[0] = (ce); \
459 (slot)[1] = (ptr); \
460 } while (0)
461
462 #define CACHE_SPECIAL (1<<0)
463
464 #define IS_SPECIAL_CACHE_VAL(ptr) \
465 (((uintptr_t)(ptr)) & CACHE_SPECIAL)
466
467 #define ENCODE_SPECIAL_CACHE_NUM(num) \
468 ((void*)((((uintptr_t)(num)) << 1) | CACHE_SPECIAL))
469
470 #define DECODE_SPECIAL_CACHE_NUM(ptr) \
471 (((uintptr_t)(ptr)) >> 1)
472
473 #define ENCODE_SPECIAL_CACHE_PTR(ptr) \
474 ((void*)(((uintptr_t)(ptr)) | CACHE_SPECIAL))
475
476 #define DECODE_SPECIAL_CACHE_PTR(ptr) \
477 ((void*)(((uintptr_t)(ptr)) & ~CACHE_SPECIAL))
478
479 #define SKIP_EXT_OPLINE(opline) do { \
480 while (UNEXPECTED((opline)->opcode >= ZEND_EXT_STMT \
481 && (opline)->opcode <= ZEND_TICKS)) { \
482 (opline)--; \
483 } \
484 } while (0)
485
486 #define ZEND_CLASS_HAS_TYPE_HINTS(ce) ((ce->ce_flags & ZEND_ACC_HAS_TYPE_HINTS) == ZEND_ACC_HAS_TYPE_HINTS)
487 #define ZEND_CLASS_HAS_READONLY_PROPS(ce) ((ce->ce_flags & ZEND_ACC_HAS_READONLY_PROPS) == ZEND_ACC_HAS_READONLY_PROPS)
488
489
490 ZEND_API bool zend_verify_class_constant_type(zend_class_constant *c, const zend_string *name, zval *constant);
491 ZEND_COLD void zend_verify_class_constant_type_error(const zend_class_constant *c, const zend_string *name, const zval *constant);
492
493 ZEND_API bool zend_verify_property_type(const zend_property_info *info, zval *property, bool strict);
494 ZEND_COLD void zend_verify_property_type_error(const zend_property_info *info, const zval *property);
495 ZEND_COLD void zend_magic_get_property_type_inconsistency_error(const zend_property_info *info, const zval *property);
496
497 #define ZEND_REF_ADD_TYPE_SOURCE(ref, source) \
498 zend_ref_add_type_source(&ZEND_REF_TYPE_SOURCES(ref), source)
499
500 #define ZEND_REF_DEL_TYPE_SOURCE(ref, source) \
501 zend_ref_del_type_source(&ZEND_REF_TYPE_SOURCES(ref), source)
502
503 #define ZEND_REF_FOREACH_TYPE_SOURCES(ref, prop) do { \
504 zend_property_info_source_list *_source_list = &ZEND_REF_TYPE_SOURCES(ref); \
505 zend_property_info **_prop, **_end; \
506 zend_property_info_list *_list; \
507 if (_source_list->ptr) { \
508 if (ZEND_PROPERTY_INFO_SOURCE_IS_LIST(_source_list->list)) { \
509 _list = ZEND_PROPERTY_INFO_SOURCE_TO_LIST(_source_list->list); \
510 _prop = _list->ptr; \
511 _end = _list->ptr + _list->num; \
512 } else { \
513 _prop = &_source_list->ptr; \
514 _end = _prop + 1; \
515 } \
516 for (; _prop < _end; _prop++) { \
517 prop = *_prop; \
518
519 #define ZEND_REF_FOREACH_TYPE_SOURCES_END() \
520 } \
521 } \
522 } while (0)
523
524 ZEND_COLD void zend_match_unhandled_error(const zval *value);
525
zend_get_bad_ptr(void)526 static zend_always_inline void *zend_get_bad_ptr(void)
527 {
528 ZEND_UNREACHABLE();
529 return NULL;
530 }
531
532 END_EXTERN_C()
533
534 #endif /* ZEND_EXECUTE_H */
535