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