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