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