xref: /PHP-7.1/Zend/zend_vm_execute.skl (revision 03f3b847)
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_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