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