xref: /PHP-8.0/Zend/zend_globals.h (revision c4016ecd)
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    +----------------------------------------------------------------------+
18 */
19 
20 #ifndef ZEND_GLOBALS_H
21 #define ZEND_GLOBALS_H
22 
23 
24 #include <setjmp.h>
25 
26 #include "zend_globals_macros.h"
27 
28 #include "zend_stack.h"
29 #include "zend_ptr_stack.h"
30 #include "zend_hash.h"
31 #include "zend_llist.h"
32 #include "zend_objects.h"
33 #include "zend_objects_API.h"
34 #include "zend_modules.h"
35 #include "zend_float.h"
36 #include "zend_multibyte.h"
37 #include "zend_multiply.h"
38 #include "zend_arena.h"
39 
40 /* Define ZTS if you want a thread-safe Zend */
41 /*#undef ZTS*/
42 
43 #ifdef ZTS
44 
45 BEGIN_EXTERN_C()
46 ZEND_API extern int compiler_globals_id;
47 ZEND_API extern int executor_globals_id;
48 ZEND_API extern size_t compiler_globals_offset;
49 ZEND_API extern size_t executor_globals_offset;
50 END_EXTERN_C()
51 
52 #endif
53 
54 #define SYMTABLE_CACHE_SIZE 32
55 
56 
57 #include "zend_compile.h"
58 
59 /* excpt.h on Digital Unix 4.0 defines function_table */
60 #undef function_table
61 
62 typedef struct _zend_vm_stack *zend_vm_stack;
63 typedef struct _zend_ini_entry zend_ini_entry;
64 
65 
66 struct _zend_compiler_globals {
67 	zend_stack loop_var_stack;
68 
69 	zend_class_entry *active_class_entry;
70 
71 	zend_string *compiled_filename;
72 
73 	int zend_lineno;
74 
75 	zend_op_array *active_op_array;
76 
77 	HashTable *function_table;	/* function symbol table */
78 	HashTable *class_table;		/* class table */
79 
80 	HashTable *auto_globals;
81 
82 	/* Refer to zend_yytnamerr() in zend_language_parser.y for meaning of values */
83 	zend_uchar parse_error;
84 	zend_bool in_compilation;
85 	zend_bool short_tags;
86 
87 	zend_bool unclean_shutdown;
88 
89 	zend_bool ini_parser_unbuffered_errors;
90 
91 	zend_llist open_files;
92 
93 	struct _zend_ini_parser_param *ini_parser_param;
94 
95 	zend_bool skip_shebang;
96 	zend_bool increment_lineno;
97 
98 	zend_string *doc_comment;
99 	uint32_t extra_fn_flags;
100 
101 	uint32_t compiler_options; /* set of ZEND_COMPILE_* constants */
102 
103 	zend_oparray_context context;
104 	zend_file_context file_context;
105 
106 	zend_arena *arena;
107 
108 	HashTable interned_strings;
109 
110 	const zend_encoding **script_encoding_list;
111 	size_t script_encoding_list_size;
112 	zend_bool multibyte;
113 	zend_bool detect_unicode;
114 	zend_bool encoding_declared;
115 
116 	zend_ast *ast;
117 	zend_arena *ast_arena;
118 
119 	zend_stack delayed_oplines_stack;
120 	HashTable *memoized_exprs;
121 	int memoize_mode;
122 
123 	void   *map_ptr_base;
124 	size_t  map_ptr_size;
125 	size_t  map_ptr_last;
126 
127 	HashTable *delayed_variance_obligations;
128 	HashTable *delayed_autoloads;
129 
130 	uint32_t rtd_key_counter;
131 
132 	zend_stack short_circuiting_opnums;
133 };
134 
135 
136 struct _zend_executor_globals {
137 	zval uninitialized_zval;
138 	zval error_zval;
139 
140 	/* symbol table cache */
141 	zend_array *symtable_cache[SYMTABLE_CACHE_SIZE];
142 	/* Pointer to one past the end of the symtable_cache */
143 	zend_array **symtable_cache_limit;
144 	/* Pointer to first unused symtable_cache slot */
145 	zend_array **symtable_cache_ptr;
146 
147 	zend_array symbol_table;		/* main symbol table */
148 
149 	HashTable included_files;	/* files already included */
150 
151 	JMP_BUF *bailout;
152 
153 	int error_reporting;
154 	int exit_status;
155 
156 	HashTable *function_table;	/* function symbol table */
157 	HashTable *class_table;		/* class table */
158 	HashTable *zend_constants;	/* constants table */
159 
160 	zval          *vm_stack_top;
161 	zval          *vm_stack_end;
162 	zend_vm_stack  vm_stack;
163 	size_t         vm_stack_page_size;
164 
165 	struct _zend_execute_data *current_execute_data;
166 	zend_class_entry *fake_scope; /* used to avoid checks accessing properties */
167 
168 	uint32_t jit_trace_num; /* Used by tracing JIT to reference the currently running trace */
169 
170 	zend_long precision;
171 
172 	int ticks_count;
173 
174 	uint32_t persistent_constants_count;
175 	uint32_t persistent_functions_count;
176 	uint32_t persistent_classes_count;
177 
178 	HashTable *in_autoload;
179 	zend_bool full_tables_cleanup;
180 
181 	/* for extended information support */
182 	zend_bool no_extensions;
183 
184 	zend_bool vm_interrupt;
185 	zend_bool timed_out;
186 	zend_long hard_timeout;
187 
188 #ifdef ZEND_WIN32
189 	OSVERSIONINFOEX windows_version_info;
190 #endif
191 
192 	HashTable regular_list;
193 	HashTable persistent_list;
194 
195 	int user_error_handler_error_reporting;
196 	zval user_error_handler;
197 	zval user_exception_handler;
198 	zend_stack user_error_handlers_error_reporting;
199 	zend_stack user_error_handlers;
200 	zend_stack user_exception_handlers;
201 
202 	zend_error_handling_t  error_handling;
203 	zend_class_entry      *exception_class;
204 
205 	/* timeout support */
206 	zend_long timeout_seconds;
207 
208 	int lambda_count;
209 
210 	HashTable *ini_directives;
211 	HashTable *modified_ini_directives;
212 	zend_ini_entry *error_reporting_ini_entry;
213 
214 	zend_objects_store objects_store;
215 	zend_object *exception, *prev_exception;
216 	const zend_op *opline_before_exception;
217 	zend_op exception_op[3];
218 
219 	struct _zend_module_entry *current_module;
220 
221 	zend_bool active;
222 	zend_uchar flags;
223 
224 	zend_long assertions;
225 
226 	uint32_t           ht_iterators_count;     /* number of allocatd slots */
227 	uint32_t           ht_iterators_used;      /* number of used slots */
228 	HashTableIterator *ht_iterators;
229 	HashTableIterator  ht_iterators_slots[16];
230 
231 	void *saved_fpu_cw_ptr;
232 #if XPFPA_HAVE_CW
233 	XPFPA_CW_DATATYPE saved_fpu_cw;
234 #endif
235 
236 	zend_function trampoline;
237 	zend_op       call_trampoline_op;
238 
239 	HashTable weakrefs;
240 
241 	zend_bool exception_ignore_args;
242 	zend_long exception_string_param_max_len;
243 
244 	zend_get_gc_buffer get_gc_buffer;
245 
246 	void *reserved[ZEND_MAX_RESERVED_RESOURCES];
247 };
248 
249 #define EG_FLAGS_INITIAL				(0)
250 #define EG_FLAGS_IN_SHUTDOWN			(1<<0)
251 #define EG_FLAGS_OBJECT_STORE_NO_REUSE	(1<<1)
252 #define EG_FLAGS_IN_RESOURCE_SHUTDOWN	(1<<2)
253 
254 struct _zend_ini_scanner_globals {
255 	zend_file_handle *yy_in;
256 	zend_file_handle *yy_out;
257 
258 	unsigned int yy_leng;
259 	unsigned char *yy_start;
260 	unsigned char *yy_text;
261 	unsigned char *yy_cursor;
262 	unsigned char *yy_marker;
263 	unsigned char *yy_limit;
264 	int yy_state;
265 	zend_stack state_stack;
266 
267 	char *filename;
268 	int lineno;
269 
270 	/* Modes are: ZEND_INI_SCANNER_NORMAL, ZEND_INI_SCANNER_RAW, ZEND_INI_SCANNER_TYPED */
271 	int scanner_mode;
272 };
273 
274 typedef enum {
275 	ON_TOKEN,
276 	ON_FEEDBACK,
277 	ON_STOP
278 } zend_php_scanner_event;
279 
280 struct _zend_php_scanner_globals {
281 	zend_file_handle *yy_in;
282 	zend_file_handle *yy_out;
283 
284 	unsigned int yy_leng;
285 	unsigned char *yy_start;
286 	unsigned char *yy_text;
287 	unsigned char *yy_cursor;
288 	unsigned char *yy_marker;
289 	unsigned char *yy_limit;
290 	int yy_state;
291 	zend_stack state_stack;
292 	zend_ptr_stack heredoc_label_stack;
293 	zend_stack nest_location_stack; /* for syntax error reporting */
294 	zend_bool heredoc_scan_ahead;
295 	int heredoc_indentation;
296 	zend_bool heredoc_indentation_uses_spaces;
297 
298 	/* original (unfiltered) script */
299 	unsigned char *script_org;
300 	size_t script_org_size;
301 
302 	/* filtered script */
303 	unsigned char *script_filtered;
304 	size_t script_filtered_size;
305 
306 	/* input/output filters */
307 	zend_encoding_filter input_filter;
308 	zend_encoding_filter output_filter;
309 	const zend_encoding *script_encoding;
310 
311 	/* initial string length after scanning to first variable */
312 	int scanned_string_len;
313 
314 	/* hooks */
315 	void (*on_event)(
316 		zend_php_scanner_event event, int token, int line,
317 		const char *text, size_t length, void *context);
318 	void *on_event_context;
319 };
320 
321 #endif /* ZEND_GLOBALS_H */
322