/src/php-src/Zend/zend_execute.c
Line | Count | Source |
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 | | #define ZEND_INTENSIVE_DEBUGGING 0 |
22 | | |
23 | | #include <stdio.h> |
24 | | #include <signal.h> |
25 | | |
26 | | #include "zend.h" |
27 | | #include "zend_compile.h" |
28 | | #include "zend_execute.h" |
29 | | #include "zend_API.h" |
30 | | #include "zend_ptr_stack.h" |
31 | | #include "zend_constants.h" |
32 | | #include "zend_extensions.h" |
33 | | #include "zend_ini.h" |
34 | | #include "zend_exceptions.h" |
35 | | #include "zend_interfaces.h" |
36 | | #include "zend_closures.h" |
37 | | #include "zend_generators.h" |
38 | | #include "zend_vm.h" |
39 | | #include "zend_dtrace.h" |
40 | | #include "zend_inheritance.h" |
41 | | #include "zend_type_info.h" |
42 | | #include "zend_smart_str.h" |
43 | | #include "zend_observer.h" |
44 | | #include "zend_system_id.h" |
45 | | #include "zend_call_stack.h" |
46 | | #include "zend_attributes.h" |
47 | | #include "Optimizer/zend_func_info.h" |
48 | | |
49 | | /* Virtual current working directory support */ |
50 | | #include "zend_virtual_cwd.h" |
51 | | |
52 | | #ifdef HAVE_GCC_GLOBAL_REGS |
53 | | # if defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(i386) |
54 | | # define ZEND_VM_FP_GLOBAL_REG "%esi" |
55 | | # define ZEND_VM_IP_GLOBAL_REG "%edi" |
56 | | # elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__x86_64__) |
57 | | # define ZEND_VM_FP_GLOBAL_REG "%r14" |
58 | | # define ZEND_VM_IP_GLOBAL_REG "%r15" |
59 | | # elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__powerpc64__) |
60 | | # define ZEND_VM_FP_GLOBAL_REG "r14" |
61 | | # define ZEND_VM_IP_GLOBAL_REG "r15" |
62 | | # elif defined(__IBMC__) && ZEND_GCC_VERSION >= 4002 && defined(__powerpc64__) |
63 | | # define ZEND_VM_FP_GLOBAL_REG "r14" |
64 | | # define ZEND_VM_IP_GLOBAL_REG "r15" |
65 | | # elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__aarch64__) |
66 | | # define ZEND_VM_FP_GLOBAL_REG "x27" |
67 | | # define ZEND_VM_IP_GLOBAL_REG "x28" |
68 | | #elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__riscv) && __riscv_xlen == 64 |
69 | | # define ZEND_VM_FP_GLOBAL_REG "x18" |
70 | | # define ZEND_VM_IP_GLOBAL_REG "x19" |
71 | | # endif |
72 | | #endif |
73 | | |
74 | | #if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
75 | | # pragma GCC diagnostic ignored "-Wvolatile-register-var" |
76 | | register zend_execute_data* volatile execute_data __asm__(ZEND_VM_FP_GLOBAL_REG); |
77 | | # pragma GCC diagnostic warning "-Wvolatile-register-var" |
78 | | #endif |
79 | | |
80 | | #if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
81 | | # define EXECUTE_DATA_D void |
82 | | # define EXECUTE_DATA_C |
83 | | # define EXECUTE_DATA_DC |
84 | | # define EXECUTE_DATA_CC |
85 | | # define NO_EXECUTE_DATA_CC |
86 | | #else |
87 | | # define EXECUTE_DATA_D zend_execute_data* execute_data |
88 | 8.58M | # define EXECUTE_DATA_C execute_data |
89 | | # define EXECUTE_DATA_DC , EXECUTE_DATA_D |
90 | 7.40M | # define EXECUTE_DATA_CC , EXECUTE_DATA_C |
91 | 357 | # define NO_EXECUTE_DATA_CC , NULL |
92 | | #endif |
93 | | |
94 | | #if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
95 | | # define OPLINE_D void |
96 | | # define OPLINE_C |
97 | | # define OPLINE_DC |
98 | | # define OPLINE_CC |
99 | | #else |
100 | | # define OPLINE_D const zend_op* opline |
101 | 1.57M | # define OPLINE_C opline |
102 | | # define OPLINE_DC , OPLINE_D |
103 | 1.57M | # define OPLINE_CC , OPLINE_C |
104 | | #endif |
105 | | |
106 | | #if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
107 | | # pragma GCC diagnostic ignored "-Wvolatile-register-var" |
108 | | register const zend_op* volatile opline __asm__(ZEND_VM_IP_GLOBAL_REG); |
109 | | # pragma GCC diagnostic warning "-Wvolatile-register-var" |
110 | | #else |
111 | | #endif |
112 | | |
113 | 40.0M | #define _CONST_CODE 0 |
114 | 40.0M | #define _TMP_CODE 1 |
115 | 40.0M | #define _VAR_CODE 2 |
116 | 200M | #define _UNUSED_CODE 3 |
117 | 40.0M | #define _CV_CODE 4 |
118 | | |
119 | | typedef int (ZEND_FASTCALL *incdec_t)(zval *); |
120 | | |
121 | 1.47k | #define get_zval_ptr(op_type, node, type) _get_zval_ptr(op_type, node, type EXECUTE_DATA_CC OPLINE_CC) |
122 | 46 | #define get_zval_ptr_deref(op_type, node, type) _get_zval_ptr_deref(op_type, node, type EXECUTE_DATA_CC OPLINE_CC) |
123 | 1.76k | #define get_zval_ptr_undef(op_type, node, type) _get_zval_ptr_undef(op_type, node, type EXECUTE_DATA_CC OPLINE_CC) |
124 | 5.70k | #define get_op_data_zval_ptr_r(op_type, node) _get_op_data_zval_ptr_r(op_type, node EXECUTE_DATA_CC OPLINE_CC) |
125 | 0 | #define get_op_data_zval_ptr_deref_r(op_type, node) _get_op_data_zval_ptr_deref_r(op_type, node EXECUTE_DATA_CC OPLINE_CC) |
126 | 234 | #define get_zval_ptr_ptr(op_type, node, type) _get_zval_ptr_ptr(op_type, node, type EXECUTE_DATA_CC) |
127 | | #define get_zval_ptr_ptr_undef(op_type, node, type) _get_zval_ptr_ptr(op_type, node, type EXECUTE_DATA_CC) |
128 | | #define get_obj_zval_ptr(op_type, node, type) _get_obj_zval_ptr(op_type, node, type EXECUTE_DATA_CC OPLINE_CC) |
129 | | #define get_obj_zval_ptr_deref(op_type, node, type) _get_obj_zval_ptr_deref(op_type, node, type EXECUTE_DATA_CC OPLINE_CC) |
130 | | #define get_obj_zval_ptr_undef(op_type, node, type) _get_obj_zval_ptr_undef(op_type, node, type EXECUTE_DATA_CC OPLINE_CC) |
131 | | #define get_obj_zval_ptr_ptr(op_type, node, type) _get_obj_zval_ptr_ptr(op_type, node, type EXECUTE_DATA_CC) |
132 | | |
133 | 575k | #define RETURN_VALUE_USED(opline) ((opline)->result_type != IS_UNUSED) |
134 | | |
135 | | static ZEND_FUNCTION(pass) |
136 | 218 | { |
137 | 218 | } |
138 | | |
139 | | ZEND_BEGIN_ARG_INFO_EX(zend_pass_function_arg_info, 0, 0, 0) |
140 | | ZEND_END_ARG_INFO() |
141 | | |
142 | | ZEND_API const zend_internal_function zend_pass_function = { |
143 | | ZEND_INTERNAL_FUNCTION, /* type */ |
144 | | {0, 0, 0}, /* arg_flags */ |
145 | | 0, /* fn_flags */ |
146 | | NULL, /* name */ |
147 | | NULL, /* scope */ |
148 | | NULL, /* prototype */ |
149 | | 0, /* num_args */ |
150 | | 0, /* required_num_args */ |
151 | | (zend_internal_arg_info *) zend_pass_function_arg_info + 1, /* arg_info */ |
152 | | NULL, /* attributes */ |
153 | | NULL, /* run_time_cache */ |
154 | | NULL, /* doc_comment */ |
155 | | 0, /* T */ |
156 | | NULL, /* prop_info */ |
157 | | ZEND_FN(pass), /* handler */ |
158 | | NULL, /* module */ |
159 | | NULL, /* frameless_function_infos */ |
160 | | {NULL,NULL,NULL,NULL} /* reserved */ |
161 | | }; |
162 | | |
163 | 3.53k | #define FREE_VAR_PTR_AND_EXTRACT_RESULT_IF_NECESSARY(free_var) do { \ |
164 | 3.53k | zval *__container_to_free = EX_VAR(free_var); \ |
165 | 3.53k | if (UNEXPECTED(Z_REFCOUNTED_P(__container_to_free))) { \ |
166 | 293 | zend_refcounted *__ref = Z_COUNTED_P(__container_to_free); \ |
167 | 293 | if (UNEXPECTED(!GC_DELREF(__ref))) { \ |
168 | 157 | zval *__zv = EX_VAR(opline->result.var); \ |
169 | 157 | if (EXPECTED(Z_TYPE_P(__zv) == IS_INDIRECT)) { \ |
170 | 151 | ZVAL_COPY(__zv, Z_INDIRECT_P(__zv)); \ |
171 | 151 | } \ |
172 | 157 | rc_dtor_func(__ref); \ |
173 | 157 | } \ |
174 | 293 | } \ |
175 | 3.53k | } while (0) |
176 | | |
177 | | #define FREE_OP(type, var) \ |
178 | 15.1k | if ((type) & (IS_TMP_VAR|IS_VAR)) { \ |
179 | 6.24k | zval_ptr_dtor_nogc(EX_VAR(var)); \ |
180 | 6.24k | } |
181 | | |
182 | 1.30M | #define CV_DEF_OF(i) (EX(func)->op_array.vars[i]) |
183 | | |
184 | 556k | #define ZEND_VM_STACK_PAGE_SLOTS (16 * 1024) /* should be a power of 2 */ |
185 | | |
186 | 556k | #define ZEND_VM_STACK_PAGE_SIZE (ZEND_VM_STACK_PAGE_SLOTS * sizeof(zval)) |
187 | | |
188 | | #define ZEND_VM_STACK_PAGE_ALIGNED_SIZE(size, page_size) \ |
189 | 63 | (((size) + ZEND_VM_STACK_HEADER_SLOTS * sizeof(zval) \ |
190 | 63 | + ((page_size) - 1)) & ~((page_size) - 1)) |
191 | | |
192 | | ZEND_API void zend_vm_stack_init(void) |
193 | 278k | { |
194 | 278k | EG(vm_stack_page_size) = ZEND_VM_STACK_PAGE_SIZE; |
195 | 278k | EG(vm_stack) = zend_vm_stack_new_page(ZEND_VM_STACK_PAGE_SIZE, NULL); |
196 | 278k | EG(vm_stack_top) = EG(vm_stack)->top; |
197 | 278k | EG(vm_stack_end) = EG(vm_stack)->end; |
198 | 278k | } |
199 | | |
200 | | ZEND_API void zend_vm_stack_init_ex(size_t page_size) |
201 | 0 | { |
202 | | /* page_size must be a power of 2 */ |
203 | 0 | ZEND_ASSERT(page_size > 0 && (page_size & (page_size - 1)) == 0); |
204 | 0 | EG(vm_stack_page_size) = page_size; |
205 | 0 | EG(vm_stack) = zend_vm_stack_new_page(page_size, NULL); |
206 | 0 | EG(vm_stack_top) = EG(vm_stack)->top; |
207 | 0 | EG(vm_stack_end) = EG(vm_stack)->end; |
208 | 0 | } |
209 | | |
210 | | ZEND_API void zend_vm_stack_destroy(void) |
211 | 279k | { |
212 | 279k | zend_vm_stack stack = EG(vm_stack); |
213 | | |
214 | 558k | while (stack != NULL) { |
215 | 279k | zend_vm_stack p = stack->prev; |
216 | 279k | efree(stack); |
217 | 279k | stack = p; |
218 | 279k | } |
219 | 279k | } |
220 | | |
221 | | ZEND_API void* zend_vm_stack_extend(size_t size) |
222 | 64 | { |
223 | 64 | zend_vm_stack stack; |
224 | 64 | void *ptr; |
225 | | |
226 | 64 | stack = EG(vm_stack); |
227 | 64 | stack->top = EG(vm_stack_top); |
228 | 64 | EG(vm_stack) = stack = zend_vm_stack_new_page( |
229 | 64 | EXPECTED(size < EG(vm_stack_page_size) - (ZEND_VM_STACK_HEADER_SLOTS * sizeof(zval))) ? |
230 | 63 | EG(vm_stack_page_size) : ZEND_VM_STACK_PAGE_ALIGNED_SIZE(size, EG(vm_stack_page_size)), |
231 | 64 | stack); |
232 | 64 | ptr = stack->top; |
233 | 64 | EG(vm_stack_top) = (void*)(((char*)ptr) + size); |
234 | 64 | EG(vm_stack_end) = stack->end; |
235 | 64 | return ptr; |
236 | 64 | } |
237 | | |
238 | | ZEND_API zval* zend_get_compiled_variable_value(const zend_execute_data *execute_data, uint32_t var) |
239 | 0 | { |
240 | 0 | return EX_VAR(var); |
241 | 0 | } |
242 | | |
243 | | ZEND_API bool zend_gcc_global_regs(void) |
244 | 0 | { |
245 | | #if defined(HAVE_GCC_GLOBAL_REGS) |
246 | | return 1; |
247 | | #else |
248 | 0 | return 0; |
249 | 0 | #endif |
250 | 0 | } |
251 | | |
252 | | static zend_always_inline zval *_get_zval_ptr_tmp(uint32_t var EXECUTE_DATA_DC) |
253 | 819k | { |
254 | 819k | zval *ret = EX_VAR(var); |
255 | | |
256 | 819k | ZEND_ASSERT(Z_TYPE_P(ret) != IS_REFERENCE); |
257 | | |
258 | 819k | return ret; |
259 | 819k | } |
260 | | |
261 | | static zend_always_inline zval *_get_zval_ptr_var(uint32_t var EXECUTE_DATA_DC) |
262 | 2.86M | { |
263 | 2.86M | zval *ret = EX_VAR(var); |
264 | | |
265 | 2.86M | return ret; |
266 | 2.86M | } |
267 | | |
268 | | static zend_always_inline zval *_get_zval_ptr_var_deref(uint32_t var EXECUTE_DATA_DC) |
269 | 1.39k | { |
270 | 1.39k | zval *ret = EX_VAR(var); |
271 | | |
272 | 1.39k | ZVAL_DEREF(ret); |
273 | 1.39k | return ret; |
274 | 1.39k | } |
275 | | |
276 | | static zend_never_inline ZEND_COLD zval* zval_undefined_cv(uint32_t var EXECUTE_DATA_DC) |
277 | 1.30M | { |
278 | 1.30M | if (EXPECTED(EG(exception) == NULL)) { |
279 | 1.30M | zend_string *cv = CV_DEF_OF(EX_VAR_TO_NUM(var)); |
280 | 1.30M | zend_error_unchecked(E_WARNING, "Undefined variable $%S", cv); |
281 | 1.30M | } |
282 | 1.30M | return &EG(uninitialized_zval); |
283 | 1.30M | } |
284 | | |
285 | | static zend_never_inline ZEND_COLD zval* ZEND_FASTCALL _zval_undefined_op1(EXECUTE_DATA_D) |
286 | 796k | { |
287 | 796k | return zval_undefined_cv(EX(opline)->op1.var EXECUTE_DATA_CC); |
288 | 796k | } |
289 | | |
290 | | static zend_never_inline ZEND_COLD zval* ZEND_FASTCALL _zval_undefined_op2(EXECUTE_DATA_D) |
291 | 376k | { |
292 | 376k | return zval_undefined_cv(EX(opline)->op2.var EXECUTE_DATA_CC); |
293 | 376k | } |
294 | | |
295 | 796k | #define ZVAL_UNDEFINED_OP1() _zval_undefined_op1(EXECUTE_DATA_C) |
296 | 376k | #define ZVAL_UNDEFINED_OP2() _zval_undefined_op2(EXECUTE_DATA_C) |
297 | | |
298 | | static zend_never_inline ZEND_COLD zval *_get_zval_cv_lookup(zval *ptr, uint32_t var, int type EXECUTE_DATA_DC) |
299 | 68 | { |
300 | 68 | switch (type) { |
301 | 68 | case BP_VAR_R: |
302 | 68 | case BP_VAR_UNSET: |
303 | 68 | ptr = zval_undefined_cv(var EXECUTE_DATA_CC); |
304 | 68 | break; |
305 | 0 | case BP_VAR_IS: |
306 | 0 | ptr = &EG(uninitialized_zval); |
307 | 0 | break; |
308 | 0 | case BP_VAR_RW: |
309 | 0 | zval_undefined_cv(var EXECUTE_DATA_CC); |
310 | 0 | ZEND_FALLTHROUGH; |
311 | 0 | case BP_VAR_W: |
312 | 0 | ZVAL_NULL(ptr); |
313 | 0 | break; |
314 | 68 | } |
315 | 68 | return ptr; |
316 | 68 | } |
317 | | |
318 | | static zend_always_inline zval *_get_zval_ptr_cv(uint32_t var, int type EXECUTE_DATA_DC) |
319 | 1.05k | { |
320 | 1.05k | zval *ret = EX_VAR(var); |
321 | | |
322 | 1.05k | if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) { |
323 | 39 | if (type == BP_VAR_W) { |
324 | 12 | ZVAL_NULL(ret); |
325 | 27 | } else { |
326 | 27 | return _get_zval_cv_lookup(ret, var, type EXECUTE_DATA_CC); |
327 | 27 | } |
328 | 39 | } |
329 | 1.03k | return ret; |
330 | 1.05k | } |
331 | | |
332 | | static zend_always_inline zval *_get_zval_ptr_cv_deref(uint32_t var, int type EXECUTE_DATA_DC) |
333 | 288 | { |
334 | 288 | zval *ret = EX_VAR(var); |
335 | | |
336 | 288 | if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) { |
337 | 41 | if (type == BP_VAR_W) { |
338 | 0 | ZVAL_NULL(ret); |
339 | 0 | return ret; |
340 | 41 | } else { |
341 | 41 | return _get_zval_cv_lookup(ret, var, type EXECUTE_DATA_CC); |
342 | 41 | } |
343 | 41 | } |
344 | 247 | ZVAL_DEREF(ret); |
345 | 247 | return ret; |
346 | 288 | } |
347 | | |
348 | | static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_R(uint32_t var EXECUTE_DATA_DC) |
349 | 83.9k | { |
350 | 83.9k | zval *ret = EX_VAR(var); |
351 | | |
352 | 83.9k | if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) { |
353 | 9.58k | return zval_undefined_cv(var EXECUTE_DATA_CC); |
354 | 9.58k | } |
355 | 74.3k | return ret; |
356 | 83.9k | } |
357 | | |
358 | | static zend_always_inline zval *_get_zval_ptr_cv_deref_BP_VAR_R(uint32_t var EXECUTE_DATA_DC) |
359 | 24.0k | { |
360 | 24.0k | zval *ret = EX_VAR(var); |
361 | | |
362 | 24.0k | if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) { |
363 | 1.95k | return zval_undefined_cv(var EXECUTE_DATA_CC); |
364 | 1.95k | } |
365 | 22.0k | ZVAL_DEREF(ret); |
366 | 22.0k | return ret; |
367 | 24.0k | } |
368 | | |
369 | | static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_IS(uint32_t var EXECUTE_DATA_DC) |
370 | 1.28k | { |
371 | 1.28k | zval *ret = EX_VAR(var); |
372 | | |
373 | 1.28k | return ret; |
374 | 1.28k | } |
375 | | |
376 | | static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_RW(uint32_t var EXECUTE_DATA_DC) |
377 | 1.47M | { |
378 | 1.47M | zval *ret = EX_VAR(var); |
379 | | |
380 | 1.47M | if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) { |
381 | 117k | zval_undefined_cv(var EXECUTE_DATA_CC); |
382 | 117k | ZVAL_NULL(ret); |
383 | 117k | return ret; |
384 | 117k | } |
385 | 1.35M | return ret; |
386 | 1.47M | } |
387 | | |
388 | | static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_W(uint32_t var EXECUTE_DATA_DC) |
389 | 19.9k | { |
390 | 19.9k | zval *ret = EX_VAR(var); |
391 | | |
392 | 19.9k | if (Z_TYPE_P(ret) == IS_UNDEF) { |
393 | 1.27k | ZVAL_NULL(ret); |
394 | 1.27k | } |
395 | 19.9k | return ret; |
396 | 19.9k | } |
397 | | |
398 | | static zend_always_inline zval *_get_zval_ptr_tmpvarcv(int op_type, znode_op node, int type EXECUTE_DATA_DC) |
399 | 351 | { |
400 | 351 | if (op_type & (IS_TMP_VAR|IS_VAR)) { |
401 | 121 | if (op_type == IS_TMP_VAR) { |
402 | 31 | return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC); |
403 | 90 | } else { |
404 | 90 | ZEND_ASSERT(op_type == IS_VAR); |
405 | 90 | return _get_zval_ptr_var_deref(node.var EXECUTE_DATA_CC); |
406 | 90 | } |
407 | 230 | } else { |
408 | 230 | ZEND_ASSERT(op_type == IS_CV); |
409 | 230 | return _get_zval_ptr_cv_deref(node.var, type EXECUTE_DATA_CC); |
410 | 230 | } |
411 | 351 | } |
412 | | |
413 | | static zend_always_inline zval *_get_zval_ptr(int op_type, znode_op node, int type EXECUTE_DATA_DC OPLINE_DC) |
414 | 1.47k | { |
415 | 1.47k | if (op_type & (IS_TMP_VAR|IS_VAR)) { |
416 | 238 | if (!ZEND_DEBUG || op_type == IS_VAR) { |
417 | 91 | return _get_zval_ptr_var(node.var EXECUTE_DATA_CC); |
418 | 147 | } else { |
419 | 147 | ZEND_ASSERT(op_type == IS_TMP_VAR); |
420 | 147 | return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC); |
421 | 147 | } |
422 | 1.23k | } else { |
423 | 1.23k | if (op_type == IS_CONST) { |
424 | 232 | return RT_CONSTANT(opline, node); |
425 | 1.00k | } else if (op_type == IS_CV) { |
426 | 1.00k | return _get_zval_ptr_cv(node.var, type EXECUTE_DATA_CC); |
427 | 1.00k | } else { |
428 | 0 | return NULL; |
429 | 0 | } |
430 | 1.23k | } |
431 | 1.47k | } |
432 | | |
433 | | static zend_always_inline zval *_get_op_data_zval_ptr_r(int op_type, znode_op node EXECUTE_DATA_DC OPLINE_DC) |
434 | 5.89k | { |
435 | 5.89k | if (op_type & (IS_TMP_VAR|IS_VAR)) { |
436 | 855 | if (!ZEND_DEBUG || op_type == IS_VAR) { |
437 | 38 | return _get_zval_ptr_var(node.var EXECUTE_DATA_CC); |
438 | 817 | } else { |
439 | 817 | ZEND_ASSERT(op_type == IS_TMP_VAR); |
440 | 817 | return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC); |
441 | 817 | } |
442 | 5.04k | } else { |
443 | 5.04k | if (op_type == IS_CONST) { |
444 | 3.87k | return RT_CONSTANT(opline + 1, node); |
445 | 3.87k | } else if (op_type == IS_CV) { |
446 | 1.17k | return _get_zval_ptr_cv_BP_VAR_R(node.var EXECUTE_DATA_CC); |
447 | 1.17k | } else { |
448 | 0 | return NULL; |
449 | 0 | } |
450 | 5.04k | } |
451 | 5.89k | } |
452 | | |
453 | | static zend_always_inline ZEND_ATTRIBUTE_UNUSED zval *_get_zval_ptr_deref(int op_type, znode_op node, int type EXECUTE_DATA_DC OPLINE_DC) |
454 | 309 | { |
455 | 309 | if (op_type & (IS_TMP_VAR|IS_VAR)) { |
456 | 243 | if (op_type == IS_TMP_VAR) { |
457 | 143 | return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC); |
458 | 143 | } else { |
459 | 100 | ZEND_ASSERT(op_type == IS_VAR); |
460 | 100 | return _get_zval_ptr_var_deref(node.var EXECUTE_DATA_CC); |
461 | 100 | } |
462 | 243 | } else { |
463 | 66 | if (op_type == IS_CONST) { |
464 | 8 | return RT_CONSTANT(opline, node); |
465 | 58 | } else if (op_type == IS_CV) { |
466 | 58 | return _get_zval_ptr_cv_deref(node.var, type EXECUTE_DATA_CC); |
467 | 58 | } else { |
468 | 0 | return NULL; |
469 | 0 | } |
470 | 66 | } |
471 | 309 | } |
472 | | |
473 | | static zend_always_inline ZEND_ATTRIBUTE_UNUSED zval *_get_op_data_zval_ptr_deref_r(int op_type, znode_op node EXECUTE_DATA_DC OPLINE_DC) |
474 | 0 | { |
475 | 0 | if (op_type & (IS_TMP_VAR|IS_VAR)) { |
476 | 0 | if (op_type == IS_TMP_VAR) { |
477 | 0 | return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC); |
478 | 0 | } else { |
479 | 0 | ZEND_ASSERT(op_type == IS_VAR); |
480 | 0 | return _get_zval_ptr_var_deref(node.var EXECUTE_DATA_CC); |
481 | 0 | } |
482 | 0 | } else { |
483 | 0 | if (op_type == IS_CONST) { |
484 | 0 | return RT_CONSTANT(opline + 1, node); |
485 | 0 | } else if (op_type == IS_CV) { |
486 | 0 | return _get_zval_ptr_cv_deref_BP_VAR_R(node.var EXECUTE_DATA_CC); |
487 | 0 | } else { |
488 | 0 | return NULL; |
489 | 0 | } |
490 | 0 | } |
491 | 0 | } |
492 | | |
493 | | static zend_always_inline zval *_get_zval_ptr_undef(int op_type, znode_op node, int type EXECUTE_DATA_DC OPLINE_DC) |
494 | 1.76k | { |
495 | 1.76k | if (op_type & (IS_TMP_VAR|IS_VAR)) { |
496 | 304 | if (!ZEND_DEBUG || op_type == IS_VAR) { |
497 | 282 | return _get_zval_ptr_var(node.var EXECUTE_DATA_CC); |
498 | 282 | } else { |
499 | 22 | ZEND_ASSERT(op_type == IS_TMP_VAR); |
500 | 22 | return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC); |
501 | 22 | } |
502 | 1.45k | } else { |
503 | 1.45k | if (op_type == IS_CONST) { |
504 | 398 | return RT_CONSTANT(opline, node); |
505 | 1.05k | } else if (op_type == IS_CV) { |
506 | 1.05k | return EX_VAR(node.var); |
507 | 1.05k | } else { |
508 | 0 | return NULL; |
509 | 0 | } |
510 | 1.45k | } |
511 | 1.76k | } |
512 | | |
513 | | static zend_always_inline zval *_get_zval_ptr_ptr_var(uint32_t var EXECUTE_DATA_DC) |
514 | 61.4k | { |
515 | 61.4k | zval *ret = EX_VAR(var); |
516 | | |
517 | 61.4k | if (EXPECTED(Z_TYPE_P(ret) == IS_INDIRECT)) { |
518 | 55.4k | ret = Z_INDIRECT_P(ret); |
519 | 55.4k | } |
520 | 61.4k | return ret; |
521 | 61.4k | } |
522 | | |
523 | | static inline zval *_get_zval_ptr_ptr(int op_type, znode_op node, int type EXECUTE_DATA_DC) |
524 | 234 | { |
525 | 234 | if (op_type == IS_CV) { |
526 | 54 | return _get_zval_ptr_cv(node.var, type EXECUTE_DATA_CC); |
527 | 180 | } else /* if (op_type == IS_VAR) */ { |
528 | 180 | ZEND_ASSERT(op_type == IS_VAR); |
529 | 180 | return _get_zval_ptr_ptr_var(node.var EXECUTE_DATA_CC); |
530 | 180 | } |
531 | 234 | } |
532 | | |
533 | | static inline ZEND_ATTRIBUTE_UNUSED zval *_get_obj_zval_ptr(int op_type, znode_op op, int type EXECUTE_DATA_DC OPLINE_DC) |
534 | 0 | { |
535 | 0 | if (op_type == IS_UNUSED) { |
536 | 0 | return &EX(This); |
537 | 0 | } |
538 | 0 | return get_zval_ptr(op_type, op, type); |
539 | 0 | } |
540 | | |
541 | | static inline ZEND_ATTRIBUTE_UNUSED zval *_get_obj_zval_ptr_deref(int op_type, znode_op op, int type EXECUTE_DATA_DC OPLINE_DC) |
542 | 0 | { |
543 | 0 | if (op_type == IS_UNUSED) { |
544 | 0 | return &EX(This); |
545 | 0 | } |
546 | 0 | return get_zval_ptr_deref(op_type, op, type); |
547 | 0 | } |
548 | | |
549 | | static inline ZEND_ATTRIBUTE_UNUSED zval *_get_obj_zval_ptr_undef(int op_type, znode_op op, int type EXECUTE_DATA_DC OPLINE_DC) |
550 | 0 | { |
551 | 0 | if (op_type == IS_UNUSED) { |
552 | 0 | return &EX(This); |
553 | 0 | } |
554 | 0 | return get_zval_ptr_undef(op_type, op, type); |
555 | 0 | } |
556 | | |
557 | | static inline ZEND_ATTRIBUTE_UNUSED zval *_get_obj_zval_ptr_ptr(int op_type, znode_op node, int type EXECUTE_DATA_DC) |
558 | 0 | { |
559 | 0 | if (op_type == IS_UNUSED) { |
560 | 0 | return &EX(This); |
561 | 0 | } |
562 | 0 | return get_zval_ptr_ptr(op_type, node, type); |
563 | 0 | } |
564 | | |
565 | | static inline void zend_assign_to_variable_reference(zval *variable_ptr, zval *value_ptr, zend_refcounted **garbage_ptr) |
566 | 17.5k | { |
567 | 17.5k | zend_reference *ref; |
568 | | |
569 | 17.5k | if (EXPECTED(!Z_ISREF_P(value_ptr))) { |
570 | 5.63k | ZVAL_NEW_REF(value_ptr, value_ptr); |
571 | 11.8k | } else if (UNEXPECTED(variable_ptr == value_ptr)) { |
572 | 2.27k | return; |
573 | 2.27k | } |
574 | | |
575 | 15.2k | ref = Z_REF_P(value_ptr); |
576 | 15.2k | GC_ADDREF(ref); |
577 | 15.2k | if (Z_REFCOUNTED_P(variable_ptr)) { |
578 | 4.38k | *garbage_ptr = Z_COUNTED_P(variable_ptr); |
579 | 4.38k | } |
580 | 15.2k | ZVAL_REF(variable_ptr, ref); |
581 | 15.2k | } |
582 | | |
583 | | static zend_never_inline zval* zend_assign_to_typed_property_reference(zend_property_info *prop_info, zval *prop, zval *value_ptr, zend_refcounted **garbage_ptr EXECUTE_DATA_DC) |
584 | 679 | { |
585 | 679 | if (!zend_verify_prop_assignable_by_ref(prop_info, value_ptr, EX_USES_STRICT_TYPES())) { |
586 | 126 | return &EG(uninitialized_zval); |
587 | 126 | } |
588 | 553 | if (Z_ISREF_P(prop)) { |
589 | 269 | ZEND_REF_DEL_TYPE_SOURCE(Z_REF_P(prop), prop_info); |
590 | 269 | } |
591 | 553 | zend_assign_to_variable_reference(prop, value_ptr, garbage_ptr); |
592 | 553 | ZEND_REF_ADD_TYPE_SOURCE(Z_REF_P(prop), prop_info); |
593 | 553 | return prop; |
594 | 679 | } |
595 | | |
596 | | static zend_never_inline ZEND_COLD zval *zend_wrong_assign_to_variable_reference(zval *variable_ptr, zval *value_ptr, zend_refcounted **garbage_ptr OPLINE_DC EXECUTE_DATA_DC) |
597 | 56 | { |
598 | 56 | zend_error(E_NOTICE, "Only variables should be assigned by reference"); |
599 | 56 | if (UNEXPECTED(EG(exception) != NULL)) { |
600 | 0 | return &EG(uninitialized_zval); |
601 | 0 | } |
602 | | |
603 | | /* Use IS_TMP_VAR instead of IS_VAR to avoid ISREF check */ |
604 | 56 | Z_TRY_ADDREF_P(value_ptr); |
605 | 56 | return zend_assign_to_variable_ex(variable_ptr, value_ptr, IS_TMP_VAR, EX_USES_STRICT_TYPES(), garbage_ptr); |
606 | 56 | } |
607 | | |
608 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_cannot_pass_by_reference(uint32_t arg_num) |
609 | 118 | { |
610 | 118 | const zend_execute_data *execute_data = EG(current_execute_data); |
611 | 118 | zend_string *func_name = get_function_or_method_name(EX(call)->func); |
612 | 118 | const char *param_name = get_function_arg_name(EX(call)->func, arg_num); |
613 | | |
614 | 118 | zend_throw_error(NULL, "%s(): Argument #%d%s%s%s could not be passed by reference", |
615 | 118 | ZSTR_VAL(func_name), arg_num, param_name ? " ($" : "", param_name ? param_name : "", param_name ? ")" : "" |
616 | 118 | ); |
617 | | |
618 | 118 | zend_string_release(func_name); |
619 | 118 | } |
620 | | |
621 | 21 | static zend_never_inline ZEND_COLD void zend_throw_auto_init_in_prop_error(const zend_property_info *prop) { |
622 | 21 | zend_string *type_str = zend_type_to_string(prop->type); |
623 | 21 | zend_type_error( |
624 | 21 | "Cannot auto-initialize an array inside property %s::$%s of type %s", |
625 | 21 | ZSTR_VAL(prop->ce->name), zend_get_unmangled_property_name(prop->name), |
626 | 21 | ZSTR_VAL(type_str) |
627 | 21 | ); |
628 | 21 | zend_string_release(type_str); |
629 | 21 | } |
630 | | |
631 | 10 | static zend_never_inline ZEND_COLD void zend_throw_auto_init_in_ref_error(const zend_property_info *prop) { |
632 | 10 | zend_string *type_str = zend_type_to_string(prop->type); |
633 | 10 | zend_type_error( |
634 | 10 | "Cannot auto-initialize an array inside a reference held by property %s::$%s of type %s", |
635 | 10 | ZSTR_VAL(prop->ce->name), zend_get_unmangled_property_name(prop->name), |
636 | 10 | ZSTR_VAL(type_str) |
637 | 10 | ); |
638 | 10 | zend_string_release(type_str); |
639 | 10 | } |
640 | | |
641 | | static zend_never_inline ZEND_COLD void zend_throw_access_uninit_prop_by_ref_error( |
642 | 18 | const zend_property_info *prop) { |
643 | 18 | zend_throw_error(NULL, |
644 | 18 | "Cannot access uninitialized non-nullable property %s::$%s by reference", |
645 | 18 | ZSTR_VAL(prop->ce->name), |
646 | 18 | zend_get_unmangled_property_name(prop->name)); |
647 | 18 | } |
648 | | |
649 | | /* this should modify object only if it's empty */ |
650 | | static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_throw_non_object_error(const zval *object, zval *property OPLINE_DC EXECUTE_DATA_DC) |
651 | 574 | { |
652 | 574 | zend_string *tmp_property_name; |
653 | 574 | zend_string *property_name = zval_get_tmp_string(property, &tmp_property_name); |
654 | | |
655 | 574 | if (opline->opcode == ZEND_PRE_INC_OBJ |
656 | 525 | || opline->opcode == ZEND_PRE_DEC_OBJ |
657 | 510 | || opline->opcode == ZEND_POST_INC_OBJ |
658 | 485 | || opline->opcode == ZEND_POST_DEC_OBJ) { |
659 | 94 | zend_throw_error(NULL, |
660 | 94 | "Attempt to increment/decrement property \"%s\" on %s", |
661 | 94 | ZSTR_VAL(property_name), zend_zval_value_name(object) |
662 | 94 | ); |
663 | 480 | } else if (opline->opcode == ZEND_FETCH_OBJ_W |
664 | 394 | || opline->opcode == ZEND_FETCH_OBJ_RW |
665 | 368 | || opline->opcode == ZEND_FETCH_OBJ_FUNC_ARG |
666 | 368 | || opline->opcode == ZEND_ASSIGN_OBJ_REF) { |
667 | 148 | zend_throw_error(NULL, |
668 | 148 | "Attempt to modify property \"%s\" on %s", |
669 | 148 | ZSTR_VAL(property_name), zend_zval_value_name(object) |
670 | 148 | ); |
671 | 332 | } else { |
672 | 332 | zend_throw_error(NULL, |
673 | 332 | "Attempt to assign property \"%s\" on %s", |
674 | 332 | ZSTR_VAL(property_name), zend_zval_value_name(object) |
675 | 332 | ); |
676 | 332 | } |
677 | 574 | zend_tmp_string_release(tmp_property_name); |
678 | | |
679 | 574 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
680 | 260 | ZVAL_NULL(EX_VAR(opline->result.var)); |
681 | 260 | } |
682 | 574 | } |
683 | | |
684 | | static ZEND_COLD void zend_verify_type_error_common( |
685 | | const zend_function *zf, const zend_arg_info *arg_info, const zval *value, |
686 | | const char **fname, const char **fsep, const char **fclass, |
687 | | zend_string **need_msg, const char **given_kind) |
688 | 1.04k | { |
689 | 1.04k | *fname = ZSTR_VAL(zf->common.function_name); |
690 | 1.04k | if (zf->common.scope) { |
691 | 287 | *fsep = "::"; |
692 | 287 | *fclass = ZSTR_VAL(zf->common.scope->name); |
693 | 759 | } else { |
694 | 759 | *fsep = ""; |
695 | 759 | *fclass = ""; |
696 | 759 | } |
697 | | |
698 | 1.04k | *need_msg = zend_type_to_string_resolved(arg_info->type, zf->common.scope); |
699 | | |
700 | 1.04k | if (value) { |
701 | 940 | *given_kind = zend_zval_value_name(value); |
702 | 940 | } else { |
703 | 106 | *given_kind = "none"; |
704 | 106 | } |
705 | 1.04k | } |
706 | | |
707 | | ZEND_API ZEND_COLD void zend_verify_arg_error( |
708 | | const zend_function *zf, const zend_arg_info *arg_info, uint32_t arg_num, const zval *value) |
709 | 684 | { |
710 | 684 | const zend_execute_data *ptr = EG(current_execute_data)->prev_execute_data; |
711 | 684 | const char *fname, *fsep, *fclass; |
712 | 684 | zend_string *need_msg; |
713 | 684 | const char *given_msg; |
714 | | |
715 | 684 | zend_verify_type_error_common( |
716 | 684 | zf, arg_info, value, &fname, &fsep, &fclass, &need_msg, &given_msg); |
717 | | |
718 | 684 | ZEND_ASSERT(zf->common.type == ZEND_USER_FUNCTION |
719 | 684 | && "Arginfo verification is not performed for internal functions"); |
720 | 684 | if (ptr && ptr->func && ZEND_USER_CODE(ptr->func->common.type)) { |
721 | 664 | zend_argument_type_error(arg_num, "must be of type %s, %s given, called in %s on line %d", |
722 | 664 | ZSTR_VAL(need_msg), given_msg, |
723 | 664 | ZSTR_VAL(ptr->func->op_array.filename), ptr->opline->lineno |
724 | 664 | ); |
725 | 664 | } else { |
726 | 20 | zend_argument_type_error(arg_num, |
727 | 20 | "must be of type %s, %s given", ZSTR_VAL(need_msg), given_msg); |
728 | 20 | } |
729 | | |
730 | 684 | zend_string_release(need_msg); |
731 | 684 | } |
732 | | |
733 | | static bool zend_verify_weak_scalar_type_hint(uint32_t type_mask, zval *arg) |
734 | 2.62k | { |
735 | 2.62k | zend_long lval; |
736 | 2.62k | double dval; |
737 | 2.62k | zend_string *str; |
738 | 2.62k | bool bval; |
739 | | |
740 | | /* Type preference order: int -> float -> string -> bool */ |
741 | 2.62k | if (type_mask & MAY_BE_LONG) { |
742 | | /* For an int|float union type and string value, |
743 | | * determine chosen type by is_numeric_string() semantics. */ |
744 | 1.19k | if ((type_mask & MAY_BE_DOUBLE) && Z_TYPE_P(arg) == IS_STRING) { |
745 | 31 | uint8_t type = is_numeric_str_function(Z_STR_P(arg), &lval, &dval); |
746 | 31 | if (type == IS_LONG) { |
747 | 6 | zend_string_release(Z_STR_P(arg)); |
748 | 6 | ZVAL_LONG(arg, lval); |
749 | 6 | return true; |
750 | 6 | } |
751 | 25 | if (type == IS_DOUBLE) { |
752 | 8 | zend_string_release(Z_STR_P(arg)); |
753 | 8 | ZVAL_DOUBLE(arg, dval); |
754 | 8 | return true; |
755 | 8 | } |
756 | 1.16k | } else if (zend_parse_arg_long_weak(arg, &lval, 0)) { |
757 | 709 | zval_ptr_dtor(arg); |
758 | 709 | ZVAL_LONG(arg, lval); |
759 | 709 | return true; |
760 | 709 | } else if (UNEXPECTED(EG(exception))) { |
761 | 0 | return false; |
762 | 0 | } |
763 | 1.19k | } |
764 | 1.89k | if ((type_mask & MAY_BE_DOUBLE) && zend_parse_arg_double_weak(arg, &dval, 0)) { |
765 | 190 | zval_ptr_dtor(arg); |
766 | 190 | ZVAL_DOUBLE(arg, dval); |
767 | 190 | return true; |
768 | 190 | } |
769 | 1.70k | if ((type_mask & MAY_BE_STRING) && zend_parse_arg_str_weak(arg, &str, 0)) { |
770 | | /* on success "arg" is converted to IS_STRING */ |
771 | 423 | return true; |
772 | 423 | } |
773 | 1.28k | if ((type_mask & MAY_BE_BOOL) == MAY_BE_BOOL && zend_parse_arg_bool_weak(arg, &bval, 0)) { |
774 | 50 | zval_ptr_dtor(arg); |
775 | 50 | ZVAL_BOOL(arg, bval); |
776 | 50 | return true; |
777 | 50 | } |
778 | 1.23k | return false; |
779 | 1.28k | } |
780 | | |
781 | | #if ZEND_DEBUG |
782 | 3.63k | static bool can_convert_to_string(const zval *zv) { |
783 | | /* We don't call cast_object here, because this check must be side-effect free. As this |
784 | | * is only used for a sanity check of arginfo/zpp consistency, it's okay if we accept |
785 | | * more than actually allowed here. */ |
786 | 3.63k | if (Z_TYPE_P(zv) == IS_OBJECT) { |
787 | 871 | return Z_OBJ_HT_P(zv)->cast_object != zend_std_cast_object_tostring |
788 | 871 | || Z_OBJCE_P(zv)->__tostring; |
789 | 871 | } |
790 | 2.76k | return Z_TYPE_P(zv) <= IS_STRING; |
791 | 3.63k | } |
792 | | |
793 | | /* Used to sanity-check internal arginfo types without performing any actual type conversions. */ |
794 | | static bool zend_verify_weak_scalar_type_hint_no_sideeffect(uint32_t type_mask, const zval *arg) |
795 | 5.85k | { |
796 | 5.85k | zend_long lval; |
797 | 5.85k | double dval; |
798 | 5.85k | bool bval; |
799 | | |
800 | | /* Pass (uint32_t)-1 as arg_num to indicate to ZPP not to emit any deprecation notice, |
801 | | * this is needed because the version with side effects also uses 0 (e.g. for typed properties) */ |
802 | 5.85k | if ((type_mask & MAY_BE_LONG) && zend_parse_arg_long_weak(arg, &lval, (uint32_t)-1)) { |
803 | 348 | return true; |
804 | 348 | } |
805 | 5.51k | if ((type_mask & MAY_BE_DOUBLE) && zend_parse_arg_double_weak(arg, &dval, (uint32_t)-1)) { |
806 | 409 | return true; |
807 | 409 | } |
808 | 5.10k | if ((type_mask & MAY_BE_STRING) && can_convert_to_string(arg)) { |
809 | 3.55k | return true; |
810 | 3.55k | } |
811 | 1.54k | if ((type_mask & MAY_BE_BOOL) == MAY_BE_BOOL && zend_parse_arg_bool_weak(arg, &bval, (uint32_t)-1)) { |
812 | 1.20k | return true; |
813 | 1.20k | } |
814 | 335 | return false; |
815 | 1.54k | } |
816 | | #endif |
817 | | |
818 | | ZEND_API bool zend_verify_scalar_type_hint(uint32_t type_mask, zval *arg, bool strict, bool is_internal_arg) |
819 | 12.8k | { |
820 | 12.8k | if (UNEXPECTED(strict)) { |
821 | | /* SSTH Exception: IS_LONG may be accepted as IS_DOUBLE (converted) */ |
822 | 285 | if (!(type_mask & MAY_BE_DOUBLE) || Z_TYPE_P(arg) != IS_LONG) { |
823 | 280 | return 0; |
824 | 280 | } |
825 | 12.5k | } else if (UNEXPECTED(Z_TYPE_P(arg) == IS_NULL)) { |
826 | | /* NULL may be accepted only by nullable hints (this is already checked). |
827 | | * As an exception for internal functions, null is allowed for scalar types in weak mode. */ |
828 | 4.40k | return is_internal_arg |
829 | 4.19k | && (type_mask & (MAY_BE_TRUE|MAY_BE_FALSE|MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING)); |
830 | 4.40k | } |
831 | 8.14k | #if ZEND_DEBUG |
832 | 8.14k | if (is_internal_arg) { |
833 | 5.85k | return zend_verify_weak_scalar_type_hint_no_sideeffect(type_mask, arg); |
834 | 5.85k | } |
835 | 2.28k | #endif |
836 | 2.28k | return zend_verify_weak_scalar_type_hint(type_mask, arg); |
837 | 8.14k | } |
838 | | |
839 | | ZEND_COLD zend_never_inline void zend_verify_class_constant_type_error(const zend_class_constant *c, const zend_string *name, const zval *constant) |
840 | 62 | { |
841 | 62 | zend_string *type_str = zend_type_to_string(c->type); |
842 | | |
843 | 62 | zend_type_error("Cannot assign %s to class constant %s::%s of type %s", |
844 | 62 | zend_zval_type_name(constant), ZSTR_VAL(c->ce->name), ZSTR_VAL(name), ZSTR_VAL(type_str)); |
845 | | |
846 | 62 | zend_string_release(type_str); |
847 | 62 | } |
848 | | |
849 | | ZEND_COLD zend_never_inline void zend_verify_property_type_error(const zend_property_info *info, const zval *property) |
850 | 594 | { |
851 | 594 | zend_string *type_str; |
852 | | |
853 | | /* we _may_ land here in case reading already errored and runtime cache thus has not been updated (i.e. it contains a valid but unrelated info) */ |
854 | 594 | if (EG(exception)) { |
855 | 16 | return; |
856 | 16 | } |
857 | | |
858 | 578 | type_str = zend_type_to_string(info->type); |
859 | 578 | zend_type_error("Cannot assign %s to property %s::$%s of type %s", |
860 | 578 | zend_zval_value_name(property), |
861 | 578 | ZSTR_VAL(info->ce->name), |
862 | 578 | zend_get_unmangled_property_name(info->name), |
863 | 578 | ZSTR_VAL(type_str)); |
864 | 578 | zend_string_release(type_str); |
865 | 578 | } |
866 | | |
867 | | ZEND_COLD zend_never_inline void zend_magic_get_property_type_inconsistency_error(const zend_property_info *info, const zval *property) |
868 | 18 | { |
869 | | /* we _may_ land here in case reading already errored and runtime cache thus has not been updated (i.e. it contains a valid but unrelated info) */ |
870 | 18 | if (EG(exception)) { |
871 | 2 | return; |
872 | 2 | } |
873 | | |
874 | 16 | zend_string *type_str = zend_type_to_string(info->type); |
875 | 16 | zend_type_error("Value of type %s returned from %s::__get() must be compatible with unset property %s::$%s of type %s", |
876 | 16 | zend_zval_type_name(property), |
877 | 16 | ZSTR_VAL(info->ce->name), |
878 | 16 | ZSTR_VAL(info->ce->name), |
879 | 16 | zend_get_unmangled_property_name(info->name), |
880 | 16 | ZSTR_VAL(type_str)); |
881 | 16 | zend_string_release(type_str); |
882 | 16 | } |
883 | | |
884 | | ZEND_COLD void zend_match_unhandled_error(const zval *value) |
885 | 178 | { |
886 | 178 | zend_long max_len = EG(exception_string_param_max_len); |
887 | 178 | smart_str msg = {0}; |
888 | 178 | if ( |
889 | 178 | EG(exception_ignore_args) |
890 | 178 | || (Z_TYPE_P(value) == IS_STRING && max_len == 0) |
891 | 178 | || smart_str_append_zval(&msg, value, max_len) != SUCCESS |
892 | 178 | ) { |
893 | 13 | smart_str_appendl(&msg, "of type ", sizeof("of type ")-1); |
894 | 13 | smart_str_appends(&msg, zend_zval_type_name(value)); |
895 | 13 | } |
896 | 178 | smart_str_0(&msg); |
897 | | |
898 | 178 | zend_throw_exception_ex( |
899 | 178 | zend_ce_unhandled_match_error, 0, "Unhandled match case %s", ZSTR_VAL(msg.s)); |
900 | | |
901 | 178 | smart_str_free(&msg); |
902 | 178 | } |
903 | | |
904 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_modification_error( |
905 | 247 | const zend_property_info *info) { |
906 | 247 | zend_readonly_property_modification_error_ex( |
907 | 247 | ZSTR_VAL(info->ce->name), zend_get_unmangled_property_name(info->name)); |
908 | 247 | } |
909 | | |
910 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_modification_error_ex( |
911 | 247 | const char *class_name, const char *prop_name) { |
912 | 247 | zend_throw_error(NULL, "Cannot modify readonly property %s::$%s", class_name, prop_name); |
913 | 247 | } |
914 | | |
915 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_indirect_modification_error(const zend_property_info *info) |
916 | 144 | { |
917 | 144 | zend_throw_error(NULL, "Cannot indirectly modify readonly property %s::$%s", |
918 | 144 | ZSTR_VAL(info->ce->name), zend_get_unmangled_property_name(info->name)); |
919 | 144 | } |
920 | | |
921 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_invalid_class_constant_type_error(const uint8_t type) |
922 | 158 | { |
923 | 158 | zend_type_error("Cannot use value of type %s as class constant name", zend_get_type_by_const(type)); |
924 | 158 | } |
925 | | |
926 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_object_released_while_assigning_to_property_error(const zend_property_info *info) |
927 | 12 | { |
928 | 12 | zend_throw_error(NULL, "Object was released while assigning to property %s::$%s", |
929 | 12 | ZSTR_VAL(info->ce->name), zend_get_unmangled_property_name(info->name)); |
930 | 12 | } |
931 | | |
932 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_asymmetric_visibility_property_modification_error( |
933 | | const zend_property_info *prop_info, const char *operation |
934 | 420 | ) { |
935 | 420 | const zend_class_entry *scope; |
936 | 420 | if (EG(fake_scope)) { |
937 | 5 | scope = EG(fake_scope); |
938 | 415 | } else { |
939 | 415 | scope = zend_get_called_scope(EG(current_execute_data)); |
940 | 415 | } |
941 | | |
942 | 420 | const char *visibility; |
943 | 420 | if (prop_info->flags & ZEND_ACC_PRIVATE_SET) { |
944 | 352 | visibility = "private(set)"; |
945 | 352 | } else { |
946 | 68 | ZEND_ASSERT(prop_info->flags & ZEND_ACC_PROTECTED_SET); |
947 | 68 | if (prop_info->flags & ZEND_ACC_READONLY) { |
948 | 48 | visibility = "protected(set) readonly"; |
949 | 48 | } else { |
950 | 20 | visibility = "protected(set)"; |
951 | 20 | } |
952 | 68 | } |
953 | | |
954 | 420 | zend_throw_error(NULL, "Cannot %s %s property %s::$%s from %s%s", |
955 | 420 | operation, |
956 | 420 | visibility, |
957 | 420 | ZSTR_VAL(prop_info->ce->name), |
958 | 420 | ZSTR_VAL(prop_info->name), |
959 | 420 | scope ? "scope " : "global scope", scope ? ZSTR_VAL(scope->name) : ""); |
960 | 420 | } |
961 | | |
962 | 60 | static const zend_class_entry *resolve_single_class_type(zend_string *name, const zend_class_entry *self_ce) { |
963 | 60 | if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_SELF))) { |
964 | 31 | return self_ce; |
965 | 31 | } else if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_PARENT))) { |
966 | 13 | return self_ce->parent; |
967 | 16 | } else { |
968 | 16 | return zend_lookup_class_ex(name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD); |
969 | 16 | } |
970 | 60 | } |
971 | | |
972 | | static zend_always_inline const zend_class_entry *zend_ce_from_type( |
973 | 241k | const zend_class_entry *scope, const zend_type *type) { |
974 | 241k | ZEND_ASSERT(ZEND_TYPE_HAS_NAME(*type)); |
975 | 241k | zend_string *name = ZEND_TYPE_NAME(*type); |
976 | 241k | if (ZSTR_HAS_CE_CACHE(name)) { |
977 | 241k | zend_class_entry *ce = ZSTR_GET_CE_CACHE(name); |
978 | 241k | if (!ce) { |
979 | 1.86k | ce = zend_lookup_class_ex(name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD); |
980 | 1.86k | } |
981 | 241k | return ce; |
982 | 241k | } |
983 | 60 | return resolve_single_class_type(name, scope); |
984 | 241k | } |
985 | | |
986 | | static bool zend_check_intersection_for_property_or_class_constant_class_type( |
987 | | const zend_class_entry *scope, const zend_type_list *intersection_type_list, const zend_class_entry *value_ce) |
988 | 198 | { |
989 | 198 | const zend_type *list_type; |
990 | | |
991 | 580 | ZEND_TYPE_LIST_FOREACH(intersection_type_list, list_type) { |
992 | 580 | ZEND_ASSERT(!ZEND_TYPE_HAS_LIST(*list_type)); |
993 | 580 | const zend_class_entry *ce = zend_ce_from_type(scope, list_type); |
994 | 382 | if (!ce || !instanceof_function(value_ce, ce)) { |
995 | 84 | return false; |
996 | 84 | } |
997 | 382 | } ZEND_TYPE_LIST_FOREACH_END(); |
998 | 114 | return true; |
999 | 198 | } |
1000 | | |
1001 | | static bool zend_check_and_resolve_property_or_class_constant_class_type( |
1002 | 241k | const zend_class_entry *scope, const zend_type member_type, const zend_class_entry *value_ce) { |
1003 | 241k | if (ZEND_TYPE_HAS_LIST(member_type)) { |
1004 | 264 | if (ZEND_TYPE_IS_INTERSECTION(member_type)) { |
1005 | 99 | return zend_check_intersection_for_property_or_class_constant_class_type( |
1006 | 99 | scope, ZEND_TYPE_LIST(member_type), value_ce); |
1007 | 165 | } else { |
1008 | 165 | const zend_type *list_type; |
1009 | 395 | ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(member_type), list_type) { |
1010 | 395 | if (ZEND_TYPE_IS_INTERSECTION(*list_type)) { |
1011 | 99 | if (zend_check_intersection_for_property_or_class_constant_class_type( |
1012 | 99 | scope, ZEND_TYPE_LIST(*list_type), value_ce)) { |
1013 | 69 | return true; |
1014 | 69 | } |
1015 | 30 | continue; |
1016 | 99 | } |
1017 | 131 | ZEND_ASSERT(!ZEND_TYPE_HAS_LIST(*list_type)); |
1018 | 131 | const zend_class_entry *ce = zend_ce_from_type(scope, list_type); |
1019 | 131 | if (ce && instanceof_function(value_ce, ce)) { |
1020 | 59 | return true; |
1021 | 59 | } |
1022 | 131 | } ZEND_TYPE_LIST_FOREACH_END(); |
1023 | | |
1024 | 37 | if ((ZEND_TYPE_PURE_MASK(member_type) & MAY_BE_STATIC)) { |
1025 | 0 | return value_ce == scope; |
1026 | 0 | } |
1027 | | |
1028 | 37 | return false; |
1029 | 37 | } |
1030 | 240k | } else if ((ZEND_TYPE_PURE_MASK(member_type) & MAY_BE_STATIC) && value_ce == scope) { |
1031 | 15 | return true; |
1032 | 240k | } else if (ZEND_TYPE_HAS_NAME(member_type)) { |
1033 | 240k | const zend_class_entry *ce = zend_ce_from_type(scope, &member_type); |
1034 | 240k | return ce && instanceof_function(value_ce, ce); |
1035 | 240k | } |
1036 | | |
1037 | 6 | return false; |
1038 | 241k | } |
1039 | | |
1040 | | static zend_always_inline bool i_zend_check_property_type(const zend_property_info *info, zval *property, bool strict) |
1041 | 294k | { |
1042 | 294k | ZEND_ASSERT(!Z_ISREF_P(property)); |
1043 | 294k | if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(info->type, Z_TYPE_P(property)))) { |
1044 | 70.6k | return 1; |
1045 | 70.6k | } |
1046 | | |
1047 | 223k | if (ZEND_TYPE_IS_COMPLEX(info->type) && Z_TYPE_P(property) == IS_OBJECT |
1048 | 222k | && zend_check_and_resolve_property_or_class_constant_class_type(info->ce, info->type, Z_OBJCE_P(property))) { |
1049 | 222k | return 1; |
1050 | 222k | } |
1051 | | |
1052 | 1.25k | uint32_t type_mask = ZEND_TYPE_FULL_MASK(info->type); |
1053 | 1.25k | ZEND_ASSERT(!(type_mask & (MAY_BE_CALLABLE|MAY_BE_STATIC|MAY_BE_NEVER|MAY_BE_VOID))); |
1054 | 1.25k | return zend_verify_scalar_type_hint(type_mask, property, strict, false); |
1055 | 1.25k | } |
1056 | | |
1057 | | static zend_always_inline bool i_zend_verify_property_type(const zend_property_info *info, zval *property, bool strict) |
1058 | 134k | { |
1059 | 134k | if (i_zend_check_property_type(info, property, strict)) { |
1060 | 133k | return 1; |
1061 | 133k | } |
1062 | | |
1063 | 504 | zend_verify_property_type_error(info, property); |
1064 | 504 | return 0; |
1065 | 134k | } |
1066 | | |
1067 | 132k | ZEND_API bool zend_never_inline zend_verify_property_type(const zend_property_info *info, zval *property, bool strict) { |
1068 | 132k | return i_zend_verify_property_type(info, property, strict); |
1069 | 132k | } |
1070 | | |
1071 | | static zend_never_inline zval* zend_assign_to_typed_prop(const zend_property_info *info, zval *property_val, zval *value, zend_refcounted **garbage_ptr EXECUTE_DATA_DC) |
1072 | 1.92k | { |
1073 | 1.92k | zval tmp; |
1074 | | |
1075 | 1.92k | if (UNEXPECTED(info->flags & (ZEND_ACC_READONLY|ZEND_ACC_PPP_SET_MASK))) { |
1076 | 128 | if ((info->flags & ZEND_ACC_READONLY) && !(Z_PROP_FLAG_P(property_val) & IS_PROP_REINITABLE)) { |
1077 | 31 | zend_readonly_property_modification_error(info); |
1078 | 31 | return &EG(uninitialized_zval); |
1079 | 31 | } |
1080 | 97 | if (info->flags & ZEND_ACC_PPP_SET_MASK && !zend_asymmetric_property_has_set_access(info)) { |
1081 | 16 | zend_asymmetric_visibility_property_modification_error(info, "modify"); |
1082 | 16 | return &EG(uninitialized_zval); |
1083 | 16 | } |
1084 | 97 | } |
1085 | | |
1086 | 1.88k | ZVAL_DEREF(value); |
1087 | 1.88k | ZVAL_COPY(&tmp, value); |
1088 | | |
1089 | 1.88k | if (UNEXPECTED(!i_zend_verify_property_type(info, &tmp, EX_USES_STRICT_TYPES()))) { |
1090 | 78 | zval_ptr_dtor(&tmp); |
1091 | 78 | return &EG(uninitialized_zval); |
1092 | 78 | } |
1093 | | |
1094 | 1.80k | Z_PROP_FLAG_P(property_val) &= ~IS_PROP_REINITABLE; |
1095 | | |
1096 | 1.80k | return zend_assign_to_variable_ex(property_val, &tmp, IS_TMP_VAR, EX_USES_STRICT_TYPES(), garbage_ptr); |
1097 | 1.88k | } |
1098 | | |
1099 | 203 | static zend_always_inline bool zend_value_instanceof_static(const zval *zv) { |
1100 | 203 | if (Z_TYPE_P(zv) != IS_OBJECT) { |
1101 | 0 | return 0; |
1102 | 0 | } |
1103 | | |
1104 | 203 | zend_class_entry *called_scope = zend_get_called_scope(EG(current_execute_data)); |
1105 | 203 | if (!called_scope) { |
1106 | 5 | return 0; |
1107 | 5 | } |
1108 | 198 | return instanceof_function(Z_OBJCE_P(zv), called_scope); |
1109 | 203 | } |
1110 | | |
1111 | | static zend_always_inline zend_class_entry *zend_fetch_ce_from_type( |
1112 | | const zend_type *type) |
1113 | 39.2k | { |
1114 | 39.2k | zend_string *name = ZEND_TYPE_NAME(*type); |
1115 | 39.2k | zend_class_entry *ce; |
1116 | 39.2k | if (ZSTR_HAS_CE_CACHE(name)) { |
1117 | 39.1k | ce = ZSTR_GET_CE_CACHE(name); |
1118 | 39.1k | if (!ce) { |
1119 | 3.44k | ce = zend_lookup_class_ex(name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD); |
1120 | 3.44k | if (UNEXPECTED(!ce)) { |
1121 | | /* Cannot resolve */ |
1122 | 69 | return NULL; |
1123 | 69 | } |
1124 | 3.44k | } |
1125 | 39.1k | } else { |
1126 | 138 | ce = zend_fetch_class(name, |
1127 | 138 | ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_NO_AUTOLOAD | ZEND_FETCH_CLASS_SILENT); |
1128 | 138 | if (UNEXPECTED(!ce)) { |
1129 | 6 | return NULL; |
1130 | 6 | } |
1131 | 138 | } |
1132 | 39.2k | return ce; |
1133 | 39.2k | } |
1134 | | |
1135 | | static bool zend_check_intersection_type_from_list( |
1136 | | const zend_type_list *intersection_type_list, |
1137 | | zend_class_entry *arg_ce) |
1138 | 532 | { |
1139 | 532 | zend_class_entry *ce; |
1140 | 532 | const zend_type *list_type; |
1141 | 1.43k | ZEND_TYPE_LIST_FOREACH(intersection_type_list, list_type) { |
1142 | 1.43k | ce = zend_fetch_ce_from_type(list_type); |
1143 | | /* If type is not an instance of one of the types taking part in the |
1144 | | * intersection it cannot be a valid instance of the whole intersection type. */ |
1145 | 1.43k | if (!ce || !instanceof_function(arg_ce, ce)) { |
1146 | 218 | return false; |
1147 | 218 | } |
1148 | 1.43k | } ZEND_TYPE_LIST_FOREACH_END(); |
1149 | 314 | return true; |
1150 | 532 | } |
1151 | | |
1152 | | static zend_always_inline bool zend_check_type_slow( |
1153 | | const zend_type *type, zval *arg, const zend_reference *ref, |
1154 | | bool is_return_type, bool is_internal) |
1155 | 57.9k | { |
1156 | 57.9k | if (ZEND_TYPE_IS_COMPLEX(*type) && EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) { |
1157 | 38.6k | zend_class_entry *ce; |
1158 | 38.6k | if (UNEXPECTED(ZEND_TYPE_HAS_LIST(*type))) { |
1159 | 541 | if (ZEND_TYPE_IS_INTERSECTION(*type)) { |
1160 | 69 | return zend_check_intersection_type_from_list(ZEND_TYPE_LIST(*type), Z_OBJCE_P(arg)); |
1161 | 472 | } else { |
1162 | 472 | const zend_type *list_type; |
1163 | 1.19k | ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(*type), list_type) { |
1164 | 1.19k | if (ZEND_TYPE_IS_INTERSECTION(*list_type)) { |
1165 | 463 | if (zend_check_intersection_type_from_list(ZEND_TYPE_LIST(*list_type), Z_OBJCE_P(arg))) { |
1166 | 254 | return true; |
1167 | 254 | } |
1168 | 463 | } else { |
1169 | 255 | ZEND_ASSERT(!ZEND_TYPE_HAS_LIST(*list_type)); |
1170 | 255 | ce = zend_fetch_ce_from_type(list_type); |
1171 | | /* Instance of a single type part of a union is sufficient to pass the type check */ |
1172 | 255 | if (ce && instanceof_function(Z_OBJCE_P(arg), ce)) { |
1173 | 102 | return true; |
1174 | 102 | } |
1175 | 255 | } |
1176 | 1.19k | } ZEND_TYPE_LIST_FOREACH_END(); |
1177 | 472 | } |
1178 | 38.1k | } else { |
1179 | 38.1k | ce = zend_fetch_ce_from_type(type); |
1180 | | /* If we have a CE we check if it satisfies the type constraint, |
1181 | | * otherwise it will check if a standard type satisfies it. */ |
1182 | 38.1k | if (ce && instanceof_function(Z_OBJCE_P(arg), ce)) { |
1183 | 37.9k | return true; |
1184 | 37.9k | } |
1185 | 38.1k | } |
1186 | 38.6k | } |
1187 | | |
1188 | 19.5k | const uint32_t type_mask = ZEND_TYPE_FULL_MASK(*type); |
1189 | 19.5k | if ((type_mask & MAY_BE_CALLABLE) && |
1190 | 8.05k | zend_is_callable(arg, is_internal ? IS_CALLABLE_SUPPRESS_DEPRECATIONS : 0, NULL)) { |
1191 | 7.83k | return 1; |
1192 | 7.83k | } |
1193 | 11.6k | if ((type_mask & MAY_BE_STATIC) && zend_value_instanceof_static(arg)) { |
1194 | 183 | return 1; |
1195 | 183 | } |
1196 | 11.5k | if (ref && ZEND_REF_HAS_TYPE_SOURCES(ref)) { |
1197 | | /* We cannot have conversions for typed refs. */ |
1198 | 0 | return 0; |
1199 | 0 | } |
1200 | 11.5k | if (is_internal && is_return_type) { |
1201 | | /* For internal returns, the type has to match exactly, because we're not |
1202 | | * going to check it for non-debug builds, and there will be no chance to |
1203 | | * apply coercions. */ |
1204 | 0 | return 0; |
1205 | 0 | } |
1206 | | |
1207 | 11.5k | return zend_verify_scalar_type_hint(type_mask, arg, |
1208 | 11.5k | is_return_type ? ZEND_RET_USES_STRICT_TYPES() : ZEND_ARG_USES_STRICT_TYPES(), |
1209 | 11.5k | is_internal); |
1210 | | |
1211 | | /* Special handling for IS_VOID is not necessary (for return types), |
1212 | | * because this case is already checked at compile-time. */ |
1213 | 11.5k | } |
1214 | | |
1215 | | static zend_always_inline bool zend_check_type( |
1216 | | const zend_type *type, zval *arg, zend_class_entry *scope, |
1217 | | bool is_return_type, bool is_internal) |
1218 | 2.25M | { |
1219 | 2.25M | const zend_reference *ref = NULL; |
1220 | 2.25M | ZEND_ASSERT(ZEND_TYPE_IS_SET(*type)); |
1221 | | |
1222 | 2.25M | if (UNEXPECTED(Z_ISREF_P(arg))) { |
1223 | 3.76k | ref = Z_REF_P(arg); |
1224 | 3.76k | arg = Z_REFVAL_P(arg); |
1225 | 3.76k | } |
1226 | | |
1227 | 2.25M | if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(*type, Z_TYPE_P(arg)))) { |
1228 | 2.20M | return 1; |
1229 | 2.20M | } |
1230 | | |
1231 | 57.2k | return zend_check_type_slow(type, arg, ref, is_return_type, is_internal); |
1232 | 2.25M | } |
1233 | | |
1234 | | ZEND_API bool zend_check_user_type_slow( |
1235 | | const zend_type *type, zval *arg, const zend_reference *ref, bool is_return_type) |
1236 | 0 | { |
1237 | 0 | return zend_check_type_slow( |
1238 | 0 | type, arg, ref, is_return_type, /* is_internal */ false); |
1239 | 0 | } |
1240 | | |
1241 | | static zend_always_inline bool zend_verify_recv_arg_type(const zend_function *zf, uint32_t arg_num, zval *arg) |
1242 | 5.86k | { |
1243 | 5.86k | const zend_arg_info *cur_arg_info; |
1244 | | |
1245 | 5.86k | ZEND_ASSERT(arg_num <= zf->common.num_args); |
1246 | 5.86k | cur_arg_info = &zf->common.arg_info[arg_num-1]; |
1247 | | |
1248 | 5.86k | if (ZEND_TYPE_IS_SET(cur_arg_info->type) |
1249 | 5.54k | && UNEXPECTED(!zend_check_type(&cur_arg_info->type, arg, zf->common.scope, false, false))) { |
1250 | 649 | zend_verify_arg_error(zf, cur_arg_info, arg_num, arg); |
1251 | 649 | return 0; |
1252 | 649 | } |
1253 | | |
1254 | 5.21k | return 1; |
1255 | 5.86k | } |
1256 | | |
1257 | | static zend_always_inline bool zend_verify_variadic_arg_type( |
1258 | | const zend_function *zf, const zend_arg_info *arg_info, uint32_t arg_num, zval *arg) |
1259 | 226 | { |
1260 | 226 | ZEND_ASSERT(ZEND_TYPE_IS_SET(arg_info->type)); |
1261 | 226 | if (UNEXPECTED(!zend_check_type(&arg_info->type, arg, zf->common.scope, false, false))) { |
1262 | 35 | zend_verify_arg_error(zf, arg_info, arg_num, arg); |
1263 | 35 | return 0; |
1264 | 35 | } |
1265 | | |
1266 | 191 | return 1; |
1267 | 226 | } |
1268 | | |
1269 | | static zend_never_inline ZEND_ATTRIBUTE_UNUSED bool zend_verify_internal_arg_types(const zend_function *fbc, zend_execute_data *call) |
1270 | 1.37M | { |
1271 | 1.37M | uint32_t i; |
1272 | 1.37M | uint32_t num_args = ZEND_CALL_NUM_ARGS(call); |
1273 | 1.37M | zval *arg = ZEND_CALL_ARG(call, 1); |
1274 | | |
1275 | 3.27M | for (i = 0; i < num_args; ++i) { |
1276 | 1.89M | zend_arg_info *cur_arg_info; |
1277 | 1.89M | if (EXPECTED(i < fbc->common.num_args)) { |
1278 | 1.88M | cur_arg_info = &fbc->common.arg_info[i]; |
1279 | 1.88M | } else if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_VARIADIC)) { |
1280 | 11.9k | cur_arg_info = &fbc->common.arg_info[fbc->common.num_args]; |
1281 | 11.9k | } else { |
1282 | 0 | break; |
1283 | 0 | } |
1284 | | |
1285 | 1.89M | if (ZEND_TYPE_IS_SET(cur_arg_info->type) |
1286 | 1.88M | && UNEXPECTED(!zend_check_type(&cur_arg_info->type, arg, fbc->common.scope, false, /* is_internal */ true))) { |
1287 | 493 | return 0; |
1288 | 493 | } |
1289 | 1.89M | arg++; |
1290 | 1.89M | } |
1291 | 1.37M | return 1; |
1292 | 1.37M | } |
1293 | | |
1294 | | #if ZEND_DEBUG |
1295 | | /* Determine whether an internal call should throw, because the passed arguments violate |
1296 | | * an arginfo constraint. This is only checked in debug builds. In release builds, we |
1297 | | * trust that arginfo matches what is enforced by zend_parse_parameters. */ |
1298 | | ZEND_API bool zend_internal_call_should_throw(const zend_function *fbc, zend_execute_data *call) |
1299 | 1.53M | { |
1300 | 1.53M | if (fbc->internal_function.handler == ZEND_FN(pass) || (fbc->internal_function.fn_flags & ZEND_ACC_FAKE_CLOSURE)) { |
1301 | | /* Be lenient about the special pass function and about fake closures. */ |
1302 | 706 | return 0; |
1303 | 706 | } |
1304 | | |
1305 | 1.53M | if (fbc->common.required_num_args > ZEND_CALL_NUM_ARGS(call)) { |
1306 | | /* Required argument not passed. */ |
1307 | 372 | return 1; |
1308 | 372 | } |
1309 | | |
1310 | 1.53M | if (fbc->common.num_args < ZEND_CALL_NUM_ARGS(call) |
1311 | 8.30k | && !(fbc->common.fn_flags & ZEND_ACC_VARIADIC)) { |
1312 | | /* Too many arguments passed. For internal functions (unlike userland functions), |
1313 | | * this should always throw. */ |
1314 | 133 | return 1; |
1315 | 133 | } |
1316 | | |
1317 | 1.53M | if ((fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) && |
1318 | 1.37M | !zend_verify_internal_arg_types(fbc, call)) { |
1319 | 493 | return 1; |
1320 | 493 | } |
1321 | | |
1322 | 1.53M | return 0; |
1323 | 1.53M | } |
1324 | | |
1325 | | ZEND_API ZEND_COLD void zend_internal_call_arginfo_violation(const zend_function *fbc) |
1326 | 0 | { |
1327 | 0 | zend_error_noreturn(E_ERROR, "Arginfo / zpp mismatch during call of %s%s%s()", |
1328 | 0 | fbc->common.scope ? ZSTR_VAL(fbc->common.scope->name) : "", |
1329 | 0 | fbc->common.scope ? "::" : "", |
1330 | 0 | ZSTR_VAL(fbc->common.function_name)); |
1331 | 0 | } |
1332 | | |
1333 | | #ifndef ZEND_VERIFY_FUNC_INFO |
1334 | | # define ZEND_VERIFY_FUNC_INFO 0 |
1335 | | #endif |
1336 | | |
1337 | 521k | static void zend_verify_internal_func_info(const zend_function *fn, const zval *retval) { |
1338 | | #if ZEND_VERIFY_FUNC_INFO |
1339 | | zend_string *name = fn->common.function_name; |
1340 | | const uint32_t type_mask = zend_get_internal_func_info(fn, NULL, NULL); |
1341 | | if (!type_mask) { |
1342 | | return; |
1343 | | } |
1344 | | |
1345 | | /* Always check refcount of arrays, as immutable arrays are RCN. */ |
1346 | | if (Z_REFCOUNTED_P(retval) || Z_TYPE_P(retval) == IS_ARRAY) { |
1347 | | if (!(type_mask & MAY_BE_RC1)) { |
1348 | | zend_error_noreturn(E_CORE_ERROR, "%s() missing rc1", ZSTR_VAL(name)); |
1349 | | } |
1350 | | if (Z_REFCOUNT_P(retval) > 1 && !(type_mask & MAY_BE_RCN)) { |
1351 | | zend_error_noreturn(E_CORE_ERROR, "%s() missing rcn", ZSTR_VAL(name)); |
1352 | | } |
1353 | | } |
1354 | | |
1355 | | const uint32_t type = 1u << Z_TYPE_P(retval); |
1356 | | if (!(type_mask & type)) { |
1357 | | zend_error_noreturn(E_CORE_ERROR, "%s() missing type %s", |
1358 | | ZSTR_VAL(name), zend_get_type_by_const(Z_TYPE_P(retval))); |
1359 | | } |
1360 | | |
1361 | | if (Z_TYPE_P(retval) == IS_ARRAY) { |
1362 | | const HashTable *ht = Z_ARRVAL_P(retval); |
1363 | | uint32_t num_checked = 0; |
1364 | | zend_string *str; |
1365 | | zval *val; |
1366 | | ZEND_HASH_FOREACH_STR_KEY_VAL(ht, str, val) { |
1367 | | if (str) { |
1368 | | if (!(type_mask & MAY_BE_ARRAY_KEY_STRING)) { |
1369 | | zend_error_noreturn(E_CORE_ERROR, |
1370 | | "%s() missing array_key_string", ZSTR_VAL(name)); |
1371 | | } |
1372 | | } else { |
1373 | | if (!(type_mask & MAY_BE_ARRAY_KEY_LONG)) { |
1374 | | zend_error_noreturn(E_CORE_ERROR, |
1375 | | "%s() missing array_key_long", ZSTR_VAL(name)); |
1376 | | } |
1377 | | } |
1378 | | |
1379 | | const uint32_t array_type = 1u << (Z_TYPE_P(val) + MAY_BE_ARRAY_SHIFT); |
1380 | | if (!(type_mask & array_type)) { |
1381 | | zend_error_noreturn(E_CORE_ERROR, |
1382 | | "%s() missing array element type %s", |
1383 | | ZSTR_VAL(name), zend_get_type_by_const(Z_TYPE_P(retval))); |
1384 | | } |
1385 | | |
1386 | | /* Don't check all elements of large arrays. */ |
1387 | | if (++num_checked > 16) { |
1388 | | break; |
1389 | | } |
1390 | | } ZEND_HASH_FOREACH_END(); |
1391 | | } |
1392 | | #endif |
1393 | 521k | } |
1394 | | #endif |
1395 | | |
1396 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_missing_arg_error(const zend_execute_data *execute_data) |
1397 | 314 | { |
1398 | 314 | const zend_execute_data *ptr = EX(prev_execute_data); |
1399 | | |
1400 | 314 | if (ptr && ptr->func && ZEND_USER_CODE(ptr->func->common.type)) { |
1401 | 314 | zend_throw_error(zend_ce_argument_count_error, "Too few arguments to function %s%s%s(), %d passed in %s on line %d and %s %d expected", |
1402 | 314 | EX(func)->common.scope ? ZSTR_VAL(EX(func)->common.scope->name) : "", |
1403 | 314 | EX(func)->common.scope ? "::" : "", |
1404 | 314 | ZSTR_VAL(EX(func)->common.function_name), |
1405 | 314 | EX_NUM_ARGS(), |
1406 | 314 | ZSTR_VAL(ptr->func->op_array.filename), |
1407 | 314 | ptr->opline->lineno, |
1408 | 314 | EX(func)->common.required_num_args == EX(func)->common.num_args ? "exactly" : "at least", |
1409 | 314 | EX(func)->common.required_num_args); |
1410 | 314 | } else { |
1411 | 0 | zend_throw_error(zend_ce_argument_count_error, "Too few arguments to function %s%s%s(), %d passed and %s %d expected", |
1412 | 0 | EX(func)->common.scope ? ZSTR_VAL(EX(func)->common.scope->name) : "", |
1413 | 0 | EX(func)->common.scope ? "::" : "", |
1414 | 0 | ZSTR_VAL(EX(func)->common.function_name), |
1415 | 0 | EX_NUM_ARGS(), |
1416 | 0 | EX(func)->common.required_num_args == EX(func)->common.num_args ? "exactly" : "at least", |
1417 | 0 | EX(func)->common.required_num_args); |
1418 | 0 | } |
1419 | 314 | } |
1420 | | |
1421 | | ZEND_API ZEND_COLD void zend_verify_return_error(const zend_function *zf, const zval *value) |
1422 | 362 | { |
1423 | 362 | const zend_arg_info *arg_info = &zf->common.arg_info[-1]; |
1424 | 362 | const char *fname, *fsep, *fclass; |
1425 | 362 | zend_string *need_msg; |
1426 | 362 | const char *given_msg; |
1427 | | |
1428 | 362 | zend_verify_type_error_common( |
1429 | 362 | zf, arg_info, value, &fname, &fsep, &fclass, &need_msg, &given_msg); |
1430 | | |
1431 | 362 | zend_type_error("%s%s%s(): Return value must be of type %s, %s returned", |
1432 | 362 | fclass, fsep, fname, ZSTR_VAL(need_msg), given_msg); |
1433 | | |
1434 | 362 | zend_string_release(need_msg); |
1435 | 362 | } |
1436 | | |
1437 | | ZEND_API ZEND_COLD void zend_verify_never_error(const zend_function *zf) |
1438 | 20 | { |
1439 | 20 | zend_string *func_name = get_function_or_method_name(zf); |
1440 | | |
1441 | 20 | zend_type_error("%s(): never-returning %s must not implicitly return", |
1442 | 20 | ZSTR_VAL(func_name), zf->common.scope ? "method" : "function"); |
1443 | | |
1444 | 20 | zend_string_release(func_name); |
1445 | 20 | } |
1446 | | |
1447 | | #if ZEND_DEBUG |
1448 | | static ZEND_COLD void zend_verify_internal_return_error(const zend_function *zf, const zval *value) |
1449 | 0 | { |
1450 | 0 | const zend_arg_info *arg_info = &zf->common.arg_info[-1]; |
1451 | 0 | const char *fname, *fsep, *fclass; |
1452 | 0 | zend_string *need_msg; |
1453 | 0 | const char *given_msg; |
1454 | |
|
1455 | 0 | zend_verify_type_error_common( |
1456 | 0 | zf, arg_info, value, &fname, &fsep, &fclass, &need_msg, &given_msg); |
1457 | |
|
1458 | 0 | zend_error_noreturn(E_CORE_ERROR, "%s%s%s(): Return value must be of type %s, %s returned", |
1459 | 0 | fclass, fsep, fname, ZSTR_VAL(need_msg), given_msg); |
1460 | 0 | } |
1461 | | |
1462 | | static ZEND_COLD void zend_verify_void_return_error(const zend_function *zf, const char *returned_msg, const char *returned_kind) |
1463 | 0 | { |
1464 | 0 | const char *fname = ZSTR_VAL(zf->common.function_name); |
1465 | 0 | const char *fsep; |
1466 | 0 | const char *fclass; |
1467 | |
|
1468 | 0 | if (zf->common.scope) { |
1469 | 0 | fsep = "::"; |
1470 | 0 | fclass = ZSTR_VAL(zf->common.scope->name); |
1471 | 0 | } else { |
1472 | 0 | fsep = ""; |
1473 | 0 | fclass = ""; |
1474 | 0 | } |
1475 | |
|
1476 | 0 | zend_type_error("%s%s%s() must not return a value, %s%s returned", |
1477 | 0 | fclass, fsep, fname, returned_msg, returned_kind); |
1478 | 0 | } |
1479 | | |
1480 | | ZEND_API bool zend_verify_internal_return_type(const zend_function *zf, zval *ret) |
1481 | 972k | { |
1482 | 972k | const zend_internal_arg_info *ret_info = zf->internal_function.arg_info - 1; |
1483 | | |
1484 | 972k | if (ZEND_TYPE_FULL_MASK(ret_info->type) & MAY_BE_VOID) { |
1485 | 605k | if (UNEXPECTED(Z_TYPE_P(ret) != IS_NULL)) { |
1486 | 0 | zend_verify_void_return_error(zf, zend_zval_value_name(ret), ""); |
1487 | 0 | return 0; |
1488 | 0 | } |
1489 | 605k | return 1; |
1490 | 605k | } |
1491 | | |
1492 | 366k | if (UNEXPECTED(!zend_check_type(&ret_info->type, ret, NULL, true, /* is_internal */ true))) { |
1493 | 0 | zend_verify_internal_return_error(zf, ret); |
1494 | 0 | return 0; |
1495 | 0 | } |
1496 | | |
1497 | 366k | return 1; |
1498 | 366k | } |
1499 | | #endif |
1500 | | |
1501 | | static ZEND_COLD void zend_verify_missing_return_type(const zend_function *zf) |
1502 | 106 | { |
1503 | | /* VERIFY_RETURN_TYPE is not emitted for "void" functions, so this is always an error. */ |
1504 | 106 | zend_verify_return_error(zf, NULL); |
1505 | 106 | } |
1506 | | |
1507 | | static zend_always_inline bool zend_check_class_constant_type(const zend_class_constant *c, zval *constant) |
1508 | 274 | { |
1509 | 274 | ZEND_ASSERT(!Z_ISREF_P(constant)); |
1510 | 274 | if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(c->type, Z_TYPE_P(constant)))) { |
1511 | 13 | return 1; |
1512 | 13 | } |
1513 | | |
1514 | 261 | if (((ZEND_TYPE_PURE_MASK(c->type) & MAY_BE_STATIC) || ZEND_TYPE_IS_COMPLEX(c->type)) && Z_TYPE_P(constant) == IS_OBJECT |
1515 | 245 | && zend_check_and_resolve_property_or_class_constant_class_type(c->ce, c->type, Z_OBJCE_P(constant))) { |
1516 | 199 | return 1; |
1517 | 199 | } |
1518 | | |
1519 | 62 | uint32_t type_mask = ZEND_TYPE_FULL_MASK(c->type); |
1520 | 62 | ZEND_ASSERT(!(type_mask & (MAY_BE_CALLABLE|MAY_BE_NEVER|MAY_BE_VOID))); |
1521 | 62 | return zend_verify_scalar_type_hint(type_mask, constant, true, false); |
1522 | 62 | } |
1523 | | |
1524 | | ZEND_API bool zend_never_inline zend_verify_class_constant_type(const zend_class_constant *c, const zend_string *name, zval *constant) |
1525 | 274 | { |
1526 | 274 | if (!zend_check_class_constant_type(c, constant)) { |
1527 | 62 | zend_verify_class_constant_type_error(c, name, constant); |
1528 | 62 | return 0; |
1529 | 62 | } |
1530 | | |
1531 | 212 | return 1; |
1532 | 274 | } |
1533 | | |
1534 | | static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_object_as_array(const zend_object *object) |
1535 | 7 | { |
1536 | 7 | zend_throw_error(NULL, "Cannot use object of type %s as array", ZSTR_VAL(object->ce->name)); |
1537 | 7 | } |
1538 | | |
1539 | | static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_array_offset_access(const zval *offset) |
1540 | 138 | { |
1541 | 138 | zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_RW); |
1542 | 138 | } |
1543 | | |
1544 | | static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_array_offset_isset(const zval *offset) |
1545 | 34 | { |
1546 | 34 | zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_IS); |
1547 | 34 | } |
1548 | | |
1549 | | static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_array_offset_unset(const zval *offset) |
1550 | 5 | { |
1551 | 5 | zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_UNSET); |
1552 | 5 | } |
1553 | | |
1554 | | static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_string_offset(const zval *offset, int type) |
1555 | 246 | { |
1556 | 246 | zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_STRING), offset, type); |
1557 | 246 | } |
1558 | | |
1559 | | static zend_never_inline void zend_assign_to_object_dim(zend_object *obj, zval *dim, zval *value OPLINE_DC EXECUTE_DATA_DC) |
1560 | 1.65k | { |
1561 | 1.65k | obj->handlers->write_dimension(obj, dim, value); |
1562 | | |
1563 | 1.65k | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
1564 | 77 | ZVAL_COPY(EX_VAR(opline->result.var), value); |
1565 | 77 | } |
1566 | 1.65k | } |
1567 | | |
1568 | | static void frameless_observed_call_copy(zend_execute_data *call, uint32_t arg, zval *zv) |
1569 | 0 | { |
1570 | 0 | if (Z_ISUNDEF_P(zv)) { |
1571 | 0 | ZVAL_NULL(ZEND_CALL_VAR_NUM(call, arg)); |
1572 | 0 | } else { |
1573 | 0 | ZVAL_COPY_DEREF(ZEND_CALL_VAR_NUM(call, arg), zv); |
1574 | 0 | } |
1575 | 0 | } |
1576 | | |
1577 | | ZEND_API void zend_frameless_observed_call(zend_execute_data *execute_data) |
1578 | 0 | { |
1579 | 0 | const zend_op *opline = EX(opline); |
1580 | 0 | uint8_t num_args = ZEND_FLF_NUM_ARGS(opline->opcode); |
1581 | 0 | zend_function *fbc = ZEND_FLF_FUNC(opline); |
1582 | 0 | zval *result = EX_VAR(opline->result.var); |
1583 | |
|
1584 | 0 | zend_execute_data *call = zend_vm_stack_push_call_frame_ex(zend_vm_calc_used_stack(num_args, fbc), ZEND_CALL_NESTED_FUNCTION, fbc, num_args, NULL); |
1585 | 0 | call->prev_execute_data = execute_data; |
1586 | |
|
1587 | 0 | switch (num_args) { |
1588 | 0 | case 3: frameless_observed_call_copy(call, 2, zend_get_zval_ptr(opline+1, (opline+1)->op1_type, &(opline+1)->op1, execute_data)); ZEND_FALLTHROUGH; |
1589 | 0 | case 2: frameless_observed_call_copy(call, 1, zend_get_zval_ptr(opline, opline->op2_type, &opline->op2, execute_data)); ZEND_FALLTHROUGH; |
1590 | 0 | case 1: frameless_observed_call_copy(call, 0, zend_get_zval_ptr(opline, opline->op1_type, &opline->op1, execute_data)); |
1591 | 0 | } |
1592 | |
|
1593 | 0 | EG(current_execute_data) = call; |
1594 | |
|
1595 | 0 | zend_observer_fcall_begin_prechecked(call, ZEND_OBSERVER_DATA(fbc)); |
1596 | 0 | fbc->internal_function.handler(call, result); |
1597 | 0 | zend_observer_fcall_end(call, result); |
1598 | |
|
1599 | 0 | EG(current_execute_data) = execute_data; |
1600 | |
|
1601 | 0 | if (UNEXPECTED(EG(exception) != NULL)) { |
1602 | 0 | zend_rethrow_exception(execute_data); |
1603 | 0 | } |
1604 | |
|
1605 | 0 | zend_vm_stack_free_args(call); |
1606 | |
|
1607 | 0 | uint32_t call_info = ZEND_CALL_INFO(call); |
1608 | 0 | if (UNEXPECTED(call_info & ZEND_CALL_ALLOCATED)) { |
1609 | 0 | zend_vm_stack_free_call_frame_ex(call_info, call); |
1610 | 0 | } else { |
1611 | 0 | EG(vm_stack_top) = (zval*)call; |
1612 | 0 | } |
1613 | 0 | } |
1614 | | |
1615 | | |
1616 | | static zend_always_inline int zend_binary_op(zval *ret, zval *op1, zval *op2 OPLINE_DC) |
1617 | 1.48M | { |
1618 | 1.48M | static const binary_op_type zend_binary_ops[] = { |
1619 | 1.48M | add_function, |
1620 | 1.48M | sub_function, |
1621 | 1.48M | mul_function, |
1622 | 1.48M | div_function, |
1623 | 1.48M | mod_function, |
1624 | 1.48M | shift_left_function, |
1625 | 1.48M | shift_right_function, |
1626 | 1.48M | concat_function, |
1627 | 1.48M | bitwise_or_function, |
1628 | 1.48M | bitwise_and_function, |
1629 | 1.48M | bitwise_xor_function, |
1630 | 1.48M | pow_function |
1631 | 1.48M | }; |
1632 | | /* size_t cast makes GCC to better optimize 64-bit PIC code */ |
1633 | 1.48M | size_t opcode = (size_t)opline->extended_value; |
1634 | | |
1635 | 1.48M | return zend_binary_ops[opcode - ZEND_ADD](ret, op1, op2); |
1636 | 1.48M | } |
1637 | | |
1638 | | static zend_never_inline void zend_binary_assign_op_obj_dim(zend_object *obj, zval *property OPLINE_DC EXECUTE_DATA_DC) |
1639 | 68 | { |
1640 | 68 | zval *value; |
1641 | 68 | zval *z; |
1642 | 68 | zval rv, res; |
1643 | | |
1644 | 68 | GC_ADDREF(obj); |
1645 | 68 | if (property && UNEXPECTED(Z_ISUNDEF_P(property))) { |
1646 | 0 | property = ZVAL_UNDEFINED_OP2(); |
1647 | 0 | } |
1648 | 68 | value = get_op_data_zval_ptr_r((opline+1)->op1_type, (opline+1)->op1); |
1649 | 68 | if ((z = obj->handlers->read_dimension(obj, property, BP_VAR_R, &rv)) != NULL) { |
1650 | | |
1651 | 61 | if (zend_binary_op(&res, z, value OPLINE_CC) == SUCCESS) { |
1652 | 53 | obj->handlers->write_dimension(obj, property, &res); |
1653 | 53 | } |
1654 | 61 | if (z == &rv) { |
1655 | 41 | zval_ptr_dtor(&rv); |
1656 | 41 | } |
1657 | 61 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
1658 | 5 | ZVAL_COPY(EX_VAR(opline->result.var), &res); |
1659 | 5 | } |
1660 | 61 | zval_ptr_dtor(&res); |
1661 | 61 | } else { |
1662 | 7 | zend_use_object_as_array(obj); |
1663 | 7 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
1664 | 0 | ZVAL_NULL(EX_VAR(opline->result.var)); |
1665 | 0 | } |
1666 | 7 | } |
1667 | 68 | FREE_OP((opline+1)->op1_type, (opline+1)->op1.var); |
1668 | 68 | if (UNEXPECTED(GC_DELREF(obj) == 0)) { |
1669 | 0 | zend_objects_store_del(obj); |
1670 | 0 | } |
1671 | 68 | } |
1672 | | |
1673 | | static zend_never_inline void zend_binary_assign_op_typed_ref(zend_reference *ref, zval *value OPLINE_DC EXECUTE_DATA_DC) |
1674 | 202 | { |
1675 | 202 | zval z_copy; |
1676 | | |
1677 | | /* Make sure that in-place concatenation is used if the LHS is a string. */ |
1678 | 202 | if (opline->extended_value == ZEND_CONCAT && Z_TYPE(ref->val) == IS_STRING) { |
1679 | 35 | concat_function(&ref->val, &ref->val, value); |
1680 | 35 | ZEND_ASSERT(Z_TYPE(ref->val) == IS_STRING && "Concat should return string"); |
1681 | 35 | return; |
1682 | 35 | } |
1683 | | |
1684 | 167 | zend_binary_op(&z_copy, &ref->val, value OPLINE_CC); |
1685 | 167 | if (EXPECTED(zend_verify_ref_assignable_zval(ref, &z_copy, EX_USES_STRICT_TYPES()))) { |
1686 | 129 | zval_ptr_dtor(&ref->val); |
1687 | 129 | ZVAL_COPY_VALUE(&ref->val, &z_copy); |
1688 | 129 | } else { |
1689 | 38 | zval_ptr_dtor(&z_copy); |
1690 | 38 | } |
1691 | 167 | } |
1692 | | |
1693 | | static zend_never_inline void zend_binary_assign_op_typed_prop(const zend_property_info *prop_info, zval *zptr, zval *value OPLINE_DC EXECUTE_DATA_DC) |
1694 | 215 | { |
1695 | 215 | zval z_copy; |
1696 | | |
1697 | | /* Make sure that in-place concatenation is used if the LHS is a string. */ |
1698 | 215 | if (opline->extended_value == ZEND_CONCAT && Z_TYPE_P(zptr) == IS_STRING) { |
1699 | 80 | concat_function(zptr, zptr, value); |
1700 | 80 | ZEND_ASSERT(Z_TYPE_P(zptr) == IS_STRING && "Concat should return string"); |
1701 | 80 | return; |
1702 | 80 | } |
1703 | | |
1704 | 135 | zend_binary_op(&z_copy, zptr, value OPLINE_CC); |
1705 | 135 | if (EXPECTED(zend_verify_property_type(prop_info, &z_copy, EX_USES_STRICT_TYPES()))) { |
1706 | 93 | zval_ptr_dtor(zptr); |
1707 | 93 | ZVAL_COPY_VALUE(zptr, &z_copy); |
1708 | 93 | } else { |
1709 | 42 | zval_ptr_dtor(&z_copy); |
1710 | 42 | } |
1711 | 135 | } |
1712 | | |
1713 | | static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type EXECUTE_DATA_DC) |
1714 | 346 | { |
1715 | 346 | zend_long offset; |
1716 | | |
1717 | 346 | try_again: |
1718 | 346 | switch(Z_TYPE_P(dim)) { |
1719 | 138 | case IS_LONG: |
1720 | 138 | return Z_LVAL_P(dim); |
1721 | 80 | case IS_STRING: |
1722 | 80 | { |
1723 | 80 | bool trailing_data = false; |
1724 | | /* For BC reasons we allow errors so that we can warn on leading numeric string */ |
1725 | 80 | if (IS_LONG == is_numeric_string_ex(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL, |
1726 | 80 | /* allow errors */ true, NULL, &trailing_data)) { |
1727 | 13 | if (UNEXPECTED(trailing_data) && type != BP_VAR_UNSET) { |
1728 | 13 | zend_error(E_WARNING, "Illegal string offset \"%s\"", Z_STRVAL_P(dim)); |
1729 | 13 | } |
1730 | 13 | return offset; |
1731 | 13 | } |
1732 | 67 | zend_illegal_string_offset(dim, type); |
1733 | 67 | return 0; |
1734 | 80 | } |
1735 | 29 | case IS_DOUBLE: |
1736 | | /* Suppress potential double warning */ |
1737 | 29 | zend_error(E_WARNING, "String offset cast occurred"); |
1738 | 29 | return zend_dval_to_lval_silent(Z_DVAL_P(dim)); |
1739 | 0 | case IS_UNDEF: |
1740 | 0 | ZVAL_UNDEFINED_OP2(); |
1741 | 0 | ZEND_FALLTHROUGH; |
1742 | 92 | case IS_NULL: |
1743 | 93 | case IS_FALSE: |
1744 | 94 | case IS_TRUE: |
1745 | 94 | zend_error(E_WARNING, "String offset cast occurred"); |
1746 | 94 | break; |
1747 | 0 | case IS_REFERENCE: |
1748 | 0 | dim = Z_REFVAL_P(dim); |
1749 | 0 | goto try_again; |
1750 | 5 | default: |
1751 | 5 | zend_illegal_string_offset(dim, type); |
1752 | 5 | return 0; |
1753 | 346 | } |
1754 | | |
1755 | 94 | return zval_get_long_func(dim, /* is_strict */ false); |
1756 | 346 | } |
1757 | | |
1758 | | ZEND_API ZEND_COLD void zend_wrong_string_offset_error(void) |
1759 | 164 | { |
1760 | 164 | const char *msg = NULL; |
1761 | 164 | const zend_execute_data *execute_data = EG(current_execute_data); |
1762 | 164 | const zend_op *opline = execute_data->opline; |
1763 | | |
1764 | 164 | if (UNEXPECTED(EG(exception) != NULL)) { |
1765 | 7 | return; |
1766 | 7 | } |
1767 | | |
1768 | 157 | switch (opline->opcode) { |
1769 | 11 | case ZEND_ASSIGN_DIM_OP: |
1770 | 11 | msg = "Cannot use assign-op operators with string offsets"; |
1771 | 11 | break; |
1772 | 8 | case ZEND_FETCH_LIST_W: |
1773 | 8 | msg = "Cannot create references to/from string offsets"; |
1774 | 8 | break; |
1775 | 71 | case ZEND_FETCH_DIM_W: |
1776 | 112 | case ZEND_FETCH_DIM_RW: |
1777 | 120 | case ZEND_FETCH_DIM_FUNC_ARG: |
1778 | 138 | case ZEND_FETCH_DIM_UNSET: |
1779 | 138 | switch (opline->extended_value) { |
1780 | 51 | case ZEND_FETCH_DIM_REF: |
1781 | 51 | msg = "Cannot create references to/from string offsets"; |
1782 | 51 | break; |
1783 | 34 | case ZEND_FETCH_DIM_DIM: |
1784 | 34 | msg = "Cannot use string offset as an array"; |
1785 | 34 | break; |
1786 | 45 | case ZEND_FETCH_DIM_OBJ: |
1787 | 45 | msg = "Cannot use string offset as an object"; |
1788 | 45 | break; |
1789 | 8 | case ZEND_FETCH_DIM_INCDEC: |
1790 | 8 | msg = "Cannot increment/decrement string offsets"; |
1791 | 8 | break; |
1792 | 0 | EMPTY_SWITCH_DEFAULT_CASE(); |
1793 | 138 | } |
1794 | 138 | break; |
1795 | 138 | EMPTY_SWITCH_DEFAULT_CASE(); |
1796 | 157 | } |
1797 | 157 | ZEND_ASSERT(msg != NULL); |
1798 | 157 | zend_throw_error(NULL, "%s", msg); |
1799 | 157 | } |
1800 | | |
1801 | | ZEND_COLD static zend_result ZEND_FASTCALL get_deprecation_suffix_from_attribute(HashTable *attributes, zend_class_entry* scope, zend_string **message_suffix) |
1802 | 630 | { |
1803 | 630 | *message_suffix = ZSTR_EMPTY_ALLOC(); |
1804 | | |
1805 | 630 | if (!attributes) { |
1806 | 0 | return SUCCESS; |
1807 | 0 | } |
1808 | | |
1809 | 630 | zend_attribute *deprecated = zend_get_attribute_str(attributes, "deprecated", sizeof("deprecated")-1); |
1810 | | |
1811 | 630 | if (!deprecated) { |
1812 | 0 | return SUCCESS; |
1813 | 0 | } |
1814 | | |
1815 | 630 | if (deprecated->argc == 0) { |
1816 | 201 | return SUCCESS; |
1817 | 201 | } |
1818 | | |
1819 | 429 | zend_result result = FAILURE; |
1820 | | |
1821 | 429 | zend_string *message = ZSTR_EMPTY_ALLOC(); |
1822 | 429 | zend_string *since = ZSTR_EMPTY_ALLOC(); |
1823 | | |
1824 | 429 | zval obj; |
1825 | 429 | ZVAL_UNDEF(&obj); |
1826 | 429 | zval *z; |
1827 | | |
1828 | | /* Construct the Deprecated object to correctly handle parameter processing. */ |
1829 | 429 | if (FAILURE == zend_get_attribute_object(&obj, zend_ce_deprecated, deprecated, scope, NULL)) { |
1830 | 29 | goto out; |
1831 | 29 | } |
1832 | | |
1833 | | /* Extract the $message property. */ |
1834 | 400 | z = zend_read_property_ex(zend_ce_deprecated, Z_OBJ_P(&obj), ZSTR_KNOWN(ZEND_STR_MESSAGE), false, NULL); |
1835 | 400 | ZEND_ASSERT(z != &EG(uninitialized_zval)); |
1836 | 400 | if (Z_TYPE_P(z) == IS_STRING) { |
1837 | 318 | message = Z_STR_P(z); |
1838 | 318 | } |
1839 | | |
1840 | | /* Extract the $since property. */ |
1841 | 400 | z = zend_read_property_ex(zend_ce_deprecated, Z_OBJ_P(&obj), ZSTR_KNOWN(ZEND_STR_SINCE), false, NULL); |
1842 | 400 | ZEND_ASSERT(z != &EG(uninitialized_zval)); |
1843 | 400 | if (Z_TYPE_P(z) == IS_STRING) { |
1844 | 241 | since = Z_STR_P(z); |
1845 | 241 | } |
1846 | | |
1847 | | /* Construct the suffix. */ |
1848 | 400 | *message_suffix = zend_strpprintf_unchecked( |
1849 | 400 | 0, |
1850 | 400 | "%s%S%s%S", |
1851 | 400 | ZSTR_LEN(since) > 0 ? " since " : "", |
1852 | 400 | since, |
1853 | 400 | ZSTR_LEN(message) > 0 ? ", " : "", |
1854 | 400 | message |
1855 | 400 | ); |
1856 | | |
1857 | 400 | result = SUCCESS; |
1858 | | |
1859 | 429 | out: |
1860 | | |
1861 | 429 | zval_ptr_dtor(&obj); |
1862 | | |
1863 | 429 | return result; |
1864 | 400 | } |
1865 | | |
1866 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_function(const zend_function *fbc) |
1867 | 334 | { |
1868 | 334 | zend_string *message_suffix = ZSTR_EMPTY_ALLOC(); |
1869 | | |
1870 | 334 | if (get_deprecation_suffix_from_attribute(fbc->common.attributes, fbc->common.scope, &message_suffix) == FAILURE) { |
1871 | 27 | return; |
1872 | 27 | } |
1873 | | |
1874 | 307 | int code = fbc->type == ZEND_INTERNAL_FUNCTION ? E_DEPRECATED : E_USER_DEPRECATED; |
1875 | | |
1876 | 307 | if (fbc->common.scope) { |
1877 | 122 | zend_error_unchecked(code, "Method %s::%s() is deprecated%S", |
1878 | 122 | ZSTR_VAL(fbc->common.scope->name), |
1879 | 122 | ZSTR_VAL(fbc->common.function_name), |
1880 | 122 | message_suffix |
1881 | 122 | ); |
1882 | 185 | } else { |
1883 | 185 | zend_error_unchecked(code, "Function %s() is deprecated%S", |
1884 | 185 | ZSTR_VAL(fbc->common.function_name), |
1885 | 185 | message_suffix |
1886 | 185 | ); |
1887 | 185 | } |
1888 | | |
1889 | 307 | zend_string_release(message_suffix); |
1890 | 307 | } |
1891 | | |
1892 | | ZEND_COLD static zend_result ZEND_FASTCALL get_nodiscard_suffix_from_attribute(HashTable *attributes, zend_class_entry* scope, zend_string **message_suffix) |
1893 | 207 | { |
1894 | 207 | *message_suffix = ZSTR_EMPTY_ALLOC(); |
1895 | | |
1896 | 207 | if (!attributes) { |
1897 | 0 | return SUCCESS; |
1898 | 0 | } |
1899 | | |
1900 | 207 | zend_attribute *nodiscard = zend_get_attribute_str(attributes, "nodiscard", sizeof("nodiscard")-1); |
1901 | | |
1902 | 207 | if (!nodiscard) { |
1903 | 0 | return SUCCESS; |
1904 | 0 | } |
1905 | | |
1906 | 207 | if (nodiscard->argc == 0) { |
1907 | 177 | return SUCCESS; |
1908 | 177 | } |
1909 | | |
1910 | 30 | zend_result result = FAILURE; |
1911 | | |
1912 | 30 | zend_string *message = ZSTR_EMPTY_ALLOC(); |
1913 | | |
1914 | 30 | zval obj; |
1915 | 30 | ZVAL_UNDEF(&obj); |
1916 | 30 | zval *z; |
1917 | | |
1918 | | /* Construct the NoDiscard object to correctly handle parameter processing. */ |
1919 | 30 | if (FAILURE == zend_get_attribute_object(&obj, zend_ce_nodiscard, nodiscard, scope, NULL)) { |
1920 | 6 | goto out; |
1921 | 6 | } |
1922 | | |
1923 | | /* Extract the $message property. */ |
1924 | 24 | z = zend_read_property_ex(zend_ce_nodiscard, Z_OBJ_P(&obj), ZSTR_KNOWN(ZEND_STR_MESSAGE), false, NULL); |
1925 | 24 | ZEND_ASSERT(z != &EG(uninitialized_zval)); |
1926 | 24 | if (Z_TYPE_P(z) == IS_STRING) { |
1927 | 24 | message = Z_STR_P(z); |
1928 | 24 | } |
1929 | | |
1930 | | /* Construct the suffix. */ |
1931 | 24 | *message_suffix = zend_strpprintf_unchecked( |
1932 | 24 | 0, |
1933 | 24 | "%s%S", |
1934 | 24 | ZSTR_LEN(message) > 0 ? ", " : "", |
1935 | 24 | message |
1936 | 24 | ); |
1937 | | |
1938 | 24 | result = SUCCESS; |
1939 | | |
1940 | 30 | out: |
1941 | | |
1942 | 30 | zval_ptr_dtor(&obj); |
1943 | | |
1944 | 30 | return result; |
1945 | 24 | } |
1946 | | |
1947 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_nodiscard_function(const zend_function *fbc) |
1948 | 207 | { |
1949 | 207 | zend_string *message_suffix = ZSTR_EMPTY_ALLOC(); |
1950 | | |
1951 | 207 | if (get_nodiscard_suffix_from_attribute(fbc->common.attributes, fbc->common.scope, &message_suffix) == FAILURE) { |
1952 | 6 | return; |
1953 | 6 | } |
1954 | | |
1955 | 201 | int code = fbc->type == ZEND_INTERNAL_FUNCTION ? E_WARNING : E_USER_WARNING; |
1956 | | |
1957 | 201 | if (fbc->common.scope) { |
1958 | 55 | zend_error_unchecked(code, "The return value of method %s::%s() should either be used or intentionally ignored by casting it as (void)%S", |
1959 | 55 | ZSTR_VAL(fbc->common.scope->name), |
1960 | 55 | ZSTR_VAL(fbc->common.function_name), |
1961 | 55 | message_suffix |
1962 | 55 | ); |
1963 | 146 | } else { |
1964 | 146 | zend_error_unchecked(code, "The return value of function %s() should either be used or intentionally ignored by casting it as (void)%S", |
1965 | 146 | ZSTR_VAL(fbc->common.function_name), |
1966 | 146 | message_suffix |
1967 | 146 | ); |
1968 | 146 | } |
1969 | | |
1970 | 201 | zend_string_release(message_suffix); |
1971 | 201 | } |
1972 | | |
1973 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_class_constant(const zend_class_constant *c, const zend_string *constant_name) |
1974 | 80 | { |
1975 | 80 | zend_string *message_suffix = ZSTR_EMPTY_ALLOC(); |
1976 | | |
1977 | 80 | if (get_deprecation_suffix_from_attribute(c->attributes, c->ce, &message_suffix) == FAILURE) { |
1978 | 0 | return; |
1979 | 0 | } |
1980 | | |
1981 | 80 | int code = c->ce->type == ZEND_INTERNAL_CLASS ? E_DEPRECATED : E_USER_DEPRECATED; |
1982 | 80 | char *type = (ZEND_CLASS_CONST_FLAGS(c) & ZEND_CLASS_CONST_IS_CASE) ? "Enum case" : "Constant"; |
1983 | | |
1984 | 80 | zend_error_unchecked(code, "%s %s::%s is deprecated%S", |
1985 | 80 | type, |
1986 | 80 | ZSTR_VAL(c->ce->name), |
1987 | 80 | ZSTR_VAL(constant_name), |
1988 | 80 | message_suffix |
1989 | 80 | ); |
1990 | | |
1991 | 80 | zend_string_release(message_suffix); |
1992 | 80 | } |
1993 | | |
1994 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_constant(const zend_constant *c, const zend_string *constant_name) |
1995 | 157 | { |
1996 | 157 | zend_string *message_suffix = ZSTR_EMPTY_ALLOC(); |
1997 | | |
1998 | 157 | if (get_deprecation_suffix_from_attribute(c->attributes, NULL, &message_suffix) == FAILURE) { |
1999 | 2 | return; |
2000 | 2 | } |
2001 | | |
2002 | 155 | int code = ZEND_CONSTANT_MODULE_NUMBER(c) == PHP_USER_CONSTANT ? E_USER_DEPRECATED : E_DEPRECATED; |
2003 | | |
2004 | 155 | zend_error_unchecked(code, "Constant %s is deprecated%S", |
2005 | 155 | ZSTR_VAL(constant_name), |
2006 | 155 | message_suffix |
2007 | 155 | ); |
2008 | | |
2009 | 155 | zend_string_release(message_suffix); |
2010 | 155 | } |
2011 | | |
2012 | | ZEND_API ZEND_COLD void zend_use_of_deprecated_trait( |
2013 | | zend_class_entry *trait, |
2014 | | const zend_string *used_by |
2015 | 59 | ) { |
2016 | 59 | zend_string *message_suffix = ZSTR_EMPTY_ALLOC(); |
2017 | | |
2018 | 59 | if (get_deprecation_suffix_from_attribute(trait->attributes, trait, &message_suffix) == FAILURE) { |
2019 | 0 | return; |
2020 | 0 | } |
2021 | | |
2022 | 59 | int code = trait->type == ZEND_INTERNAL_CLASS ? E_DEPRECATED : E_USER_DEPRECATED; |
2023 | | |
2024 | 59 | zend_error_unchecked(code, "Trait %s used by %s is deprecated%S", |
2025 | 59 | ZSTR_VAL(trait->name), |
2026 | 59 | ZSTR_VAL(used_by), |
2027 | 59 | message_suffix |
2028 | 59 | ); |
2029 | | |
2030 | 59 | zend_string_release(message_suffix); |
2031 | 59 | } |
2032 | | |
2033 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_false_to_array_deprecated(void) |
2034 | 521 | { |
2035 | 521 | zend_error(E_DEPRECATED, "Automatic conversion of false to array is deprecated"); |
2036 | 521 | } |
2037 | | |
2038 | | static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim, zval *value OPLINE_DC EXECUTE_DATA_DC) |
2039 | 445 | { |
2040 | 445 | zend_uchar c; |
2041 | 445 | size_t string_len; |
2042 | 445 | zend_long offset; |
2043 | 445 | zend_string *s; |
2044 | | |
2045 | | /* separate string */ |
2046 | 445 | if (Z_REFCOUNTED_P(str) && Z_REFCOUNT_P(str) == 1) { |
2047 | 218 | s = Z_STR_P(str); |
2048 | 227 | } else { |
2049 | 227 | s = zend_string_init(Z_STRVAL_P(str), Z_STRLEN_P(str), 0); |
2050 | 227 | ZSTR_H(s) = ZSTR_H(Z_STR_P(str)); |
2051 | 227 | if (Z_REFCOUNTED_P(str)) { |
2052 | 57 | GC_DELREF(Z_STR_P(str)); |
2053 | 57 | } |
2054 | 227 | ZVAL_NEW_STR(str, s); |
2055 | 227 | } |
2056 | | |
2057 | 445 | if (EXPECTED(Z_TYPE_P(dim) == IS_LONG)) { |
2058 | 263 | offset = Z_LVAL_P(dim); |
2059 | 263 | } else { |
2060 | | /* The string may be destroyed while throwing the notice. |
2061 | | * Temporarily increase the refcount to detect this situation. */ |
2062 | 182 | GC_ADDREF(s); |
2063 | 182 | offset = zend_check_string_offset(dim, BP_VAR_W EXECUTE_DATA_CC); |
2064 | 182 | if (UNEXPECTED(GC_DELREF(s) == 0)) { |
2065 | 0 | zend_string_efree(s); |
2066 | 0 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2067 | 0 | ZVAL_NULL(EX_VAR(opline->result.var)); |
2068 | 0 | } |
2069 | 0 | return; |
2070 | 0 | } |
2071 | | /* Illegal offset assignment */ |
2072 | 182 | if (UNEXPECTED(EG(exception) != NULL)) { |
2073 | 65 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2074 | 14 | ZVAL_UNDEF(EX_VAR(opline->result.var)); |
2075 | 14 | } |
2076 | 65 | return; |
2077 | 65 | } |
2078 | 182 | } |
2079 | | |
2080 | 380 | if (UNEXPECTED(offset < -(zend_long)ZSTR_LEN(s))) { |
2081 | | /* Error on negative offset */ |
2082 | 81 | zend_error(E_WARNING, "Illegal string offset " ZEND_LONG_FMT, offset); |
2083 | 81 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2084 | 75 | ZVAL_NULL(EX_VAR(opline->result.var)); |
2085 | 75 | } |
2086 | 81 | return; |
2087 | 81 | } |
2088 | | |
2089 | 299 | if (offset < 0) { /* Handle negative offset */ |
2090 | 46 | offset += (zend_long)ZSTR_LEN(s); |
2091 | 46 | } |
2092 | | |
2093 | 299 | if (UNEXPECTED(Z_TYPE_P(value) != IS_STRING)) { |
2094 | 95 | zend_string *tmp; |
2095 | | |
2096 | | /* The string may be destroyed while throwing the notice. |
2097 | | * Temporarily increase the refcount to detect this situation. */ |
2098 | 95 | GC_ADDREF(s); |
2099 | 95 | if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) { |
2100 | 0 | zval_undefined_cv((opline+1)->op1.var EXECUTE_DATA_CC); |
2101 | 0 | } |
2102 | | /* Convert to string, just the time to pick the 1st byte */ |
2103 | 95 | tmp = zval_try_get_string_func(value); |
2104 | 95 | if (UNEXPECTED(GC_DELREF(s) == 0)) { |
2105 | 0 | zend_string_efree(s); |
2106 | 0 | if (tmp) { |
2107 | 0 | zend_string_release_ex(tmp, 0); |
2108 | 0 | } |
2109 | 0 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2110 | 0 | ZVAL_NULL(EX_VAR(opline->result.var)); |
2111 | 0 | } |
2112 | 0 | return; |
2113 | 0 | } |
2114 | 95 | if (UNEXPECTED(!tmp)) { |
2115 | 5 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2116 | 0 | ZVAL_UNDEF(EX_VAR(opline->result.var)); |
2117 | 0 | } |
2118 | 5 | return; |
2119 | 5 | } |
2120 | | |
2121 | 90 | string_len = ZSTR_LEN(tmp); |
2122 | 90 | c = (zend_uchar)ZSTR_VAL(tmp)[0]; |
2123 | 90 | zend_string_release_ex(tmp, 0); |
2124 | 204 | } else { |
2125 | 204 | string_len = Z_STRLEN_P(value); |
2126 | 204 | c = (zend_uchar)Z_STRVAL_P(value)[0]; |
2127 | 204 | } |
2128 | | |
2129 | 294 | if (UNEXPECTED(string_len != 1)) { |
2130 | 102 | if (string_len == 0) { |
2131 | | /* Error on empty input string */ |
2132 | 29 | zend_throw_error(NULL, "Cannot assign an empty string to a string offset"); |
2133 | 29 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2134 | 29 | ZVAL_NULL(EX_VAR(opline->result.var)); |
2135 | 29 | } |
2136 | 29 | return; |
2137 | 29 | } |
2138 | | |
2139 | | /* The string may be destroyed while throwing the notice. |
2140 | | * Temporarily increase the refcount to detect this situation. */ |
2141 | 73 | GC_ADDREF(s); |
2142 | 73 | zend_error(E_WARNING, "Only the first byte will be assigned to the string offset"); |
2143 | 73 | if (UNEXPECTED(GC_DELREF(s) == 0)) { |
2144 | 0 | zend_string_efree(s); |
2145 | 0 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2146 | 0 | ZVAL_NULL(EX_VAR(opline->result.var)); |
2147 | 0 | } |
2148 | 0 | return; |
2149 | 0 | } |
2150 | | /* Illegal offset assignment */ |
2151 | 73 | if (UNEXPECTED(EG(exception) != NULL)) { |
2152 | 0 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2153 | 0 | ZVAL_UNDEF(EX_VAR(opline->result.var)); |
2154 | 0 | } |
2155 | 0 | return; |
2156 | 0 | } |
2157 | 73 | } |
2158 | | |
2159 | 265 | if ((size_t)offset >= ZSTR_LEN(s)) { |
2160 | | /* Extend string if needed */ |
2161 | 40 | zend_long old_len = ZSTR_LEN(s); |
2162 | 40 | ZVAL_NEW_STR(str, zend_string_extend(s, (size_t)offset + 1, 0)); |
2163 | 40 | memset(Z_STRVAL_P(str) + old_len, ' ', offset - old_len); |
2164 | 40 | Z_STRVAL_P(str)[offset+1] = 0; |
2165 | 225 | } else { |
2166 | 225 | zend_string_forget_hash_val(Z_STR_P(str)); |
2167 | 225 | } |
2168 | | |
2169 | 265 | Z_STRVAL_P(str)[offset] = c; |
2170 | | |
2171 | 265 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2172 | | /* Return the new character */ |
2173 | 85 | ZVAL_CHAR(EX_VAR(opline->result.var), c); |
2174 | 85 | } |
2175 | 265 | } |
2176 | | |
2177 | | static zend_property_info *zend_get_prop_not_accepting_double(zend_reference *ref) |
2178 | 299 | { |
2179 | 299 | zend_property_info *prop; |
2180 | 897 | ZEND_REF_FOREACH_TYPE_SOURCES(ref, prop) { |
2181 | 897 | if (!(ZEND_TYPE_FULL_MASK(prop->type) & MAY_BE_DOUBLE)) { |
2182 | 242 | return prop; |
2183 | 242 | } |
2184 | 897 | } ZEND_REF_FOREACH_TYPE_SOURCES_END(); |
2185 | 57 | return NULL; |
2186 | 299 | } |
2187 | | |
2188 | | static ZEND_COLD zend_long zend_throw_incdec_ref_error( |
2189 | | zend_reference *ref, zend_property_info *error_prop OPLINE_DC) |
2190 | 242 | { |
2191 | 242 | zend_string *type_str = zend_type_to_string(error_prop->type); |
2192 | 242 | if (ZEND_IS_INCREMENT(opline->opcode)) { |
2193 | 119 | zend_type_error( |
2194 | 119 | "Cannot increment a reference held by property %s::$%s of type %s past its maximal value", |
2195 | 119 | ZSTR_VAL(error_prop->ce->name), |
2196 | 119 | zend_get_unmangled_property_name(error_prop->name), |
2197 | 119 | ZSTR_VAL(type_str)); |
2198 | 119 | zend_string_release(type_str); |
2199 | 119 | return ZEND_LONG_MAX; |
2200 | 123 | } else { |
2201 | 123 | zend_type_error( |
2202 | 123 | "Cannot decrement a reference held by property %s::$%s of type %s past its minimal value", |
2203 | 123 | ZSTR_VAL(error_prop->ce->name), |
2204 | 123 | zend_get_unmangled_property_name(error_prop->name), |
2205 | 123 | ZSTR_VAL(type_str)); |
2206 | 123 | zend_string_release(type_str); |
2207 | 123 | return ZEND_LONG_MIN; |
2208 | 123 | } |
2209 | 242 | } |
2210 | | |
2211 | 113 | static ZEND_COLD zend_long zend_throw_incdec_prop_error(zend_property_info *prop OPLINE_DC) { |
2212 | 113 | zend_string *type_str = zend_type_to_string(prop->type); |
2213 | 113 | if (ZEND_IS_INCREMENT(opline->opcode)) { |
2214 | 69 | zend_type_error("Cannot increment property %s::$%s of type %s past its maximal value", |
2215 | 69 | ZSTR_VAL(prop->ce->name), |
2216 | 69 | zend_get_unmangled_property_name(prop->name), |
2217 | 69 | ZSTR_VAL(type_str)); |
2218 | 69 | zend_string_release(type_str); |
2219 | 69 | return ZEND_LONG_MAX; |
2220 | 69 | } else { |
2221 | 44 | zend_type_error("Cannot decrement property %s::$%s of type %s past its minimal value", |
2222 | 44 | ZSTR_VAL(prop->ce->name), |
2223 | 44 | zend_get_unmangled_property_name(prop->name), |
2224 | 44 | ZSTR_VAL(type_str)); |
2225 | 44 | zend_string_release(type_str); |
2226 | 44 | return ZEND_LONG_MIN; |
2227 | 44 | } |
2228 | 113 | } |
2229 | | |
2230 | | static void zend_incdec_typed_ref(zend_reference *ref, zval *copy OPLINE_DC EXECUTE_DATA_DC) |
2231 | 506 | { |
2232 | 506 | zval tmp; |
2233 | 506 | zval *var_ptr = &ref->val; |
2234 | | |
2235 | 506 | if (!copy) { |
2236 | 372 | copy = &tmp; |
2237 | 372 | } |
2238 | | |
2239 | 506 | ZVAL_COPY(copy, var_ptr); |
2240 | | |
2241 | 506 | if (ZEND_IS_INCREMENT(opline->opcode)) { |
2242 | 216 | increment_function(var_ptr); |
2243 | 290 | } else { |
2244 | 290 | decrement_function(var_ptr); |
2245 | 290 | } |
2246 | | |
2247 | 506 | if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE_P(copy) == IS_LONG) { |
2248 | 299 | zend_property_info *error_prop = zend_get_prop_not_accepting_double(ref); |
2249 | 299 | if (UNEXPECTED(error_prop)) { |
2250 | 242 | zend_long val = zend_throw_incdec_ref_error(ref, error_prop OPLINE_CC); |
2251 | 242 | ZVAL_LONG(var_ptr, val); |
2252 | 242 | } |
2253 | 299 | } else if (UNEXPECTED(!zend_verify_ref_assignable_zval(ref, var_ptr, EX_USES_STRICT_TYPES()))) { |
2254 | 6 | zval_ptr_dtor(var_ptr); |
2255 | 6 | ZVAL_COPY_VALUE(var_ptr, copy); |
2256 | 6 | ZVAL_UNDEF(copy); |
2257 | 201 | } else if (copy == &tmp) { |
2258 | 147 | zval_ptr_dtor(&tmp); |
2259 | 147 | } |
2260 | 506 | } |
2261 | | |
2262 | | static void zend_incdec_typed_prop(zend_property_info *prop_info, zval *var_ptr, zval *copy OPLINE_DC EXECUTE_DATA_DC) |
2263 | 82 | { |
2264 | 82 | zval tmp; |
2265 | | |
2266 | 82 | if (!copy) { |
2267 | 63 | copy = &tmp; |
2268 | 63 | } |
2269 | | |
2270 | 82 | ZVAL_COPY(copy, var_ptr); |
2271 | | |
2272 | 82 | if (ZEND_IS_INCREMENT(opline->opcode)) { |
2273 | 56 | increment_function(var_ptr); |
2274 | 56 | } else { |
2275 | 26 | decrement_function(var_ptr); |
2276 | 26 | } |
2277 | | |
2278 | 82 | if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE_P(copy) == IS_LONG) { |
2279 | 0 | if (!(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) { |
2280 | 0 | zend_long val = zend_throw_incdec_prop_error(prop_info OPLINE_CC); |
2281 | 0 | ZVAL_LONG(var_ptr, val); |
2282 | 0 | } |
2283 | 82 | } else if (UNEXPECTED(!zend_verify_property_type(prop_info, var_ptr, EX_USES_STRICT_TYPES()))) { |
2284 | 12 | zval_ptr_dtor(var_ptr); |
2285 | 12 | ZVAL_COPY_VALUE(var_ptr, copy); |
2286 | 12 | ZVAL_UNDEF(copy); |
2287 | 70 | } else if (copy == &tmp) { |
2288 | 56 | zval_ptr_dtor(&tmp); |
2289 | 56 | } |
2290 | 82 | } |
2291 | | |
2292 | | static void zend_pre_incdec_property_zval(zval *prop, zend_property_info *prop_info OPLINE_DC EXECUTE_DATA_DC) |
2293 | 1.39k | { |
2294 | 1.39k | if (EXPECTED(Z_TYPE_P(prop) == IS_LONG)) { |
2295 | 719 | if (ZEND_IS_INCREMENT(opline->opcode)) { |
2296 | 614 | fast_long_increment_function(prop); |
2297 | 614 | } else { |
2298 | 105 | fast_long_decrement_function(prop); |
2299 | 105 | } |
2300 | 719 | if (UNEXPECTED(Z_TYPE_P(prop) != IS_LONG) && prop_info |
2301 | 133 | && !(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) { |
2302 | 94 | zend_long val = zend_throw_incdec_prop_error(prop_info OPLINE_CC); |
2303 | 94 | ZVAL_LONG(prop, val); |
2304 | 94 | } |
2305 | 719 | } else { |
2306 | 671 | do { |
2307 | 671 | if (Z_ISREF_P(prop)) { |
2308 | 170 | zend_reference *ref = Z_REF_P(prop); |
2309 | 170 | prop = Z_REFVAL_P(prop); |
2310 | 170 | if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { |
2311 | 127 | zend_incdec_typed_ref(ref, NULL OPLINE_CC EXECUTE_DATA_CC); |
2312 | 127 | break; |
2313 | 127 | } |
2314 | 170 | } |
2315 | | |
2316 | 544 | if (prop_info) { |
2317 | 63 | zend_incdec_typed_prop(prop_info, prop, NULL OPLINE_CC EXECUTE_DATA_CC); |
2318 | 481 | } else if (ZEND_IS_INCREMENT(opline->opcode)) { |
2319 | 446 | increment_function(prop); |
2320 | 446 | } else { |
2321 | 35 | decrement_function(prop); |
2322 | 35 | } |
2323 | 544 | } while (0); |
2324 | 671 | } |
2325 | 1.39k | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2326 | 892 | ZVAL_COPY(EX_VAR(opline->result.var), prop); |
2327 | 892 | } |
2328 | 1.39k | } |
2329 | | |
2330 | | static void zend_post_incdec_property_zval(zval *prop, zend_property_info *prop_info OPLINE_DC EXECUTE_DATA_DC) |
2331 | 1.17k | { |
2332 | 1.17k | if (EXPECTED(Z_TYPE_P(prop) == IS_LONG)) { |
2333 | 1.05k | ZVAL_LONG(EX_VAR(opline->result.var), Z_LVAL_P(prop)); |
2334 | 1.05k | if (ZEND_IS_INCREMENT(opline->opcode)) { |
2335 | 304 | fast_long_increment_function(prop); |
2336 | 746 | } else { |
2337 | 746 | fast_long_decrement_function(prop); |
2338 | 746 | } |
2339 | 1.05k | if (UNEXPECTED(Z_TYPE_P(prop) != IS_LONG) && prop_info |
2340 | 62 | && !(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) { |
2341 | 19 | zend_long val = zend_throw_incdec_prop_error(prop_info OPLINE_CC); |
2342 | 19 | ZVAL_LONG(prop, val); |
2343 | 19 | } |
2344 | 1.05k | } else { |
2345 | 129 | if (Z_ISREF_P(prop)) { |
2346 | 84 | zend_reference *ref = Z_REF_P(prop); |
2347 | 84 | prop = Z_REFVAL_P(prop); |
2348 | 84 | if (ZEND_REF_HAS_TYPE_SOURCES(ref)) { |
2349 | 65 | zend_incdec_typed_ref(ref, EX_VAR(opline->result.var) OPLINE_CC EXECUTE_DATA_CC); |
2350 | 65 | return; |
2351 | 65 | } |
2352 | 84 | } |
2353 | | |
2354 | 64 | if (prop_info) { |
2355 | 19 | zend_incdec_typed_prop(prop_info, prop, EX_VAR(opline->result.var) OPLINE_CC EXECUTE_DATA_CC); |
2356 | 45 | } else { |
2357 | 45 | ZVAL_COPY(EX_VAR(opline->result.var), prop); |
2358 | 45 | if (ZEND_IS_INCREMENT(opline->opcode)) { |
2359 | 40 | increment_function(prop); |
2360 | 40 | } else { |
2361 | 5 | decrement_function(prop); |
2362 | 5 | } |
2363 | 45 | } |
2364 | 64 | } |
2365 | 1.17k | } |
2366 | | |
2367 | | static zend_never_inline void zend_post_incdec_overloaded_property(zend_object *object, zend_string *name, void **cache_slot OPLINE_DC EXECUTE_DATA_DC) |
2368 | 32 | { |
2369 | 32 | zval rv; |
2370 | 32 | zval *z; |
2371 | 32 | zval z_copy; |
2372 | | |
2373 | 32 | GC_ADDREF(object); |
2374 | 32 | z =object->handlers->read_property(object, name, BP_VAR_R, cache_slot, &rv); |
2375 | 32 | if (UNEXPECTED(EG(exception))) { |
2376 | 4 | OBJ_RELEASE(object); |
2377 | 4 | ZVAL_UNDEF(EX_VAR(opline->result.var)); |
2378 | 4 | return; |
2379 | 4 | } |
2380 | | |
2381 | 28 | ZVAL_COPY_DEREF(&z_copy, z); |
2382 | 28 | ZVAL_COPY(EX_VAR(opline->result.var), &z_copy); |
2383 | 28 | if (ZEND_IS_INCREMENT(opline->opcode)) { |
2384 | 23 | increment_function(&z_copy); |
2385 | 23 | } else { |
2386 | 5 | decrement_function(&z_copy); |
2387 | 5 | } |
2388 | 28 | object->handlers->write_property(object, name, &z_copy, cache_slot); |
2389 | 28 | OBJ_RELEASE(object); |
2390 | 28 | zval_ptr_dtor(&z_copy); |
2391 | 28 | if (z == &rv) { |
2392 | 16 | zval_ptr_dtor(z); |
2393 | 16 | } |
2394 | 28 | } |
2395 | | |
2396 | | static zend_never_inline void zend_pre_incdec_overloaded_property(zend_object *object, zend_string *name, void **cache_slot OPLINE_DC EXECUTE_DATA_DC) |
2397 | 244 | { |
2398 | 244 | zval rv; |
2399 | 244 | zval *z; |
2400 | 244 | zval z_copy; |
2401 | | |
2402 | 244 | GC_ADDREF(object); |
2403 | 244 | z = object->handlers->read_property(object, name, BP_VAR_R, cache_slot, &rv); |
2404 | 244 | if (UNEXPECTED(EG(exception))) { |
2405 | 5 | OBJ_RELEASE(object); |
2406 | 5 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2407 | 0 | ZVAL_NULL(EX_VAR(opline->result.var)); |
2408 | 0 | } |
2409 | 5 | return; |
2410 | 5 | } |
2411 | | |
2412 | 239 | ZVAL_COPY_DEREF(&z_copy, z); |
2413 | 239 | if (ZEND_IS_INCREMENT(opline->opcode)) { |
2414 | 180 | increment_function(&z_copy); |
2415 | 180 | } else { |
2416 | 59 | decrement_function(&z_copy); |
2417 | 59 | } |
2418 | 239 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2419 | 13 | ZVAL_COPY(EX_VAR(opline->result.var), &z_copy); |
2420 | 13 | } |
2421 | 239 | object->handlers->write_property(object, name, &z_copy, cache_slot); |
2422 | 239 | OBJ_RELEASE(object); |
2423 | 239 | zval_ptr_dtor(&z_copy); |
2424 | 239 | if (z == &rv) { |
2425 | 119 | zval_ptr_dtor(z); |
2426 | 119 | } |
2427 | 239 | } |
2428 | | |
2429 | | static zend_never_inline void zend_assign_op_overloaded_property(zend_object *object, zend_string *name, void **cache_slot, zval *value OPLINE_DC EXECUTE_DATA_DC) |
2430 | 264 | { |
2431 | 264 | zval *z; |
2432 | 264 | zval rv, res; |
2433 | | |
2434 | 264 | GC_ADDREF(object); |
2435 | 264 | z = object->handlers->read_property(object, name, BP_VAR_R, cache_slot, &rv); |
2436 | 264 | if (UNEXPECTED(EG(exception))) { |
2437 | 9 | OBJ_RELEASE(object); |
2438 | 9 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2439 | 0 | ZVAL_UNDEF(EX_VAR(opline->result.var)); |
2440 | 0 | } |
2441 | 9 | return; |
2442 | 9 | } |
2443 | 255 | if (zend_binary_op(&res, z, value OPLINE_CC) == SUCCESS) { |
2444 | 237 | object->handlers->write_property(object, name, &res, cache_slot); |
2445 | 237 | } |
2446 | 255 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
2447 | 66 | ZVAL_COPY(EX_VAR(opline->result.var), &res); |
2448 | 66 | } |
2449 | 255 | if (z == &rv) { |
2450 | 181 | zval_ptr_dtor(z); |
2451 | 181 | } |
2452 | 255 | zval_ptr_dtor(&res); |
2453 | 255 | OBJ_RELEASE(object); |
2454 | 255 | } |
2455 | | |
2456 | | /* Utility Functions for Extensions */ |
2457 | | static void zend_extension_statement_handler(const zend_extension *extension, zend_execute_data *frame) |
2458 | 0 | { |
2459 | 0 | if (extension->statement_handler) { |
2460 | 0 | extension->statement_handler(frame); |
2461 | 0 | } |
2462 | 0 | } |
2463 | | |
2464 | | |
2465 | | static void zend_extension_fcall_begin_handler(const zend_extension *extension, zend_execute_data *frame) |
2466 | 0 | { |
2467 | 0 | if (extension->fcall_begin_handler) { |
2468 | 0 | extension->fcall_begin_handler(frame); |
2469 | 0 | } |
2470 | 0 | } |
2471 | | |
2472 | | |
2473 | | static void zend_extension_fcall_end_handler(const zend_extension *extension, zend_execute_data *frame) |
2474 | 0 | { |
2475 | 0 | if (extension->fcall_end_handler) { |
2476 | 0 | extension->fcall_end_handler(frame); |
2477 | 0 | } |
2478 | 0 | } |
2479 | | |
2480 | | |
2481 | | static zend_always_inline HashTable *zend_get_target_symbol_table(int fetch_type EXECUTE_DATA_DC) |
2482 | 55.7k | { |
2483 | 55.7k | HashTable *ht; |
2484 | | |
2485 | 55.7k | if (EXPECTED(fetch_type & (ZEND_FETCH_GLOBAL_LOCK | ZEND_FETCH_GLOBAL))) { |
2486 | 5.07k | ht = &EG(symbol_table); |
2487 | 50.6k | } else { |
2488 | 50.6k | ZEND_ASSERT(fetch_type & ZEND_FETCH_LOCAL); |
2489 | 50.6k | if (!(EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE)) { |
2490 | 5.24k | zend_rebuild_symbol_table(); |
2491 | 5.24k | } |
2492 | 50.6k | ht = EX(symbol_table); |
2493 | 50.6k | } |
2494 | 55.7k | return ht; |
2495 | 55.7k | } |
2496 | | |
2497 | | static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_undefined_offset(zend_long lval) |
2498 | 1.92k | { |
2499 | 1.92k | zend_error(E_WARNING, "Undefined array key " ZEND_LONG_FMT, lval); |
2500 | 1.92k | } |
2501 | | |
2502 | | static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_undefined_index(const zend_string *offset) |
2503 | 2.09k | { |
2504 | 2.09k | zend_error(E_WARNING, "Undefined array key \"%s\"", ZSTR_VAL(offset)); |
2505 | 2.09k | } |
2506 | | |
2507 | | ZEND_API ZEND_COLD zval* ZEND_FASTCALL zend_undefined_offset_write(HashTable *ht, zend_long lval) |
2508 | 329 | { |
2509 | | /* The array may be destroyed while throwing the notice. |
2510 | | * Temporarily increase the refcount to detect this situation. */ |
2511 | 329 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { |
2512 | 329 | GC_ADDREF(ht); |
2513 | 329 | } |
2514 | 329 | zend_undefined_offset(lval); |
2515 | 329 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { |
2516 | 0 | if (!GC_REFCOUNT(ht)) { |
2517 | 0 | zend_array_destroy(ht); |
2518 | 0 | } |
2519 | 0 | return NULL; |
2520 | 0 | } |
2521 | 329 | if (EG(exception)) { |
2522 | 0 | return NULL; |
2523 | 0 | } |
2524 | 329 | return zend_hash_index_add_new(ht, lval, &EG(uninitialized_zval)); |
2525 | 329 | } |
2526 | | |
2527 | | ZEND_API ZEND_COLD zval* ZEND_FASTCALL zend_undefined_index_write(HashTable *ht, zend_string *offset) |
2528 | 1.16k | { |
2529 | 1.16k | zval *retval; |
2530 | | |
2531 | | /* The array may be destroyed while throwing the notice. |
2532 | | * Temporarily increase the refcount to detect this situation. */ |
2533 | 1.16k | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { |
2534 | 1.16k | GC_ADDREF(ht); |
2535 | 1.16k | } |
2536 | | /* Key may be released while throwing the undefined index warning. */ |
2537 | 1.16k | zend_string_addref(offset); |
2538 | 1.16k | zend_undefined_index(offset); |
2539 | 1.16k | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { |
2540 | 0 | if (!GC_REFCOUNT(ht)) { |
2541 | 0 | zend_array_destroy(ht); |
2542 | 0 | } |
2543 | 0 | retval = NULL; |
2544 | 1.16k | } else if (EG(exception)) { |
2545 | 0 | retval = NULL; |
2546 | 1.16k | } else { |
2547 | 1.16k | retval = zend_hash_add_new(ht, offset, &EG(uninitialized_zval)); |
2548 | 1.16k | } |
2549 | 1.16k | zend_string_release(offset); |
2550 | 1.16k | return retval; |
2551 | 1.16k | } |
2552 | | |
2553 | | ZEND_API zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_undefined_method(const zend_class_entry *ce, const zend_string *method) |
2554 | 458 | { |
2555 | 458 | zend_throw_error(NULL, "Call to undefined method %s::%s()", ZSTR_VAL(ce->name), ZSTR_VAL(method)); |
2556 | 458 | } |
2557 | | |
2558 | | static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_invalid_method_call(zval *object, zval *function_name) |
2559 | 587 | { |
2560 | 587 | zend_throw_error(NULL, "Call to a member function %s() on %s", |
2561 | 587 | Z_STRVAL_P(function_name), zend_zval_value_name(object)); |
2562 | 587 | } |
2563 | | |
2564 | | ZEND_API void ZEND_FASTCALL zend_non_static_method_call(const zend_function *fbc) |
2565 | 59 | { |
2566 | 59 | zend_throw_error( |
2567 | 59 | zend_ce_error, |
2568 | 59 | "Non-static method %s::%s() cannot be called statically", |
2569 | 59 | ZSTR_VAL(fbc->common.scope->name), ZSTR_VAL(fbc->common.function_name)); |
2570 | 59 | } |
2571 | | |
2572 | | ZEND_COLD void ZEND_FASTCALL zend_param_must_be_ref(const zend_function *func, uint32_t arg_num) |
2573 | 390 | { |
2574 | 390 | const char *arg_name = get_function_arg_name(func, arg_num); |
2575 | | |
2576 | 390 | zend_error(E_WARNING, "%s%s%s(): Argument #%d%s%s%s must be passed by reference, value given", |
2577 | 390 | func->common.scope ? ZSTR_VAL(func->common.scope->name) : "", |
2578 | 390 | func->common.scope ? "::" : "", |
2579 | 390 | ZSTR_VAL(func->common.function_name), |
2580 | 390 | arg_num, |
2581 | 390 | arg_name ? " ($" : "", |
2582 | 390 | arg_name ? arg_name : "", |
2583 | 390 | arg_name ? ")" : "" |
2584 | 390 | ); |
2585 | 390 | } |
2586 | | |
2587 | | static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_scalar_as_array(void) |
2588 | 172 | { |
2589 | 172 | zend_throw_error(NULL, "Cannot use a scalar value as an array"); |
2590 | 172 | } |
2591 | | |
2592 | | ZEND_API zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_cannot_add_element(void) |
2593 | 146 | { |
2594 | 146 | zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied"); |
2595 | 146 | } |
2596 | | |
2597 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_use_resource_as_offset(const zval *dim) |
2598 | 0 | { |
2599 | 0 | zend_error(E_WARNING, |
2600 | 0 | "Resource ID#" ZEND_LONG_FMT " used as offset, casting to integer (" ZEND_LONG_FMT ")", |
2601 | 0 | Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim)); |
2602 | 0 | } |
2603 | | |
2604 | | static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_new_element_for_string(void) |
2605 | 41 | { |
2606 | 41 | zend_throw_error(NULL, "[] operator not supported for strings"); |
2607 | 41 | } |
2608 | | |
2609 | | #ifdef ZEND_CHECK_STACK_LIMIT |
2610 | | ZEND_API zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_call_stack_size_error(void) |
2611 | 0 | { |
2612 | 0 | size_t max_stack_size = 0; |
2613 | 0 | if ((uintptr_t) EG(stack_base) > (uintptr_t) EG(stack_limit)) { |
2614 | 0 | max_stack_size = (size_t) ((uintptr_t) EG(stack_base) - (uintptr_t) EG(stack_limit)); |
2615 | 0 | } |
2616 | |
|
2617 | 0 | zend_throw_error(NULL, "Maximum call stack size of %zu bytes (zend.max_allowed_stack_size - zend.reserved_stack_size) reached. Infinite recursion?", |
2618 | 0 | max_stack_size); |
2619 | 0 | } |
2620 | | #endif /* ZEND_CHECK_STACK_LIMIT */ |
2621 | | |
2622 | | static ZEND_COLD void zend_binary_assign_op_dim_slow(zval *container, zval *dim OPLINE_DC EXECUTE_DATA_DC) |
2623 | 29 | { |
2624 | 29 | if (UNEXPECTED(Z_TYPE_P(container) == IS_STRING)) { |
2625 | 17 | if (opline->op2_type == IS_UNUSED) { |
2626 | 6 | zend_use_new_element_for_string(); |
2627 | 11 | } else { |
2628 | 11 | zend_check_string_offset(dim, BP_VAR_RW EXECUTE_DATA_CC); |
2629 | 11 | zend_wrong_string_offset_error(); |
2630 | 11 | } |
2631 | 17 | } else { |
2632 | 12 | zend_use_scalar_as_array(); |
2633 | 12 | } |
2634 | 29 | } |
2635 | | |
2636 | | static zend_never_inline uint8_t slow_index_convert(HashTable *ht, const zval *dim, zend_value *value EXECUTE_DATA_DC) |
2637 | 849 | { |
2638 | 849 | switch (Z_TYPE_P(dim)) { |
2639 | 411 | case IS_UNDEF: { |
2640 | | /* The array may be destroyed while throwing the notice. |
2641 | | * Temporarily increase the refcount to detect this situation. */ |
2642 | 411 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { |
2643 | 151 | GC_ADDREF(ht); |
2644 | 151 | } |
2645 | 411 | ZVAL_UNDEFINED_OP2(); |
2646 | 411 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { |
2647 | 0 | zend_array_destroy(ht); |
2648 | 0 | return IS_NULL; |
2649 | 0 | } |
2650 | 411 | if (EG(exception)) { |
2651 | 0 | return IS_NULL; |
2652 | 0 | } |
2653 | 411 | ZEND_FALLTHROUGH; |
2654 | 411 | } |
2655 | 596 | case IS_NULL: |
2656 | | /* The array may be destroyed while throwing the notice. |
2657 | | * Temporarily increase the refcount to detect this situation. */ |
2658 | 596 | GC_TRY_ADDREF(ht); |
2659 | | |
2660 | 596 | zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead"); |
2661 | | |
2662 | 596 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { |
2663 | 0 | zend_array_destroy(ht); |
2664 | 0 | return IS_NULL; |
2665 | 0 | } |
2666 | | |
2667 | 596 | if (EG(exception)) { |
2668 | 0 | return IS_NULL; |
2669 | 0 | } |
2670 | | |
2671 | 596 | value->str = ZSTR_EMPTY_ALLOC(); |
2672 | 596 | return IS_STRING; |
2673 | 192 | case IS_DOUBLE: |
2674 | | /* The array may be destroyed while throwing the notice. |
2675 | | * Temporarily increase the refcount to detect this situation. */ |
2676 | 192 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { |
2677 | 127 | GC_ADDREF(ht); |
2678 | 127 | } |
2679 | 192 | value->lval = zend_dval_to_lval_safe(Z_DVAL_P(dim)); |
2680 | 192 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { |
2681 | 0 | zend_array_destroy(ht); |
2682 | 0 | return IS_NULL; |
2683 | 0 | } |
2684 | 192 | if (EG(exception)) { |
2685 | 0 | return IS_NULL; |
2686 | 0 | } |
2687 | 192 | return IS_LONG; |
2688 | 0 | case IS_RESOURCE: |
2689 | | /* The array may be destroyed while throwing the notice. |
2690 | | * Temporarily increase the refcount to detect this situation. */ |
2691 | 0 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { |
2692 | 0 | GC_ADDREF(ht); |
2693 | 0 | } |
2694 | 0 | zend_use_resource_as_offset(dim); |
2695 | 0 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { |
2696 | 0 | zend_array_destroy(ht); |
2697 | 0 | return IS_NULL; |
2698 | 0 | } |
2699 | 0 | if (EG(exception)) { |
2700 | 0 | return IS_NULL; |
2701 | 0 | } |
2702 | 0 | value->lval = Z_RES_HANDLE_P(dim); |
2703 | 0 | return IS_LONG; |
2704 | 23 | case IS_FALSE: |
2705 | 23 | value->lval = 0; |
2706 | 23 | return IS_LONG; |
2707 | 18 | case IS_TRUE: |
2708 | 18 | value->lval = 1; |
2709 | 18 | return IS_LONG; |
2710 | 20 | default: |
2711 | 20 | zend_illegal_array_offset_access(dim); |
2712 | 20 | return IS_NULL; |
2713 | 849 | } |
2714 | 849 | } |
2715 | | |
2716 | | static zend_never_inline uint8_t slow_index_convert_w(HashTable *ht, const zval *dim, zend_value *value EXECUTE_DATA_DC) |
2717 | 9.83k | { |
2718 | 9.83k | switch (Z_TYPE_P(dim)) { |
2719 | 8.36k | case IS_UNDEF: { |
2720 | | /* The array may be destroyed while throwing the notice. |
2721 | | * Temporarily increase the refcount to detect this situation. */ |
2722 | 8.36k | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { |
2723 | 8.36k | GC_ADDREF(ht); |
2724 | 8.36k | } |
2725 | 8.36k | ZVAL_UNDEFINED_OP2(); |
2726 | 8.36k | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { |
2727 | 0 | if (!GC_REFCOUNT(ht)) { |
2728 | 0 | zend_array_destroy(ht); |
2729 | 0 | } |
2730 | 0 | return IS_NULL; |
2731 | 0 | } |
2732 | 8.36k | if (EG(exception)) { |
2733 | 0 | return IS_NULL; |
2734 | 0 | } |
2735 | 8.36k | ZEND_FALLTHROUGH; |
2736 | 8.36k | } |
2737 | 9.50k | case IS_NULL: |
2738 | | /* The array may be destroyed while throwing the notice. |
2739 | | * Temporarily increase the refcount to detect this situation. */ |
2740 | 9.50k | GC_TRY_ADDREF(ht); |
2741 | | |
2742 | 9.50k | zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead"); |
2743 | | |
2744 | 9.50k | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { |
2745 | 0 | if (!GC_REFCOUNT(ht)) { |
2746 | 0 | zend_array_destroy(ht); |
2747 | 0 | } |
2748 | 0 | return IS_NULL; |
2749 | 0 | } |
2750 | 9.50k | if (EG(exception)) { |
2751 | 0 | return IS_NULL; |
2752 | 0 | } |
2753 | 9.50k | value->str = ZSTR_EMPTY_ALLOC(); |
2754 | 9.50k | return IS_STRING; |
2755 | 29 | case IS_DOUBLE: |
2756 | | /* The array may be destroyed while throwing the notice. |
2757 | | * Temporarily increase the refcount to detect this situation. */ |
2758 | 29 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { |
2759 | 29 | GC_ADDREF(ht); |
2760 | 29 | } |
2761 | 29 | value->lval = zend_dval_to_lval_safe(Z_DVAL_P(dim)); |
2762 | 29 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { |
2763 | 0 | if (!GC_REFCOUNT(ht)) { |
2764 | 0 | zend_array_destroy(ht); |
2765 | 0 | } |
2766 | 0 | return IS_NULL; |
2767 | 0 | } |
2768 | 29 | if (EG(exception)) { |
2769 | 0 | return IS_NULL; |
2770 | 0 | } |
2771 | 29 | return IS_LONG; |
2772 | 0 | case IS_RESOURCE: |
2773 | | /* The array may be destroyed while throwing the notice. |
2774 | | * Temporarily increase the refcount to detect this situation. */ |
2775 | 0 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { |
2776 | 0 | GC_ADDREF(ht); |
2777 | 0 | } |
2778 | 0 | zend_use_resource_as_offset(dim); |
2779 | 0 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { |
2780 | 0 | if (!GC_REFCOUNT(ht)) { |
2781 | 0 | zend_array_destroy(ht); |
2782 | 0 | } |
2783 | 0 | return IS_NULL; |
2784 | 0 | } |
2785 | 0 | if (EG(exception)) { |
2786 | 0 | return IS_NULL; |
2787 | 0 | } |
2788 | 0 | value->lval = Z_RES_HANDLE_P(dim); |
2789 | 0 | return IS_LONG; |
2790 | 12 | case IS_FALSE: |
2791 | 12 | value->lval = 0; |
2792 | 12 | return IS_LONG; |
2793 | 183 | case IS_TRUE: |
2794 | 183 | value->lval = 1; |
2795 | 183 | return IS_LONG; |
2796 | 101 | default: |
2797 | 101 | zend_illegal_array_offset_access(dim); |
2798 | 101 | return IS_NULL; |
2799 | 9.83k | } |
2800 | 9.83k | } |
2801 | | |
2802 | | static zend_always_inline zval *zend_fetch_dimension_address_inner(HashTable *ht, const zval *dim, int dim_type, int type EXECUTE_DATA_DC) |
2803 | 60.2k | { |
2804 | 60.2k | zval *retval = NULL; |
2805 | 60.2k | zend_string *offset_key; |
2806 | 60.2k | zend_ulong hval; |
2807 | | |
2808 | 60.2k | try_again: |
2809 | 60.2k | if (EXPECTED(Z_TYPE_P(dim) == IS_LONG)) { |
2810 | 36.9k | hval = Z_LVAL_P(dim); |
2811 | 37.8k | num_index: |
2812 | 37.8k | if (type != BP_VAR_W) { |
2813 | 10.6k | ZEND_HASH_INDEX_FIND(ht, hval, retval, num_undef); |
2814 | 9.55k | return retval; |
2815 | 1.12k | num_undef: |
2816 | 1.12k | switch (type) { |
2817 | 710 | case BP_VAR_R: |
2818 | 710 | zend_undefined_offset(hval); |
2819 | 710 | ZEND_FALLTHROUGH; |
2820 | 712 | case BP_VAR_UNSET: |
2821 | 799 | case BP_VAR_IS: |
2822 | 799 | retval = &EG(uninitialized_zval); |
2823 | 799 | break; |
2824 | 329 | case BP_VAR_RW: |
2825 | 329 | retval = zend_undefined_offset_write(ht, hval); |
2826 | 329 | break; |
2827 | 1.12k | } |
2828 | 27.1k | } else { |
2829 | 27.1k | ZEND_HASH_INDEX_LOOKUP(ht, hval, retval); |
2830 | 27.1k | } |
2831 | 37.8k | } else if (EXPECTED(Z_TYPE_P(dim) == IS_STRING)) { |
2832 | 12.5k | offset_key = Z_STR_P(dim); |
2833 | 12.5k | if (ZEND_CONST_COND(dim_type != IS_CONST, 1)) { |
2834 | 12.5k | if (ZEND_HANDLE_NUMERIC(offset_key, hval)) { |
2835 | 388 | goto num_index; |
2836 | 388 | } |
2837 | 12.5k | } |
2838 | 22.3k | str_index: |
2839 | 22.3k | if (type != BP_VAR_W) { |
2840 | 8.75k | retval = zend_hash_find_ex(ht, offset_key, ZEND_CONST_COND(dim_type == IS_CONST, 0)); |
2841 | 8.75k | if (!retval) { |
2842 | 2.40k | switch (type) { |
2843 | 929 | case BP_VAR_R: |
2844 | 929 | zend_undefined_index(offset_key); |
2845 | 929 | ZEND_FALLTHROUGH; |
2846 | 932 | case BP_VAR_UNSET: |
2847 | 1.23k | case BP_VAR_IS: |
2848 | 1.23k | retval = &EG(uninitialized_zval); |
2849 | 1.23k | break; |
2850 | 1.16k | case BP_VAR_RW: |
2851 | 1.16k | retval = zend_undefined_index_write(ht, offset_key); |
2852 | 1.16k | break; |
2853 | 2.40k | } |
2854 | 2.40k | } |
2855 | 13.5k | } else { |
2856 | 13.5k | retval = zend_hash_lookup(ht, offset_key); |
2857 | 13.5k | } |
2858 | 22.3k | } else if (EXPECTED(Z_TYPE_P(dim) == IS_REFERENCE)) { |
2859 | 3 | dim = Z_REFVAL_P(dim); |
2860 | 3 | goto try_again; |
2861 | 10.6k | } else { |
2862 | 10.6k | zend_value val; |
2863 | 10.6k | uint8_t t; |
2864 | | |
2865 | 10.6k | if (type != BP_VAR_W && type != BP_VAR_RW) { |
2866 | 849 | t = slow_index_convert(ht, dim, &val EXECUTE_DATA_CC); |
2867 | 9.83k | } else { |
2868 | 9.83k | t = slow_index_convert_w(ht, dim, &val EXECUTE_DATA_CC); |
2869 | 9.83k | } |
2870 | 10.6k | if (t == IS_STRING) { |
2871 | 10.1k | offset_key = val.str; |
2872 | 10.1k | goto str_index; |
2873 | 10.1k | } else if (t == IS_LONG) { |
2874 | 457 | hval = val.lval; |
2875 | 457 | goto num_index; |
2876 | 457 | } else { |
2877 | 121 | retval = (type == BP_VAR_W || type == BP_VAR_RW) ? |
2878 | 121 | NULL : &EG(uninitialized_zval); |
2879 | 121 | } |
2880 | 10.6k | } |
2881 | 50.7k | return retval; |
2882 | 60.2k | } |
2883 | | |
2884 | | static zend_never_inline zval* ZEND_FASTCALL zend_fetch_dimension_address_inner_W(HashTable *ht, const zval *dim EXECUTE_DATA_DC) |
2885 | 19.4k | { |
2886 | 19.4k | return zend_fetch_dimension_address_inner(ht, dim, IS_TMP_VAR, BP_VAR_W EXECUTE_DATA_CC); |
2887 | 19.4k | } |
2888 | | |
2889 | | static zend_never_inline zval* ZEND_FASTCALL zend_fetch_dimension_address_inner_W_CONST(HashTable *ht, const zval *dim EXECUTE_DATA_DC) |
2890 | 4.11k | { |
2891 | 4.11k | return zend_fetch_dimension_address_inner(ht, dim, IS_CONST, BP_VAR_W EXECUTE_DATA_CC); |
2892 | 4.11k | } |
2893 | | |
2894 | | static zend_never_inline zval* ZEND_FASTCALL zend_fetch_dimension_address_inner_RW(HashTable *ht, const zval *dim EXECUTE_DATA_DC) |
2895 | 2.93k | { |
2896 | 2.93k | return zend_fetch_dimension_address_inner(ht, dim, IS_TMP_VAR, BP_VAR_RW EXECUTE_DATA_CC); |
2897 | 2.93k | } |
2898 | | |
2899 | | static zend_never_inline zval* ZEND_FASTCALL zend_fetch_dimension_address_inner_RW_CONST(HashTable *ht, const zval *dim EXECUTE_DATA_DC) |
2900 | 1.26k | { |
2901 | 1.26k | return zend_fetch_dimension_address_inner(ht, dim, IS_CONST, BP_VAR_RW EXECUTE_DATA_CC); |
2902 | 1.26k | } |
2903 | | |
2904 | | static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *container, zval *dim, int dim_type, int type EXECUTE_DATA_DC) |
2905 | 20.9k | { |
2906 | 20.9k | zval *retval; |
2907 | | |
2908 | 20.9k | if (EXPECTED(Z_TYPE_P(container) == IS_ARRAY)) { |
2909 | 17.2k | try_array: |
2910 | 17.2k | SEPARATE_ARRAY(container); |
2911 | 20.0k | fetch_from_array: |
2912 | 20.0k | if (dim == NULL) { |
2913 | 2.03k | retval = zend_hash_next_index_insert(Z_ARRVAL_P(container), &EG(uninitialized_zval)); |
2914 | 2.03k | if (UNEXPECTED(retval == NULL)) { |
2915 | 38 | zend_cannot_add_element(); |
2916 | 38 | ZVAL_UNDEF(result); |
2917 | 38 | return; |
2918 | 38 | } |
2919 | 18.0k | } else { |
2920 | 18.0k | retval = zend_fetch_dimension_address_inner(Z_ARRVAL_P(container), dim, dim_type, type EXECUTE_DATA_CC); |
2921 | 18.0k | if (UNEXPECTED(!retval)) { |
2922 | | /* This may fail without throwing if the array was modified while throwing an |
2923 | | * undefined index error. */ |
2924 | 14 | ZVAL_NULL(result); |
2925 | 14 | return; |
2926 | 14 | } |
2927 | 18.0k | } |
2928 | 20.0k | ZVAL_INDIRECT(result, retval); |
2929 | 20.0k | return; |
2930 | 20.0k | } else if (EXPECTED(Z_TYPE_P(container) == IS_REFERENCE)) { |
2931 | 4.23k | zend_reference *ref = Z_REF_P(container); |
2932 | 4.23k | container = Z_REFVAL_P(container); |
2933 | 4.23k | if (EXPECTED(Z_TYPE_P(container) == IS_ARRAY)) { |
2934 | 4.06k | goto try_array; |
2935 | 4.06k | } else if (EXPECTED(Z_TYPE_P(container) <= IS_FALSE)) { |
2936 | 139 | if (type != BP_VAR_UNSET) { |
2937 | 139 | if (ZEND_REF_HAS_TYPE_SOURCES(ref)) { |
2938 | 5 | if (UNEXPECTED(!zend_verify_ref_array_assignable(ref))) { |
2939 | 5 | ZVAL_UNDEF(result); |
2940 | 5 | return; |
2941 | 5 | } |
2942 | 5 | } |
2943 | 134 | array_init(container); |
2944 | 134 | goto fetch_from_array; |
2945 | 139 | } else { |
2946 | 0 | goto return_null; |
2947 | 0 | } |
2948 | 139 | } |
2949 | 4.23k | } |
2950 | 3.52k | if (UNEXPECTED(Z_TYPE_P(container) == IS_STRING)) { |
2951 | 159 | if (dim == NULL) { |
2952 | 6 | zend_use_new_element_for_string(); |
2953 | 153 | } else { |
2954 | 153 | zend_check_string_offset(dim, type EXECUTE_DATA_CC); |
2955 | 153 | zend_wrong_string_offset_error(); |
2956 | 153 | } |
2957 | 159 | ZVAL_UNDEF(result); |
2958 | 3.36k | } else if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) { |
2959 | 562 | zend_object *obj = Z_OBJ_P(container); |
2960 | 562 | GC_ADDREF(obj); |
2961 | 562 | if (ZEND_CONST_COND(dim_type == IS_CV, dim != NULL) && UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) { |
2962 | 0 | dim = ZVAL_UNDEFINED_OP2(); |
2963 | 562 | } else if (dim_type == IS_CONST && Z_EXTRA_P(dim) == ZEND_EXTRA_VALUE) { |
2964 | 0 | dim++; |
2965 | 0 | } |
2966 | 562 | retval = obj->handlers->read_dimension(obj, dim, type, result); |
2967 | | |
2968 | 562 | if (UNEXPECTED(retval == &EG(uninitialized_zval))) { |
2969 | 0 | zend_class_entry *ce = obj->ce; |
2970 | |
|
2971 | 0 | ZVAL_NULL(result); |
2972 | 0 | zend_error(E_NOTICE, "Indirect modification of overloaded element of %s has no effect", ZSTR_VAL(ce->name)); |
2973 | 562 | } else if (EXPECTED(retval && Z_TYPE_P(retval) != IS_UNDEF)) { |
2974 | 543 | if (!Z_ISREF_P(retval)) { |
2975 | 289 | if (result != retval) { |
2976 | 271 | ZVAL_COPY(result, retval); |
2977 | 271 | retval = result; |
2978 | 271 | } |
2979 | 289 | if (Z_TYPE_P(retval) != IS_OBJECT) { |
2980 | 214 | zend_class_entry *ce = obj->ce; |
2981 | 214 | zend_error(E_NOTICE, "Indirect modification of overloaded element of %s has no effect", ZSTR_VAL(ce->name)); |
2982 | 214 | } |
2983 | 289 | } else if (UNEXPECTED(Z_REFCOUNT_P(retval) == 1)) { |
2984 | 166 | ZVAL_UNREF(retval); |
2985 | 166 | } |
2986 | 543 | if (result != retval) { |
2987 | 157 | ZVAL_INDIRECT(result, retval); |
2988 | 157 | } |
2989 | 543 | } else { |
2990 | 19 | ZEND_ASSERT(EG(exception) && "read_dimension() returned NULL without exception"); |
2991 | 19 | ZVAL_UNDEF(result); |
2992 | 19 | } |
2993 | 562 | if (UNEXPECTED(GC_DELREF(obj) == 0)) { |
2994 | 0 | zend_objects_store_del(obj); |
2995 | 0 | } |
2996 | 2.79k | } else { |
2997 | 2.79k | if (EXPECTED(Z_TYPE_P(container) <= IS_FALSE)) { |
2998 | 2.71k | if (type != BP_VAR_W && UNEXPECTED(Z_TYPE_P(container) == IS_UNDEF)) { |
2999 | 190 | ZVAL_UNDEFINED_OP1(); |
3000 | 190 | } |
3001 | 2.71k | if (type != BP_VAR_UNSET) { |
3002 | 2.67k | HashTable *ht = zend_new_array(0); |
3003 | 2.67k | uint8_t old_type = Z_TYPE_P(container); |
3004 | | |
3005 | 2.67k | ZVAL_ARR(container, ht); |
3006 | 2.67k | if (UNEXPECTED(old_type == IS_FALSE)) { |
3007 | 131 | GC_ADDREF(ht); |
3008 | 131 | zend_false_to_array_deprecated(); |
3009 | 131 | if (UNEXPECTED(GC_DELREF(ht) == 0)) { |
3010 | 0 | zend_array_destroy(ht); |
3011 | 0 | goto return_null; |
3012 | 0 | } |
3013 | 131 | } |
3014 | 2.67k | goto fetch_from_array; |
3015 | 2.67k | } else { |
3016 | 42 | if (UNEXPECTED(Z_TYPE_P(container) == IS_FALSE)) { |
3017 | 10 | zend_false_to_array_deprecated(); |
3018 | 10 | } |
3019 | 42 | return_null: |
3020 | | /* for read-mode only */ |
3021 | 42 | if (ZEND_CONST_COND(dim_type == IS_CV, dim != NULL) && UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) { |
3022 | 0 | ZVAL_UNDEFINED_OP2(); |
3023 | 0 | } |
3024 | 42 | ZVAL_NULL(result); |
3025 | 42 | } |
3026 | 2.71k | } else { |
3027 | 83 | if (type == BP_VAR_UNSET) { |
3028 | 15 | zend_throw_error(NULL, "Cannot unset offset in a non-array variable"); |
3029 | 15 | ZVAL_UNDEF(result); |
3030 | 68 | } else { |
3031 | 68 | zend_use_scalar_as_array(); |
3032 | 68 | ZVAL_UNDEF(result); |
3033 | 68 | } |
3034 | 83 | } |
3035 | 2.79k | } |
3036 | 3.52k | } |
3037 | | |
3038 | | static zend_never_inline void ZEND_FASTCALL zend_fetch_dimension_address_W(zval *container_ptr, zval *dim, int dim_type OPLINE_DC EXECUTE_DATA_DC) |
3039 | 19.8k | { |
3040 | 19.8k | zval *result = EX_VAR(opline->result.var); |
3041 | 19.8k | zend_fetch_dimension_address(result, container_ptr, dim, dim_type, BP_VAR_W EXECUTE_DATA_CC); |
3042 | 19.8k | } |
3043 | | |
3044 | | static zend_never_inline void ZEND_FASTCALL zend_fetch_dimension_address_RW(zval *container_ptr, zval *dim, int dim_type OPLINE_DC EXECUTE_DATA_DC) |
3045 | 960 | { |
3046 | 960 | zval *result = EX_VAR(opline->result.var); |
3047 | 960 | zend_fetch_dimension_address(result, container_ptr, dim, dim_type, BP_VAR_RW EXECUTE_DATA_CC); |
3048 | 960 | } |
3049 | | |
3050 | | static zend_never_inline void ZEND_FASTCALL zend_fetch_dimension_address_UNSET(zval *container_ptr, zval *dim, int dim_type OPLINE_DC EXECUTE_DATA_DC) |
3051 | 148 | { |
3052 | 148 | zval *result = EX_VAR(opline->result.var); |
3053 | 148 | zend_fetch_dimension_address(result, container_ptr, dim, dim_type, BP_VAR_UNSET EXECUTE_DATA_CC); |
3054 | 148 | } |
3055 | | |
3056 | | static zend_always_inline void zend_fetch_dimension_address_read(zval *result, zval *container, zval *dim, int dim_type, int type, bool is_list, bool slow EXECUTE_DATA_DC) |
3057 | 16.2k | { |
3058 | 16.2k | zval *retval; |
3059 | | |
3060 | 16.2k | if (!slow) { |
3061 | 6.79k | if (EXPECTED(Z_TYPE_P(container) == IS_ARRAY)) { |
3062 | 5.01k | try_array: |
3063 | 5.01k | retval = zend_fetch_dimension_address_inner(Z_ARRVAL_P(container), dim, dim_type, type EXECUTE_DATA_CC); |
3064 | 5.01k | ZVAL_COPY_DEREF(result, retval); |
3065 | 5.01k | return; |
3066 | 4.99k | } else if (EXPECTED(Z_TYPE_P(container) == IS_REFERENCE)) { |
3067 | 71 | container = Z_REFVAL_P(container); |
3068 | 71 | if (EXPECTED(Z_TYPE_P(container) == IS_ARRAY)) { |
3069 | 23 | goto try_array; |
3070 | 23 | } |
3071 | 71 | } |
3072 | 6.79k | } |
3073 | 11.2k | if (!is_list && EXPECTED(Z_TYPE_P(container) == IS_STRING)) { |
3074 | 2.71k | zend_string *str = Z_STR_P(container); |
3075 | 2.71k | zend_long offset; |
3076 | | |
3077 | 2.71k | try_string_offset: |
3078 | 2.71k | if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) { |
3079 | 927 | switch (Z_TYPE_P(dim)) { |
3080 | 455 | case IS_STRING: |
3081 | 455 | { |
3082 | 455 | bool trailing_data = false; |
3083 | | /* For BC reasons we allow errors so that we can warn on leading numeric string */ |
3084 | 455 | if (IS_LONG == is_numeric_string_ex(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, |
3085 | 455 | NULL, /* allow errors */ true, NULL, &trailing_data)) { |
3086 | 244 | if (UNEXPECTED(trailing_data)) { |
3087 | 110 | zend_error(E_WARNING, "Illegal string offset \"%s\"", Z_STRVAL_P(dim)); |
3088 | 110 | } |
3089 | 244 | goto out; |
3090 | 244 | } |
3091 | 211 | if (type == BP_VAR_IS) { |
3092 | 63 | ZVAL_NULL(result); |
3093 | 63 | return; |
3094 | 63 | } |
3095 | 148 | zend_illegal_string_offset(dim, BP_VAR_R); |
3096 | 148 | ZVAL_NULL(result); |
3097 | 148 | return; |
3098 | 211 | } |
3099 | 39 | case IS_UNDEF: |
3100 | | /* The string may be destroyed while throwing the notice. |
3101 | | * Temporarily increase the refcount to detect this situation. */ |
3102 | 39 | if (!(GC_FLAGS(str) & IS_STR_INTERNED)) { |
3103 | 0 | GC_ADDREF(str); |
3104 | 0 | } |
3105 | 39 | ZVAL_UNDEFINED_OP2(); |
3106 | 39 | if (!(GC_FLAGS(str) & IS_STR_INTERNED) && UNEXPECTED(GC_DELREF(str) == 0)) { |
3107 | 0 | zend_string_efree(str); |
3108 | 0 | ZVAL_NULL(result); |
3109 | 0 | return; |
3110 | 0 | } |
3111 | 39 | ZEND_FALLTHROUGH; |
3112 | 380 | case IS_DOUBLE: |
3113 | 398 | case IS_NULL: |
3114 | 428 | case IS_FALSE: |
3115 | 446 | case IS_TRUE: |
3116 | 446 | if (type != BP_VAR_IS) { |
3117 | | /* The string may be destroyed while throwing the notice. |
3118 | | * Temporarily increase the refcount to detect this situation. */ |
3119 | 434 | if (!(GC_FLAGS(str) & IS_STR_INTERNED)) { |
3120 | 1 | GC_ADDREF(str); |
3121 | 1 | } |
3122 | 434 | zend_error(E_WARNING, "String offset cast occurred"); |
3123 | 434 | if (!(GC_FLAGS(str) & IS_STR_INTERNED) && UNEXPECTED(GC_DELREF(str) == 0)) { |
3124 | 0 | zend_string_efree(str); |
3125 | 0 | ZVAL_NULL(result); |
3126 | 0 | return; |
3127 | 0 | } |
3128 | 434 | } |
3129 | | /* To prevent double warning */ |
3130 | 446 | if (Z_TYPE_P(dim) == IS_DOUBLE) { |
3131 | 341 | offset = zend_dval_to_lval_silent(Z_DVAL_P(dim)); |
3132 | 341 | goto out; |
3133 | 341 | } |
3134 | 105 | break; |
3135 | 105 | case IS_REFERENCE: |
3136 | 0 | dim = Z_REFVAL_P(dim); |
3137 | 0 | goto try_string_offset; |
3138 | 26 | default: |
3139 | 26 | zend_illegal_string_offset(dim, BP_VAR_R); |
3140 | 26 | ZVAL_NULL(result); |
3141 | 26 | return; |
3142 | 927 | } |
3143 | | |
3144 | 105 | offset = zval_get_long_func(dim, /* is_strict */ false); |
3145 | 1.78k | } else { |
3146 | 1.78k | offset = Z_LVAL_P(dim); |
3147 | 1.78k | } |
3148 | 2.47k | out: |
3149 | | |
3150 | 2.47k | if (UNEXPECTED(ZSTR_LEN(str) < ((offset < 0) ? -(size_t)offset : ((size_t)offset + 1)))) { |
3151 | 805 | if (type != BP_VAR_IS) { |
3152 | 786 | zend_error(E_WARNING, "Uninitialized string offset " ZEND_LONG_FMT, offset); |
3153 | 786 | ZVAL_EMPTY_STRING(result); |
3154 | 786 | } else { |
3155 | 19 | ZVAL_NULL(result); |
3156 | 19 | } |
3157 | 1.67k | } else { |
3158 | 1.67k | zend_uchar c; |
3159 | 1.67k | zend_long real_offset; |
3160 | | |
3161 | 1.67k | real_offset = (UNEXPECTED(offset < 0)) /* Handle negative offset */ |
3162 | 1.67k | ? (zend_long)ZSTR_LEN(str) + offset : offset; |
3163 | 1.67k | c = (zend_uchar)ZSTR_VAL(str)[real_offset]; |
3164 | | |
3165 | 1.67k | ZVAL_CHAR(result, c); |
3166 | 1.67k | } |
3167 | 8.51k | } else if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) { |
3168 | 2.52k | zend_object *obj = Z_OBJ_P(container); |
3169 | | |
3170 | 2.52k | GC_ADDREF(obj); |
3171 | 2.52k | if (ZEND_CONST_COND(dim_type == IS_CV, 1) && UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) { |
3172 | 4 | dim = ZVAL_UNDEFINED_OP2(); |
3173 | 4 | } |
3174 | 2.52k | if (dim_type == IS_CONST && Z_EXTRA_P(dim) == ZEND_EXTRA_VALUE) { |
3175 | 5 | dim++; |
3176 | 5 | } |
3177 | 2.52k | retval = obj->handlers->read_dimension(obj, dim, type, result); |
3178 | | |
3179 | 2.52k | ZEND_ASSERT(result != NULL); |
3180 | 2.52k | if (retval) { |
3181 | 1.95k | if (result != retval) { |
3182 | 1.53k | ZVAL_COPY_DEREF(result, retval); |
3183 | 1.53k | } else if (UNEXPECTED(Z_ISREF_P(retval))) { |
3184 | 85 | zend_unwrap_reference(result); |
3185 | 85 | } |
3186 | 1.95k | } else { |
3187 | 74 | ZVAL_NULL(result); |
3188 | 74 | } |
3189 | 2.02k | if (UNEXPECTED(GC_DELREF(obj) == 0)) { |
3190 | 5 | zend_objects_store_del(obj); |
3191 | 5 | } |
3192 | 5.99k | } else { |
3193 | 5.99k | if (type != BP_VAR_IS && UNEXPECTED(Z_TYPE_P(container) == IS_UNDEF)) { |
3194 | 3.62k | container = ZVAL_UNDEFINED_OP1(); |
3195 | 3.62k | } |
3196 | 5.99k | if (ZEND_CONST_COND(dim_type == IS_CV, 1) && UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) { |
3197 | 600 | ZVAL_UNDEFINED_OP2(); |
3198 | 600 | } |
3199 | 5.99k | if (is_list && Z_TYPE_P(container) > IS_NULL) { |
3200 | 266 | zend_error(E_WARNING, "Cannot use %s as array", zend_zval_type_name(container)); |
3201 | 266 | } |
3202 | 5.99k | if (!is_list && type != BP_VAR_IS) { |
3203 | 5.02k | zend_error(E_WARNING, "Trying to access array offset on %s", |
3204 | 5.02k | zend_zval_value_name(container)); |
3205 | 5.02k | } |
3206 | 5.99k | ZVAL_NULL(result); |
3207 | 5.99k | } |
3208 | 11.2k | } |
3209 | | |
3210 | | static zend_never_inline void ZEND_FASTCALL zend_fetch_dimension_address_read_R(zval *container, zval *dim, int dim_type OPLINE_DC EXECUTE_DATA_DC) |
3211 | 942 | { |
3212 | 942 | zval *result = EX_VAR(opline->result.var); |
3213 | 942 | zend_fetch_dimension_address_read(result, container, dim, dim_type, BP_VAR_R, 0, 0 EXECUTE_DATA_CC); |
3214 | 942 | } |
3215 | | |
3216 | | static zend_never_inline void zend_fetch_dimension_address_read_R_slow(zval *container, zval *dim OPLINE_DC EXECUTE_DATA_DC) |
3217 | 9.44k | { |
3218 | 9.44k | zval *result = EX_VAR(opline->result.var); |
3219 | 9.44k | zend_fetch_dimension_address_read(result, container, dim, IS_CV, BP_VAR_R, 0, 1 EXECUTE_DATA_CC); |
3220 | 9.44k | } |
3221 | | |
3222 | | static zend_never_inline void ZEND_FASTCALL zend_fetch_dimension_address_read_IS(zval *container, zval *dim, int dim_type OPLINE_DC EXECUTE_DATA_DC) |
3223 | 2.32k | { |
3224 | 2.32k | zval *result = EX_VAR(opline->result.var); |
3225 | 2.32k | zend_fetch_dimension_address_read(result, container, dim, dim_type, BP_VAR_IS, 0, 0 EXECUTE_DATA_CC); |
3226 | 2.32k | } |
3227 | | |
3228 | | static zend_never_inline void ZEND_FASTCALL zend_fetch_dimension_address_LIST_r(zval *container, zval *dim, int dim_type OPLINE_DC EXECUTE_DATA_DC) |
3229 | 3.17k | { |
3230 | 3.17k | zval *result = EX_VAR(opline->result.var); |
3231 | 3.17k | zend_fetch_dimension_address_read(result, container, dim, dim_type, BP_VAR_R, 1, 0 EXECUTE_DATA_CC); |
3232 | 3.17k | } |
3233 | | |
3234 | | ZEND_API void zend_fetch_dimension_const(zval *result, zval *container, zval *dim, int type) |
3235 | 357 | { |
3236 | 357 | zend_fetch_dimension_address_read(result, container, dim, IS_TMP_VAR, type, 0, 0 NO_EXECUTE_DATA_CC); |
3237 | 357 | } |
3238 | | |
3239 | | static zend_never_inline zval* ZEND_FASTCALL zend_find_array_dim_slow(HashTable *ht, zval *offset EXECUTE_DATA_DC) |
3240 | 75 | { |
3241 | 75 | zend_ulong hval; |
3242 | | |
3243 | 75 | if (Z_TYPE_P(offset) == IS_DOUBLE) { |
3244 | | /* The array may be destroyed while throwing a warning in case the float is not representable as an int. |
3245 | | * Temporarily increase the refcount to detect this situation. */ |
3246 | 8 | GC_TRY_ADDREF(ht); |
3247 | 8 | hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); |
3248 | 8 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { |
3249 | 0 | zend_array_destroy(ht); |
3250 | 0 | return NULL; |
3251 | 0 | } |
3252 | 8 | if (EG(exception)) { |
3253 | 0 | return NULL; |
3254 | 0 | } |
3255 | 18 | num_idx: |
3256 | 18 | return zend_hash_index_find(ht, hval); |
3257 | 67 | } else if (Z_TYPE_P(offset) == IS_NULL) { |
3258 | 23 | null_undef_idx: |
3259 | | /* The array may be destroyed while throwing the notice. |
3260 | | * Temporarily increase the refcount to detect this situation. */ |
3261 | 23 | GC_TRY_ADDREF(ht); |
3262 | | |
3263 | 23 | zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead"); |
3264 | | |
3265 | 23 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { |
3266 | 0 | zend_array_destroy(ht); |
3267 | 0 | return NULL; |
3268 | 0 | } |
3269 | | |
3270 | 23 | if (EG(exception)) { |
3271 | 0 | return NULL; |
3272 | 0 | } |
3273 | | |
3274 | 23 | return zend_hash_find_known_hash(ht, ZSTR_EMPTY_ALLOC()); |
3275 | 56 | } else if (Z_TYPE_P(offset) == IS_FALSE) { |
3276 | 5 | hval = 0; |
3277 | 5 | goto num_idx; |
3278 | 51 | } else if (Z_TYPE_P(offset) == IS_TRUE) { |
3279 | 5 | hval = 1; |
3280 | 5 | goto num_idx; |
3281 | 46 | } else if (Z_TYPE_P(offset) == IS_RESOURCE) { |
3282 | 0 | zend_use_resource_as_offset(offset); |
3283 | 0 | hval = Z_RES_HANDLE_P(offset); |
3284 | 0 | goto num_idx; |
3285 | 46 | } else if (/*OP2_TYPE == IS_CV &&*/ Z_TYPE_P(offset) == IS_UNDEF) { |
3286 | 12 | ZVAL_UNDEFINED_OP2(); |
3287 | 12 | goto null_undef_idx; |
3288 | 34 | } else { |
3289 | 34 | zend_illegal_array_offset_isset(offset); |
3290 | 34 | return NULL; |
3291 | 34 | } |
3292 | 75 | } |
3293 | | |
3294 | | static zend_never_inline bool ZEND_FASTCALL zend_isset_dim_slow(zval *container, zval *offset EXECUTE_DATA_DC) |
3295 | 1.40k | { |
3296 | 1.40k | if (/*OP2_TYPE == IS_CV &&*/ UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) { |
3297 | 17 | offset = ZVAL_UNDEFINED_OP2(); |
3298 | 17 | } |
3299 | | |
3300 | 1.40k | if (/*OP1_TYPE != IS_CONST &&*/ EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) { |
3301 | 359 | return Z_OBJ_HT_P(container)->has_dimension(Z_OBJ_P(container), offset, 0); |
3302 | 1.04k | } else if (EXPECTED(Z_TYPE_P(container) == IS_STRING)) { /* string offsets */ |
3303 | 611 | zend_long lval; |
3304 | | |
3305 | 611 | if (EXPECTED(Z_TYPE_P(offset) == IS_LONG)) { |
3306 | 231 | lval = Z_LVAL_P(offset); |
3307 | 464 | str_offset: |
3308 | 464 | if (UNEXPECTED(lval < 0)) { /* Handle negative offset */ |
3309 | 104 | lval += (zend_long)Z_STRLEN_P(container); |
3310 | 104 | } |
3311 | 464 | if (EXPECTED(lval >= 0) && (size_t)lval < Z_STRLEN_P(container)) { |
3312 | 347 | return 1; |
3313 | 347 | } else { |
3314 | 117 | return 0; |
3315 | 117 | } |
3316 | 464 | } else { |
3317 | | /*if (OP2_TYPE & (IS_CV|IS_VAR)) {*/ |
3318 | 380 | ZVAL_DEREF(offset); |
3319 | | /*}*/ |
3320 | 380 | if (Z_TYPE_P(offset) < IS_STRING /* simple scalar types */ |
3321 | 312 | || (Z_TYPE_P(offset) == IS_STRING /* or numeric string */ |
3322 | 290 | && IS_LONG == is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), NULL, NULL, 0))) { |
3323 | 233 | lval = zval_get_long_ex(offset, /* is_strict */ true); |
3324 | 233 | goto str_offset; |
3325 | 233 | } |
3326 | 147 | return 0; |
3327 | 380 | } |
3328 | 611 | } else { |
3329 | 431 | return 0; |
3330 | 431 | } |
3331 | 1.40k | } |
3332 | | |
3333 | | static zend_never_inline bool ZEND_FASTCALL zend_isempty_dim_slow(zval *container, zval *offset EXECUTE_DATA_DC) |
3334 | 536 | { |
3335 | 536 | if (/*OP2_TYPE == IS_CV &&*/ UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) { |
3336 | 5 | offset = ZVAL_UNDEFINED_OP2(); |
3337 | 5 | } |
3338 | | |
3339 | 536 | if (/*OP1_TYPE != IS_CONST &&*/ EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) { |
3340 | 119 | return !Z_OBJ_HT_P(container)->has_dimension(Z_OBJ_P(container), offset, 1); |
3341 | 417 | } else if (EXPECTED(Z_TYPE_P(container) == IS_STRING)) { /* string offsets */ |
3342 | 379 | zend_long lval; |
3343 | | |
3344 | 379 | if (EXPECTED(Z_TYPE_P(offset) == IS_LONG)) { |
3345 | 151 | lval = Z_LVAL_P(offset); |
3346 | 292 | str_offset: |
3347 | 292 | if (UNEXPECTED(lval < 0)) { /* Handle negative offset */ |
3348 | 96 | lval += (zend_long)Z_STRLEN_P(container); |
3349 | 96 | } |
3350 | 292 | if (EXPECTED(lval >= 0) && (size_t)lval < Z_STRLEN_P(container)) { |
3351 | 226 | return (Z_STRVAL_P(container)[lval] == '0'); |
3352 | 226 | } else { |
3353 | 66 | return 1; |
3354 | 66 | } |
3355 | 292 | } else { |
3356 | | /*if (OP2_TYPE & (IS_CV|IS_VAR)) {*/ |
3357 | 228 | ZVAL_DEREF(offset); |
3358 | | /*}*/ |
3359 | 228 | if (Z_TYPE_P(offset) < IS_STRING /* simple scalar types */ |
3360 | 163 | || (Z_TYPE_P(offset) == IS_STRING /* or numeric string */ |
3361 | 141 | && IS_LONG == is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), NULL, NULL, 0))) { |
3362 | 141 | lval = zval_get_long_ex(offset, /* is_strict */ true); |
3363 | 141 | goto str_offset; |
3364 | 141 | } |
3365 | 87 | return 1; |
3366 | 228 | } |
3367 | 379 | } else { |
3368 | 38 | return 1; |
3369 | 38 | } |
3370 | 536 | } |
3371 | | |
3372 | | static zend_never_inline bool ZEND_FASTCALL zend_array_key_exists_fast(HashTable *ht, zval *key OPLINE_DC EXECUTE_DATA_DC) |
3373 | 359 | { |
3374 | 359 | zend_string *str; |
3375 | 359 | zend_ulong hval; |
3376 | | |
3377 | 359 | try_again: |
3378 | 359 | if (EXPECTED(Z_TYPE_P(key) == IS_STRING)) { |
3379 | 228 | str = Z_STR_P(key); |
3380 | 228 | if (ZEND_HANDLE_NUMERIC(str, hval)) { |
3381 | 0 | goto num_key; |
3382 | 0 | } |
3383 | 252 | str_key: |
3384 | 252 | return zend_hash_exists(ht, str); |
3385 | 228 | } else if (EXPECTED(Z_TYPE_P(key) == IS_LONG)) { |
3386 | 107 | hval = Z_LVAL_P(key); |
3387 | 107 | num_key: |
3388 | 107 | return zend_hash_index_exists(ht, hval); |
3389 | 107 | } else if (EXPECTED(Z_ISREF_P(key))) { |
3390 | 0 | key = Z_REFVAL_P(key); |
3391 | 0 | goto try_again; |
3392 | 24 | } else if (Z_TYPE_P(key) == IS_DOUBLE) { |
3393 | | /* The array may be destroyed while throwing a warning in case the float is not representable as an int. |
3394 | | * Temporarily increase the refcount to detect this situation. */ |
3395 | 0 | GC_TRY_ADDREF(ht); |
3396 | 0 | hval = zend_dval_to_lval_safe(Z_DVAL_P(key)); |
3397 | 0 | if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { |
3398 | 0 | zend_array_destroy(ht); |
3399 | 0 | return false; |
3400 | 0 | } |
3401 | 0 | if (EG(exception)) { |
3402 | 0 | return false; |
3403 | 0 | } |
3404 | 0 | goto num_key; |
3405 | 24 | } else if (Z_TYPE_P(key) == IS_FALSE) { |
3406 | 0 | hval = 0; |
3407 | 0 | goto num_key; |
3408 | 24 | } else if (Z_TYPE_P(key) == IS_TRUE) { |
3409 | 0 | hval = 1; |
3410 | 0 | goto num_key; |
3411 | 24 | } else if (Z_TYPE_P(key) == IS_RESOURCE) { |
3412 | 0 | zend_use_resource_as_offset(key); |
3413 | 0 | hval = Z_RES_HANDLE_P(key); |
3414 | 0 | goto num_key; |
3415 | 24 | } else if (Z_TYPE_P(key) <= IS_NULL) { |
3416 | 24 | if (UNEXPECTED(Z_TYPE_P(key) == IS_UNDEF)) { |
3417 | 15 | ZVAL_UNDEFINED_OP1(); |
3418 | 15 | } else { |
3419 | 9 | ZEND_ASSERT(Z_TYPE_P(key) == IS_NULL); |
3420 | 9 | zend_error(E_DEPRECATED, "Using null as the key parameter for array_key_exists() is deprecated, use an empty string instead"); |
3421 | 9 | } |
3422 | 24 | str = ZSTR_EMPTY_ALLOC(); |
3423 | 24 | goto str_key; |
3424 | 24 | } else { |
3425 | 0 | zend_illegal_array_offset_access(key); |
3426 | 0 | return 0; |
3427 | 0 | } |
3428 | 359 | } |
3429 | | |
3430 | | static ZEND_COLD void ZEND_FASTCALL zend_array_key_exists_error( |
3431 | | zval *subject, zval *key OPLINE_DC EXECUTE_DATA_DC) |
3432 | 16 | { |
3433 | 16 | if (Z_TYPE_P(key) == IS_UNDEF) { |
3434 | 0 | ZVAL_UNDEFINED_OP1(); |
3435 | 0 | } |
3436 | 16 | if (Z_TYPE_P(subject) == IS_UNDEF) { |
3437 | 4 | ZVAL_UNDEFINED_OP2(); |
3438 | 4 | } |
3439 | 16 | if (!EG(exception)) { |
3440 | 16 | zend_type_error("array_key_exists(): Argument #2 ($array) must be of type array, %s given", |
3441 | 16 | zend_zval_value_name(subject)); |
3442 | 16 | } |
3443 | 16 | } |
3444 | | |
3445 | 121 | static zend_always_inline bool promotes_to_array(zval *val) { |
3446 | 121 | return Z_TYPE_P(val) <= IS_FALSE |
3447 | 64 | || (Z_ISREF_P(val) && Z_TYPE_P(Z_REFVAL_P(val)) <= IS_FALSE); |
3448 | 121 | } |
3449 | | |
3450 | 72 | static zend_always_inline bool check_type_array_assignable(zend_type type) { |
3451 | 72 | if (!ZEND_TYPE_IS_SET(type)) { |
3452 | 0 | return 1; |
3453 | 0 | } |
3454 | 72 | return (ZEND_TYPE_FULL_MASK(type) & MAY_BE_ARRAY) != 0; |
3455 | 72 | } |
3456 | | |
3457 | | /* Checks whether an array can be assigned to the reference. Throws error if not assignable. */ |
3458 | 15 | ZEND_API bool zend_verify_ref_array_assignable(zend_reference *ref) { |
3459 | 15 | zend_property_info *prop; |
3460 | 15 | ZEND_ASSERT(ZEND_REF_HAS_TYPE_SOURCES(ref)); |
3461 | 45 | ZEND_REF_FOREACH_TYPE_SOURCES(ref, prop) { |
3462 | 45 | if (!check_type_array_assignable(prop->type)) { |
3463 | 10 | zend_throw_auto_init_in_ref_error(prop); |
3464 | 10 | return 0; |
3465 | 10 | } |
3466 | 45 | } ZEND_REF_FOREACH_TYPE_SOURCES_END(); |
3467 | 5 | return 1; |
3468 | 15 | } |
3469 | | |
3470 | | static zend_never_inline bool zend_handle_fetch_obj_flags( |
3471 | | zval *result, zval *ptr, zend_object *obj, zend_property_info *prop_info, uint32_t flags) |
3472 | 1.43k | { |
3473 | 1.43k | switch (flags) { |
3474 | 121 | case ZEND_FETCH_DIM_WRITE: |
3475 | 121 | if (promotes_to_array(ptr)) { |
3476 | 57 | if (!prop_info) { |
3477 | 0 | break; |
3478 | 0 | } |
3479 | 57 | if (!check_type_array_assignable(prop_info->type)) { |
3480 | 21 | zend_throw_auto_init_in_prop_error(prop_info); |
3481 | 21 | if (result) ZVAL_ERROR(result); |
3482 | 21 | return 0; |
3483 | 21 | } |
3484 | 57 | } |
3485 | 100 | break; |
3486 | 1.31k | case ZEND_FETCH_REF: |
3487 | 1.31k | if (Z_TYPE_P(ptr) != IS_REFERENCE) { |
3488 | 837 | if (!prop_info) { |
3489 | 0 | break; |
3490 | 0 | } |
3491 | 837 | if (Z_TYPE_P(ptr) == IS_UNDEF) { |
3492 | 73 | if (!ZEND_TYPE_ALLOW_NULL(prop_info->type)) { |
3493 | 18 | zend_throw_access_uninit_prop_by_ref_error(prop_info); |
3494 | 18 | if (result) ZVAL_ERROR(result); |
3495 | 18 | return 0; |
3496 | 18 | } |
3497 | 55 | ZVAL_NULL(ptr); |
3498 | 55 | } |
3499 | | |
3500 | 819 | ZVAL_NEW_REF(ptr, ptr); |
3501 | 819 | ZEND_REF_ADD_TYPE_SOURCE(Z_REF_P(ptr), prop_info); |
3502 | 819 | } |
3503 | 1.29k | break; |
3504 | 1.43k | EMPTY_SWITCH_DEFAULT_CASE() |
3505 | 1.43k | } |
3506 | 1.39k | return 1; |
3507 | 1.43k | } |
3508 | | |
3509 | | static zend_always_inline void zend_fetch_property_address(zval *result, zval *container, uint32_t container_op_type, zval *prop_ptr, uint32_t prop_op_type, void **cache_slot, int type, uint32_t flags, zend_property_info **prop_info_p OPLINE_DC EXECUTE_DATA_DC) |
3510 | 7.11k | { |
3511 | 7.11k | zval *ptr; |
3512 | 7.11k | zend_object *zobj; |
3513 | 7.11k | zend_string *name, *tmp_name; |
3514 | 7.11k | void *_cache_slot[3] = {0}; |
3515 | 7.11k | if (prop_op_type != IS_CONST) { |
3516 | 968 | cache_slot = _cache_slot; |
3517 | 6.14k | } else { |
3518 | 6.14k | ZEND_ASSERT(cache_slot); |
3519 | 6.14k | } |
3520 | | |
3521 | 7.11k | if (container_op_type != IS_UNUSED && UNEXPECTED(Z_TYPE_P(container) != IS_OBJECT)) { |
3522 | 271 | do { |
3523 | 271 | if (Z_ISREF_P(container) && Z_TYPE_P(Z_REFVAL_P(container)) == IS_OBJECT) { |
3524 | 93 | container = Z_REFVAL_P(container); |
3525 | 93 | break; |
3526 | 93 | } |
3527 | | |
3528 | 178 | if (container_op_type == IS_CV |
3529 | 76 | && type != BP_VAR_W |
3530 | 10 | && UNEXPECTED(Z_TYPE_P(container) == IS_UNDEF)) { |
3531 | 10 | ZVAL_UNDEFINED_OP1(); |
3532 | 10 | } |
3533 | | |
3534 | | /* this should modify object only if it's empty */ |
3535 | 178 | if (type == BP_VAR_UNSET) { |
3536 | 30 | ZVAL_NULL(result); |
3537 | 30 | return; |
3538 | 30 | } |
3539 | | |
3540 | 148 | zend_throw_non_object_error(container, prop_ptr OPLINE_CC EXECUTE_DATA_CC); |
3541 | 148 | ZVAL_ERROR(result); |
3542 | 148 | return; |
3543 | 178 | } while (0); |
3544 | 271 | } |
3545 | | |
3546 | 6.93k | zobj = Z_OBJ_P(container); |
3547 | 6.93k | if (prop_op_type == IS_CONST && |
3548 | 5.99k | EXPECTED(zobj->ce == CACHED_PTR_EX(cache_slot))) { |
3549 | 2.94k | uintptr_t prop_offset = (uintptr_t)CACHED_PTR_EX(cache_slot + 1); |
3550 | 2.94k | if (prop_info_p) { |
3551 | 43 | *prop_info_p = CACHED_PTR_EX(cache_slot + 2); |
3552 | 43 | } |
3553 | | |
3554 | 2.94k | if (EXPECTED(IS_VALID_PROPERTY_OFFSET(prop_offset))) { |
3555 | 2.62k | ptr = OBJ_PROP(zobj, prop_offset); |
3556 | 2.62k | if (EXPECTED(Z_TYPE_P(ptr) != IS_UNDEF)) { |
3557 | 2.45k | ZVAL_INDIRECT(result, ptr); |
3558 | 2.45k | zend_property_info *prop_info = CACHED_PTR_EX(cache_slot + 2); |
3559 | 2.45k | if (prop_info) { |
3560 | 601 | if (UNEXPECTED(prop_info->flags & (ZEND_ACC_READONLY|ZEND_ACC_PPP_SET_MASK)) |
3561 | 59 | && ((prop_info->flags & ZEND_ACC_READONLY) || !zend_asymmetric_property_has_set_access(prop_info))) { |
3562 | | /* For objects, W/RW/UNSET fetch modes might not actually modify object. |
3563 | | * Similar as with magic __get() allow them, but return the value as a copy |
3564 | | * to make sure no actual modification is possible. */ |
3565 | 59 | ZEND_ASSERT(type == BP_VAR_W || type == BP_VAR_RW || type == BP_VAR_UNSET); |
3566 | 59 | if (Z_TYPE_P(ptr) == IS_OBJECT) { |
3567 | 25 | ZVAL_COPY(result, ptr); |
3568 | 34 | } else { |
3569 | 34 | if (prop_info->flags & ZEND_ACC_READONLY) { |
3570 | 25 | zend_readonly_property_indirect_modification_error(prop_info); |
3571 | 25 | } else { |
3572 | 9 | zend_asymmetric_visibility_property_modification_error(prop_info, "indirectly modify"); |
3573 | 9 | } |
3574 | 34 | ZVAL_ERROR(result); |
3575 | 34 | } |
3576 | 59 | return; |
3577 | 59 | } |
3578 | 542 | flags &= ZEND_FETCH_OBJ_FLAGS; |
3579 | 542 | if (flags) { |
3580 | 286 | zend_handle_fetch_obj_flags(result, ptr, NULL, prop_info, flags); |
3581 | 286 | } |
3582 | 542 | } |
3583 | 2.39k | return; |
3584 | 2.45k | } |
3585 | 2.62k | } else if (UNEXPECTED(IS_HOOKED_PROPERTY_OFFSET(prop_offset))) { |
3586 | | /* Fall through to read_property for hooks. */ |
3587 | 296 | } else if (EXPECTED(zobj->properties != NULL)) { |
3588 | 151 | ZEND_ASSERT(IS_DYNAMIC_PROPERTY_OFFSET(prop_offset)); |
3589 | 151 | if (UNEXPECTED(GC_REFCOUNT(zobj->properties) > 1)) { |
3590 | 0 | if (EXPECTED(!(GC_FLAGS(zobj->properties) & IS_ARRAY_IMMUTABLE))) { |
3591 | 0 | GC_DELREF(zobj->properties); |
3592 | 0 | } |
3593 | 0 | zobj->properties = zend_array_dup(zobj->properties); |
3594 | 0 | } |
3595 | 151 | ptr = zend_hash_find_known_hash(zobj->properties, Z_STR_P(prop_ptr)); |
3596 | 151 | if (EXPECTED(ptr)) { |
3597 | 138 | ZVAL_INDIRECT(result, ptr); |
3598 | 138 | return; |
3599 | 138 | } |
3600 | 151 | } |
3601 | 3.99k | } else if (prop_op_type == IS_CONST) { |
3602 | | /* CE mismatch, make cache slot consistent */ |
3603 | 3.04k | cache_slot[0] = cache_slot[1] = cache_slot[2] = NULL; |
3604 | 3.04k | } |
3605 | | |
3606 | | /* Pointer on property callback is required */ |
3607 | 4.34k | ZEND_ASSERT(zobj->handlers->get_property_ptr_ptr != NULL); |
3608 | | |
3609 | 4.34k | if (prop_op_type == IS_CONST) { |
3610 | 3.39k | name = Z_STR_P(prop_ptr); |
3611 | 3.39k | } else { |
3612 | 948 | name = zval_get_tmp_string(prop_ptr, &tmp_name); |
3613 | 948 | } |
3614 | 4.34k | ptr = zobj->handlers->get_property_ptr_ptr(zobj, name, type, cache_slot); |
3615 | 4.34k | if (NULL == ptr) { |
3616 | 770 | ptr = zobj->handlers->read_property(zobj, name, type, cache_slot, result); |
3617 | 770 | if (ptr == result) { |
3618 | 474 | if (UNEXPECTED(Z_ISREF_P(ptr) && Z_REFCOUNT_P(ptr) == 1)) { |
3619 | 9 | ZVAL_UNREF(ptr); |
3620 | 9 | } |
3621 | 474 | goto end; |
3622 | 474 | } |
3623 | 296 | if (UNEXPECTED(EG(exception))) { |
3624 | 210 | ZVAL_ERROR(result); |
3625 | 210 | goto end; |
3626 | 210 | } |
3627 | 3.57k | } else if (UNEXPECTED(Z_ISERROR_P(ptr))) { |
3628 | 29 | ZVAL_ERROR(result); |
3629 | 29 | goto end; |
3630 | 29 | } |
3631 | | |
3632 | 3.63k | ZVAL_INDIRECT(result, ptr); |
3633 | 3.63k | flags &= ZEND_FETCH_OBJ_FLAGS; |
3634 | 3.63k | if (flags) { |
3635 | 2.52k | zend_property_info *prop_info = CACHED_PTR_EX(cache_slot + 2); |
3636 | 2.52k | if (prop_info && ZEND_TYPE_IS_SET(prop_info->type)) { |
3637 | 1.01k | if (UNEXPECTED(!zend_handle_fetch_obj_flags(result, ptr, NULL, prop_info, flags))) { |
3638 | 34 | goto end; |
3639 | 34 | } |
3640 | 1.01k | } |
3641 | 2.52k | } |
3642 | | |
3643 | 4.34k | end: |
3644 | 4.34k | if (prop_info_p) { |
3645 | 826 | *prop_info_p = CACHED_PTR_EX(cache_slot + 2); |
3646 | 826 | } |
3647 | 4.34k | if (prop_op_type != IS_CONST) { |
3648 | 948 | zend_tmp_string_release(tmp_name); |
3649 | 948 | } |
3650 | 4.34k | } |
3651 | | |
3652 | | static zend_always_inline void zend_assign_to_property_reference(zval *container, uint32_t container_op_type, zval *prop_ptr, uint32_t prop_op_type, zval *value_ptr OPLINE_DC EXECUTE_DATA_DC) |
3653 | 899 | { |
3654 | 899 | zval variable, *variable_ptr = &variable; |
3655 | 899 | void **cache_addr = (prop_op_type == IS_CONST) ? CACHE_ADDR(opline->extended_value & ~ZEND_RETURNS_FUNCTION) : NULL; |
3656 | 899 | zend_refcounted *garbage = NULL; |
3657 | 899 | zend_property_info *prop_info = NULL; |
3658 | | |
3659 | 899 | zend_fetch_property_address(variable_ptr, container, container_op_type, prop_ptr, prop_op_type, |
3660 | 899 | cache_addr, BP_VAR_W, 0, &prop_info OPLINE_CC EXECUTE_DATA_CC); |
3661 | | |
3662 | 899 | if (EXPECTED(Z_TYPE_P(variable_ptr) == IS_INDIRECT)) { |
3663 | 812 | variable_ptr = Z_INDIRECT_P(variable_ptr); |
3664 | 812 | if (/*OP_DATA_TYPE == IS_VAR &&*/ |
3665 | 812 | (opline->extended_value & ZEND_RETURNS_FUNCTION) && |
3666 | 6 | UNEXPECTED(!Z_ISREF_P(value_ptr))) { |
3667 | | |
3668 | 6 | variable_ptr = zend_wrong_assign_to_variable_reference( |
3669 | 6 | variable_ptr, value_ptr, &garbage OPLINE_CC EXECUTE_DATA_CC); |
3670 | 806 | } else if (prop_info && ZEND_TYPE_IS_SET(prop_info->type)) { |
3671 | 472 | variable_ptr = zend_assign_to_typed_property_reference(prop_info, variable_ptr, value_ptr, &garbage EXECUTE_DATA_CC); |
3672 | 472 | } else { |
3673 | 334 | zend_assign_to_variable_reference(variable_ptr, value_ptr, &garbage); |
3674 | 334 | } |
3675 | 812 | } else if (Z_ISERROR_P(variable_ptr)) { |
3676 | 50 | variable_ptr = &EG(uninitialized_zval); |
3677 | 50 | } else { |
3678 | 37 | zend_throw_error(NULL, "Cannot assign by reference to overloaded object"); |
3679 | 37 | zval_ptr_dtor(&variable); |
3680 | 37 | variable_ptr = &EG(uninitialized_zval); |
3681 | 37 | } |
3682 | | |
3683 | 899 | if (UNEXPECTED(RETURN_VALUE_USED(opline))) { |
3684 | 108 | ZVAL_COPY(EX_VAR(opline->result.var), variable_ptr); |
3685 | 108 | } |
3686 | 899 | if (garbage) { |
3687 | 311 | GC_DTOR(garbage); |
3688 | 311 | } |
3689 | 899 | } |
3690 | | |
3691 | | static zend_never_inline void zend_assign_to_property_reference_this_const(zval *container, zval *prop_ptr, zval *value_ptr OPLINE_DC EXECUTE_DATA_DC) |
3692 | 86 | { |
3693 | 86 | zend_assign_to_property_reference(container, IS_UNUSED, prop_ptr, IS_CONST, value_ptr |
3694 | 86 | OPLINE_CC EXECUTE_DATA_CC); |
3695 | 86 | } |
3696 | | |
3697 | | static zend_never_inline void zend_assign_to_property_reference_var_const(zval *container, zval *prop_ptr, zval *value_ptr OPLINE_DC EXECUTE_DATA_DC) |
3698 | 427 | { |
3699 | 427 | zend_assign_to_property_reference(container, IS_VAR, prop_ptr, IS_CONST, value_ptr |
3700 | 427 | OPLINE_CC EXECUTE_DATA_CC); |
3701 | 427 | } |
3702 | | |
3703 | | static zend_never_inline void zend_assign_to_property_reference_this_var(zval *container, zval *prop_ptr, zval *value_ptr OPLINE_DC EXECUTE_DATA_DC) |
3704 | 4 | { |
3705 | 4 | zend_assign_to_property_reference(container, IS_UNUSED, prop_ptr, IS_VAR, value_ptr |
3706 | 4 | OPLINE_CC EXECUTE_DATA_CC); |
3707 | 4 | } |
3708 | | |
3709 | | static zend_never_inline void zend_assign_to_property_reference_var_var(zval *container, zval *prop_ptr, zval *value_ptr OPLINE_DC EXECUTE_DATA_DC) |
3710 | 382 | { |
3711 | 382 | zend_assign_to_property_reference(container, IS_VAR, prop_ptr, IS_VAR, value_ptr |
3712 | 382 | OPLINE_CC EXECUTE_DATA_CC); |
3713 | 382 | } |
3714 | | |
3715 | 3.50k | static zend_never_inline zval* zend_fetch_static_property_address_ex(zend_property_info **prop_info, uint32_t cache_slot, int fetch_type OPLINE_DC EXECUTE_DATA_DC) { |
3716 | 3.50k | zval *result; |
3717 | 3.50k | zend_string *name; |
3718 | 3.50k | zend_class_entry *ce; |
3719 | 3.50k | zend_property_info *property_info; |
3720 | | |
3721 | 3.50k | uint8_t op1_type = opline->op1_type, op2_type = opline->op2_type; |
3722 | | |
3723 | 3.50k | if (EXPECTED(op2_type == IS_CONST)) { |
3724 | 2.19k | zval *class_name = RT_CONSTANT(opline, opline->op2); |
3725 | | |
3726 | 2.19k | ZEND_ASSERT(op1_type != IS_CONST || CACHED_PTR(cache_slot) == NULL); |
3727 | | |
3728 | 2.19k | if (EXPECTED((ce = CACHED_PTR(cache_slot)) == NULL)) { |
3729 | 2.10k | ce = zend_fetch_class_by_name(Z_STR_P(class_name), Z_STR_P(class_name + 1), ZEND_FETCH_CLASS_DEFAULT | ZEND_FETCH_CLASS_EXCEPTION); |
3730 | 2.10k | if (UNEXPECTED(ce == NULL)) { |
3731 | 72 | FREE_OP(op1_type, opline->op1.var); |
3732 | 72 | return NULL; |
3733 | 72 | } |
3734 | 2.03k | if (UNEXPECTED(op1_type != IS_CONST)) { |
3735 | 24 | CACHE_PTR(cache_slot, ce); |
3736 | 24 | } |
3737 | 2.03k | } |
3738 | 2.19k | } else { |
3739 | 1.30k | if (EXPECTED(op2_type == IS_UNUSED)) { |
3740 | 1.17k | ce = zend_fetch_class(NULL, opline->op2.num); |
3741 | 1.17k | if (UNEXPECTED(ce == NULL)) { |
3742 | 24 | FREE_OP(op1_type, opline->op1.var); |
3743 | 24 | return NULL; |
3744 | 24 | } |
3745 | 1.17k | } else { |
3746 | 126 | ce = Z_CE_P(EX_VAR(opline->op2.var)); |
3747 | 126 | } |
3748 | 1.28k | if (EXPECTED(op1_type == IS_CONST) && EXPECTED(CACHED_PTR(cache_slot) == ce)) { |
3749 | 45 | result = CACHED_PTR(cache_slot + sizeof(void *)); |
3750 | 45 | *prop_info = CACHED_PTR(cache_slot + sizeof(void *) * 2); |
3751 | 45 | return result; |
3752 | 45 | } |
3753 | 1.28k | } |
3754 | | |
3755 | 3.35k | if (EXPECTED(op1_type == IS_CONST)) { |
3756 | 3.23k | name = Z_STR_P(RT_CONSTANT(opline, opline->op1)); |
3757 | 3.23k | result = zend_std_get_static_property_with_info(ce, name, fetch_type, &property_info); |
3758 | 3.23k | } else { |
3759 | 123 | zend_string *tmp_name; |
3760 | 123 | zval *varname = get_zval_ptr_undef(opline->op1_type, opline->op1, BP_VAR_R); |
3761 | 123 | if (EXPECTED(Z_TYPE_P(varname) == IS_STRING)) { |
3762 | 103 | name = Z_STR_P(varname); |
3763 | 103 | tmp_name = NULL; |
3764 | 103 | } else { |
3765 | 20 | if (op1_type == IS_CV && UNEXPECTED(Z_TYPE_P(varname) == IS_UNDEF)) { |
3766 | 6 | zval_undefined_cv(opline->op1.var EXECUTE_DATA_CC); |
3767 | 6 | } |
3768 | 20 | name = zval_get_tmp_string(varname, &tmp_name); |
3769 | 20 | } |
3770 | 123 | result = zend_std_get_static_property_with_info(ce, name, fetch_type, &property_info); |
3771 | | |
3772 | 123 | zend_tmp_string_release(tmp_name); |
3773 | | |
3774 | 123 | FREE_OP(op1_type, opline->op1.var); |
3775 | 123 | } |
3776 | | |
3777 | 3.35k | if (UNEXPECTED(result == NULL)) { |
3778 | 360 | return NULL; |
3779 | 360 | } |
3780 | | |
3781 | 2.99k | *prop_info = property_info; |
3782 | | |
3783 | 2.99k | if (EXPECTED(op1_type == IS_CONST) |
3784 | 2.89k | && EXPECTED(!(property_info->ce->ce_flags & ZEND_ACC_TRAIT))) { |
3785 | 2.81k | CACHE_POLYMORPHIC_PTR(cache_slot, ce, result); |
3786 | 2.81k | CACHE_PTR(cache_slot + sizeof(void *) * 2, property_info); |
3787 | 2.81k | } |
3788 | | |
3789 | 2.99k | return result; |
3790 | 3.35k | } |
3791 | | |
3792 | | |
3793 | 7.57k | static zend_always_inline zval* zend_fetch_static_property_address(zend_property_info **prop_info, uint32_t cache_slot, int fetch_type, int flags OPLINE_DC EXECUTE_DATA_DC) { |
3794 | 7.57k | zval *result; |
3795 | 7.57k | zend_property_info *property_info; |
3796 | | |
3797 | 7.57k | if (opline->op1_type == IS_CONST |
3798 | 7.43k | && (opline->op2_type == IS_CONST |
3799 | 3.48k | || (opline->op2_type == IS_UNUSED |
3800 | 3.36k | && ((opline->op2.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_SELF |
3801 | 243 | || (opline->op2.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_PARENT))) |
3802 | 7.08k | && EXPECTED(CACHED_PTR(cache_slot + sizeof(void *)) != NULL)) { |
3803 | 4.07k | result = CACHED_PTR(cache_slot + sizeof(void *)); |
3804 | 4.07k | property_info = CACHED_PTR(cache_slot + sizeof(void *) * 2); |
3805 | | |
3806 | 4.07k | if ((fetch_type == BP_VAR_R || fetch_type == BP_VAR_RW) |
3807 | 2.32k | && UNEXPECTED(Z_TYPE_P(result) == IS_UNDEF) |
3808 | 10 | && ZEND_TYPE_IS_SET(property_info->type)) { |
3809 | 10 | zend_throw_error(NULL, "Typed static property %s::$%s must not be accessed before initialization", |
3810 | 10 | ZSTR_VAL(property_info->ce->name), |
3811 | 10 | zend_get_unmangled_property_name(property_info->name)); |
3812 | 10 | return NULL; |
3813 | 10 | } |
3814 | 4.07k | } else { |
3815 | 3.50k | result = zend_fetch_static_property_address_ex(&property_info, cache_slot, fetch_type OPLINE_CC EXECUTE_DATA_CC); |
3816 | 3.50k | if (UNEXPECTED(!result)) { |
3817 | 456 | return NULL; |
3818 | 456 | } |
3819 | 3.50k | } |
3820 | | |
3821 | 7.11k | flags &= ZEND_FETCH_OBJ_FLAGS; |
3822 | 7.11k | if (flags && ZEND_TYPE_IS_SET(property_info->type)) { |
3823 | 135 | zend_handle_fetch_obj_flags(NULL, result, NULL, property_info, flags); |
3824 | 135 | } |
3825 | | |
3826 | 7.11k | if (prop_info) { |
3827 | 6.96k | *prop_info = property_info; |
3828 | 6.96k | } |
3829 | | |
3830 | 7.11k | return result; |
3831 | 7.57k | } |
3832 | | |
3833 | 0 | ZEND_API zval* ZEND_FASTCALL zend_fetch_static_property(zend_execute_data *ex, int fetch_type) { |
3834 | 0 | zval *result; |
3835 | 0 | zend_property_info *property_info; |
3836 | | #if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
3837 | | zend_execute_data *orig_execute_data = execute_data; |
3838 | | #else |
3839 | 0 | zend_execute_data *execute_data; |
3840 | 0 | #endif |
3841 | 0 | execute_data = ex; |
3842 | | #if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
3843 | | const zend_op *orig_opline = opline; |
3844 | | #else |
3845 | 0 | const zend_op *opline; |
3846 | 0 | #endif |
3847 | 0 | opline = execute_data->opline; |
3848 | |
|
3849 | 0 | uint32_t cache_slot = opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS; |
3850 | 0 | uint32_t flags = 0; |
3851 | |
|
3852 | 0 | if (fetch_type == BP_VAR_W) { |
3853 | 0 | flags = opline->extended_value & ZEND_FETCH_OBJ_FLAGS; |
3854 | 0 | } |
3855 | 0 | result = zend_fetch_static_property_address_ex(&property_info, cache_slot, fetch_type OPLINE_CC EXECUTE_DATA_CC); |
3856 | 0 | if (EXPECTED(result)) { |
3857 | 0 | if (flags && ZEND_TYPE_IS_SET(property_info->type)) { |
3858 | 0 | zend_handle_fetch_obj_flags(NULL, result, NULL, property_info, flags); |
3859 | 0 | } |
3860 | 0 | } else { |
3861 | 0 | result = &EG(uninitialized_zval); |
3862 | 0 | } |
3863 | |
|
3864 | | #if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
3865 | | EX(opline) = opline; |
3866 | | opline = orig_opline; |
3867 | | #endif |
3868 | | #if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
3869 | | execute_data = orig_execute_data; |
3870 | | #endif |
3871 | |
|
3872 | 0 | return result; |
3873 | 0 | } |
3874 | | |
3875 | 67 | ZEND_API ZEND_COLD void zend_throw_ref_type_error_type(const zend_property_info *prop1, const zend_property_info *prop2, const zval *zv) { |
3876 | 67 | zend_string *type1_str = zend_type_to_string(prop1->type); |
3877 | 67 | zend_string *type2_str = zend_type_to_string(prop2->type); |
3878 | 67 | zend_type_error("Reference with value of type %s held by property %s::$%s of type %s is not compatible with property %s::$%s of type %s", |
3879 | 67 | zend_zval_type_name(zv), |
3880 | 67 | ZSTR_VAL(prop1->ce->name), |
3881 | 67 | zend_get_unmangled_property_name(prop1->name), |
3882 | 67 | ZSTR_VAL(type1_str), |
3883 | 67 | ZSTR_VAL(prop2->ce->name), |
3884 | 67 | zend_get_unmangled_property_name(prop2->name), |
3885 | 67 | ZSTR_VAL(type2_str) |
3886 | 67 | ); |
3887 | 67 | zend_string_release(type1_str); |
3888 | 67 | zend_string_release(type2_str); |
3889 | 67 | } |
3890 | | |
3891 | 390 | ZEND_API ZEND_COLD void zend_throw_ref_type_error_zval(const zend_property_info *prop, const zval *zv) { |
3892 | 390 | zend_string *type_str = zend_type_to_string(prop->type); |
3893 | 390 | zend_type_error("Cannot assign %s to reference held by property %s::$%s of type %s", |
3894 | 390 | zend_zval_value_name(zv), |
3895 | 390 | ZSTR_VAL(prop->ce->name), |
3896 | 390 | zend_get_unmangled_property_name(prop->name), |
3897 | 390 | ZSTR_VAL(type_str) |
3898 | 390 | ); |
3899 | 390 | zend_string_release(type_str); |
3900 | 390 | } |
3901 | | |
3902 | 38 | ZEND_API ZEND_COLD void zend_throw_conflicting_coercion_error(const zend_property_info *prop1, const zend_property_info *prop2, const zval *zv) { |
3903 | 38 | zend_string *type1_str = zend_type_to_string(prop1->type); |
3904 | 38 | zend_string *type2_str = zend_type_to_string(prop2->type); |
3905 | 38 | zend_type_error("Cannot assign %s to reference held by property %s::$%s of type %s and property %s::$%s of type %s, as this would result in an inconsistent type conversion", |
3906 | 38 | zend_zval_value_name(zv), |
3907 | 38 | ZSTR_VAL(prop1->ce->name), |
3908 | 38 | zend_get_unmangled_property_name(prop1->name), |
3909 | 38 | ZSTR_VAL(type1_str), |
3910 | 38 | ZSTR_VAL(prop2->ce->name), |
3911 | 38 | zend_get_unmangled_property_name(prop2->name), |
3912 | 38 | ZSTR_VAL(type2_str) |
3913 | 38 | ); |
3914 | 38 | zend_string_release(type1_str); |
3915 | 38 | zend_string_release(type2_str); |
3916 | 38 | } |
3917 | | |
3918 | | /* 1: valid, 0: invalid, -1: may be valid after type coercion */ |
3919 | | static zend_always_inline int i_zend_verify_type_assignable_zval( |
3920 | 43.0k | const zend_property_info *info, const zval *zv, bool strict) { |
3921 | 43.0k | zend_type type = info->type; |
3922 | 43.0k | uint32_t type_mask; |
3923 | 43.0k | uint8_t zv_type = Z_TYPE_P(zv); |
3924 | | |
3925 | 43.0k | if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(type, zv_type))) { |
3926 | 24.3k | return 1; |
3927 | 24.3k | } |
3928 | | |
3929 | 18.6k | if (ZEND_TYPE_IS_COMPLEX(type) && zv_type == IS_OBJECT |
3930 | 18.0k | && zend_check_and_resolve_property_or_class_constant_class_type(info->ce, info->type, Z_OBJCE_P(zv))) { |
3931 | 18.0k | return 1; |
3932 | 18.0k | } |
3933 | | |
3934 | 654 | type_mask = ZEND_TYPE_FULL_MASK(type); |
3935 | 654 | ZEND_ASSERT(!(type_mask & (MAY_BE_CALLABLE|MAY_BE_STATIC))); |
3936 | | |
3937 | | /* SSTH Exception: IS_LONG may be accepted as IS_DOUBLE (converted) */ |
3938 | 654 | if (strict) { |
3939 | 27 | if ((type_mask & MAY_BE_DOUBLE) && zv_type == IS_LONG) { |
3940 | 0 | return -1; |
3941 | 0 | } |
3942 | 27 | return 0; |
3943 | 27 | } |
3944 | | |
3945 | | /* NULL may be accepted only by nullable hints (this is already checked) */ |
3946 | 627 | if (zv_type == IS_NULL) { |
3947 | 106 | return 0; |
3948 | 106 | } |
3949 | | |
3950 | | /* Does not contain any type to which a coercion is possible */ |
3951 | 521 | if (!(type_mask & (MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING)) |
3952 | 170 | && (type_mask & MAY_BE_BOOL) != MAY_BE_BOOL) { |
3953 | 170 | return 0; |
3954 | 170 | } |
3955 | | |
3956 | | /* Coercion may be necessary, check separately */ |
3957 | 351 | return -1; |
3958 | 521 | } |
3959 | | |
3960 | | ZEND_API bool ZEND_FASTCALL zend_verify_ref_assignable_zval(zend_reference *ref, zval *zv, bool strict) |
3961 | 1.62k | { |
3962 | 1.62k | const zend_property_info *prop; |
3963 | | |
3964 | | /* The value must satisfy each property type, and coerce to the same value for each property |
3965 | | * type. Remember the first coerced type and value we've seen for this purpose. */ |
3966 | 1.62k | const zend_property_info *first_prop = NULL; |
3967 | 1.62k | zval coerced_value; |
3968 | 1.62k | ZVAL_UNDEF(&coerced_value); |
3969 | | |
3970 | 1.62k | ZEND_ASSERT(Z_TYPE_P(zv) != IS_REFERENCE); |
3971 | 5.14k | ZEND_REF_FOREACH_TYPE_SOURCES(ref, prop) { |
3972 | 5.14k | int result = i_zend_verify_type_assignable_zval(prop, zv, strict); |
3973 | 5.14k | if (result == 0) { |
3974 | 390 | type_error: |
3975 | 390 | zend_throw_ref_type_error_zval(prop, zv); |
3976 | 390 | zval_ptr_dtor(&coerced_value); |
3977 | 390 | return 0; |
3978 | 267 | } |
3979 | | |
3980 | 1.63k | if (result < 0) { |
3981 | 284 | if (!first_prop) { |
3982 | 259 | first_prop = prop; |
3983 | 259 | ZVAL_COPY(&coerced_value, zv); |
3984 | 259 | if (!zend_verify_weak_scalar_type_hint( |
3985 | 259 | ZEND_TYPE_FULL_MASK(prop->type), &coerced_value)) { |
3986 | 123 | goto type_error; |
3987 | 123 | } |
3988 | 259 | } else if (Z_ISUNDEF(coerced_value)) { |
3989 | | /* A previous property did not require coercion, but this one does, |
3990 | | * so they are incompatible. */ |
3991 | 19 | goto conflicting_coercion_error; |
3992 | 19 | } else { |
3993 | 6 | zval tmp; |
3994 | 6 | ZVAL_COPY(&tmp, zv); |
3995 | 6 | if (!zend_verify_weak_scalar_type_hint(ZEND_TYPE_FULL_MASK(prop->type), &tmp)) { |
3996 | 0 | zval_ptr_dtor(&tmp); |
3997 | 0 | goto type_error; |
3998 | 0 | } |
3999 | 6 | if (!zend_is_identical(&coerced_value, &tmp)) { |
4000 | 0 | zval_ptr_dtor(&tmp); |
4001 | 0 | goto conflicting_coercion_error; |
4002 | 0 | } |
4003 | 6 | zval_ptr_dtor(&tmp); |
4004 | 6 | } |
4005 | 1.35k | } else { |
4006 | 1.35k | if (!first_prop) { |
4007 | 1.16k | first_prop = prop; |
4008 | 1.16k | } else if (!Z_ISUNDEF(coerced_value)) { |
4009 | | /* A previous property required coercion, but this one doesn't, |
4010 | | * so they are incompatible. */ |
4011 | 38 | conflicting_coercion_error: |
4012 | 38 | zend_throw_conflicting_coercion_error(first_prop, prop, zv); |
4013 | 38 | zval_ptr_dtor(&coerced_value); |
4014 | 38 | return 0; |
4015 | 19 | } |
4016 | 1.35k | } |
4017 | 1.63k | } ZEND_REF_FOREACH_TYPE_SOURCES_END(); |
4018 | | |
4019 | 1.19k | if (!Z_ISUNDEF(coerced_value)) { |
4020 | 117 | zval_ptr_dtor(zv); |
4021 | 117 | ZVAL_COPY_VALUE(zv, &coerced_value); |
4022 | 117 | } |
4023 | | |
4024 | 1.19k | return 1; |
4025 | 1.62k | } |
4026 | | |
4027 | 774 | static zend_always_inline void i_zval_ptr_dtor_noref(zval *zval_ptr) { |
4028 | 774 | if (Z_REFCOUNTED_P(zval_ptr)) { |
4029 | 262 | zend_refcounted *ref = Z_COUNTED_P(zval_ptr); |
4030 | 262 | ZEND_ASSERT(Z_TYPE_P(zval_ptr) != IS_REFERENCE); |
4031 | 262 | GC_DTOR_NO_REF(ref); |
4032 | 262 | } |
4033 | 774 | } |
4034 | | |
4035 | | ZEND_API zval* zend_assign_to_typed_ref_ex(zval *variable_ptr, zval *orig_value, uint8_t value_type, bool strict, zend_refcounted **garbage_ptr) |
4036 | 1.23k | { |
4037 | 1.23k | bool ret; |
4038 | 1.23k | zval value; |
4039 | 1.23k | zend_refcounted *ref = NULL; |
4040 | | |
4041 | 1.23k | if (Z_ISREF_P(orig_value)) { |
4042 | 0 | ref = Z_COUNTED_P(orig_value); |
4043 | 0 | orig_value = Z_REFVAL_P(orig_value); |
4044 | 0 | } |
4045 | | |
4046 | 1.23k | ZVAL_COPY(&value, orig_value); |
4047 | 1.23k | ret = zend_verify_ref_assignable_zval(Z_REF_P(variable_ptr), &value, strict); |
4048 | 1.23k | variable_ptr = Z_REFVAL_P(variable_ptr); |
4049 | 1.23k | if (EXPECTED(ret)) { |
4050 | 852 | if (Z_REFCOUNTED_P(variable_ptr)) { |
4051 | 232 | *garbage_ptr = Z_COUNTED_P(variable_ptr); |
4052 | 232 | } |
4053 | 852 | ZVAL_COPY_VALUE(variable_ptr, &value); |
4054 | 852 | } else { |
4055 | 382 | zval_ptr_dtor_nogc(&value); |
4056 | 382 | } |
4057 | 1.23k | if (value_type & (IS_VAR|IS_TMP_VAR)) { |
4058 | 774 | if (UNEXPECTED(ref)) { |
4059 | 0 | if (UNEXPECTED(GC_DELREF(ref) == 0)) { |
4060 | 0 | zval_ptr_dtor(orig_value); |
4061 | 0 | efree_size(ref, sizeof(zend_reference)); |
4062 | 0 | } |
4063 | 774 | } else { |
4064 | 774 | i_zval_ptr_dtor_noref(orig_value); |
4065 | 774 | } |
4066 | 774 | } |
4067 | 1.23k | return variable_ptr; |
4068 | 1.23k | } |
4069 | | |
4070 | | ZEND_API zval* zend_assign_to_typed_ref(zval *variable_ptr, zval *orig_value, uint8_t value_type, bool strict) |
4071 | 400 | { |
4072 | 400 | zend_refcounted *garbage = NULL; |
4073 | 400 | zval *result = zend_assign_to_typed_ref_ex(variable_ptr, orig_value, value_type, strict, &garbage); |
4074 | 400 | if (garbage) { |
4075 | 12 | GC_DTOR_NO_REF(garbage); |
4076 | 12 | } |
4077 | 400 | return result; |
4078 | 400 | } |
4079 | | |
4080 | 201k | 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) { |
4081 | 201k | zval *val = orig_val; |
4082 | 201k | if (Z_ISREF_P(val) && ZEND_REF_HAS_TYPE_SOURCES(Z_REF_P(val))) { |
4083 | 41.1k | int result; |
4084 | | |
4085 | 41.1k | val = Z_REFVAL_P(val); |
4086 | 41.1k | result = i_zend_verify_type_assignable_zval(prop_info, val, strict); |
4087 | 41.1k | if (result > 0) { |
4088 | 41.0k | return 1; |
4089 | 41.0k | } |
4090 | | |
4091 | 103 | if (result < 0) { |
4092 | | /* This is definitely an error, but we still need to determined why: Either because |
4093 | | * the value is simply illegal for the type, or because or a conflicting coercion. */ |
4094 | 67 | zval tmp; |
4095 | 67 | ZVAL_COPY(&tmp, val); |
4096 | 67 | if (zend_verify_weak_scalar_type_hint(ZEND_TYPE_FULL_MASK(prop_info->type), &tmp)) { |
4097 | 67 | const zend_property_info *ref_prop = ZEND_REF_FIRST_SOURCE(Z_REF_P(orig_val)); |
4098 | 67 | zend_throw_ref_type_error_type(ref_prop, prop_info, val); |
4099 | 67 | zval_ptr_dtor(&tmp); |
4100 | 67 | return 0; |
4101 | 67 | } |
4102 | 0 | zval_ptr_dtor(&tmp); |
4103 | 0 | } |
4104 | 160k | } else { |
4105 | 160k | ZVAL_DEREF(val); |
4106 | 160k | if (i_zend_check_property_type(prop_info, val, strict)) { |
4107 | 160k | return 1; |
4108 | 160k | } |
4109 | 160k | } |
4110 | | |
4111 | 108 | if (EXPECTED(context == ZEND_VERIFY_PROP_ASSIGNABLE_BY_REF_CONTEXT_ASSIGNMENT)) { |
4112 | 90 | zend_verify_property_type_error(prop_info, val); |
4113 | 90 | } else { |
4114 | 18 | ZEND_ASSERT(context == ZEND_VERIFY_PROP_ASSIGNABLE_BY_REF_CONTEXT_MAGIC_GET); |
4115 | 18 | zend_magic_get_property_type_inconsistency_error(prop_info, val); |
4116 | 18 | } |
4117 | | |
4118 | 108 | return 0; |
4119 | 108 | } |
4120 | | |
4121 | 201k | ZEND_API bool ZEND_FASTCALL zend_verify_prop_assignable_by_ref(const zend_property_info *prop_info, zval *orig_val, bool strict) { |
4122 | 201k | return zend_verify_prop_assignable_by_ref_ex(prop_info, orig_val, strict, ZEND_VERIFY_PROP_ASSIGNABLE_BY_REF_CONTEXT_ASSIGNMENT); |
4123 | 201k | } |
4124 | | |
4125 | | ZEND_API void ZEND_FASTCALL zend_ref_add_type_source(zend_property_info_source_list *source_list, zend_property_info *prop) |
4126 | 43.4k | { |
4127 | 43.4k | zend_property_info_list *list; |
4128 | 43.4k | if (source_list->ptr == NULL) { |
4129 | 2.38k | source_list->ptr = prop; |
4130 | 2.38k | return; |
4131 | 2.38k | } |
4132 | | |
4133 | 41.0k | list = ZEND_PROPERTY_INFO_SOURCE_TO_LIST(source_list->list); |
4134 | 41.0k | if (!ZEND_PROPERTY_INFO_SOURCE_IS_LIST(source_list->list)) { |
4135 | 516 | list = emalloc(sizeof(zend_property_info_list) + (4 - 1) * sizeof(zend_property_info *)); |
4136 | 516 | list->ptr[0] = source_list->ptr; |
4137 | 516 | list->num_allocated = 4; |
4138 | 516 | list->num = 1; |
4139 | 40.5k | } else if (list->num_allocated == list->num) { |
4140 | 715 | list->num_allocated = list->num * 2; |
4141 | 715 | list = erealloc(list, sizeof(zend_property_info_list) + (list->num_allocated - 1) * sizeof(zend_property_info *)); |
4142 | 715 | } |
4143 | | |
4144 | 41.0k | list->ptr[list->num++] = prop; |
4145 | 41.0k | source_list->list = ZEND_PROPERTY_INFO_SOURCE_FROM_LIST(list); |
4146 | 41.0k | } |
4147 | | |
4148 | | ZEND_API void ZEND_FASTCALL zend_ref_del_type_source(zend_property_info_source_list *source_list, const zend_property_info *prop) |
4149 | 43.4k | { |
4150 | 43.4k | zend_property_info_list *list = ZEND_PROPERTY_INFO_SOURCE_TO_LIST(source_list->list); |
4151 | 43.4k | zend_property_info **ptr, **end; |
4152 | | |
4153 | 43.4k | ZEND_ASSERT(prop); |
4154 | 43.4k | if (!ZEND_PROPERTY_INFO_SOURCE_IS_LIST(source_list->list)) { |
4155 | 1.86k | ZEND_ASSERT(source_list->ptr == prop); |
4156 | 1.86k | source_list->ptr = NULL; |
4157 | 1.86k | return; |
4158 | 1.86k | } |
4159 | | |
4160 | 41.5k | if (list->num == 1) { |
4161 | 516 | ZEND_ASSERT(*list->ptr == prop); |
4162 | 516 | efree(list); |
4163 | 516 | source_list->ptr = NULL; |
4164 | 516 | return; |
4165 | 516 | } |
4166 | | |
4167 | | /* Checking against end here to get a more graceful failure mode if we missed adding a type |
4168 | | * source at some point. */ |
4169 | 41.0k | ptr = list->ptr; |
4170 | 41.0k | end = ptr + list->num; |
4171 | 41.2k | while (ptr < end && *ptr != prop) { |
4172 | 183 | ptr++; |
4173 | 183 | } |
4174 | 41.0k | ZEND_ASSERT(*ptr == prop); |
4175 | | |
4176 | | /* Copy the last list element into the deleted slot. */ |
4177 | 41.0k | *ptr = list->ptr[--list->num]; |
4178 | | |
4179 | 41.0k | if (list->num >= 4 && list->num * 4 == list->num_allocated) { |
4180 | 524 | list->num_allocated = list->num * 2; |
4181 | 524 | source_list->list = ZEND_PROPERTY_INFO_SOURCE_FROM_LIST(erealloc(list, sizeof(zend_property_info_list) + (list->num_allocated - 1) * sizeof(zend_property_info *))); |
4182 | 524 | } |
4183 | 41.0k | } |
4184 | | |
4185 | | static zend_never_inline void zend_fetch_this_var(int type OPLINE_DC EXECUTE_DATA_DC) |
4186 | 103 | { |
4187 | 103 | zval *result = EX_VAR(opline->result.var); |
4188 | | |
4189 | 103 | switch (type) { |
4190 | 97 | case BP_VAR_R: |
4191 | 97 | if (EXPECTED(Z_TYPE(EX(This)) == IS_OBJECT)) { |
4192 | 94 | ZVAL_OBJ(result, Z_OBJ(EX(This))); |
4193 | 94 | Z_ADDREF_P(result); |
4194 | 94 | } else { |
4195 | 3 | ZVAL_NULL(result); |
4196 | 3 | zend_error_unchecked(E_WARNING, "Undefined variable $this"); |
4197 | 3 | } |
4198 | 97 | break; |
4199 | 0 | case BP_VAR_IS: |
4200 | 0 | if (EXPECTED(Z_TYPE(EX(This)) == IS_OBJECT)) { |
4201 | 0 | ZVAL_OBJ(result, Z_OBJ(EX(This))); |
4202 | 0 | Z_ADDREF_P(result); |
4203 | 0 | } else { |
4204 | 0 | ZVAL_NULL(result); |
4205 | 0 | } |
4206 | 0 | break; |
4207 | 0 | case BP_VAR_RW: |
4208 | 6 | case BP_VAR_W: |
4209 | 6 | ZVAL_UNDEF(result); |
4210 | 6 | zend_throw_error(NULL, "Cannot re-assign $this"); |
4211 | 6 | break; |
4212 | 0 | case BP_VAR_UNSET: |
4213 | 0 | ZVAL_UNDEF(result); |
4214 | 0 | zend_throw_error(NULL, "Cannot unset $this"); |
4215 | 0 | break; |
4216 | 103 | EMPTY_SWITCH_DEFAULT_CASE() |
4217 | 103 | } |
4218 | 103 | } |
4219 | | |
4220 | | #if ZEND_INTENSIVE_DEBUGGING |
4221 | | |
4222 | | #define CHECK_SYMBOL_TABLES() \ |
4223 | | zend_hash_apply(&EG(symbol_table), zend_check_symbol); \ |
4224 | | if (&EG(symbol_table)!=EX(symbol_table)) { \ |
4225 | | zend_hash_apply(EX(symbol_table), zend_check_symbol); \ |
4226 | | } |
4227 | | |
4228 | | static void zend_check_symbol(zval *pz) |
4229 | | { |
4230 | | if (Z_TYPE_P(pz) == IS_INDIRECT) { |
4231 | | pz = Z_INDIRECT_P(pz); |
4232 | | } |
4233 | | if (Z_TYPE_P(pz) > 10) { |
4234 | | fprintf(stderr, "Warning! %x has invalid type!\n", *pz); |
4235 | | /* See http://support.microsoft.com/kb/190351 */ |
4236 | | #ifdef ZEND_WIN32 |
4237 | | fflush(stderr); |
4238 | | #endif |
4239 | | } else if (Z_TYPE_P(pz) == IS_ARRAY) { |
4240 | | zend_hash_apply(Z_ARRVAL_P(pz), zend_check_symbol); |
4241 | | } else if (Z_TYPE_P(pz) == IS_OBJECT) { |
4242 | | /* OBJ-TBI - doesn't support new object model! */ |
4243 | | zend_hash_apply(Z_OBJPROP_P(pz), zend_check_symbol); |
4244 | | } |
4245 | | } |
4246 | | |
4247 | | |
4248 | | #else |
4249 | | #define CHECK_SYMBOL_TABLES() |
4250 | | #endif |
4251 | | |
4252 | | ZEND_API void execute_internal(zend_execute_data *execute_data, zval *return_value) |
4253 | 1.01M | { |
4254 | 1.01M | execute_data->func->internal_function.handler(execute_data, return_value); |
4255 | 1.01M | } |
4256 | | |
4257 | | ZEND_API void zend_clean_and_cache_symbol_table(zend_array *symbol_table) /* {{{ */ |
4258 | 5.80k | { |
4259 | | /* Clean before putting into the cache, since clean could call dtors, |
4260 | | * which could use the cached hash. Also do this before the check for |
4261 | | * available cache slots, as those may be used by a dtor as well. */ |
4262 | 5.80k | zend_symtable_clean(symbol_table); |
4263 | 5.80k | if (EG(symtable_cache_ptr) >= EG(symtable_cache_limit)) { |
4264 | 208 | zend_array_destroy(symbol_table); |
4265 | 5.59k | } else { |
4266 | 5.59k | *(EG(symtable_cache_ptr)++) = symbol_table; |
4267 | 5.59k | } |
4268 | 5.80k | } |
4269 | | /* }}} */ |
4270 | | |
4271 | | static zend_always_inline void i_free_compiled_variables(zend_execute_data *execute_data) /* {{{ */ |
4272 | 202k | { |
4273 | 202k | zval *cv = EX_VAR_NUM(0); |
4274 | 202k | int count = EX(func)->op_array.last_var; |
4275 | 565k | while (EXPECTED(count != 0)) { |
4276 | 363k | i_zval_ptr_dtor(cv); |
4277 | 363k | cv++; |
4278 | 363k | count--; |
4279 | 363k | } |
4280 | 202k | } |
4281 | | /* }}} */ |
4282 | | |
4283 | | ZEND_API void ZEND_FASTCALL zend_free_compiled_variables(zend_execute_data *execute_data) /* {{{ */ |
4284 | 4.62k | { |
4285 | 4.62k | i_free_compiled_variables(execute_data); |
4286 | 4.62k | } |
4287 | | /* }}} */ |
4288 | | |
4289 | | ZEND_API ZEND_COLD void ZEND_FASTCALL zend_fcall_interrupt(zend_execute_data *call) |
4290 | 0 | { |
4291 | 0 | zend_atomic_bool_store_ex(&EG(vm_interrupt), false); |
4292 | 0 | if (zend_atomic_bool_load_ex(&EG(timed_out))) { |
4293 | 0 | zend_timeout(); |
4294 | 0 | } else if (zend_interrupt_function) { |
4295 | 0 | zend_interrupt_function(call); |
4296 | 0 | } |
4297 | 0 | } |
4298 | | |
4299 | 1.23M | #define ZEND_VM_INTERRUPT_CHECK() do { \ |
4300 | 1.23M | if (UNEXPECTED(zend_atomic_bool_load_ex(&EG(vm_interrupt)))) { \ |
4301 | 0 | ZEND_VM_INTERRUPT(); \ |
4302 | 0 | } \ |
4303 | 1.23M | } while (0) |
4304 | | |
4305 | 109k | #define ZEND_VM_LOOP_INTERRUPT_CHECK() do { \ |
4306 | 109k | if (UNEXPECTED(zend_atomic_bool_load_ex(&EG(vm_interrupt)))) { \ |
4307 | 0 | ZEND_VM_LOOP_INTERRUPT(); \ |
4308 | 0 | } \ |
4309 | 109k | } while (0) |
4310 | | |
4311 | 932k | #define ZEND_VM_FCALL_INTERRUPT_CHECK(call) do { \ |
4312 | 932k | if (UNEXPECTED(zend_atomic_bool_load_ex(&EG(vm_interrupt)))) { \ |
4313 | 0 | zend_fcall_interrupt(call); \ |
4314 | 0 | } \ |
4315 | 932k | } while (0) |
4316 | | |
4317 | | /* |
4318 | | * Stack Frame Layout (the whole stack frame is allocated at once) |
4319 | | * ================== |
4320 | | * |
4321 | | * +========================================+ |
4322 | | * EG(current_execute_data) -> | zend_execute_data | |
4323 | | * +----------------------------------------+ |
4324 | | * EX_VAR_NUM(0) --------> | VAR[0] = ARG[1] | |
4325 | | * | ... | |
4326 | | * | VAR[op_array->num_args-1] = ARG[N] | |
4327 | | * | ... | |
4328 | | * | VAR[op_array->last_var-1] | |
4329 | | * | VAR[op_array->last_var] = TMP[0] | |
4330 | | * | ... | |
4331 | | * | VAR[op_array->last_var+op_array->T-1] | |
4332 | | * | ARG[N+1] (extra_args) | |
4333 | | * | ... | |
4334 | | * +----------------------------------------+ |
4335 | | */ |
4336 | | |
4337 | | /* zend_copy_extra_args is used when the actually passed number of arguments |
4338 | | * (EX_NUM_ARGS) is greater than what the function defined (op_array->num_args). |
4339 | | * |
4340 | | * The extra arguments will be copied into the call frame after all the compiled variables. |
4341 | | * |
4342 | | * If there are extra arguments copied, a flag "ZEND_CALL_FREE_EXTRA_ARGS" will be set |
4343 | | * on the zend_execute_data, and when the executor leaves the function, the |
4344 | | * args will be freed in zend_leave_helper. |
4345 | | */ |
4346 | | static zend_never_inline void zend_copy_extra_args(EXECUTE_DATA_D) |
4347 | 7.58k | { |
4348 | 7.58k | zend_op_array *op_array = &EX(func)->op_array; |
4349 | 7.58k | uint32_t first_extra_arg = op_array->num_args; |
4350 | 7.58k | uint32_t num_args = EX_NUM_ARGS(); |
4351 | 7.58k | zval *src; |
4352 | 7.58k | size_t delta; |
4353 | 7.58k | uint32_t count; |
4354 | 7.58k | uint32_t type_flags = 0; |
4355 | | |
4356 | 7.58k | if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) { |
4357 | | /* Skip useless ZEND_RECV and ZEND_RECV_INIT opcodes */ |
4358 | | #if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
4359 | | opline += first_extra_arg; |
4360 | | #else |
4361 | 7.45k | EX(opline) += first_extra_arg; |
4362 | 7.45k | #endif |
4363 | | |
4364 | 7.45k | } |
4365 | | |
4366 | | /* move extra args into separate array after all CV and TMP vars */ |
4367 | 7.58k | src = EX_VAR_NUM(num_args - 1); |
4368 | 7.58k | delta = op_array->last_var + op_array->T - first_extra_arg; |
4369 | 7.58k | count = num_args - first_extra_arg; |
4370 | 7.58k | if (EXPECTED(delta != 0)) { |
4371 | 5.88k | delta *= sizeof(zval); |
4372 | 379k | do { |
4373 | 379k | type_flags |= Z_TYPE_INFO_P(src); |
4374 | 379k | ZVAL_COPY_VALUE((zval*)(((char*)src) + delta), src); |
4375 | 379k | ZVAL_UNDEF(src); |
4376 | 379k | src--; |
4377 | 379k | } while (--count); |
4378 | 5.88k | if (Z_TYPE_INFO_REFCOUNTED(type_flags)) { |
4379 | 4.61k | ZEND_ADD_CALL_FLAG(execute_data, ZEND_CALL_FREE_EXTRA_ARGS); |
4380 | 4.61k | } |
4381 | 5.88k | } else { |
4382 | 1.08M | do { |
4383 | 1.08M | if (Z_REFCOUNTED_P(src)) { |
4384 | 323 | ZEND_ADD_CALL_FLAG(execute_data, ZEND_CALL_FREE_EXTRA_ARGS); |
4385 | 323 | break; |
4386 | 323 | } |
4387 | 1.08M | src--; |
4388 | 1.08M | } while (--count); |
4389 | 1.70k | } |
4390 | 7.58k | } |
4391 | | |
4392 | | static zend_always_inline void zend_init_cvs(uint32_t first, uint32_t last EXECUTE_DATA_DC) |
4393 | 231k | { |
4394 | 231k | if (EXPECTED(first < last)) { |
4395 | 152k | uint32_t count = last - first; |
4396 | 152k | zval *var = EX_VAR_NUM(first); |
4397 | | |
4398 | 1.09M | do { |
4399 | 1.09M | ZVAL_UNDEF(var); |
4400 | 1.09M | var++; |
4401 | 1.09M | } while (--count); |
4402 | 152k | } |
4403 | 231k | } |
4404 | | |
4405 | | static zend_always_inline void i_init_func_execute_data(zend_op_array *op_array, zval *return_value, bool may_be_trampoline EXECUTE_DATA_DC) /* {{{ */ |
4406 | 230k | { |
4407 | 230k | uint32_t first_extra_arg, num_args; |
4408 | 230k | ZEND_ASSERT(EX(func) == (zend_function*)op_array); |
4409 | | |
4410 | | #if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
4411 | | opline = op_array->opcodes; |
4412 | | #else |
4413 | 230k | EX(opline) = op_array->opcodes; |
4414 | 230k | #endif |
4415 | 230k | EX(call) = NULL; |
4416 | 230k | EX(return_value) = return_value; |
4417 | | |
4418 | | /* Handle arguments */ |
4419 | 230k | first_extra_arg = op_array->num_args; |
4420 | 230k | num_args = EX_NUM_ARGS(); |
4421 | 230k | if (UNEXPECTED(num_args > first_extra_arg)) { |
4422 | 7.99k | if (!may_be_trampoline || EXPECTED(!(op_array->fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE))) { |
4423 | 7.58k | zend_copy_extra_args(EXECUTE_DATA_C); |
4424 | 7.58k | } |
4425 | 222k | } else if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) { |
4426 | | /* Skip useless ZEND_RECV and ZEND_RECV_INIT opcodes */ |
4427 | | #if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
4428 | | opline += num_args; |
4429 | | #else |
4430 | 210k | EX(opline) += num_args; |
4431 | 210k | #endif |
4432 | 210k | } |
4433 | | |
4434 | | /* Initialize CV variables (skip arguments) */ |
4435 | 230k | zend_init_cvs(num_args, op_array->last_var EXECUTE_DATA_CC); |
4436 | | |
4437 | 230k | EX(run_time_cache) = RUN_TIME_CACHE(op_array); |
4438 | | |
4439 | 230k | EG(current_execute_data) = execute_data; |
4440 | 230k | } |
4441 | | /* }}} */ |
4442 | | |
4443 | | static zend_always_inline void init_func_run_time_cache_i(zend_op_array *op_array) /* {{{ */ |
4444 | 31.7k | { |
4445 | 31.7k | void **run_time_cache; |
4446 | | |
4447 | 31.7k | ZEND_ASSERT(RUN_TIME_CACHE(op_array) == NULL); |
4448 | 31.7k | run_time_cache = zend_arena_alloc(&CG(arena), op_array->cache_size); |
4449 | 31.7k | memset(run_time_cache, 0, op_array->cache_size); |
4450 | 31.7k | ZEND_MAP_PTR_SET(op_array->run_time_cache, run_time_cache); |
4451 | 31.7k | } |
4452 | | /* }}} */ |
4453 | | |
4454 | | static zend_never_inline void ZEND_FASTCALL init_func_run_time_cache(zend_op_array *op_array) /* {{{ */ |
4455 | 31.3k | { |
4456 | 31.3k | init_func_run_time_cache_i(op_array); |
4457 | 31.3k | } |
4458 | | /* }}} */ |
4459 | | |
4460 | | ZEND_API zend_function * ZEND_FASTCALL zend_fetch_function(zend_string *name) /* {{{ */ |
4461 | 7.19k | { |
4462 | 7.19k | zval *zv = zend_hash_find(EG(function_table), name); |
4463 | | |
4464 | 7.19k | if (EXPECTED(zv != NULL)) { |
4465 | 3.56k | zend_function *fbc = Z_FUNC_P(zv); |
4466 | | |
4467 | 3.56k | if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) { |
4468 | 373 | init_func_run_time_cache_i(&fbc->op_array); |
4469 | 373 | } |
4470 | 3.56k | return fbc; |
4471 | 3.56k | } |
4472 | 3.63k | return NULL; |
4473 | 7.19k | } /* }}} */ |
4474 | | |
4475 | | ZEND_API zend_function * ZEND_FASTCALL zend_fetch_function_str(const char *name, size_t len) /* {{{ */ |
4476 | 16 | { |
4477 | 16 | zval *zv = zend_hash_str_find(EG(function_table), name, len); |
4478 | | |
4479 | 16 | if (EXPECTED(zv != NULL)) { |
4480 | 16 | zend_function *fbc = Z_FUNC_P(zv); |
4481 | | |
4482 | 16 | if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) { |
4483 | 0 | init_func_run_time_cache_i(&fbc->op_array); |
4484 | 0 | } |
4485 | 16 | return fbc; |
4486 | 16 | } |
4487 | 0 | return NULL; |
4488 | 16 | } /* }}} */ |
4489 | | |
4490 | | ZEND_API void ZEND_FASTCALL zend_init_func_run_time_cache(zend_op_array *op_array) /* {{{ */ |
4491 | 0 | { |
4492 | 0 | if (!RUN_TIME_CACHE(op_array)) { |
4493 | 0 | init_func_run_time_cache_i(op_array); |
4494 | 0 | } |
4495 | 0 | } /* }}} */ |
4496 | | |
4497 | | static zend_always_inline void i_init_code_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value) /* {{{ */ |
4498 | 171k | { |
4499 | 171k | ZEND_ASSERT(EX(func) == (zend_function*)op_array); |
4500 | | |
4501 | 171k | EX(opline) = op_array->opcodes; |
4502 | 171k | EX(call) = NULL; |
4503 | 171k | EX(return_value) = return_value; |
4504 | | |
4505 | 171k | if (op_array->last_var) { |
4506 | 117k | zend_attach_symbol_table(execute_data); |
4507 | 117k | } |
4508 | | |
4509 | 171k | if (!ZEND_MAP_PTR(op_array->run_time_cache)) { |
4510 | 171k | void *ptr; |
4511 | | |
4512 | 171k | ZEND_ASSERT(op_array->fn_flags & ZEND_ACC_HEAP_RT_CACHE); |
4513 | 171k | ptr = emalloc(op_array->cache_size); |
4514 | 171k | ZEND_MAP_PTR_INIT(op_array->run_time_cache, ptr); |
4515 | 171k | memset(ptr, 0, op_array->cache_size); |
4516 | 171k | } |
4517 | 171k | EX(run_time_cache) = RUN_TIME_CACHE(op_array); |
4518 | | |
4519 | 171k | EG(current_execute_data) = execute_data; |
4520 | 171k | } |
4521 | | /* }}} */ |
4522 | | |
4523 | | ZEND_API void zend_init_func_execute_data(zend_execute_data *ex, zend_op_array *op_array, zval *return_value) /* {{{ */ |
4524 | 161k | { |
4525 | | #if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
4526 | | zend_execute_data *orig_execute_data = execute_data; |
4527 | | #endif |
4528 | | #if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
4529 | | const zend_op *orig_opline = opline; |
4530 | | #endif |
4531 | | #if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
4532 | | execute_data = ex; |
4533 | | #else |
4534 | 161k | zend_execute_data *execute_data = ex; |
4535 | 161k | #endif |
4536 | | |
4537 | 161k | EX(prev_execute_data) = EG(current_execute_data); |
4538 | 161k | if (!RUN_TIME_CACHE(op_array)) { |
4539 | 7.10k | init_func_run_time_cache(op_array); |
4540 | 7.10k | } |
4541 | 161k | i_init_func_execute_data(op_array, return_value, 1 EXECUTE_DATA_CC); |
4542 | | |
4543 | | #if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
4544 | | EX(opline) = opline; |
4545 | | opline = orig_opline; |
4546 | | #endif |
4547 | | #if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
4548 | | execute_data = orig_execute_data; |
4549 | | #endif |
4550 | 161k | } |
4551 | | /* }}} */ |
4552 | | |
4553 | | ZEND_API void zend_init_code_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value) /* {{{ */ |
4554 | 0 | { |
4555 | 0 | EX(prev_execute_data) = EG(current_execute_data); |
4556 | 0 | i_init_code_execute_data(execute_data, op_array, return_value); |
4557 | 0 | } |
4558 | | /* }}} */ |
4559 | | |
4560 | | ZEND_API void zend_init_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value) /* {{{ */ |
4561 | 0 | { |
4562 | 0 | if (EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE) { |
4563 | 0 | zend_init_code_execute_data(execute_data, op_array, return_value); |
4564 | 0 | } else { |
4565 | 0 | zend_init_func_execute_data(execute_data, op_array, return_value); |
4566 | 0 | } |
4567 | 0 | } |
4568 | | /* }}} */ |
4569 | | |
4570 | | zend_execute_data *zend_vm_stack_copy_call_frame(zend_execute_data *call, uint32_t passed_args, uint32_t additional_args) /* {{{ */ |
4571 | 63 | { |
4572 | 63 | zend_execute_data *new_call; |
4573 | 63 | int used_stack = (EG(vm_stack_top) - (zval*)call) + additional_args; |
4574 | | |
4575 | | /* copy call frame into new stack segment */ |
4576 | 63 | new_call = zend_vm_stack_extend(used_stack * sizeof(zval)); |
4577 | 63 | *new_call = *call; |
4578 | 63 | ZEND_ADD_CALL_FLAG(new_call, ZEND_CALL_ALLOCATED); |
4579 | | |
4580 | 63 | if (passed_args) { |
4581 | 12 | zval *src = ZEND_CALL_ARG(call, 1); |
4582 | 12 | zval *dst = ZEND_CALL_ARG(new_call, 1); |
4583 | 120k | do { |
4584 | 120k | ZVAL_COPY_VALUE(dst, src); |
4585 | 120k | passed_args--; |
4586 | 120k | src++; |
4587 | 120k | dst++; |
4588 | 120k | } while (passed_args); |
4589 | 12 | } |
4590 | | |
4591 | | /* delete old call_frame from previous stack segment */ |
4592 | 63 | EG(vm_stack)->prev->top = (zval*)call; |
4593 | | |
4594 | | /* delete previous stack segment if it became empty */ |
4595 | 63 | if (UNEXPECTED(EG(vm_stack)->prev->top == ZEND_VM_STACK_ELEMENTS(EG(vm_stack)->prev))) { |
4596 | 0 | zend_vm_stack r = EG(vm_stack)->prev; |
4597 | |
|
4598 | 0 | EG(vm_stack)->prev = r->prev; |
4599 | 0 | efree(r); |
4600 | 0 | } |
4601 | | |
4602 | 63 | return new_call; |
4603 | 63 | } |
4604 | | /* }}} */ |
4605 | | |
4606 | | static zend_always_inline zend_generator *zend_get_running_generator(EXECUTE_DATA_D) /* {{{ */ |
4607 | 8.06k | { |
4608 | | /* The generator object is stored in EX(return_value) */ |
4609 | 8.06k | zend_generator *generator = (zend_generator *) EX(return_value); |
4610 | | /* However control may currently be delegated to another generator. |
4611 | | * That's the one we're interested in. */ |
4612 | 8.06k | return generator; |
4613 | 8.06k | } |
4614 | | /* }}} */ |
4615 | | |
4616 | | 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) /* {{{ */ |
4617 | 335 | { |
4618 | 335 | zend_op *opline = EX(func)->op_array.opcodes + op_num; |
4619 | 335 | int level; |
4620 | 335 | int do_exit; |
4621 | 335 | uint32_t num_args; |
4622 | | |
4623 | 335 | if (UNEXPECTED(opline->opcode == ZEND_INIT_FCALL || |
4624 | 335 | opline->opcode == ZEND_INIT_FCALL_BY_NAME || |
4625 | 335 | opline->opcode == ZEND_INIT_NS_FCALL_BY_NAME || |
4626 | 335 | opline->opcode == ZEND_INIT_DYNAMIC_CALL || |
4627 | 335 | opline->opcode == ZEND_INIT_USER_CALL || |
4628 | 335 | opline->opcode == ZEND_INIT_METHOD_CALL || |
4629 | 335 | opline->opcode == ZEND_INIT_STATIC_METHOD_CALL || |
4630 | 335 | opline->opcode == ZEND_NEW)) { |
4631 | 0 | ZEND_ASSERT(op_num); |
4632 | 0 | opline--; |
4633 | 0 | } |
4634 | | |
4635 | 385 | do { |
4636 | | /* find the number of actually passed arguments */ |
4637 | 385 | level = 0; |
4638 | 385 | do_exit = 0; |
4639 | 385 | num_args = ZEND_CALL_NUM_ARGS(call); |
4640 | 1.00k | do { |
4641 | 1.00k | switch (opline->opcode) { |
4642 | 91 | case ZEND_DO_FCALL: |
4643 | 91 | case ZEND_DO_ICALL: |
4644 | 147 | case ZEND_DO_UCALL: |
4645 | 147 | case ZEND_DO_FCALL_BY_NAME: |
4646 | 147 | case ZEND_CALLABLE_CONVERT: |
4647 | 147 | level++; |
4648 | 147 | break; |
4649 | 270 | case ZEND_INIT_FCALL: |
4650 | 270 | case ZEND_INIT_FCALL_BY_NAME: |
4651 | 270 | case ZEND_INIT_NS_FCALL_BY_NAME: |
4652 | 296 | case ZEND_INIT_DYNAMIC_CALL: |
4653 | 296 | case ZEND_INIT_USER_CALL: |
4654 | 328 | case ZEND_INIT_METHOD_CALL: |
4655 | 338 | case ZEND_INIT_STATIC_METHOD_CALL: |
4656 | 382 | case ZEND_NEW: |
4657 | 382 | if (level == 0) { |
4658 | 235 | num_args = 0; |
4659 | 235 | do_exit = 1; |
4660 | 235 | } |
4661 | 382 | level--; |
4662 | 382 | break; |
4663 | 29 | case ZEND_SEND_VAL: |
4664 | 41 | case ZEND_SEND_VAL_EX: |
4665 | 73 | case ZEND_SEND_VAR: |
4666 | 179 | case ZEND_SEND_VAR_EX: |
4667 | 179 | case ZEND_SEND_FUNC_ARG: |
4668 | 179 | case ZEND_SEND_REF: |
4669 | 179 | case ZEND_SEND_VAR_NO_REF: |
4670 | 179 | case ZEND_SEND_VAR_NO_REF_EX: |
4671 | 179 | case ZEND_SEND_USER: |
4672 | 179 | if (level == 0) { |
4673 | | /* For named args, the number of arguments is up to date. */ |
4674 | 150 | if (opline->op2_type != IS_CONST) { |
4675 | 78 | num_args = opline->op2.num; |
4676 | 78 | } |
4677 | 150 | do_exit = 1; |
4678 | 150 | } |
4679 | 179 | break; |
4680 | 0 | case ZEND_SEND_ARRAY: |
4681 | 0 | case ZEND_SEND_UNPACK: |
4682 | 0 | case ZEND_CHECK_UNDEF_ARGS: |
4683 | 0 | if (level == 0) { |
4684 | 0 | do_exit = 1; |
4685 | 0 | } |
4686 | 0 | break; |
4687 | 1.00k | } |
4688 | 1.00k | if (!do_exit) { |
4689 | 619 | opline--; |
4690 | 619 | } |
4691 | 1.00k | } while (!do_exit); |
4692 | 385 | if (call->prev_execute_data) { |
4693 | | /* skip current call region */ |
4694 | 50 | level = 0; |
4695 | 50 | do_exit = 0; |
4696 | 76 | do { |
4697 | 76 | switch (opline->opcode) { |
4698 | 0 | case ZEND_DO_FCALL: |
4699 | 0 | case ZEND_DO_ICALL: |
4700 | 0 | case ZEND_DO_UCALL: |
4701 | 0 | case ZEND_DO_FCALL_BY_NAME: |
4702 | 0 | case ZEND_CALLABLE_CONVERT: |
4703 | 0 | level++; |
4704 | 0 | break; |
4705 | 44 | case ZEND_INIT_FCALL: |
4706 | 44 | case ZEND_INIT_FCALL_BY_NAME: |
4707 | 44 | case ZEND_INIT_NS_FCALL_BY_NAME: |
4708 | 44 | case ZEND_INIT_DYNAMIC_CALL: |
4709 | 44 | case ZEND_INIT_USER_CALL: |
4710 | 50 | case ZEND_INIT_METHOD_CALL: |
4711 | 50 | case ZEND_INIT_STATIC_METHOD_CALL: |
4712 | 50 | case ZEND_NEW: |
4713 | 50 | if (level == 0) { |
4714 | 50 | do_exit = 1; |
4715 | 50 | } |
4716 | 50 | level--; |
4717 | 50 | break; |
4718 | 76 | } |
4719 | 76 | opline--; |
4720 | 76 | } while (!do_exit); |
4721 | 50 | } |
4722 | | |
4723 | 385 | if (EXPECTED(num_args > 0)) { |
4724 | 78 | zval *p = ZEND_CALL_ARG(call, 1); |
4725 | 80 | do { |
4726 | 80 | zend_get_gc_buffer_add_zval(buf, p); |
4727 | 80 | p++; |
4728 | 80 | } while (--num_args); |
4729 | 78 | } |
4730 | 385 | if (ZEND_CALL_INFO(call) & ZEND_CALL_RELEASE_THIS) { |
4731 | 58 | zend_get_gc_buffer_add_obj(buf, Z_OBJ(call->This)); |
4732 | 58 | } |
4733 | 385 | if (ZEND_CALL_INFO(call) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) { |
4734 | 72 | zval *val; |
4735 | 216 | ZEND_HASH_FOREACH_VAL(call->extra_named_params, val) { |
4736 | 216 | zend_get_gc_buffer_add_zval(buf, val); |
4737 | 216 | } ZEND_HASH_FOREACH_END(); |
4738 | 72 | } |
4739 | 385 | if (call->func->common.fn_flags & ZEND_ACC_CLOSURE) { |
4740 | 26 | zend_get_gc_buffer_add_obj(buf, ZEND_CLOSURE_OBJECT(call->func)); |
4741 | 26 | } |
4742 | | |
4743 | 385 | call = call->prev_execute_data; |
4744 | 385 | } while (call); |
4745 | 335 | } |
4746 | | /* }}} */ |
4747 | | |
4748 | | static void cleanup_unfinished_calls(zend_execute_data *execute_data, uint32_t op_num) /* {{{ */ |
4749 | 563k | { |
4750 | 563k | if (UNEXPECTED(EX(call))) { |
4751 | 6.51k | zend_execute_data *call = EX(call); |
4752 | 6.51k | zend_op *opline = EX(func)->op_array.opcodes + op_num; |
4753 | 6.51k | int level; |
4754 | 6.51k | int do_exit; |
4755 | | |
4756 | 6.51k | if (UNEXPECTED(opline->opcode == ZEND_INIT_FCALL || |
4757 | 6.51k | opline->opcode == ZEND_INIT_FCALL_BY_NAME || |
4758 | 6.51k | opline->opcode == ZEND_INIT_NS_FCALL_BY_NAME || |
4759 | 6.51k | opline->opcode == ZEND_INIT_DYNAMIC_CALL || |
4760 | 6.51k | opline->opcode == ZEND_INIT_USER_CALL || |
4761 | 6.51k | opline->opcode == ZEND_INIT_METHOD_CALL || |
4762 | 6.51k | opline->opcode == ZEND_INIT_STATIC_METHOD_CALL || |
4763 | 6.51k | opline->opcode == ZEND_INIT_PARENT_PROPERTY_HOOK_CALL || |
4764 | 6.51k | opline->opcode == ZEND_NEW)) { |
4765 | 798 | ZEND_ASSERT(op_num); |
4766 | 798 | opline--; |
4767 | 798 | } |
4768 | | |
4769 | 7.45k | do { |
4770 | | /* If the exception was thrown during a function call there might be |
4771 | | * arguments pushed to the stack that have to be dtor'ed. */ |
4772 | | |
4773 | | /* find the number of actually passed arguments */ |
4774 | 7.45k | level = 0; |
4775 | 7.45k | do_exit = 0; |
4776 | 21.3k | do { |
4777 | 21.3k | switch (opline->opcode) { |
4778 | 2.14k | case ZEND_DO_FCALL: |
4779 | 2.14k | case ZEND_DO_ICALL: |
4780 | 2.54k | case ZEND_DO_UCALL: |
4781 | 2.54k | case ZEND_DO_FCALL_BY_NAME: |
4782 | 2.55k | case ZEND_CALLABLE_CONVERT: |
4783 | 2.55k | level++; |
4784 | 2.55k | break; |
4785 | 6.94k | case ZEND_INIT_FCALL: |
4786 | 6.96k | case ZEND_INIT_FCALL_BY_NAME: |
4787 | 7.10k | case ZEND_INIT_NS_FCALL_BY_NAME: |
4788 | 7.40k | case ZEND_INIT_DYNAMIC_CALL: |
4789 | 7.41k | case ZEND_INIT_USER_CALL: |
4790 | 8.27k | case ZEND_INIT_METHOD_CALL: |
4791 | 8.53k | case ZEND_INIT_STATIC_METHOD_CALL: |
4792 | 8.54k | case ZEND_INIT_PARENT_PROPERTY_HOOK_CALL: |
4793 | 9.08k | case ZEND_NEW: |
4794 | 9.08k | if (level == 0) { |
4795 | 6.53k | ZEND_CALL_NUM_ARGS(call) = 0; |
4796 | 6.53k | do_exit = 1; |
4797 | 6.53k | } |
4798 | 9.08k | level--; |
4799 | 9.08k | break; |
4800 | 1.18k | case ZEND_SEND_VAL: |
4801 | 1.71k | case ZEND_SEND_VAL_EX: |
4802 | 2.15k | case ZEND_SEND_VAR: |
4803 | 2.26k | case ZEND_SEND_VAR_EX: |
4804 | 2.27k | case ZEND_SEND_FUNC_ARG: |
4805 | 2.29k | case ZEND_SEND_REF: |
4806 | 2.29k | case ZEND_SEND_VAR_NO_REF: |
4807 | 2.35k | case ZEND_SEND_VAR_NO_REF_EX: |
4808 | 2.35k | case ZEND_SEND_USER: |
4809 | 2.35k | if (level == 0) { |
4810 | | /* For named args, the number of arguments is up to date. */ |
4811 | 685 | if (opline->op2_type != IS_CONST) { |
4812 | 558 | ZEND_CALL_NUM_ARGS(call) = opline->op2.num; |
4813 | 558 | } |
4814 | 685 | do_exit = 1; |
4815 | 685 | } |
4816 | 2.35k | break; |
4817 | 75 | case ZEND_SEND_ARRAY: |
4818 | 206 | case ZEND_SEND_UNPACK: |
4819 | 255 | case ZEND_CHECK_UNDEF_ARGS: |
4820 | 255 | if (level == 0) { |
4821 | 235 | do_exit = 1; |
4822 | 235 | } |
4823 | 255 | break; |
4824 | 21.3k | } |
4825 | 21.3k | if (!do_exit) { |
4826 | 13.8k | opline--; |
4827 | 13.8k | } |
4828 | 21.3k | } while (!do_exit); |
4829 | 7.45k | if (call->prev_execute_data) { |
4830 | | /* skip current call region */ |
4831 | 933 | level = 0; |
4832 | 933 | do_exit = 0; |
4833 | 1.26k | do { |
4834 | 1.26k | switch (opline->opcode) { |
4835 | 4 | case ZEND_DO_FCALL: |
4836 | 4 | case ZEND_DO_ICALL: |
4837 | 4 | case ZEND_DO_UCALL: |
4838 | 4 | case ZEND_DO_FCALL_BY_NAME: |
4839 | 4 | case ZEND_CALLABLE_CONVERT: |
4840 | 4 | level++; |
4841 | 4 | break; |
4842 | 398 | case ZEND_INIT_FCALL: |
4843 | 398 | case ZEND_INIT_FCALL_BY_NAME: |
4844 | 411 | case ZEND_INIT_NS_FCALL_BY_NAME: |
4845 | 416 | case ZEND_INIT_DYNAMIC_CALL: |
4846 | 416 | case ZEND_INIT_USER_CALL: |
4847 | 912 | case ZEND_INIT_METHOD_CALL: |
4848 | 920 | case ZEND_INIT_STATIC_METHOD_CALL: |
4849 | 920 | case ZEND_INIT_PARENT_PROPERTY_HOOK_CALL: |
4850 | 937 | case ZEND_NEW: |
4851 | 937 | if (level == 0) { |
4852 | 933 | do_exit = 1; |
4853 | 933 | } |
4854 | 937 | level--; |
4855 | 937 | break; |
4856 | 1.26k | } |
4857 | 1.26k | opline--; |
4858 | 1.26k | } while (!do_exit); |
4859 | 933 | } |
4860 | | |
4861 | 7.45k | zend_vm_stack_free_args(EX(call)); |
4862 | | |
4863 | 7.45k | if (ZEND_CALL_INFO(call) & ZEND_CALL_RELEASE_THIS) { |
4864 | 730 | OBJ_RELEASE(Z_OBJ(call->This)); |
4865 | 730 | } |
4866 | 7.45k | if (ZEND_CALL_INFO(call) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) { |
4867 | 23 | zend_free_extra_named_params(call->extra_named_params); |
4868 | 23 | } |
4869 | 7.45k | if (call->func->common.fn_flags & ZEND_ACC_CLOSURE) { |
4870 | 62 | zend_object_release(ZEND_CLOSURE_OBJECT(call->func)); |
4871 | 7.38k | } else if (call->func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) { |
4872 | 39 | zend_string_release_ex(call->func->common.function_name, 0); |
4873 | 39 | zend_free_trampoline(call->func); |
4874 | 39 | } |
4875 | | |
4876 | 7.45k | EX(call) = call->prev_execute_data; |
4877 | 7.45k | zend_vm_stack_free_call_frame(call); |
4878 | 7.45k | call = EX(call); |
4879 | 7.45k | } while (call); |
4880 | 6.51k | } |
4881 | 563k | } |
4882 | | /* }}} */ |
4883 | | |
4884 | | static const zend_live_range *find_live_range(const zend_op_array *op_array, uint32_t op_num, uint32_t var_num) /* {{{ */ |
4885 | 33 | { |
4886 | 33 | int i; |
4887 | 86 | for (i = 0; i < op_array->last_live_range; i++) { |
4888 | 86 | const zend_live_range *range = &op_array->live_range[i]; |
4889 | 86 | if (op_num >= range->start && op_num < range->end |
4890 | 43 | && var_num == (range->var & ~ZEND_LIVE_MASK)) { |
4891 | 33 | return range; |
4892 | 33 | } |
4893 | 86 | } |
4894 | 0 | return NULL; |
4895 | 33 | } |
4896 | | /* }}} */ |
4897 | | |
4898 | | static void cleanup_live_vars(zend_execute_data *execute_data, uint32_t op_num, uint32_t catch_op_num) /* {{{ */ |
4899 | 564k | { |
4900 | 564k | int i; |
4901 | | |
4902 | 2.00M | for (i = 0; i < EX(func)->op_array.last_live_range; i++) { |
4903 | 1.75M | const zend_live_range *range = &EX(func)->op_array.live_range[i]; |
4904 | 1.75M | if (range->start > op_num) { |
4905 | | /* further blocks will not be relevant... */ |
4906 | 314k | break; |
4907 | 1.44M | } else if (op_num < range->end) { |
4908 | 611k | if (!catch_op_num || catch_op_num >= range->end) { |
4909 | 403k | uint32_t kind = range->var & ZEND_LIVE_MASK; |
4910 | 403k | uint32_t var_num = range->var & ~ZEND_LIVE_MASK; |
4911 | 403k | zval *var = EX_VAR(var_num); |
4912 | | |
4913 | 403k | if (kind == ZEND_LIVE_TMPVAR) { |
4914 | 1.43k | zval_ptr_dtor_nogc(var); |
4915 | 401k | } else if (kind == ZEND_LIVE_NEW) { |
4916 | 396k | zend_object *obj; |
4917 | 396k | ZEND_ASSERT(Z_TYPE_P(var) == IS_OBJECT); |
4918 | 396k | obj = Z_OBJ_P(var); |
4919 | 396k | zend_object_store_ctor_failed(obj); |
4920 | 396k | OBJ_RELEASE(obj); |
4921 | 396k | } else if (kind == ZEND_LIVE_LOOP) { |
4922 | 933 | if (Z_TYPE_P(var) != IS_ARRAY && Z_FE_ITER_P(var) != (uint32_t)-1) { |
4923 | 89 | zend_hash_iterator_del(Z_FE_ITER_P(var)); |
4924 | 89 | } |
4925 | 933 | zval_ptr_dtor_nogc(var); |
4926 | 4.11k | } else if (kind == ZEND_LIVE_ROPE) { |
4927 | 265 | zend_string **rope = (zend_string **)var; |
4928 | 265 | zend_op *last = EX(func)->op_array.opcodes + op_num; |
4929 | 336 | while ((last->opcode != ZEND_ROPE_ADD && last->opcode != ZEND_ROPE_INIT) |
4930 | 265 | || last->result.var != var_num) { |
4931 | 71 | ZEND_ASSERT(last >= EX(func)->op_array.opcodes); |
4932 | 71 | last--; |
4933 | 71 | } |
4934 | 265 | if (last->opcode == ZEND_ROPE_INIT) { |
4935 | 17 | zend_string_release_ex(*rope, 0); |
4936 | 248 | } else { |
4937 | 248 | int j = last->extended_value; |
4938 | 3.47k | do { |
4939 | 3.47k | zend_string_release_ex(rope[j], 0); |
4940 | 3.47k | } while (j--); |
4941 | 248 | } |
4942 | 3.85k | } else if (kind == ZEND_LIVE_SILENCE) { |
4943 | | /* restore previous error_reporting value */ |
4944 | 3.85k | if (E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting)) |
4945 | 3.78k | && !E_HAS_ONLY_FATAL_ERRORS(Z_LVAL_P(var))) { |
4946 | 41 | EG(error_reporting) = Z_LVAL_P(var); |
4947 | 41 | } |
4948 | 3.85k | } |
4949 | 403k | } |
4950 | 611k | } |
4951 | 1.75M | } |
4952 | 564k | } |
4953 | | /* }}} */ |
4954 | | |
4955 | 1.08k | ZEND_API void zend_cleanup_unfinished_execution(zend_execute_data *execute_data, uint32_t op_num, uint32_t catch_op_num) { |
4956 | 1.08k | cleanup_unfinished_calls(execute_data, op_num); |
4957 | 1.08k | cleanup_live_vars(execute_data, op_num, catch_op_num); |
4958 | 1.08k | } |
4959 | | |
4960 | | 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) |
4961 | 0 | { |
4962 | 0 | return zend_unfinished_execution_gc_ex(execute_data, call, gc_buffer, false); |
4963 | 0 | } |
4964 | | |
4965 | | 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) |
4966 | 7.55k | { |
4967 | 7.55k | if (!EX(func)) { |
4968 | 140 | return NULL; |
4969 | 140 | } |
4970 | | |
4971 | 7.41k | if (EX_CALL_INFO() & ZEND_CALL_RELEASE_THIS) { |
4972 | 396 | zend_get_gc_buffer_add_obj(gc_buffer, Z_OBJ(execute_data->This)); |
4973 | 396 | } |
4974 | | |
4975 | 7.41k | if (EX_CALL_INFO() & ZEND_CALL_CLOSURE) { |
4976 | 1.83k | zend_get_gc_buffer_add_obj(gc_buffer, ZEND_CLOSURE_OBJECT(EX(func))); |
4977 | 1.83k | } |
4978 | | |
4979 | 7.41k | if (!ZEND_USER_CODE(EX(func)->common.type)) { |
4980 | 3.32k | ZEND_ASSERT(!(EX_CALL_INFO() & (ZEND_CALL_HAS_SYMBOL_TABLE|ZEND_CALL_FREE_EXTRA_ARGS|ZEND_CALL_HAS_EXTRA_NAMED_PARAMS))); |
4981 | 3.32k | return NULL; |
4982 | 3.32k | } |
4983 | | |
4984 | 4.08k | zend_op_array *op_array = &EX(func)->op_array; |
4985 | | |
4986 | 4.08k | if (!(EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE)) { |
4987 | 3.76k | uint32_t i, num_cvs = EX(func)->op_array.last_var; |
4988 | 7.58k | for (i = 0; i < num_cvs; i++) { |
4989 | 3.81k | zend_get_gc_buffer_add_zval(gc_buffer, EX_VAR_NUM(i)); |
4990 | 3.81k | } |
4991 | 3.76k | } |
4992 | | |
4993 | 4.08k | if (EX_CALL_INFO() & ZEND_CALL_FREE_EXTRA_ARGS) { |
4994 | 58 | zval *zv = EX_VAR_NUM(op_array->last_var + op_array->T); |
4995 | 58 | zval *end = zv + (EX_NUM_ARGS() - op_array->num_args); |
4996 | 118 | while (zv != end) { |
4997 | 60 | zend_get_gc_buffer_add_zval(gc_buffer, zv++); |
4998 | 60 | } |
4999 | 58 | } |
5000 | | |
5001 | 4.08k | if (EX_CALL_INFO() & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) { |
5002 | 0 | zval extra_named_params; |
5003 | 0 | ZVAL_ARR(&extra_named_params, EX(extra_named_params)); |
5004 | 0 | zend_get_gc_buffer_add_zval(gc_buffer, &extra_named_params); |
5005 | 0 | } |
5006 | | |
5007 | 4.08k | uint32_t op_num; |
5008 | 4.08k | if (UNEXPECTED(execute_data->opline->opcode == ZEND_HANDLE_EXCEPTION)) { |
5009 | 0 | op_num = EG(opline_before_exception) - op_array->opcodes; |
5010 | 4.08k | } else { |
5011 | 4.08k | op_num = execute_data->opline - op_array->opcodes; |
5012 | 4.08k | } |
5013 | 4.08k | ZEND_ASSERT(op_num < op_array->last); |
5014 | | |
5015 | 4.08k | if (call) { |
5016 | 335 | zend_unfinished_calls_gc(execute_data, call, op_num, gc_buffer); |
5017 | 335 | } |
5018 | | |
5019 | 4.08k | if (execute_data->opline != op_array->opcodes) { |
5020 | 3.96k | uint32_t i; |
5021 | 4.94k | for (i = 0; i < op_array->last_live_range; i++) { |
5022 | 1.05k | const zend_live_range *range = &op_array->live_range[i]; |
5023 | 1.05k | if (range->start > op_num) { |
5024 | 78 | break; |
5025 | 980 | } else if (op_num < range->end) { |
5026 | 108 | uint32_t kind = range->var & ZEND_LIVE_MASK; |
5027 | 108 | uint32_t var_num = range->var & ~ZEND_LIVE_MASK; |
5028 | 108 | zval *var = EX_VAR(var_num); |
5029 | 108 | if (kind == ZEND_LIVE_TMPVAR || kind == ZEND_LIVE_LOOP) { |
5030 | 84 | zend_get_gc_buffer_add_zval(gc_buffer, var); |
5031 | 84 | } |
5032 | 108 | } |
5033 | 1.05k | } |
5034 | 3.96k | } |
5035 | | |
5036 | 4.08k | if (EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE) { |
5037 | 324 | return execute_data->symbol_table; |
5038 | 3.76k | } else { |
5039 | 3.76k | return NULL; |
5040 | 3.76k | } |
5041 | 4.08k | } |
5042 | | |
5043 | | #if ZEND_VM_SPEC |
5044 | | static void zend_swap_operands(zend_op *op) /* {{{ */ |
5045 | 254k | { |
5046 | 254k | znode_op tmp; |
5047 | 254k | uint8_t tmp_type; |
5048 | | |
5049 | 254k | tmp = op->op1; |
5050 | 254k | tmp_type = op->op1_type; |
5051 | 254k | op->op1 = op->op2; |
5052 | 254k | op->op1_type = op->op2_type; |
5053 | 254k | op->op2 = tmp; |
5054 | 254k | op->op2_type = tmp_type; |
5055 | | |
5056 | | #ifdef ZEND_VERIFY_TYPE_INFERENCE |
5057 | | uint32_t tmp_info; |
5058 | | tmp_info = op->op1_use_type; |
5059 | | op->op1_use_type = op->op2_use_type; |
5060 | | op->op2_use_type = tmp_info; |
5061 | | tmp_info = op->op1_def_type; |
5062 | | op->op1_def_type = op->op2_def_type; |
5063 | | op->op2_def_type = tmp_info; |
5064 | | #endif |
5065 | 254k | } |
5066 | | /* }}} */ |
5067 | | #endif |
5068 | | |
5069 | | static zend_never_inline zend_execute_data *zend_init_dynamic_call_string(zend_string *function, uint32_t num_args) /* {{{ */ |
5070 | 1.26k | { |
5071 | 1.26k | zend_function *fbc; |
5072 | 1.26k | zval *func; |
5073 | 1.26k | zend_class_entry *called_scope; |
5074 | 1.26k | zend_string *lcname; |
5075 | 1.26k | const char *colon; |
5076 | | |
5077 | 1.26k | if ((colon = zend_memrchr(ZSTR_VAL(function), ':', ZSTR_LEN(function))) != NULL && |
5078 | 106 | colon > ZSTR_VAL(function) && |
5079 | 93 | *(colon-1) == ':' |
5080 | 1.26k | ) { |
5081 | 85 | zend_string *mname; |
5082 | 85 | size_t cname_length = colon - ZSTR_VAL(function) - 1; |
5083 | 85 | size_t mname_length = ZSTR_LEN(function) - cname_length - (sizeof("::") - 1); |
5084 | | |
5085 | 85 | lcname = zend_string_init(ZSTR_VAL(function), cname_length, 0); |
5086 | | |
5087 | 85 | called_scope = zend_fetch_class_by_name(lcname, NULL, ZEND_FETCH_CLASS_DEFAULT | ZEND_FETCH_CLASS_EXCEPTION); |
5088 | 85 | if (UNEXPECTED(called_scope == NULL)) { |
5089 | 15 | zend_string_release_ex(lcname, 0); |
5090 | 15 | return NULL; |
5091 | 15 | } |
5092 | | |
5093 | 70 | mname = zend_string_init(ZSTR_VAL(function) + (cname_length + sizeof("::") - 1), mname_length, 0); |
5094 | | |
5095 | 70 | if (called_scope->get_static_method) { |
5096 | 0 | fbc = called_scope->get_static_method(called_scope, mname); |
5097 | 70 | } else { |
5098 | 70 | fbc = zend_std_get_static_method(called_scope, mname, NULL); |
5099 | 70 | } |
5100 | 70 | if (UNEXPECTED(fbc == NULL)) { |
5101 | 5 | if (EXPECTED(!EG(exception))) { |
5102 | 5 | zend_undefined_method(called_scope, mname); |
5103 | 5 | } |
5104 | 5 | zend_string_release_ex(lcname, 0); |
5105 | 5 | zend_string_release_ex(mname, 0); |
5106 | 5 | return NULL; |
5107 | 5 | } |
5108 | | |
5109 | 65 | zend_string_release_ex(lcname, 0); |
5110 | 65 | zend_string_release_ex(mname, 0); |
5111 | | |
5112 | 65 | if (UNEXPECTED(!(fbc->common.fn_flags & ZEND_ACC_STATIC))) { |
5113 | 14 | zend_non_static_method_call(fbc); |
5114 | 14 | if (fbc->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) { |
5115 | 9 | zend_string_release_ex(fbc->common.function_name, 0); |
5116 | 9 | zend_free_trampoline(fbc); |
5117 | 9 | } |
5118 | 14 | return NULL; |
5119 | 14 | } |
5120 | 51 | if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) { |
5121 | 20 | init_func_run_time_cache(&fbc->op_array); |
5122 | 20 | } |
5123 | 1.18k | } else { |
5124 | 1.18k | if (ZSTR_VAL(function)[0] == '\\') { |
5125 | 8 | lcname = zend_string_alloc(ZSTR_LEN(function) - 1, 0); |
5126 | 8 | zend_str_tolower_copy(ZSTR_VAL(lcname), ZSTR_VAL(function) + 1, ZSTR_LEN(function) - 1); |
5127 | 1.17k | } else { |
5128 | 1.17k | lcname = zend_string_tolower(function); |
5129 | 1.17k | } |
5130 | 1.18k | if (UNEXPECTED((func = zend_hash_find(EG(function_table), lcname)) == NULL)) { |
5131 | 63 | zend_throw_error(NULL, "Call to undefined function %s()", ZSTR_VAL(function)); |
5132 | 63 | zend_string_release_ex(lcname, 0); |
5133 | 63 | return NULL; |
5134 | 63 | } |
5135 | 1.11k | zend_string_release_ex(lcname, 0); |
5136 | | |
5137 | 1.11k | fbc = Z_FUNC_P(func); |
5138 | 1.11k | if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) { |
5139 | 278 | init_func_run_time_cache(&fbc->op_array); |
5140 | 278 | } |
5141 | 1.11k | called_scope = NULL; |
5142 | 1.11k | } |
5143 | | |
5144 | 1.16k | return zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC, |
5145 | 1.16k | fbc, num_args, called_scope); |
5146 | 1.26k | } |
5147 | | /* }}} */ |
5148 | | |
5149 | | static zend_never_inline zend_execute_data *zend_init_dynamic_call_object(zend_object *function, uint32_t num_args) /* {{{ */ |
5150 | 5.15k | { |
5151 | 5.15k | zend_function *fbc; |
5152 | 5.15k | void *object_or_called_scope; |
5153 | 5.15k | zend_class_entry *called_scope; |
5154 | 5.15k | zend_object *object; |
5155 | 5.15k | uint32_t call_info; |
5156 | | |
5157 | 5.15k | if (EXPECTED(function->handlers->get_closure) && |
5158 | 5.15k | EXPECTED(function->handlers->get_closure(function, &called_scope, &fbc, &object, 0) == SUCCESS)) { |
5159 | | |
5160 | 5.14k | object_or_called_scope = called_scope; |
5161 | 5.14k | if (EXPECTED(fbc->common.fn_flags & ZEND_ACC_CLOSURE)) { |
5162 | | /* Delay closure destruction until its invocation */ |
5163 | 4.96k | GC_ADDREF(ZEND_CLOSURE_OBJECT(fbc)); |
5164 | 4.96k | ZEND_ASSERT(ZEND_ACC_FAKE_CLOSURE == ZEND_CALL_FAKE_CLOSURE); |
5165 | 4.96k | call_info = ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC | ZEND_CALL_CLOSURE | |
5166 | 4.96k | (fbc->common.fn_flags & ZEND_ACC_FAKE_CLOSURE); |
5167 | 4.96k | if (object) { |
5168 | 1.00k | call_info |= ZEND_CALL_HAS_THIS; |
5169 | 1.00k | object_or_called_scope = object; |
5170 | 1.00k | } |
5171 | 4.96k | } else { |
5172 | 174 | call_info = ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC; |
5173 | 174 | if (object) { |
5174 | 174 | call_info |= ZEND_CALL_RELEASE_THIS | ZEND_CALL_HAS_THIS; |
5175 | 174 | GC_ADDREF(object); /* For $this pointer */ |
5176 | 174 | object_or_called_scope = object; |
5177 | 174 | } |
5178 | 174 | } |
5179 | 5.14k | } else { |
5180 | 14 | zend_throw_error(NULL, "Object of type %s is not callable", ZSTR_VAL(function->ce->name)); |
5181 | 14 | return NULL; |
5182 | 14 | } |
5183 | | |
5184 | 5.14k | if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) { |
5185 | 108 | init_func_run_time_cache(&fbc->op_array); |
5186 | 108 | } |
5187 | | |
5188 | 5.14k | return zend_vm_stack_push_call_frame(call_info, |
5189 | 5.14k | fbc, num_args, object_or_called_scope); |
5190 | 5.15k | } |
5191 | | /* }}} */ |
5192 | | |
5193 | | static zend_never_inline zend_execute_data *zend_init_dynamic_call_array(zend_array *function, uint32_t num_args) /* {{{ */ |
5194 | 311 | { |
5195 | 311 | zend_function *fbc; |
5196 | 311 | void *object_or_called_scope; |
5197 | 311 | uint32_t call_info = ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC; |
5198 | | |
5199 | 311 | if (zend_hash_num_elements(function) == 2) { |
5200 | 298 | zval *obj; |
5201 | 298 | zval *method; |
5202 | 298 | obj = zend_hash_index_find(function, 0); |
5203 | 298 | method = zend_hash_index_find(function, 1); |
5204 | | |
5205 | 298 | if (UNEXPECTED(!obj) || UNEXPECTED(!method)) { |
5206 | 6 | zend_throw_error(NULL, "Array callback has to contain indices 0 and 1"); |
5207 | 6 | return NULL; |
5208 | 6 | } |
5209 | | |
5210 | 292 | ZVAL_DEREF(obj); |
5211 | 292 | if (UNEXPECTED(Z_TYPE_P(obj) != IS_STRING) && UNEXPECTED(Z_TYPE_P(obj) != IS_OBJECT)) { |
5212 | 7 | zend_throw_error(NULL, "First array member is not a valid class name or object"); |
5213 | 7 | return NULL; |
5214 | 7 | } |
5215 | | |
5216 | 285 | ZVAL_DEREF(method); |
5217 | 285 | if (UNEXPECTED(Z_TYPE_P(method) != IS_STRING)) { |
5218 | 3 | zend_throw_error(NULL, "Second array member is not a valid method"); |
5219 | 3 | return NULL; |
5220 | 3 | } |
5221 | | |
5222 | 282 | if (Z_TYPE_P(obj) == IS_STRING) { |
5223 | 157 | zend_class_entry *called_scope = zend_fetch_class_by_name(Z_STR_P(obj), NULL, ZEND_FETCH_CLASS_DEFAULT | ZEND_FETCH_CLASS_EXCEPTION); |
5224 | | |
5225 | 157 | if (UNEXPECTED(called_scope == NULL)) { |
5226 | 26 | return NULL; |
5227 | 26 | } |
5228 | | |
5229 | 131 | if (called_scope->get_static_method) { |
5230 | 0 | fbc = called_scope->get_static_method(called_scope, Z_STR_P(method)); |
5231 | 131 | } else { |
5232 | 131 | fbc = zend_std_get_static_method(called_scope, Z_STR_P(method), NULL); |
5233 | 131 | } |
5234 | 131 | if (UNEXPECTED(fbc == NULL)) { |
5235 | 12 | if (EXPECTED(!EG(exception))) { |
5236 | 12 | zend_undefined_method(called_scope, Z_STR_P(method)); |
5237 | 12 | } |
5238 | 12 | return NULL; |
5239 | 12 | } |
5240 | 119 | if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) { |
5241 | 16 | zend_non_static_method_call(fbc); |
5242 | 16 | if (fbc->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) { |
5243 | 11 | zend_string_release_ex(fbc->common.function_name, 0); |
5244 | 11 | zend_free_trampoline(fbc); |
5245 | 11 | } |
5246 | 16 | return NULL; |
5247 | 16 | } |
5248 | 103 | object_or_called_scope = called_scope; |
5249 | 125 | } else { |
5250 | 125 | zend_object *object = Z_OBJ_P(obj); |
5251 | | |
5252 | 125 | fbc = Z_OBJ_HT_P(obj)->get_method(&object, Z_STR_P(method), NULL); |
5253 | 125 | if (UNEXPECTED(fbc == NULL)) { |
5254 | 5 | if (EXPECTED(!EG(exception))) { |
5255 | 5 | zend_undefined_method(object->ce, Z_STR_P(method)); |
5256 | 5 | } |
5257 | 5 | return NULL; |
5258 | 5 | } |
5259 | | |
5260 | 120 | if ((fbc->common.fn_flags & ZEND_ACC_STATIC) != 0) { |
5261 | 23 | object_or_called_scope = object->ce; |
5262 | 97 | } else { |
5263 | 97 | call_info |= ZEND_CALL_RELEASE_THIS | ZEND_CALL_HAS_THIS; |
5264 | 97 | GC_ADDREF(object); /* For $this pointer */ |
5265 | 97 | object_or_called_scope = object; |
5266 | 97 | } |
5267 | 120 | } |
5268 | 282 | } else { |
5269 | 13 | zend_throw_error(NULL, "Array callback must have exactly two elements"); |
5270 | 13 | return NULL; |
5271 | 13 | } |
5272 | | |
5273 | 223 | if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) { |
5274 | 67 | init_func_run_time_cache(&fbc->op_array); |
5275 | 67 | } |
5276 | | |
5277 | 223 | return zend_vm_stack_push_call_frame(call_info, |
5278 | 223 | fbc, num_args, object_or_called_scope); |
5279 | 311 | } |
5280 | | /* }}} */ |
5281 | | |
5282 | 75.2k | #define ZEND_FAKE_OP_ARRAY ((zend_op_array*)(intptr_t)-1) |
5283 | | |
5284 | | static zend_never_inline zend_op_array* ZEND_FASTCALL zend_include_or_eval(zval *inc_filename_zv, int type) /* {{{ */ |
5285 | 73.8k | { |
5286 | 73.8k | zend_op_array *new_op_array = NULL; |
5287 | 73.8k | zend_string *tmp_inc_filename; |
5288 | 73.8k | zend_string *inc_filename = zval_try_get_tmp_string(inc_filename_zv, &tmp_inc_filename); |
5289 | 73.8k | if (UNEXPECTED(!inc_filename)) { |
5290 | 8 | return NULL; |
5291 | 8 | } |
5292 | | |
5293 | 73.8k | switch (type) { |
5294 | 10 | case ZEND_INCLUDE_ONCE: |
5295 | 2.13k | case ZEND_REQUIRE_ONCE: { |
5296 | 2.13k | zend_file_handle file_handle; |
5297 | 2.13k | zend_string *resolved_path; |
5298 | | |
5299 | 2.13k | resolved_path = zend_resolve_path(inc_filename); |
5300 | 2.13k | if (EXPECTED(resolved_path)) { |
5301 | 15 | if (zend_hash_exists(&EG(included_files), resolved_path)) { |
5302 | 4 | new_op_array = ZEND_FAKE_OP_ARRAY; |
5303 | 4 | zend_string_release_ex(resolved_path, 0); |
5304 | 4 | break; |
5305 | 4 | } |
5306 | 2.11k | } else if (UNEXPECTED(EG(exception))) { |
5307 | 10 | break; |
5308 | 2.10k | } else if (UNEXPECTED(zend_str_has_nul_byte(inc_filename))) { |
5309 | 6 | zend_message_dispatcher( |
5310 | 6 | (type == ZEND_INCLUDE_ONCE) ? |
5311 | 6 | ZMSG_FAILED_INCLUDE_FOPEN : ZMSG_FAILED_REQUIRE_FOPEN, |
5312 | 6 | ZSTR_VAL(inc_filename)); |
5313 | 6 | break; |
5314 | 2.10k | } else { |
5315 | 2.10k | resolved_path = zend_string_copy(inc_filename); |
5316 | 2.10k | } |
5317 | | |
5318 | 2.11k | zend_stream_init_filename_ex(&file_handle, resolved_path); |
5319 | 2.11k | if (SUCCESS == zend_stream_open(&file_handle)) { |
5320 | | |
5321 | 11 | if (!file_handle.opened_path) { |
5322 | 0 | file_handle.opened_path = zend_string_copy(resolved_path); |
5323 | 0 | } |
5324 | | |
5325 | 11 | if (zend_hash_add_empty_element(&EG(included_files), file_handle.opened_path)) { |
5326 | 11 | new_op_array = zend_compile_file(&file_handle, (type==ZEND_INCLUDE_ONCE?ZEND_INCLUDE:ZEND_REQUIRE)); |
5327 | 11 | } else { |
5328 | 0 | new_op_array = ZEND_FAKE_OP_ARRAY; |
5329 | 0 | } |
5330 | 2.10k | } else if (!EG(exception)) { |
5331 | 125 | zend_message_dispatcher( |
5332 | 125 | (type == ZEND_INCLUDE_ONCE) ? |
5333 | 120 | ZMSG_FAILED_INCLUDE_FOPEN : ZMSG_FAILED_REQUIRE_FOPEN, |
5334 | 125 | ZSTR_VAL(inc_filename)); |
5335 | 125 | } |
5336 | 2.11k | zend_destroy_file_handle(&file_handle); |
5337 | 2.11k | zend_string_release_ex(resolved_path, 0); |
5338 | 2.11k | } |
5339 | 0 | break; |
5340 | 1.78k | case ZEND_INCLUDE: |
5341 | 67.6k | case ZEND_REQUIRE: |
5342 | 67.6k | if (UNEXPECTED(zend_str_has_nul_byte(inc_filename))) { |
5343 | 151 | zend_message_dispatcher( |
5344 | 151 | (type == ZEND_INCLUDE) ? |
5345 | 142 | ZMSG_FAILED_INCLUDE_FOPEN : ZMSG_FAILED_REQUIRE_FOPEN, |
5346 | 151 | ZSTR_VAL(inc_filename)); |
5347 | 151 | break; |
5348 | 151 | } |
5349 | 67.4k | new_op_array = compile_filename(type, inc_filename); |
5350 | 67.4k | break; |
5351 | 4.02k | case ZEND_EVAL: { |
5352 | 4.02k | char *eval_desc = zend_make_compiled_string_description("eval()'d code"); |
5353 | 4.02k | new_op_array = zend_compile_string(inc_filename, eval_desc, ZEND_COMPILE_POSITION_AFTER_OPEN_TAG); |
5354 | 4.02k | efree(eval_desc); |
5355 | 4.02k | } |
5356 | 4.02k | break; |
5357 | 73.8k | EMPTY_SWITCH_DEFAULT_CASE() |
5358 | 73.8k | } |
5359 | | |
5360 | 69.7k | zend_tmp_string_release(tmp_inc_filename); |
5361 | 69.7k | return new_op_array; |
5362 | 73.8k | } |
5363 | | /* }}} */ |
5364 | | |
5365 | | static zend_never_inline bool ZEND_FASTCALL zend_fe_reset_iterator(zval *array_ptr, int by_ref OPLINE_DC EXECUTE_DATA_DC) /* {{{ */ |
5366 | 1.50k | { |
5367 | 1.50k | zend_class_entry *ce = Z_OBJCE_P(array_ptr); |
5368 | 1.50k | zend_object_iterator *iter = ce->get_iterator(ce, array_ptr, by_ref); |
5369 | 1.50k | bool is_empty; |
5370 | | |
5371 | 1.50k | if (UNEXPECTED(!iter) || UNEXPECTED(EG(exception))) { |
5372 | 28 | if (iter) { |
5373 | 0 | OBJ_RELEASE(&iter->std); |
5374 | 0 | } |
5375 | 28 | if (!EG(exception)) { |
5376 | 0 | zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ZSTR_VAL(ce->name)); |
5377 | 0 | } |
5378 | 28 | ZVAL_UNDEF(EX_VAR(opline->result.var)); |
5379 | 28 | return 1; |
5380 | 28 | } |
5381 | | |
5382 | 1.47k | iter->index = 0; |
5383 | 1.47k | if (iter->funcs->rewind) { |
5384 | 1.47k | iter->funcs->rewind(iter); |
5385 | 1.47k | if (UNEXPECTED(EG(exception) != NULL)) { |
5386 | 128 | OBJ_RELEASE(&iter->std); |
5387 | 128 | ZVAL_UNDEF(EX_VAR(opline->result.var)); |
5388 | 128 | return 1; |
5389 | 128 | } |
5390 | 1.47k | } |
5391 | | |
5392 | 1.34k | is_empty = iter->funcs->valid(iter) != SUCCESS; |
5393 | | |
5394 | 1.34k | if (UNEXPECTED(EG(exception) != NULL)) { |
5395 | 72 | OBJ_RELEASE(&iter->std); |
5396 | 72 | ZVAL_UNDEF(EX_VAR(opline->result.var)); |
5397 | 72 | return 1; |
5398 | 72 | } |
5399 | 1.27k | iter->index = -1; /* will be set to 0 before using next handler */ |
5400 | | |
5401 | 1.27k | ZVAL_OBJ(EX_VAR(opline->result.var), &iter->std); |
5402 | 1.27k | Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1; |
5403 | | |
5404 | 1.27k | return is_empty; |
5405 | 1.34k | } |
5406 | | /* }}} */ |
5407 | | |
5408 | | static zend_always_inline zend_result _zend_quick_get_constant( |
5409 | | const zval *key, uint32_t flags, bool check_defined_only OPLINE_DC EXECUTE_DATA_DC) /* {{{ */ |
5410 | 6.83k | { |
5411 | 6.83k | zval *zv; |
5412 | 6.83k | zend_constant *c = NULL; |
5413 | | |
5414 | | /* null/true/false are resolved during compilation, so don't check for them here. */ |
5415 | 6.83k | zv = zend_hash_find_known_hash(EG(zend_constants), Z_STR_P(key)); |
5416 | 6.83k | if (zv) { |
5417 | 1.66k | c = (zend_constant*)Z_PTR_P(zv); |
5418 | 5.17k | } else if (flags & IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE) { |
5419 | 170 | key++; |
5420 | 170 | zv = zend_hash_find_known_hash(EG(zend_constants), Z_STR_P(key)); |
5421 | 170 | if (zv) { |
5422 | 70 | c = (zend_constant*)Z_PTR_P(zv); |
5423 | 70 | } |
5424 | 170 | } |
5425 | | |
5426 | 6.83k | if (!c) { |
5427 | 5.10k | if (!check_defined_only) { |
5428 | 5.06k | zend_throw_error(NULL, "Undefined constant \"%s\"", Z_STRVAL_P(RT_CONSTANT(opline, opline->op2))); |
5429 | 5.06k | ZVAL_UNDEF(EX_VAR(opline->result.var)); |
5430 | 5.06k | } |
5431 | 5.10k | return FAILURE; |
5432 | 5.10k | } |
5433 | | |
5434 | 1.73k | if (!check_defined_only) { |
5435 | 1.70k | ZVAL_COPY_OR_DUP(EX_VAR(opline->result.var), &c->value); |
5436 | 1.70k | if (ZEND_CONSTANT_FLAGS(c) & CONST_DEPRECATED) { |
5437 | 139 | if (!CONST_IS_RECURSIVE(c)) { |
5438 | 139 | CONST_PROTECT_RECURSION(c); |
5439 | 139 | zend_deprecated_constant(c, c->name); |
5440 | 139 | CONST_UNPROTECT_RECURSION(c); |
5441 | 139 | } |
5442 | 139 | return SUCCESS; |
5443 | 139 | } |
5444 | 1.70k | } |
5445 | | |
5446 | 1.59k | CACHE_PTR(opline->extended_value, c); |
5447 | 1.59k | return SUCCESS; |
5448 | 1.73k | } |
5449 | | /* }}} */ |
5450 | | |
5451 | | static zend_never_inline void ZEND_FASTCALL zend_quick_get_constant( |
5452 | | const zval *key, uint32_t flags OPLINE_DC EXECUTE_DATA_DC) /* {{{ */ |
5453 | 6.77k | { |
5454 | 6.77k | _zend_quick_get_constant(key, flags, 0 OPLINE_CC EXECUTE_DATA_CC); |
5455 | 6.77k | } /* }}} */ |
5456 | | |
5457 | | static zend_never_inline zend_result ZEND_FASTCALL zend_quick_check_constant( |
5458 | | const zval *key OPLINE_DC EXECUTE_DATA_DC) /* {{{ */ |
5459 | 62 | { |
5460 | 62 | return _zend_quick_get_constant(key, 0, 1 OPLINE_CC EXECUTE_DATA_CC); |
5461 | 62 | } /* }}} */ |
5462 | | |
5463 | | static zend_always_inline uint32_t zend_get_arg_offset_by_name( |
5464 | 5.43k | zend_function *fbc, zend_string *arg_name, void **cache_slot) { |
5465 | | /* Due to closures, the `fbc` address isn't unique if the memory address is reused. |
5466 | | * The argument info will be however and uniquely positions the arguments. |
5467 | | * We do support NULL arg_info, so we have to distinguish that from an uninitialized cache slot. */ |
5468 | 5.43k | void *unique_id = (void *) ((uintptr_t) fbc->common.arg_info | 1); |
5469 | | |
5470 | 5.43k | if (EXPECTED(*cache_slot == unique_id)) { |
5471 | 21 | return *(uintptr_t *)(cache_slot + 1); |
5472 | 21 | } |
5473 | | |
5474 | | // TODO: Use a hash table? |
5475 | 5.40k | uint32_t num_args = fbc->common.num_args; |
5476 | 5.40k | if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) |
5477 | 4.48k | || EXPECTED(fbc->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) { |
5478 | 12.4k | for (uint32_t i = 0; i < num_args; i++) { |
5479 | 10.0k | zend_arg_info *arg_info = &fbc->common.arg_info[i]; |
5480 | 10.0k | if (zend_string_equals(arg_name, arg_info->name)) { |
5481 | 2.14k | if (fbc->type == ZEND_USER_FUNCTION && (!fbc->op_array.refcount || !(fbc->op_array.fn_flags & ZEND_ACC_CLOSURE))) { |
5482 | 2.12k | *cache_slot = unique_id; |
5483 | 2.12k | *(uintptr_t *)(cache_slot + 1) = i; |
5484 | 2.12k | } |
5485 | 2.14k | return i; |
5486 | 2.14k | } |
5487 | 10.0k | } |
5488 | 4.48k | } else { |
5489 | 925 | ZEND_ASSERT(num_args == 0 || fbc->internal_function.arg_info); |
5490 | 1.76k | for (uint32_t i = 0; i < num_args; i++) { |
5491 | 1.39k | zend_internal_arg_info *arg_info = &fbc->internal_function.arg_info[i]; |
5492 | 1.39k | size_t len = strlen(arg_info->name); |
5493 | 1.39k | if (zend_string_equals_cstr(arg_name, arg_info->name, len)) { |
5494 | 559 | *cache_slot = unique_id; |
5495 | 559 | *(uintptr_t *)(cache_slot + 1) = i; |
5496 | 559 | return i; |
5497 | 559 | } |
5498 | 1.39k | } |
5499 | 925 | } |
5500 | | |
5501 | 2.70k | if (fbc->common.fn_flags & ZEND_ACC_VARIADIC) { |
5502 | 2.60k | if ((fbc->type == ZEND_USER_FUNCTION |
5503 | 2.24k | && (!fbc->op_array.refcount || !(fbc->op_array.fn_flags & ZEND_ACC_CLOSURE))) |
5504 | 355 | || (fbc->type == ZEND_INTERNAL_FUNCTION |
5505 | 2.59k | && !(fbc->common.fn_flags & ZEND_ACC_USER_ARG_INFO))) { |
5506 | 2.59k | *cache_slot = unique_id; |
5507 | 2.59k | *(uintptr_t *)(cache_slot + 1) = fbc->common.num_args; |
5508 | 2.59k | } |
5509 | 2.60k | return fbc->common.num_args; |
5510 | 2.60k | } |
5511 | | |
5512 | 103 | return (uint32_t) -1; |
5513 | 2.70k | } |
5514 | | |
5515 | | zval * ZEND_FASTCALL zend_handle_named_arg( |
5516 | | zend_execute_data **call_ptr, zend_string *arg_name, |
5517 | 4.31k | uint32_t *arg_num_ptr, void **cache_slot) { |
5518 | 4.31k | zend_execute_data *call = *call_ptr; |
5519 | 4.31k | zend_function *fbc = call->func; |
5520 | 4.31k | uint32_t arg_offset = zend_get_arg_offset_by_name(fbc, arg_name, cache_slot); |
5521 | 4.31k | if (UNEXPECTED(arg_offset == (uint32_t) -1)) { |
5522 | 100 | zend_throw_error(NULL, "Unknown named parameter $%s", ZSTR_VAL(arg_name)); |
5523 | 100 | return NULL; |
5524 | 100 | } |
5525 | | |
5526 | 4.21k | zval *arg; |
5527 | 4.21k | if (UNEXPECTED(arg_offset == fbc->common.num_args)) { |
5528 | | /* Unknown named parameter that will be collected into a variadic. */ |
5529 | 1.64k | if (!(ZEND_CALL_INFO(call) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS)) { |
5530 | 1.16k | ZEND_ADD_CALL_FLAG(call, ZEND_CALL_HAS_EXTRA_NAMED_PARAMS); |
5531 | 1.16k | call->extra_named_params = zend_new_array(0); |
5532 | 1.16k | } |
5533 | | |
5534 | 1.64k | arg = zend_hash_add_empty_element(call->extra_named_params, arg_name); |
5535 | 1.64k | if (!arg) { |
5536 | 0 | zend_throw_error(NULL, "Named parameter $%s overwrites previous argument", |
5537 | 0 | ZSTR_VAL(arg_name)); |
5538 | 0 | return NULL; |
5539 | 0 | } |
5540 | 1.64k | *arg_num_ptr = arg_offset + 1; |
5541 | 1.64k | return arg; |
5542 | 1.64k | } |
5543 | | |
5544 | 2.57k | uint32_t current_num_args = ZEND_CALL_NUM_ARGS(call); |
5545 | | // TODO: We may wish to optimize the arg_offset == current_num_args case, |
5546 | | // which is probably common (if the named parameters are in order of declaration). |
5547 | 2.57k | if (arg_offset >= current_num_args) { |
5548 | 1.68k | uint32_t new_num_args = arg_offset + 1; |
5549 | 1.68k | ZEND_CALL_NUM_ARGS(call) = new_num_args; |
5550 | | |
5551 | 1.68k | uint32_t num_extra_args = new_num_args - current_num_args; |
5552 | 1.68k | zend_vm_stack_extend_call_frame(call_ptr, current_num_args, num_extra_args); |
5553 | 1.68k | call = *call_ptr; |
5554 | | |
5555 | 1.68k | arg = ZEND_CALL_VAR_NUM(call, arg_offset); |
5556 | 1.68k | if (num_extra_args > 1) { |
5557 | 1.09k | zval *zv = ZEND_CALL_VAR_NUM(call, current_num_args); |
5558 | 3.15k | do { |
5559 | 3.15k | ZVAL_UNDEF(zv); |
5560 | 3.15k | zv++; |
5561 | 3.15k | } while (zv != arg); |
5562 | 1.09k | ZEND_ADD_CALL_FLAG(call, ZEND_CALL_MAY_HAVE_UNDEF); |
5563 | 1.09k | } |
5564 | 1.68k | } else { |
5565 | 888 | arg = ZEND_CALL_VAR_NUM(call, arg_offset); |
5566 | 888 | if (UNEXPECTED(!Z_ISUNDEF_P(arg))) { |
5567 | 59 | zend_throw_error(NULL, "Named parameter $%s overwrites previous argument", |
5568 | 59 | ZSTR_VAL(arg_name)); |
5569 | 59 | return NULL; |
5570 | 59 | } |
5571 | 888 | } |
5572 | | |
5573 | 2.51k | *arg_num_ptr = arg_offset + 1; |
5574 | 2.51k | return arg; |
5575 | 2.57k | } |
5576 | | |
5577 | 88 | static zend_execute_data *start_fake_frame(zend_execute_data *call, const zend_op *opline) { |
5578 | 88 | zend_execute_data *old_prev_execute_data = call->prev_execute_data; |
5579 | 88 | call->prev_execute_data = EG(current_execute_data); |
5580 | 88 | call->opline = opline; |
5581 | 88 | EG(current_execute_data) = call; |
5582 | 88 | return old_prev_execute_data; |
5583 | 88 | } |
5584 | | |
5585 | 88 | static void end_fake_frame(zend_execute_data *call, zend_execute_data *old_prev_execute_data) { |
5586 | 88 | zend_execute_data *prev_execute_data = call->prev_execute_data; |
5587 | 88 | EG(current_execute_data) = prev_execute_data; |
5588 | 88 | call->prev_execute_data = old_prev_execute_data; |
5589 | 88 | if (UNEXPECTED(EG(exception)) && ZEND_USER_CODE(prev_execute_data->func->common.type)) { |
5590 | 33 | zend_rethrow_exception(prev_execute_data); |
5591 | 33 | } |
5592 | 88 | } |
5593 | | |
5594 | 1.05k | ZEND_API zend_result ZEND_FASTCALL zend_handle_undef_args(zend_execute_data *call) { |
5595 | 1.05k | zend_function *fbc = call->func; |
5596 | 1.05k | if (fbc->type == ZEND_USER_FUNCTION) { |
5597 | 725 | zend_op_array *op_array = &fbc->op_array; |
5598 | 725 | uint32_t num_args = ZEND_CALL_NUM_ARGS(call); |
5599 | 4.60k | for (uint32_t i = 0; i < num_args; i++) { |
5600 | 3.91k | zval *arg = ZEND_CALL_VAR_NUM(call, i); |
5601 | 3.91k | if (!Z_ISUNDEF_P(arg)) { |
5602 | 2.11k | continue; |
5603 | 2.11k | } |
5604 | | |
5605 | 1.79k | zend_op *opline = &op_array->opcodes[i]; |
5606 | 1.79k | if (EXPECTED(opline->opcode == ZEND_RECV_INIT)) { |
5607 | 1.76k | zval *default_value = RT_CONSTANT(opline, opline->op2); |
5608 | 1.76k | if (Z_OPT_TYPE_P(default_value) == IS_CONSTANT_AST) { |
5609 | 19 | if (UNEXPECTED(!RUN_TIME_CACHE(op_array))) { |
5610 | 6 | init_func_run_time_cache(op_array); |
5611 | 6 | } |
5612 | | |
5613 | 19 | void *run_time_cache = RUN_TIME_CACHE(op_array); |
5614 | 19 | zval *cache_val = |
5615 | 19 | (zval *) ((char *) run_time_cache + Z_CACHE_SLOT_P(default_value)); |
5616 | | |
5617 | 19 | if (Z_TYPE_P(cache_val) != IS_UNDEF) { |
5618 | | /* We keep in cache only not refcounted values */ |
5619 | 0 | ZVAL_COPY_VALUE(arg, cache_val); |
5620 | 19 | } else { |
5621 | | /* Update constant inside a temporary zval, to make sure the CONSTANT_AST |
5622 | | * value is not accessible through back traces. */ |
5623 | 19 | zval tmp; |
5624 | 19 | ZVAL_COPY(&tmp, default_value); |
5625 | 19 | zend_execute_data *old = start_fake_frame(call, opline); |
5626 | 19 | zend_result ret = zval_update_constant_ex(&tmp, fbc->op_array.scope); |
5627 | 19 | end_fake_frame(call, old); |
5628 | 19 | if (UNEXPECTED(ret == FAILURE)) { |
5629 | 8 | zval_ptr_dtor_nogc(&tmp); |
5630 | 8 | return FAILURE; |
5631 | 8 | } |
5632 | 11 | ZVAL_COPY_VALUE(arg, &tmp); |
5633 | 11 | if (!Z_REFCOUNTED(tmp)) { |
5634 | 11 | ZVAL_COPY_VALUE(cache_val, &tmp); |
5635 | 11 | } |
5636 | 11 | } |
5637 | 1.74k | } else { |
5638 | 1.74k | ZVAL_COPY(arg, default_value); |
5639 | 1.74k | } |
5640 | 1.76k | } else { |
5641 | 29 | ZEND_ASSERT(opline->opcode == ZEND_RECV); |
5642 | 29 | zend_execute_data *old = start_fake_frame(call, opline); |
5643 | 29 | zend_argument_error(zend_ce_argument_count_error, i + 1, "not passed"); |
5644 | 29 | end_fake_frame(call, old); |
5645 | 29 | return FAILURE; |
5646 | 29 | } |
5647 | 1.79k | } |
5648 | | |
5649 | 688 | return SUCCESS; |
5650 | 725 | } else { |
5651 | 332 | if (fbc->common.fn_flags & ZEND_ACC_USER_ARG_INFO) { |
5652 | | /* Magic function, let it deal with it. */ |
5653 | 14 | return SUCCESS; |
5654 | 14 | } |
5655 | | |
5656 | 318 | uint32_t num_args = ZEND_CALL_NUM_ARGS(call); |
5657 | 1.04k | for (uint32_t i = 0; i < num_args; i++) { |
5658 | 752 | zval *arg = ZEND_CALL_VAR_NUM(call, i); |
5659 | 752 | if (!Z_ISUNDEF_P(arg)) { |
5660 | 567 | continue; |
5661 | 567 | } |
5662 | | |
5663 | 185 | zend_internal_arg_info *arg_info = &fbc->internal_function.arg_info[i]; |
5664 | 185 | if (i < fbc->common.required_num_args) { |
5665 | 19 | zend_execute_data *old = start_fake_frame(call, NULL); |
5666 | 19 | zend_argument_error(zend_ce_argument_count_error, i + 1, "not passed"); |
5667 | 19 | end_fake_frame(call, old); |
5668 | 19 | return FAILURE; |
5669 | 19 | } |
5670 | | |
5671 | 166 | zval default_value; |
5672 | 166 | if (zend_get_default_from_internal_arg_info(&default_value, arg_info) == FAILURE) { |
5673 | 5 | zend_execute_data *old = start_fake_frame(call, NULL); |
5674 | 5 | zend_argument_error(zend_ce_argument_count_error, i + 1, |
5675 | 5 | "must be passed explicitly, because the default value is not known"); |
5676 | 5 | end_fake_frame(call, old); |
5677 | 5 | return FAILURE; |
5678 | 5 | } |
5679 | | |
5680 | 161 | if (Z_TYPE(default_value) == IS_CONSTANT_AST) { |
5681 | 16 | zend_execute_data *old = start_fake_frame(call, NULL); |
5682 | 16 | zend_result ret = zval_update_constant_ex(&default_value, fbc->common.scope); |
5683 | 16 | end_fake_frame(call, old); |
5684 | 16 | if (ret == FAILURE) { |
5685 | 0 | return FAILURE; |
5686 | 0 | } |
5687 | 16 | } |
5688 | | |
5689 | 161 | ZVAL_COPY_VALUE(arg, &default_value); |
5690 | 161 | if (ZEND_ARG_SEND_MODE(arg_info) & ZEND_SEND_BY_REF) { |
5691 | 0 | ZVAL_NEW_REF(arg, arg); |
5692 | 0 | } |
5693 | 161 | } |
5694 | 318 | } |
5695 | | |
5696 | 294 | return SUCCESS; |
5697 | 1.05k | } |
5698 | | |
5699 | | ZEND_API void ZEND_FASTCALL zend_free_extra_named_params(zend_array *extra_named_params) |
5700 | 554 | { |
5701 | | /* Extra named params may be shared. */ |
5702 | 554 | zend_array_release(extra_named_params); |
5703 | 554 | } |
5704 | | |
5705 | | #if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)) |
5706 | | /* Special versions of functions that sets EX(opline) before calling zend_vm_stack_extend() */ |
5707 | | 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) /* {{{ */ |
5708 | | { |
5709 | | zend_execute_data *call = (zend_execute_data*)EG(vm_stack_top); |
5710 | | |
5711 | | ZEND_ASSERT_VM_STACK_GLOBAL; |
5712 | | |
5713 | | if (UNEXPECTED(used_stack > (size_t)(((char*)EG(vm_stack_end)) - (char*)call))) { |
5714 | | EX(opline) = opline; /* this is the only difference */ |
5715 | | call = (zend_execute_data*)zend_vm_stack_extend(used_stack); |
5716 | | ZEND_ASSERT_VM_STACK_GLOBAL; |
5717 | | zend_vm_init_call_frame(call, call_info | ZEND_CALL_ALLOCATED, func, num_args, object_or_called_scope); |
5718 | | return call; |
5719 | | } else { |
5720 | | EG(vm_stack_top) = (zval*)((char*)call + used_stack); |
5721 | | zend_vm_init_call_frame(call, call_info, func, num_args, object_or_called_scope); |
5722 | | return call; |
5723 | | } |
5724 | | } /* }}} */ |
5725 | | |
5726 | | 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) /* {{{ */ |
5727 | | { |
5728 | | uint32_t used_stack = zend_vm_calc_used_stack(num_args, func); |
5729 | | |
5730 | | return _zend_vm_stack_push_call_frame_ex(used_stack, call_info, |
5731 | | func, num_args, object_or_called_scope); |
5732 | | } /* }}} */ |
5733 | | #else |
5734 | 401k | # define _zend_vm_stack_push_call_frame_ex zend_vm_stack_push_call_frame_ex |
5735 | 3.31k | # define _zend_vm_stack_push_call_frame zend_vm_stack_push_call_frame |
5736 | | #endif |
5737 | | |
5738 | | #ifdef ZEND_VM_TRACE_HANDLERS |
5739 | | # include "zend_vm_trace_handlers.h" |
5740 | | #elif defined(ZEND_VM_TRACE_LINES) |
5741 | | # include "zend_vm_trace_lines.h" |
5742 | | #elif defined(ZEND_VM_TRACE_MAP) |
5743 | | # include "zend_vm_trace_map.h" |
5744 | | #elif defined(ZEND_VERIFY_TYPE_INFERENCE) |
5745 | | # include "zend_verify_type_inference.h" |
5746 | | #endif |
5747 | | |
5748 | | #define ZEND_VM_NEXT_OPCODE_EX(check_exception, skip) \ |
5749 | 9.80M | CHECK_SYMBOL_TABLES() \ |
5750 | 9.88M | if (check_exception) { \ |
5751 | 5.94M | OPLINE = EX(opline) + (skip); \ |
5752 | 5.94M | } else { \ |
5753 | 3.93M | ZEND_ASSERT(!EG(exception)); \ |
5754 | 3.93M | OPLINE = opline + (skip); \ |
5755 | 3.85M | } \ |
5756 | 9.80M | ZEND_VM_CONTINUE() |
5757 | | |
5758 | | #define ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION() \ |
5759 | 5.71M | ZEND_VM_NEXT_OPCODE_EX(1, 1) |
5760 | | |
5761 | | #define ZEND_VM_NEXT_OPCODE() \ |
5762 | 4.35M | ZEND_VM_NEXT_OPCODE_EX(0, 1) |
5763 | | |
5764 | | #define ZEND_VM_SET_NEXT_OPCODE(new_op) \ |
5765 | 281k | CHECK_SYMBOL_TABLES() \ |
5766 | 281k | OPLINE = new_op |
5767 | | |
5768 | | #define ZEND_VM_SET_OPCODE_NO_INTERRUPT(new_op) \ |
5769 | 2.19M | CHECK_SYMBOL_TABLES() \ |
5770 | 2.19M | OPLINE = new_op |
5771 | | |
5772 | | #define ZEND_VM_SET_OPCODE(new_op) \ |
5773 | 1.23M | ZEND_VM_SET_OPCODE_NO_INTERRUPT(new_op); \ |
5774 | 1.23M | ZEND_VM_INTERRUPT_CHECK() |
5775 | | |
5776 | | #define ZEND_VM_SET_RELATIVE_OPCODE(opline, offset) \ |
5777 | 11.2k | ZEND_VM_SET_OPCODE(ZEND_OFFSET_TO_OPLINE(opline, offset)) |
5778 | | |
5779 | 984k | #define ZEND_VM_JMP_EX(new_op, check_exception) do { \ |
5780 | 984k | if (check_exception && UNEXPECTED(EG(exception))) { \ |
5781 | 0 | HANDLE_EXCEPTION(); \ |
5782 | 0 | } \ |
5783 | 984k | ZEND_VM_SET_OPCODE(new_op); \ |
5784 | 984k | ZEND_VM_CONTINUE(); \ |
5785 | 984k | } while (0) |
5786 | | |
5787 | | #define ZEND_VM_JMP(new_op) \ |
5788 | 77.1k | ZEND_VM_JMP_EX(new_op, 1) |
5789 | | |
5790 | | #define ZEND_VM_INC_OPCODE() \ |
5791 | 1.70k | OPLINE++ |
5792 | | |
5793 | | |
5794 | | #define ZEND_VM_REPEATABLE_OPCODE \ |
5795 | 5.14k | do { |
5796 | | #define ZEND_VM_REPEAT_OPCODE(_opcode) \ |
5797 | 5.14k | } while (UNEXPECTED((++opline)->opcode == _opcode)); \ |
5798 | 4.22k | OPLINE = opline; \ |
5799 | 4.44k | ZEND_VM_CONTINUE() |
5800 | 280k | #define ZEND_VM_SMART_BRANCH(_result, _check) do { \ |
5801 | 280k | if ((_check) && UNEXPECTED(EG(exception))) { \ |
5802 | 139 | OPLINE = EX(opline); \ |
5803 | 279k | } else if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPZ|IS_TMP_VAR))) { \ |
5804 | 188k | if (_result) { \ |
5805 | 178k | ZEND_VM_SET_NEXT_OPCODE(opline + 2); \ |
5806 | 178k | } else { \ |
5807 | 10.6k | ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \ |
5808 | 10.6k | } \ |
5809 | 188k | } else if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPNZ|IS_TMP_VAR))) { \ |
5810 | 27.3k | if (!(_result)) { \ |
5811 | 3.75k | ZEND_VM_SET_NEXT_OPCODE(opline + 2); \ |
5812 | 23.6k | } else { \ |
5813 | 23.6k | ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \ |
5814 | 23.6k | } \ |
5815 | 63.5k | } else { \ |
5816 | 63.5k | ZVAL_BOOL(EX_VAR(opline->result.var), _result); \ |
5817 | 63.5k | ZEND_VM_SET_NEXT_OPCODE(opline + 1); \ |
5818 | 63.5k | } \ |
5819 | 280k | ZEND_VM_CONTINUE(); \ |
5820 | 280k | } while (0) |
5821 | 4.24k | #define ZEND_VM_SMART_BRANCH_JMPZ(_result, _check) do { \ |
5822 | 4.24k | if ((_check) && UNEXPECTED(EG(exception))) { \ |
5823 | 0 | OPLINE = EX(opline); \ |
5824 | 4.24k | } else if (_result) { \ |
5825 | 1.52k | ZEND_VM_SET_NEXT_OPCODE(opline + 2); \ |
5826 | 2.72k | } else { \ |
5827 | 2.72k | ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \ |
5828 | 2.72k | } \ |
5829 | 4.24k | ZEND_VM_CONTINUE(); \ |
5830 | 4.24k | } while (0) |
5831 | 18.7k | #define ZEND_VM_SMART_BRANCH_JMPNZ(_result, _check) do { \ |
5832 | 18.7k | if ((_check) && UNEXPECTED(EG(exception))) { \ |
5833 | 0 | OPLINE = EX(opline); \ |
5834 | 18.7k | } else if (!(_result)) { \ |
5835 | 1.46k | ZEND_VM_SET_NEXT_OPCODE(opline + 2); \ |
5836 | 17.3k | } else { \ |
5837 | 17.3k | ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \ |
5838 | 17.3k | } \ |
5839 | 18.7k | ZEND_VM_CONTINUE(); \ |
5840 | 18.7k | } while (0) |
5841 | 1.31k | #define ZEND_VM_SMART_BRANCH_NONE(_result, _check) do { \ |
5842 | 1.31k | ZVAL_BOOL(EX_VAR(opline->result.var), _result); \ |
5843 | 1.31k | ZEND_VM_NEXT_OPCODE_EX(_check, 1); \ |
5844 | 1.31k | ZEND_VM_CONTINUE(); \ |
5845 | 1.31k | } while (0) |
5846 | 126 | #define ZEND_VM_SMART_BRANCH_TRUE() do { \ |
5847 | 126 | if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPNZ|IS_TMP_VAR))) { \ |
5848 | 1 | ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \ |
5849 | 125 | } else if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPZ|IS_TMP_VAR))) { \ |
5850 | 103 | ZEND_VM_SET_NEXT_OPCODE(opline + 2); \ |
5851 | 103 | } else { \ |
5852 | 22 | ZVAL_TRUE(EX_VAR(opline->result.var)); \ |
5853 | 22 | ZEND_VM_SET_NEXT_OPCODE(opline + 1); \ |
5854 | 22 | } \ |
5855 | 126 | ZEND_VM_CONTINUE(); \ |
5856 | 126 | } while (0) |
5857 | 24.3k | #define ZEND_VM_SMART_BRANCH_TRUE_JMPZ() do { \ |
5858 | 24.3k | ZEND_VM_SET_NEXT_OPCODE(opline + 2); \ |
5859 | 24.3k | ZEND_VM_CONTINUE(); \ |
5860 | 24.3k | } while (0) |
5861 | 181k | #define ZEND_VM_SMART_BRANCH_TRUE_JMPNZ() do { \ |
5862 | 181k | ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \ |
5863 | 181k | ZEND_VM_CONTINUE(); \ |
5864 | 181k | } while (0) |
5865 | 5.67k | #define ZEND_VM_SMART_BRANCH_TRUE_NONE() do { \ |
5866 | 5.67k | ZVAL_TRUE(EX_VAR(opline->result.var)); \ |
5867 | 5.67k | ZEND_VM_NEXT_OPCODE(); \ |
5868 | 5.67k | } while (0) |
5869 | 2.43k | #define ZEND_VM_SMART_BRANCH_FALSE() do { \ |
5870 | 2.43k | if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPNZ|IS_TMP_VAR))) { \ |
5871 | 444 | ZEND_VM_SET_NEXT_OPCODE(opline + 2); \ |
5872 | 1.99k | } else if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPZ|IS_TMP_VAR))) { \ |
5873 | 1.05k | ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \ |
5874 | 1.05k | } else { \ |
5875 | 935 | ZVAL_FALSE(EX_VAR(opline->result.var)); \ |
5876 | 935 | ZEND_VM_SET_NEXT_OPCODE(opline + 1); \ |
5877 | 935 | } \ |
5878 | 2.43k | ZEND_VM_CONTINUE(); \ |
5879 | 2.43k | } while (0) |
5880 | 5.21k | #define ZEND_VM_SMART_BRANCH_FALSE_JMPZ() do { \ |
5881 | 5.21k | ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \ |
5882 | 5.21k | ZEND_VM_CONTINUE(); \ |
5883 | 5.21k | } while (0) |
5884 | 6.85k | #define ZEND_VM_SMART_BRANCH_FALSE_JMPNZ() do { \ |
5885 | 6.85k | ZEND_VM_SET_NEXT_OPCODE(opline + 2); \ |
5886 | 6.85k | ZEND_VM_CONTINUE(); \ |
5887 | 6.85k | } while (0) |
5888 | 6.90k | #define ZEND_VM_SMART_BRANCH_FALSE_NONE() do { \ |
5889 | 6.90k | ZVAL_FALSE(EX_VAR(opline->result.var)); \ |
5890 | 6.90k | ZEND_VM_NEXT_OPCODE(); \ |
5891 | 6.90k | } while (0) |
5892 | | |
5893 | | #ifdef __GNUC__ |
5894 | | # define ZEND_VM_GUARD(name) __asm__("#" #name) |
5895 | | #else |
5896 | | # define ZEND_VM_GUARD(name) |
5897 | | #endif |
5898 | | |
5899 | 2.20k | #define UNDEF_RESULT() do { \ |
5900 | 2.20k | if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { \ |
5901 | 1.28k | ZVAL_UNDEF(EX_VAR(opline->result.var)); \ |
5902 | 1.28k | } \ |
5903 | 2.20k | } while (0) |
5904 | | |
5905 | | /* This callback disables optimization of "vm_stack_data" variable in VM */ |
5906 | | ZEND_API void (ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data) = NULL; |
5907 | | |
5908 | | #include "zend_vm_execute.h" |
5909 | | |
5910 | | ZEND_API zend_result zend_set_user_opcode_handler(zend_uchar opcode, user_opcode_handler_t handler) |
5911 | 0 | { |
5912 | 0 | if (opcode != ZEND_USER_OPCODE) { |
5913 | 0 | if (handler == NULL) { |
5914 | | /* restore the original handler */ |
5915 | 0 | zend_user_opcodes[opcode] = opcode; |
5916 | 0 | } else { |
5917 | 0 | zend_user_opcodes[opcode] = ZEND_USER_OPCODE; |
5918 | 0 | } |
5919 | 0 | zend_user_opcode_handlers[opcode] = handler; |
5920 | 0 | return SUCCESS; |
5921 | 0 | } |
5922 | 0 | return FAILURE; |
5923 | 0 | } |
5924 | | |
5925 | | ZEND_API user_opcode_handler_t zend_get_user_opcode_handler(zend_uchar opcode) |
5926 | 4.09k | { |
5927 | 4.09k | return zend_user_opcode_handlers[opcode]; |
5928 | 4.09k | } |
5929 | | |
5930 | | ZEND_API zval *zend_get_zval_ptr(const zend_op *opline, int op_type, const znode_op *node, const zend_execute_data *execute_data) |
5931 | 0 | { |
5932 | 0 | zval *ret; |
5933 | |
|
5934 | 0 | switch (op_type) { |
5935 | 0 | case IS_CONST: |
5936 | 0 | ret = RT_CONSTANT(opline, *node); |
5937 | 0 | break; |
5938 | 0 | case IS_TMP_VAR: |
5939 | 0 | case IS_VAR: |
5940 | 0 | case IS_CV: |
5941 | 0 | ret = EX_VAR(node->var); |
5942 | 0 | break; |
5943 | 0 | default: |
5944 | 0 | ret = NULL; |
5945 | 0 | break; |
5946 | 0 | } |
5947 | 0 | return ret; |
5948 | 0 | } |