xref: /PHP-7.2/Zend/zend_vm_execute.skl (revision 60a69dae)
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}
51
52static HashTable *zend_handlers_table = NULL;
53
54static void init_opcode_serialiser(void)
55{
56	int i;
57	zval tmp;
58
59	zend_handlers_table = malloc(sizeof(HashTable));
60	zend_hash_init_ex(zend_handlers_table, zend_handlers_count, NULL, NULL, 1, 0);
61	zend_hash_real_init(zend_handlers_table, 0);
62	Z_TYPE_INFO(tmp) = IS_LONG;
63	for (i = 0; i < zend_handlers_count; i++) {
64		Z_LVAL(tmp) = i;
65		zend_hash_index_add(zend_handlers_table, (zend_long)(zend_uintptr_t)zend_opcode_handlers[i], &tmp);
66	}
67}
68
69ZEND_API void zend_serialize_opcode_handler(zend_op *op)
70{
71	zval *zv;
72
73	if (!zend_handlers_table) {
74		init_opcode_serialiser();
75	}
76	zv = zend_hash_index_find(zend_handlers_table, (zend_long)(zend_uintptr_t)op->handler);
77	ZEND_ASSERT(zv != NULL);
78	op->handler = (const void *)(zend_uintptr_t)Z_LVAL_P(zv);
79}
80
81ZEND_API void zend_deserialize_opcode_handler(zend_op *op)
82{
83	op->handler = zend_opcode_handlers[(zend_uintptr_t)op->handler];
84}
85
86ZEND_API const void *zend_get_opcode_handler_func(const zend_op *op)
87{
88#if ZEND_VM_KIND == ZEND_VM_KIND_CALL
89	return op->handler;
90#elif ZEND_VM_KIND == ZEND_VM_KIND_HYBRID
91	zval *zv;
92
93	if (!zend_handlers_table) {
94		init_opcode_serialiser();
95	}
96	zv = zend_hash_index_find(zend_handlers_table, (zend_long)(zend_uintptr_t)op->handler);
97	ZEND_ASSERT(zv != NULL);
98	return zend_opcode_handler_funcs[Z_LVAL_P(zv)];
99#else
100	return NULL;
101#endif
102}
103
104ZEND_API const zend_op *zend_get_halt_op(void)
105{
106#if ZEND_VM_KIND == ZEND_VM_KIND_HYBRID
107	return &hybrid_halt_op;
108#else
109	return NULL;
110#endif
111}
112
113ZEND_API int zend_vm_kind(void)
114{
115	return ZEND_VM_KIND;
116}
117