xref: /PHP-8.4/Zend/zend_vm_opcodes.c (revision a79c70f5)
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 #include <stdio.h>
22 #include <zend.h>
23 #include <zend_vm_opcodes.h>
24 
25 static const char *zend_vm_opcodes_names[210] = {
26 	"ZEND_NOP",
27 	"ZEND_ADD",
28 	"ZEND_SUB",
29 	"ZEND_MUL",
30 	"ZEND_DIV",
31 	"ZEND_MOD",
32 	"ZEND_SL",
33 	"ZEND_SR",
34 	"ZEND_CONCAT",
35 	"ZEND_BW_OR",
36 	"ZEND_BW_AND",
37 	"ZEND_BW_XOR",
38 	"ZEND_POW",
39 	"ZEND_BW_NOT",
40 	"ZEND_BOOL_NOT",
41 	"ZEND_BOOL_XOR",
42 	"ZEND_IS_IDENTICAL",
43 	"ZEND_IS_NOT_IDENTICAL",
44 	"ZEND_IS_EQUAL",
45 	"ZEND_IS_NOT_EQUAL",
46 	"ZEND_IS_SMALLER",
47 	"ZEND_IS_SMALLER_OR_EQUAL",
48 	"ZEND_ASSIGN",
49 	"ZEND_ASSIGN_DIM",
50 	"ZEND_ASSIGN_OBJ",
51 	"ZEND_ASSIGN_STATIC_PROP",
52 	"ZEND_ASSIGN_OP",
53 	"ZEND_ASSIGN_DIM_OP",
54 	"ZEND_ASSIGN_OBJ_OP",
55 	"ZEND_ASSIGN_STATIC_PROP_OP",
56 	"ZEND_ASSIGN_REF",
57 	"ZEND_QM_ASSIGN",
58 	"ZEND_ASSIGN_OBJ_REF",
59 	"ZEND_ASSIGN_STATIC_PROP_REF",
60 	"ZEND_PRE_INC",
61 	"ZEND_PRE_DEC",
62 	"ZEND_POST_INC",
63 	"ZEND_POST_DEC",
64 	"ZEND_PRE_INC_STATIC_PROP",
65 	"ZEND_PRE_DEC_STATIC_PROP",
66 	"ZEND_POST_INC_STATIC_PROP",
67 	"ZEND_POST_DEC_STATIC_PROP",
68 	"ZEND_JMP",
69 	"ZEND_JMPZ",
70 	"ZEND_JMPNZ",
71 	NULL,
72 	"ZEND_JMPZ_EX",
73 	"ZEND_JMPNZ_EX",
74 	"ZEND_CASE",
75 	"ZEND_CHECK_VAR",
76 	"ZEND_SEND_VAR_NO_REF_EX",
77 	"ZEND_CAST",
78 	"ZEND_BOOL",
79 	"ZEND_FAST_CONCAT",
80 	"ZEND_ROPE_INIT",
81 	"ZEND_ROPE_ADD",
82 	"ZEND_ROPE_END",
83 	"ZEND_BEGIN_SILENCE",
84 	"ZEND_END_SILENCE",
85 	"ZEND_INIT_FCALL_BY_NAME",
86 	"ZEND_DO_FCALL",
87 	"ZEND_INIT_FCALL",
88 	"ZEND_RETURN",
89 	"ZEND_RECV",
90 	"ZEND_RECV_INIT",
91 	"ZEND_SEND_VAL",
92 	"ZEND_SEND_VAR_EX",
93 	"ZEND_SEND_REF",
94 	"ZEND_NEW",
95 	"ZEND_INIT_NS_FCALL_BY_NAME",
96 	"ZEND_FREE",
97 	"ZEND_INIT_ARRAY",
98 	"ZEND_ADD_ARRAY_ELEMENT",
99 	"ZEND_INCLUDE_OR_EVAL",
100 	"ZEND_UNSET_VAR",
101 	"ZEND_UNSET_DIM",
102 	"ZEND_UNSET_OBJ",
103 	"ZEND_FE_RESET_R",
104 	"ZEND_FE_FETCH_R",
105 	NULL,
106 	"ZEND_FETCH_R",
107 	"ZEND_FETCH_DIM_R",
108 	"ZEND_FETCH_OBJ_R",
109 	"ZEND_FETCH_W",
110 	"ZEND_FETCH_DIM_W",
111 	"ZEND_FETCH_OBJ_W",
112 	"ZEND_FETCH_RW",
113 	"ZEND_FETCH_DIM_RW",
114 	"ZEND_FETCH_OBJ_RW",
115 	"ZEND_FETCH_IS",
116 	"ZEND_FETCH_DIM_IS",
117 	"ZEND_FETCH_OBJ_IS",
118 	"ZEND_FETCH_FUNC_ARG",
119 	"ZEND_FETCH_DIM_FUNC_ARG",
120 	"ZEND_FETCH_OBJ_FUNC_ARG",
121 	"ZEND_FETCH_UNSET",
122 	"ZEND_FETCH_DIM_UNSET",
123 	"ZEND_FETCH_OBJ_UNSET",
124 	"ZEND_FETCH_LIST_R",
125 	"ZEND_FETCH_CONSTANT",
126 	"ZEND_CHECK_FUNC_ARG",
127 	"ZEND_EXT_STMT",
128 	"ZEND_EXT_FCALL_BEGIN",
129 	"ZEND_EXT_FCALL_END",
130 	"ZEND_EXT_NOP",
131 	"ZEND_TICKS",
132 	"ZEND_SEND_VAR_NO_REF",
133 	"ZEND_CATCH",
134 	"ZEND_THROW",
135 	"ZEND_FETCH_CLASS",
136 	"ZEND_CLONE",
137 	"ZEND_RETURN_BY_REF",
138 	"ZEND_INIT_METHOD_CALL",
139 	"ZEND_INIT_STATIC_METHOD_CALL",
140 	"ZEND_ISSET_ISEMPTY_VAR",
141 	"ZEND_ISSET_ISEMPTY_DIM_OBJ",
142 	"ZEND_SEND_VAL_EX",
143 	"ZEND_SEND_VAR",
144 	"ZEND_INIT_USER_CALL",
145 	"ZEND_SEND_ARRAY",
146 	"ZEND_SEND_USER",
147 	"ZEND_STRLEN",
148 	"ZEND_DEFINED",
149 	"ZEND_TYPE_CHECK",
150 	"ZEND_VERIFY_RETURN_TYPE",
151 	"ZEND_FE_RESET_RW",
152 	"ZEND_FE_FETCH_RW",
153 	"ZEND_FE_FREE",
154 	"ZEND_INIT_DYNAMIC_CALL",
155 	"ZEND_DO_ICALL",
156 	"ZEND_DO_UCALL",
157 	"ZEND_DO_FCALL_BY_NAME",
158 	"ZEND_PRE_INC_OBJ",
159 	"ZEND_PRE_DEC_OBJ",
160 	"ZEND_POST_INC_OBJ",
161 	"ZEND_POST_DEC_OBJ",
162 	"ZEND_ECHO",
163 	"ZEND_OP_DATA",
164 	"ZEND_INSTANCEOF",
165 	"ZEND_GENERATOR_CREATE",
166 	"ZEND_MAKE_REF",
167 	"ZEND_DECLARE_FUNCTION",
168 	"ZEND_DECLARE_LAMBDA_FUNCTION",
169 	"ZEND_DECLARE_CONST",
170 	"ZEND_DECLARE_CLASS",
171 	"ZEND_DECLARE_CLASS_DELAYED",
172 	"ZEND_DECLARE_ANON_CLASS",
173 	"ZEND_ADD_ARRAY_UNPACK",
174 	"ZEND_ISSET_ISEMPTY_PROP_OBJ",
175 	"ZEND_HANDLE_EXCEPTION",
176 	"ZEND_USER_OPCODE",
177 	"ZEND_ASSERT_CHECK",
178 	"ZEND_JMP_SET",
179 	"ZEND_UNSET_CV",
180 	"ZEND_ISSET_ISEMPTY_CV",
181 	"ZEND_FETCH_LIST_W",
182 	"ZEND_SEPARATE",
183 	"ZEND_FETCH_CLASS_NAME",
184 	"ZEND_CALL_TRAMPOLINE",
185 	"ZEND_DISCARD_EXCEPTION",
186 	"ZEND_YIELD",
187 	"ZEND_GENERATOR_RETURN",
188 	"ZEND_FAST_CALL",
189 	"ZEND_FAST_RET",
190 	"ZEND_RECV_VARIADIC",
191 	"ZEND_SEND_UNPACK",
192 	"ZEND_YIELD_FROM",
193 	"ZEND_COPY_TMP",
194 	"ZEND_BIND_GLOBAL",
195 	"ZEND_COALESCE",
196 	"ZEND_SPACESHIP",
197 	"ZEND_FUNC_NUM_ARGS",
198 	"ZEND_FUNC_GET_ARGS",
199 	"ZEND_FETCH_STATIC_PROP_R",
200 	"ZEND_FETCH_STATIC_PROP_W",
201 	"ZEND_FETCH_STATIC_PROP_RW",
202 	"ZEND_FETCH_STATIC_PROP_IS",
203 	"ZEND_FETCH_STATIC_PROP_FUNC_ARG",
204 	"ZEND_FETCH_STATIC_PROP_UNSET",
205 	"ZEND_UNSET_STATIC_PROP",
206 	"ZEND_ISSET_ISEMPTY_STATIC_PROP",
207 	"ZEND_FETCH_CLASS_CONSTANT",
208 	"ZEND_BIND_LEXICAL",
209 	"ZEND_BIND_STATIC",
210 	"ZEND_FETCH_THIS",
211 	"ZEND_SEND_FUNC_ARG",
212 	"ZEND_ISSET_ISEMPTY_THIS",
213 	"ZEND_SWITCH_LONG",
214 	"ZEND_SWITCH_STRING",
215 	"ZEND_IN_ARRAY",
216 	"ZEND_COUNT",
217 	"ZEND_GET_CLASS",
218 	"ZEND_GET_CALLED_CLASS",
219 	"ZEND_GET_TYPE",
220 	"ZEND_ARRAY_KEY_EXISTS",
221 	"ZEND_MATCH",
222 	"ZEND_CASE_STRICT",
223 	"ZEND_MATCH_ERROR",
224 	"ZEND_JMP_NULL",
225 	"ZEND_CHECK_UNDEF_ARGS",
226 	"ZEND_FETCH_GLOBALS",
227 	"ZEND_VERIFY_NEVER_TYPE",
228 	"ZEND_CALLABLE_CONVERT",
229 	"ZEND_BIND_INIT_STATIC_OR_JMP",
230 	"ZEND_FRAMELESS_ICALL_0",
231 	"ZEND_FRAMELESS_ICALL_1",
232 	"ZEND_FRAMELESS_ICALL_2",
233 	"ZEND_FRAMELESS_ICALL_3",
234 	"ZEND_JMP_FRAMELESS",
235 	"ZEND_INIT_PARENT_PROPERTY_HOOK_CALL",
236 };
237 
238 static uint32_t zend_vm_opcodes_flags[210] = {
239 	0x00000000,
240 	0x00000b0b,
241 	0x00000b0b,
242 	0x80000b0b,
243 	0x00000707,
244 	0x00000b0b,
245 	0x00000b0b,
246 	0x00000b0b,
247 	0x40000707,
248 	0x80000b0b,
249 	0x80000b0b,
250 	0x80000b0b,
251 	0x00000707,
252 	0x0000000b,
253 	0x00000007,
254 	0x80000707,
255 	0x80000303,
256 	0x80000303,
257 	0x80000707,
258 	0x80000707,
259 	0x00000b0b,
260 	0x00000b0b,
261 	0x00000301,
262 	0x00006701,
263 	0x00040751,
264 	0x00040000,
265 	0x04000701,
266 	0x04006701,
267 	0x04000751,
268 	0x04000000,
269 	0x0b000101,
270 	0x00000003,
271 	0x0b040751,
272 	0x0b040000,
273 	0x00000001,
274 	0x00000001,
275 	0x00000001,
276 	0x00000001,
277 	0x00040000,
278 	0x00040000,
279 	0x00040000,
280 	0x00040000,
281 	0x00000020,
282 	0x00002007,
283 	0x00002007,
284 	0x00000000,
285 	0x00002007,
286 	0x00002007,
287 	0x00000705,
288 	0x00000101,
289 	0x00001301,
290 	0x07000003,
291 	0x00000007,
292 	0x00000707,
293 	0x01000701,
294 	0x01000701,
295 	0x01000701,
296 	0x00000000,
297 	0x00000001,
298 	0x01040300,
299 	0x00000000,
300 	0x01040310,
301 	0x00000003,
302 	0x00040110,
303 	0x00040310,
304 	0x00001307,
305 	0x00001301,
306 	0x00001301,
307 	0x0100a173,
308 	0x01040300,
309 	0x00000005,
310 	0x00186703,
311 	0x00106703,
312 	0x08000007,
313 	0x00010107,
314 	0x00000701,
315 	0x00040751,
316 	0x00002003,
317 	0x03000001,
318 	0x00000000,
319 	0x00010107,
320 	0x00000707,
321 	0x00040757,
322 	0x00010107,
323 	0x00006701,
324 	0x00640751,
325 	0x00010107,
326 	0x00006701,
327 	0x00040751,
328 	0x00010107,
329 	0x00000707,
330 	0x00040757,
331 	0x00010107,
332 	0x00006703,
333 	0x00240753,
334 	0x00010107,
335 	0x00000701,
336 	0x00040751,
337 	0x0000070b,
338 	0x00040391,
339 	0x00001301,
340 	0x00000000,
341 	0x00000000,
342 	0x00000000,
343 	0x00000000,
344 	0x01000000,
345 	0x00001301,
346 	0x02042003,
347 	0x00000007,
348 	0x00040771,
349 	0x00000057,
350 	0x0b000003,
351 	0x01040757,
352 	0x01048773,
353 	0x00030107,
354 	0x00020707,
355 	0x00001303,
356 	0x00001301,
357 	0x01000703,
358 	0x01000000,
359 	0x00001003,
360 	0x00000007,
361 	0x00040003,
362 	0x09000007,
363 	0x0000a103,
364 	0x00002003,
365 	0x03000001,
366 	0x00000005,
367 	0x01000700,
368 	0x00000000,
369 	0x00000000,
370 	0x00000000,
371 	0x00040751,
372 	0x00040751,
373 	0x00040751,
374 	0x00040751,
375 	0x00000007,
376 	0x00000000,
377 	0x00047305,
378 	0x00000000,
379 	0x00000101,
380 	0x00001000,
381 	0x00001003,
382 	0x00000303,
383 	0x00000003,
384 	0x00000303,
385 	0x00040000,
386 	0x00000000,
387 	0x00060757,
388 	0x00000000,
389 	0x00000000,
390 	0x00002000,
391 	0x00002003,
392 	0x00000101,
393 	0x00020101,
394 	0x00000701,
395 	0x00000101,
396 	0x00000075,
397 	0x00000000,
398 	0x00000000,
399 	0x0b000703,
400 	0x00000003,
401 	0x00000020,
402 	0x00003000,
403 	0x00040110,
404 	0x00000000,
405 	0x00000007,
406 	0x00000105,
407 	0x00040301,
408 	0x00002003,
409 	0x00000707,
410 	0x00000101,
411 	0x00000103,
412 	0x00047000,
413 	0x00647000,
414 	0x00047000,
415 	0x00047000,
416 	0x00247000,
417 	0x00047000,
418 	0x00040000,
419 	0x00067000,
420 	0x00040b73,
421 	0x00100101,
422 	0x00100001,
423 	0x00000101,
424 	0x00001301,
425 	0x00000101,
426 	0x0300030b,
427 	0x0300030b,
428 	0x01000303,
429 	0x00000107,
430 	0x00000107,
431 	0x00000101,
432 	0x00000103,
433 	0x00000707,
434 	0x0300030b,
435 	0x00000301,
436 	0x0000010b,
437 	0x00002003,
438 	0x00000101,
439 	0x00000101,
440 	0x00000101,
441 	0x00000101,
442 	0x00002001,
443 	0x00000101,
444 	0x00000100,
445 	0x00000000,
446 	0x00000000,
447 	0x01042003,
448 	0x01001103,
449 };
450 
zend_get_opcode_name(uint8_t opcode)451 ZEND_API const char* ZEND_FASTCALL zend_get_opcode_name(uint8_t opcode) {
452 	if (UNEXPECTED(opcode > ZEND_VM_LAST_OPCODE)) {
453 		return NULL;
454 	}
455 	return zend_vm_opcodes_names[opcode];
456 }
zend_get_opcode_flags(uint8_t opcode)457 ZEND_API uint32_t ZEND_FASTCALL zend_get_opcode_flags(uint8_t opcode) {
458 	if (UNEXPECTED(opcode > ZEND_VM_LAST_OPCODE)) {
459 		opcode = ZEND_NOP;
460 	}
461 	return zend_vm_opcodes_flags[opcode];
462 }
zend_get_opcode_id(const char * name,size_t length)463 ZEND_API uint8_t zend_get_opcode_id(const char *name, size_t length) {
464 	uint8_t opcode;
465 	for (opcode = 0; opcode < (sizeof(zend_vm_opcodes_names) / sizeof(zend_vm_opcodes_names[0])) - 1; opcode++) {
466 		const char *opcode_name = zend_vm_opcodes_names[opcode];
467 		if (opcode_name && strncmp(opcode_name, name, length) == 0) {
468 			return opcode;
469 		}
470 	}
471 	return ZEND_VM_LAST_OPCODE + 1;
472 }
473