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