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