xref: /PHP-7.3/Zend/zend_vm_execute.skl (revision 1c850bfc)
1{%DEFINES%}
2
3ZEND_API void {%EXECUTOR_NAME%}_ex(zend_execute_data *ex)
4{
5	DCL_OPLINE
6
7	{%HELPER_VARS%}
8
9	{%INTERNAL_LABELS%}
10
11	LOAD_OPLINE();
12	ZEND_VM_LOOP_INTERRUPT_CHECK();
13
14	while (1) {
15		{%ZEND_VM_CONTINUE_LABEL%}
16		{%ZEND_VM_DISPATCH%} {
17			{%INTERNAL_EXECUTOR%}
18		}
19
20	}
21	zend_error_noreturn(E_CORE_ERROR, "Arrived at end of main loop which shouldn't happen");
22}
23
24ZEND_API void zend_{%EXECUTOR_NAME%}(zend_op_array *op_array, zval *return_value)
25{
26	zend_execute_data *execute_data;
27
28	if (EG(exception) != NULL) {
29		return;
30	}
31
32	execute_data = zend_vm_stack_push_call_frame(ZEND_CALL_TOP_CODE | ZEND_CALL_HAS_SYMBOL_TABLE,
33		(zend_function*)op_array, 0, zend_get_called_scope(EG(current_execute_data)), zend_get_this_object(EG(current_execute_data)));
34	if (EG(current_execute_data)) {
35		execute_data->symbol_table = zend_rebuild_symbol_table();
36	} else {
37		execute_data->symbol_table = &EG(symbol_table);
38	}
39	EX(prev_execute_data) = EG(current_execute_data);
40	i_init_code_execute_data(execute_data, op_array, return_value);
41	zend_{%EXECUTOR_NAME%}_ex(execute_data);
42	zend_vm_stack_free_call_frame(execute_data);
43}
44
45{%EXTERNAL_EXECUTOR%}
46
47void {%INITIALIZER_NAME%}(void)
48{
49	{%EXTERNAL_LABELS%}
50	VM_TRACE_START();
51}
52
53void zend_vm_dtor(void)
54{
55	VM_TRACE_END();
56}
57
58static HashTable *zend_handlers_table = NULL;
59
60static void init_opcode_serialiser(void)
61{
62	int i;
63	zval tmp;
64
65	zend_handlers_table = malloc(sizeof(HashTable));
66	zend_hash_init_ex(zend_handlers_table, zend_handlers_count, NULL, NULL, 1, 0);
67	zend_hash_real_init(zend_handlers_table, 0);
68	Z_TYPE_INFO(tmp) = IS_LONG;
69	for (i = 0; i < zend_handlers_count; i++) {
70		Z_LVAL(tmp) = i;
71		zend_hash_index_add(zend_handlers_table, (zend_long)(zend_uintptr_t)zend_opcode_handlers[i], &tmp);
72	}
73}
74
75ZEND_API void ZEND_FASTCALL zend_serialize_opcode_handler(zend_op *op)
76{
77	zval *zv;
78
79	if (!zend_handlers_table) {
80		init_opcode_serialiser();
81	}
82	zv = zend_hash_index_find(zend_handlers_table, (zend_long)(zend_uintptr_t)op->handler);
83	ZEND_ASSERT(zv != NULL);
84	op->handler = (const void *)(zend_uintptr_t)Z_LVAL_P(zv);
85}
86
87ZEND_API void ZEND_FASTCALL zend_deserialize_opcode_handler(zend_op *op)
88{
89	op->handler = zend_opcode_handlers[(zend_uintptr_t)op->handler];
90}
91
92ZEND_API const void* ZEND_FASTCALL zend_get_opcode_handler_func(const zend_op *op)
93{
94#if ZEND_VM_KIND == ZEND_VM_KIND_CALL
95	return op->handler;
96#elif ZEND_VM_KIND == ZEND_VM_KIND_HYBRID
97	zval *zv;
98
99	if (!zend_handlers_table) {
100		init_opcode_serialiser();
101	}
102	zv = zend_hash_index_find(zend_handlers_table, (zend_long)(zend_uintptr_t)op->handler);
103	ZEND_ASSERT(zv != NULL);
104	return zend_opcode_handler_funcs[Z_LVAL_P(zv)];
105#else
106	return NULL;
107#endif
108}
109
110ZEND_API const zend_op *zend_get_halt_op(void)
111{
112#if ZEND_VM_KIND == ZEND_VM_KIND_HYBRID
113	return &hybrid_halt_op;
114#else
115	return NULL;
116#endif
117}
118
119ZEND_API int zend_vm_kind(void)
120{
121	return ZEND_VM_KIND;
122}
123