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 filenames_table;
81 
82 	HashTable *auto_globals;
83 
84 	zend_bool parse_error;
85 	zend_bool in_compilation;
86 	zend_bool short_tags;
87 
88 	zend_bool unclean_shutdown;
89 
90 	zend_bool ini_parser_unbuffered_errors;
91 
92 	zend_llist open_files;
93 
94 	struct _zend_ini_parser_param *ini_parser_param;
95 
96 	zend_bool skip_shebang;
97 	zend_bool increment_lineno;
98 
99 	zend_string *doc_comment;
100 	uint32_t extra_fn_flags;
101 
102 	uint32_t compiler_options; /* set of ZEND_COMPILE_* constants */
103 
104 	zend_oparray_context context;
105 	zend_file_context file_context;
106 
107 	zend_arena *arena;
108 
109 	HashTable interned_strings;
110 
111 	const zend_encoding **script_encoding_list;
112 	size_t script_encoding_list_size;
113 	zend_bool multibyte;
114 	zend_bool detect_unicode;
115 	zend_bool encoding_declared;
116 
117 	zend_ast *ast;
118 	zend_arena *ast_arena;
119 
120 	zend_stack delayed_oplines_stack;
121 	HashTable *memoized_exprs;
122 	int memoize_mode;
123 
124 	void   *map_ptr_base;
125 	size_t  map_ptr_size;
126 	size_t  map_ptr_last;
127 
128 	HashTable *delayed_variance_obligations;
129 	HashTable *delayed_autoloads;
130 
131 	uint32_t rtd_key_counter;
132 };
133 
134 
135 struct _zend_executor_globals {
136 	zval uninitialized_zval;
137 	zval error_zval;
138 
139 	/* symbol table cache */
140 	zend_array *symtable_cache[SYMTABLE_CACHE_SIZE];
141 	/* Pointer to one past the end of the symtable_cache */
142 	zend_array **symtable_cache_limit;
143 	/* Pointer to first unused symtable_cache slot */
144 	zend_array **symtable_cache_ptr;
145 
146 	zend_array symbol_table;		/* main symbol table */
147 
148 	HashTable included_files;	/* files already included */
149 
150 	JMP_BUF *bailout;
151 
152 	int error_reporting;
153 	int exit_status;
154 
155 	HashTable *function_table;	/* function symbol table */
156 	HashTable *class_table;		/* class table */
157 	HashTable *zend_constants;	/* constants table */
158 
159 	zval          *vm_stack_top;
160 	zval          *vm_stack_end;
161 	zend_vm_stack  vm_stack;
162 	size_t         vm_stack_page_size;
163 
164 	struct _zend_execute_data *current_execute_data;
165 	zend_class_entry *fake_scope; /* used to avoid checks accessing properties */
166 
167 	zend_long precision;
168 
169 	int ticks_count;
170 
171 	uint32_t persistent_constants_count;
172 	uint32_t persistent_functions_count;
173 	uint32_t persistent_classes_count;
174 
175 	HashTable *in_autoload;
176 	zend_function *autoload_func;
177 	zend_bool full_tables_cleanup;
178 
179 	/* for extended information support */
180 	zend_bool no_extensions;
181 
182 	zend_bool vm_interrupt;
183 	zend_bool timed_out;
184 	zend_long hard_timeout;
185 
186 #ifdef ZEND_WIN32
187 	OSVERSIONINFOEX windows_version_info;
188 #endif
189 
190 	HashTable regular_list;
191 	HashTable persistent_list;
192 
193 	int user_error_handler_error_reporting;
194 	zval user_error_handler;
195 	zval user_exception_handler;
196 	zend_stack user_error_handlers_error_reporting;
197 	zend_stack user_error_handlers;
198 	zend_stack user_exception_handlers;
199 
200 	zend_error_handling_t  error_handling;
201 	zend_class_entry      *exception_class;
202 
203 	/* timeout support */
204 	zend_long timeout_seconds;
205 
206 	int lambda_count;
207 
208 	HashTable *ini_directives;
209 	HashTable *modified_ini_directives;
210 	zend_ini_entry *error_reporting_ini_entry;
211 
212 	zend_objects_store objects_store;
213 	zend_object *exception, *prev_exception;
214 	const zend_op *opline_before_exception;
215 	zend_op exception_op[3];
216 
217 	struct _zend_module_entry *current_module;
218 
219 	zend_bool active;
220 	zend_uchar flags;
221 
222 	zend_long assertions;
223 
224 	uint32_t           ht_iterators_count;     /* number of allocatd slots */
225 	uint32_t           ht_iterators_used;      /* number of used slots */
226 	HashTableIterator *ht_iterators;
227 	HashTableIterator  ht_iterators_slots[16];
228 
229 	void *saved_fpu_cw_ptr;
230 #if XPFPA_HAVE_CW
231 	XPFPA_CW_DATATYPE saved_fpu_cw;
232 #endif
233 
234 	zend_function trampoline;
235 	zend_op       call_trampoline_op;
236 
237 	zend_bool each_deprecation_thrown;
238 
239 	HashTable weakrefs;
240 
241 	zend_bool exception_ignore_args;
242 
243 	void *reserved[ZEND_MAX_RESERVED_RESOURCES];
244 };
245 
246 #define EG_FLAGS_INITIAL				(0)
247 #define EG_FLAGS_IN_SHUTDOWN			(1<<0)
248 #define EG_FLAGS_OBJECT_STORE_NO_REUSE	(1<<1)
249 #define EG_FLAGS_IN_RESOURCE_SHUTDOWN	(1<<2)
250 
251 struct _zend_ini_scanner_globals {
252 	zend_file_handle *yy_in;
253 	zend_file_handle *yy_out;
254 
255 	unsigned int yy_leng;
256 	unsigned char *yy_start;
257 	unsigned char *yy_text;
258 	unsigned char *yy_cursor;
259 	unsigned char *yy_marker;
260 	unsigned char *yy_limit;
261 	int yy_state;
262 	zend_stack state_stack;
263 
264 	char *filename;
265 	int lineno;
266 
267 	/* Modes are: ZEND_INI_SCANNER_NORMAL, ZEND_INI_SCANNER_RAW, ZEND_INI_SCANNER_TYPED */
268 	int scanner_mode;
269 };
270 
271 typedef enum {
272 	ON_TOKEN,
273 	ON_FEEDBACK,
274 	ON_STOP
275 } zend_php_scanner_event;
276 
277 struct _zend_php_scanner_globals {
278 	zend_file_handle *yy_in;
279 	zend_file_handle *yy_out;
280 
281 	unsigned int yy_leng;
282 	unsigned char *yy_start;
283 	unsigned char *yy_text;
284 	unsigned char *yy_cursor;
285 	unsigned char *yy_marker;
286 	unsigned char *yy_limit;
287 	int yy_state;
288 	zend_stack state_stack;
289 	zend_ptr_stack heredoc_label_stack;
290 	zend_bool heredoc_scan_ahead;
291 	int heredoc_indentation;
292 	zend_bool heredoc_indentation_uses_spaces;
293 
294 	/* original (unfiltered) script */
295 	unsigned char *script_org;
296 	size_t script_org_size;
297 
298 	/* filtered script */
299 	unsigned char *script_filtered;
300 	size_t script_filtered_size;
301 
302 	/* input/output filters */
303 	zend_encoding_filter input_filter;
304 	zend_encoding_filter output_filter;
305 	const zend_encoding *script_encoding;
306 
307 	/* initial string length after scanning to first variable */
308 	int scanned_string_len;
309 
310 	/* hooks */
311 	void (*on_event)(zend_php_scanner_event event, int token, int line, void *context);
312 	void *on_event_context;
313 };
314 
315 #endif /* ZEND_GLOBALS_H */
316