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