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