File: zend_vm_execute.skl

package info (click to toggle)
php8.4 8.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,108 kB
  • sloc: ansic: 1,060,628; php: 35,345; sh: 11,866; cpp: 7,201; pascal: 4,913; javascript: 3,091; asm: 2,810; yacc: 2,411; makefile: 689; xml: 446; python: 301; awk: 148
file content (165 lines) | stat: -rw-r--r-- 4,276 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
{%DEFINES%}

#if (ZEND_VM_KIND != ZEND_VM_KIND_CALL) && (ZEND_GCC_VERSION >= 4000) && !defined(__clang__)
# pragma GCC push_options
# pragma GCC optimize("no-gcse")
# pragma GCC optimize("no-ivopts")
#endif
#if defined(_WIN64) && defined(_M_X64)
/* See save_xmm_x86_64_ms_masm.asm */
void {%EXECUTOR_NAME%}_ex_real(zend_execute_data *ex)
#else
ZEND_API void {%EXECUTOR_NAME%}_ex(zend_execute_data *ex)
#endif
{
	DCL_OPLINE

#if defined(__GNUC__) && defined(__aarch64__)
	__asm__ __volatile__ (""::: "v8","v9","v10","v11","v12","v13","v14","v15");
#endif

	{%HELPER_VARS%}

	{%INTERNAL_LABELS%}

	LOAD_OPLINE();
	ZEND_VM_LOOP_INTERRUPT_CHECK();

#ifdef ZEND_CHECK_STACK_LIMIT
	if (UNEXPECTED(zend_call_stack_overflowed(EG(stack_limit)))) {
		zend_call_stack_size_error();
		/* No opline was executed before exception */
		EG(opline_before_exception) = NULL;
		LOAD_OPLINE();
		/* Fall through to handle exception below. */
	}
#endif /* ZEND_CHECK_STACK_LIMIT */

	while (1) {
		{%ZEND_VM_CONTINUE_LABEL%}
		{%ZEND_VM_DISPATCH%} {
			{%INTERNAL_EXECUTOR%}
		}

	}
	zend_error_noreturn(E_CORE_ERROR, "Arrived at end of main loop which shouldn't happen");
}
#if (ZEND_VM_KIND != ZEND_VM_KIND_CALL) && (ZEND_GCC_VERSION >= 4000) && !defined(__clang__)
# pragma GCC pop_options
#endif

ZEND_API void zend_{%EXECUTOR_NAME%}(zend_op_array *op_array, zval *return_value)
{
	zend_execute_data *execute_data;
	void *object_or_called_scope;
	uint32_t call_info;

	if (EG(exception) != NULL) {
		return;
	}

	object_or_called_scope = zend_get_this_object(EG(current_execute_data));
	if (EXPECTED(!object_or_called_scope)) {
		object_or_called_scope = zend_get_called_scope(EG(current_execute_data));
		call_info = ZEND_CALL_TOP_CODE | ZEND_CALL_HAS_SYMBOL_TABLE;
	} else {
		call_info = ZEND_CALL_TOP_CODE | ZEND_CALL_HAS_SYMBOL_TABLE | ZEND_CALL_HAS_THIS;
	}
	execute_data = zend_vm_stack_push_call_frame(call_info,
		(zend_function*)op_array, 0, object_or_called_scope);
	if (EG(current_execute_data)) {
		execute_data->symbol_table = zend_rebuild_symbol_table();
	} else {
		execute_data->symbol_table = &EG(symbol_table);
	}
	EX(prev_execute_data) = EG(current_execute_data);
	i_init_code_execute_data(execute_data, op_array, return_value);
	ZEND_OBSERVER_FCALL_BEGIN(execute_data);
	zend_{%EXECUTOR_NAME%}_ex(execute_data);
	/* Observer end handlers are called from ZEND_RETURN */
	zend_vm_stack_free_call_frame(execute_data);
}

{%EXTERNAL_EXECUTOR%}

void {%INITIALIZER_NAME%}(void)
{
	{%EXTERNAL_LABELS%}
	VM_TRACE_START();
}

static HashTable *zend_handlers_table = NULL;

void zend_vm_dtor(void)
{
	VM_TRACE_END();
	if (zend_handlers_table) {
		zend_hash_destroy(zend_handlers_table);
		free(zend_handlers_table);
		zend_handlers_table = NULL;
	}
}

static void init_opcode_serialiser(void)
{
	int i;
	zval tmp;

	zend_handlers_table = malloc(sizeof(HashTable));
	zend_hash_init(zend_handlers_table, zend_handlers_count, NULL, NULL, 1);
	zend_hash_real_init(zend_handlers_table, 0);
	Z_TYPE_INFO(tmp) = IS_LONG;
	for (i = 0; i < zend_handlers_count; i++) {
		Z_LVAL(tmp) = i;
		zend_hash_index_add(zend_handlers_table, (zend_long)(uintptr_t)zend_opcode_handlers[i], &tmp);
	}
}

ZEND_API void ZEND_FASTCALL zend_serialize_opcode_handler(zend_op *op)
{
	zval *zv;

	if (!zend_handlers_table) {
		init_opcode_serialiser();
	}
	zv = zend_hash_index_find(zend_handlers_table, (zend_long)(uintptr_t)op->handler);
	ZEND_ASSERT(zv != NULL);
	op->handler = (const void *)(uintptr_t)Z_LVAL_P(zv);
}

ZEND_API void ZEND_FASTCALL zend_deserialize_opcode_handler(zend_op *op)
{
	op->handler = zend_opcode_handlers[(uintptr_t)op->handler];
}

ZEND_API const void* ZEND_FASTCALL zend_get_opcode_handler_func(const zend_op *op)
{
#if ZEND_VM_KIND == ZEND_VM_KIND_CALL
	return op->handler;
#elif ZEND_VM_KIND == ZEND_VM_KIND_HYBRID
	zval *zv;

	if (!zend_handlers_table) {
		init_opcode_serialiser();
	}
	zv = zend_hash_index_find(zend_handlers_table, (zend_long)(uintptr_t)op->handler);
	ZEND_ASSERT(zv != NULL);
	return zend_opcode_handler_funcs[Z_LVAL_P(zv)];
#else
	return NULL;
#endif
}

ZEND_API const zend_op *zend_get_halt_op(void)
{
#if ZEND_VM_KIND == ZEND_VM_KIND_HYBRID
	return &hybrid_halt_op;
#else
	return NULL;
#endif
}

ZEND_API int zend_vm_kind(void)
{
	return ZEND_VM_KIND;
}