xref: /PHP-8.2/Zend/zend_globals.h (revision 6a6e91f3)
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 #include <stdint.h>
26 #include <sys/types.h>
27 
28 #include "zend_globals_macros.h"
29 
30 #include "zend_atomic.h"
31 #include "zend_stack.h"
32 #include "zend_ptr_stack.h"
33 #include "zend_hash.h"
34 #include "zend_llist.h"
35 #include "zend_objects.h"
36 #include "zend_objects_API.h"
37 #include "zend_modules.h"
38 #include "zend_float.h"
39 #include "zend_multibyte.h"
40 #include "zend_multiply.h"
41 #include "zend_arena.h"
42 #include "zend_call_stack.h"
43 #include "zend_max_execution_timer.h"
44 
45 /* Define ZTS if you want a thread-safe Zend */
46 /*#undef ZTS*/
47 
48 #ifdef ZTS
49 
50 BEGIN_EXTERN_C()
51 ZEND_API extern int compiler_globals_id;
52 ZEND_API extern int executor_globals_id;
53 ZEND_API extern size_t compiler_globals_offset;
54 ZEND_API extern size_t executor_globals_offset;
55 END_EXTERN_C()
56 
57 #endif
58 
59 #define SYMTABLE_CACHE_SIZE 32
60 
61 #ifdef ZEND_CHECK_STACK_LIMIT
62 # define ZEND_MAX_ALLOWED_STACK_SIZE_UNCHECKED -1
63 # define ZEND_MAX_ALLOWED_STACK_SIZE_DETECT     0
64 #endif
65 
66 #include "zend_compile.h"
67 
68 /* excpt.h on Digital Unix 4.0 defines function_table */
69 #undef function_table
70 
71 typedef struct _zend_vm_stack *zend_vm_stack;
72 typedef struct _zend_ini_entry zend_ini_entry;
73 typedef struct _zend_fiber_context zend_fiber_context;
74 typedef struct _zend_fiber zend_fiber;
75 
76 typedef enum {
77 	ZEND_MEMOIZE_NONE,
78 	ZEND_MEMOIZE_COMPILE,
79 	ZEND_MEMOIZE_FETCH,
80 } zend_memoize_mode;
81 
82 struct _zend_compiler_globals {
83 	zend_stack loop_var_stack;
84 
85 	zend_class_entry *active_class_entry;
86 
87 	zend_string *compiled_filename;
88 
89 	int zend_lineno;
90 
91 	zend_op_array *active_op_array;
92 
93 	HashTable *function_table;	/* function symbol table */
94 	HashTable *class_table;		/* class table */
95 
96 	HashTable *auto_globals;
97 
98 	/* Refer to zend_yytnamerr() in zend_language_parser.y for meaning of values */
99 	uint8_t parse_error;
100 	bool in_compilation;
101 	bool short_tags;
102 
103 	bool unclean_shutdown;
104 
105 	bool ini_parser_unbuffered_errors;
106 
107 	zend_llist open_files;
108 
109 	struct _zend_ini_parser_param *ini_parser_param;
110 
111 	bool skip_shebang;
112 	bool increment_lineno;
113 
114 	bool variable_width_locale;   /* UTF-8, Shift-JIS, Big5, ISO 2022, EUC, etc */
115 	bool ascii_compatible_locale; /* locale uses ASCII characters as singletons */
116 	                              /* and don't use them as lead/trail units     */
117 
118 	zend_string *doc_comment;
119 	uint32_t extra_fn_flags;
120 
121 	uint32_t compiler_options; /* set of ZEND_COMPILE_* constants */
122 
123 	zend_oparray_context context;
124 	zend_file_context file_context;
125 
126 	zend_arena *arena;
127 
128 	HashTable interned_strings;
129 
130 	const zend_encoding **script_encoding_list;
131 	size_t script_encoding_list_size;
132 	bool multibyte;
133 	bool detect_unicode;
134 	bool encoding_declared;
135 
136 	zend_ast *ast;
137 	zend_arena *ast_arena;
138 
139 	zend_stack delayed_oplines_stack;
140 	HashTable *memoized_exprs;
141 	zend_memoize_mode memoize_mode;
142 
143 	void   *map_ptr_real_base;
144 	void   *map_ptr_base;
145 	size_t  map_ptr_size;
146 	size_t  map_ptr_last;
147 
148 	HashTable *delayed_variance_obligations;
149 	HashTable *delayed_autoloads;
150 	HashTable *unlinked_uses;
151 	zend_class_entry *current_linking_class;
152 
153 	uint32_t rtd_key_counter;
154 
155 	zend_stack short_circuiting_opnums;
156 #ifdef ZTS
157 	uint32_t copied_functions_count;
158 #endif
159 };
160 
161 
162 struct _zend_executor_globals {
163 	zval uninitialized_zval;
164 	zval error_zval;
165 
166 	/* symbol table cache */
167 	zend_array *symtable_cache[SYMTABLE_CACHE_SIZE];
168 	/* Pointer to one past the end of the symtable_cache */
169 	zend_array **symtable_cache_limit;
170 	/* Pointer to first unused symtable_cache slot */
171 	zend_array **symtable_cache_ptr;
172 
173 	zend_array symbol_table;		/* main symbol table */
174 
175 	HashTable included_files;	/* files already included */
176 
177 	JMP_BUF *bailout;
178 
179 	int error_reporting;
180 	int exit_status;
181 
182 	HashTable *function_table;	/* function symbol table */
183 	HashTable *class_table;		/* class table */
184 	HashTable *zend_constants;	/* constants table */
185 
186 	zval          *vm_stack_top;
187 	zval          *vm_stack_end;
188 	zend_vm_stack  vm_stack;
189 	size_t         vm_stack_page_size;
190 
191 	struct _zend_execute_data *current_execute_data;
192 	zend_class_entry *fake_scope; /* used to avoid checks accessing properties */
193 
194 	uint32_t jit_trace_num; /* Used by tracing JIT to reference the currently running trace */
195 
196 	int ticks_count;
197 
198 	zend_long precision;
199 
200 	uint32_t persistent_constants_count;
201 	uint32_t persistent_functions_count;
202 	uint32_t persistent_classes_count;
203 
204 	/* for extended information support */
205 	bool no_extensions;
206 
207 	bool full_tables_cleanup;
208 
209 	zend_atomic_bool vm_interrupt;
210 	zend_atomic_bool timed_out;
211 
212 	HashTable *in_autoload;
213 
214 	zend_long hard_timeout;
215 	void *stack_base;
216 	void *stack_limit;
217 
218 #ifdef ZEND_WIN32
219 	OSVERSIONINFOEX windows_version_info;
220 #endif
221 
222 	HashTable regular_list;
223 	HashTable persistent_list;
224 
225 	int user_error_handler_error_reporting;
226 	bool exception_ignore_args;
227 	zval user_error_handler;
228 	zval user_exception_handler;
229 	zend_stack user_error_handlers_error_reporting;
230 	zend_stack user_error_handlers;
231 	zend_stack user_exception_handlers;
232 
233 	zend_class_entry      *exception_class;
234 	zend_error_handling_t  error_handling;
235 
236 	int capture_warnings_during_sccp;
237 
238 	/* timeout support */
239 	zend_long timeout_seconds;
240 
241 	HashTable *ini_directives;
242 	HashTable *modified_ini_directives;
243 	zend_ini_entry *error_reporting_ini_entry;
244 
245 	zend_objects_store objects_store;
246 	zend_object *exception, *prev_exception;
247 	const zend_op *opline_before_exception;
248 	zend_op exception_op[3];
249 
250 	struct _zend_module_entry *current_module;
251 
252 	bool active;
253 	uint8_t flags;
254 
255 	zend_long assertions;
256 
257 	uint32_t           ht_iterators_count;     /* number of allocated slots */
258 	uint32_t           ht_iterators_used;      /* number of used slots */
259 	HashTableIterator *ht_iterators;
260 	HashTableIterator  ht_iterators_slots[16];
261 
262 	void *saved_fpu_cw_ptr;
263 #if XPFPA_HAVE_CW
264 	XPFPA_CW_DATATYPE saved_fpu_cw;
265 #endif
266 
267 	zend_function trampoline;
268 	zend_op       call_trampoline_op;
269 
270 	HashTable weakrefs;
271 
272 	zend_long exception_string_param_max_len;
273 
274 	zend_get_gc_buffer get_gc_buffer;
275 
276 	zend_fiber_context *main_fiber_context;
277 	zend_fiber_context *current_fiber_context;
278 
279 	/* Active instance of Fiber. */
280 	zend_fiber *active_fiber;
281 
282 	/* Default fiber C stack size. */
283 	size_t fiber_stack_size;
284 
285 	/* If record_errors is enabled, all emitted diagnostics will be recorded,
286 	 * in addition to being processed as usual. */
287 	bool record_errors;
288 	uint32_t num_errors;
289 	zend_error_info **errors;
290 
291 	/* Override filename or line number of thrown errors and exceptions */
292 	zend_string *filename_override;
293 	zend_long lineno_override;
294 
295 #ifdef ZEND_CHECK_STACK_LIMIT
296 	zend_call_stack call_stack;
297 	zend_long max_allowed_stack_size;
298 	zend_ulong reserved_stack_size;
299 #endif
300 
301 #ifdef ZEND_MAX_EXECUTION_TIMERS
302 	timer_t max_execution_timer_timer;
303 	pid_t pid;
304 	struct sigaction oldact;
305 #endif
306 
307 	void *reserved[ZEND_MAX_RESERVED_RESOURCES];
308 };
309 
310 #define EG_FLAGS_INITIAL				(0)
311 #define EG_FLAGS_IN_SHUTDOWN			(1<<0)
312 #define EG_FLAGS_OBJECT_STORE_NO_REUSE	(1<<1)
313 #define EG_FLAGS_IN_RESOURCE_SHUTDOWN	(1<<2)
314 
315 struct _zend_ini_scanner_globals {
316 	zend_file_handle *yy_in;
317 	zend_file_handle *yy_out;
318 
319 	unsigned int yy_leng;
320 	const unsigned char *yy_start;
321 	const unsigned char *yy_text;
322 	const unsigned char *yy_cursor;
323 	const unsigned char *yy_marker;
324 	const unsigned char *yy_limit;
325 	int yy_state;
326 	zend_stack state_stack;
327 
328 	zend_string *filename;
329 	int lineno;
330 
331 	/* Modes are: ZEND_INI_SCANNER_NORMAL, ZEND_INI_SCANNER_RAW, ZEND_INI_SCANNER_TYPED */
332 	int scanner_mode;
333 };
334 
335 typedef enum {
336 	ON_TOKEN,
337 	ON_FEEDBACK,
338 	ON_STOP
339 } zend_php_scanner_event;
340 
341 struct _zend_php_scanner_globals {
342 	zend_file_handle *yy_in;
343 	zend_file_handle *yy_out;
344 
345 	unsigned int yy_leng;
346 	unsigned char *yy_start;
347 	unsigned char *yy_text;
348 	unsigned char *yy_cursor;
349 	unsigned char *yy_marker;
350 	unsigned char *yy_limit;
351 	int yy_state;
352 	zend_stack state_stack;
353 	zend_ptr_stack heredoc_label_stack;
354 	zend_stack nest_location_stack; /* for syntax error reporting */
355 	bool heredoc_scan_ahead;
356 	int heredoc_indentation;
357 	bool heredoc_indentation_uses_spaces;
358 
359 	/* original (unfiltered) script */
360 	unsigned char *script_org;
361 	size_t script_org_size;
362 
363 	/* filtered script */
364 	unsigned char *script_filtered;
365 	size_t script_filtered_size;
366 
367 	/* input/output filters */
368 	zend_encoding_filter input_filter;
369 	zend_encoding_filter output_filter;
370 	const zend_encoding *script_encoding;
371 
372 	/* initial string length after scanning to first variable */
373 	int scanned_string_len;
374 
375 	/* hooks */
376 	void (*on_event)(
377 		zend_php_scanner_event event, int token, int line,
378 		const char *text, size_t length, void *context);
379 	void *on_event_context;
380 };
381 
382 #endif /* ZEND_GLOBALS_H */
383