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_H 21 #define ZEND_H 22 23 #define ZEND_VERSION "3.4.0" 24 25 #define ZEND_ENGINE_3 26 27 #include "zend_types.h" 28 #include "zend_map_ptr.h" 29 #include "zend_errors.h" 30 #include "zend_alloc.h" 31 #include "zend_llist.h" 32 #include "zend_string.h" 33 #include "zend_hash.h" 34 #include "zend_ast.h" 35 #include "zend_gc.h" 36 #include "zend_variables.h" 37 #include "zend_iterators.h" 38 #include "zend_stream.h" 39 #include "zend_smart_str_public.h" 40 #include "zend_smart_string_public.h" 41 #include "zend_signal.h" 42 43 #define zend_sprintf sprintf 44 45 #define HANDLE_BLOCK_INTERRUPTIONS() ZEND_SIGNAL_BLOCK_INTERRUPTIONS() 46 #define HANDLE_UNBLOCK_INTERRUPTIONS() ZEND_SIGNAL_UNBLOCK_INTERRUPTIONS() 47 48 #define INTERNAL_FUNCTION_PARAMETERS zend_execute_data *execute_data, zval *return_value 49 #define INTERNAL_FUNCTION_PARAM_PASSTHRU execute_data, return_value 50 51 #define USED_RET() \ 52 (!EX(prev_execute_data) || \ 53 !ZEND_USER_CODE(EX(prev_execute_data)->func->common.type) || \ 54 (EX(prev_execute_data)->opline->result_type != IS_UNUSED)) 55 56 #ifdef ZEND_ENABLE_STATIC_TSRMLS_CACHE 57 #define ZEND_TSRMG TSRMG_STATIC 58 #define ZEND_TSRMG_FAST TSRMG_FAST_STATIC 59 #define ZEND_TSRMLS_CACHE_EXTERN() TSRMLS_CACHE_EXTERN() 60 #define ZEND_TSRMLS_CACHE_DEFINE() TSRMLS_CACHE_DEFINE() 61 #define ZEND_TSRMLS_CACHE_UPDATE() TSRMLS_CACHE_UPDATE() 62 #define ZEND_TSRMLS_CACHE TSRMLS_CACHE 63 #else 64 #define ZEND_TSRMG TSRMG 65 #define ZEND_TSRMG_FAST TSRMG_FAST 66 #define ZEND_TSRMLS_CACHE_EXTERN() 67 #define ZEND_TSRMLS_CACHE_DEFINE() 68 #define ZEND_TSRMLS_CACHE_UPDATE() 69 #define ZEND_TSRMLS_CACHE 70 #endif 71 72 ZEND_TSRMLS_CACHE_EXTERN() 73 74 struct _zend_serialize_data; 75 struct _zend_unserialize_data; 76 77 typedef struct _zend_serialize_data zend_serialize_data; 78 typedef struct _zend_unserialize_data zend_unserialize_data; 79 80 typedef struct _zend_class_name { 81 zend_string *name; 82 zend_string *lc_name; 83 } zend_class_name; 84 85 typedef struct _zend_trait_method_reference { 86 zend_string *method_name; 87 zend_string *class_name; 88 } zend_trait_method_reference; 89 90 typedef struct _zend_trait_precedence { 91 zend_trait_method_reference trait_method; 92 uint32_t num_excludes; 93 zend_string *exclude_class_names[1]; 94 } zend_trait_precedence; 95 96 typedef struct _zend_trait_alias { 97 zend_trait_method_reference trait_method; 98 99 /** 100 * name for method to be added 101 */ 102 zend_string *alias; 103 104 /** 105 * modifiers to be set on trait method 106 */ 107 uint32_t modifiers; 108 } zend_trait_alias; 109 110 struct _zend_class_entry { 111 char type; 112 zend_string *name; 113 /* class_entry or string depending on ZEND_ACC_LINKED */ 114 union { 115 zend_class_entry *parent; 116 zend_string *parent_name; 117 }; 118 int refcount; 119 uint32_t ce_flags; 120 121 int default_properties_count; 122 int default_static_members_count; 123 zval *default_properties_table; 124 zval *default_static_members_table; 125 ZEND_MAP_PTR_DEF(zval *, static_members_table); 126 HashTable function_table; 127 HashTable properties_info; 128 HashTable constants_table; 129 130 struct _zend_property_info **properties_info_table; 131 132 zend_function *constructor; 133 zend_function *destructor; 134 zend_function *clone; 135 zend_function *__get; 136 zend_function *__set; 137 zend_function *__unset; 138 zend_function *__isset; 139 zend_function *__call; 140 zend_function *__callstatic; 141 zend_function *__tostring; 142 zend_function *__debugInfo; 143 zend_function *serialize_func; 144 zend_function *unserialize_func; 145 146 /* allocated only if class implements Iterator or IteratorAggregate interface */ 147 zend_class_iterator_funcs *iterator_funcs_ptr; 148 149 /* handlers */ 150 union { 151 zend_object* (*create_object)(zend_class_entry *class_type); 152 int (*interface_gets_implemented)(zend_class_entry *iface, zend_class_entry *class_type); /* a class implements this interface */ 153 }; 154 zend_object_iterator *(*get_iterator)(zend_class_entry *ce, zval *object, int by_ref); 155 zend_function *(*get_static_method)(zend_class_entry *ce, zend_string* method); 156 157 /* serializer callbacks */ 158 int (*serialize)(zval *object, unsigned char **buffer, size_t *buf_len, zend_serialize_data *data); 159 int (*unserialize)(zval *object, zend_class_entry *ce, const unsigned char *buf, size_t buf_len, zend_unserialize_data *data); 160 161 uint32_t num_interfaces; 162 uint32_t num_traits; 163 164 /* class_entry or string(s) depending on ZEND_ACC_LINKED */ 165 union { 166 zend_class_entry **interfaces; 167 zend_class_name *interface_names; 168 }; 169 170 zend_class_name *trait_names; 171 zend_trait_alias **trait_aliases; 172 zend_trait_precedence **trait_precedences; 173 174 union { 175 struct { 176 zend_string *filename; 177 uint32_t line_start; 178 uint32_t line_end; 179 zend_string *doc_comment; 180 } user; 181 struct { 182 const struct _zend_function_entry *builtin_functions; 183 struct _zend_module_entry *module; 184 } internal; 185 } info; 186 }; 187 188 typedef struct _zend_utility_functions { 189 void (*error_function)(int type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 4, 0); 190 size_t (*printf_function)(const char *format, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2); 191 size_t (*write_function)(const char *str, size_t str_length); 192 FILE *(*fopen_function)(const char *filename, zend_string **opened_path); 193 void (*message_handler)(zend_long message, const void *data); 194 zval *(*get_configuration_directive)(zend_string *name); 195 void (*ticks_function)(int ticks); 196 void (*on_timeout)(int seconds); 197 int (*stream_open_function)(const char *filename, zend_file_handle *handle); 198 void (*printf_to_smart_string_function)(smart_string *buf, const char *format, va_list ap); 199 void (*printf_to_smart_str_function)(smart_str *buf, const char *format, va_list ap); 200 char *(*getenv_function)(char *name, size_t name_len); 201 zend_string *(*resolve_path_function)(const char *filename, size_t filename_len); 202 } zend_utility_functions; 203 204 typedef struct _zend_utility_values { 205 zend_bool html_errors; 206 } zend_utility_values; 207 208 typedef int (*zend_write_func_t)(const char *str, size_t str_length); 209 210 #define zend_bailout() _zend_bailout(__FILE__, __LINE__) 211 212 #define zend_try \ 213 { \ 214 JMP_BUF *__orig_bailout = EG(bailout); \ 215 JMP_BUF __bailout; \ 216 \ 217 EG(bailout) = &__bailout; \ 218 if (SETJMP(__bailout)==0) { 219 #define zend_catch \ 220 } else { \ 221 EG(bailout) = __orig_bailout; 222 #define zend_end_try() \ 223 } \ 224 EG(bailout) = __orig_bailout; \ 225 } 226 #define zend_first_try EG(bailout)=NULL; zend_try 227 228 BEGIN_EXTERN_C() 229 int zend_startup(zend_utility_functions *utility_functions); 230 void zend_shutdown(void); 231 void zend_register_standard_ini_entries(void); 232 int zend_post_startup(void); 233 void zend_set_utility_values(zend_utility_values *utility_values); 234 235 ZEND_API ZEND_COLD ZEND_NORETURN void _zend_bailout(const char *filename, uint32_t lineno); 236 237 ZEND_API size_t zend_vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap); 238 ZEND_API size_t zend_spprintf(char **message, size_t max_len, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 3, 4); 239 ZEND_API zend_string *zend_vstrpprintf(size_t max_len, const char *format, va_list ap); 240 ZEND_API zend_string *zend_strpprintf(size_t max_len, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3); 241 242 /* Same as zend_spprintf and zend_strpprintf, without checking of format validity. 243 * For use with custom printf specifiers such as %H. */ 244 ZEND_API size_t zend_spprintf_unchecked(char **message, size_t max_len, const char *format, ...); 245 ZEND_API zend_string *zend_strpprintf_unchecked(size_t max_len, const char *format, ...); 246 247 ZEND_API char *get_zend_version(void); 248 ZEND_API int zend_make_printable_zval(zval *expr, zval *expr_copy); 249 ZEND_API size_t zend_print_zval(zval *expr, int indent); 250 ZEND_API void zend_print_zval_r(zval *expr, int indent); 251 ZEND_API zend_string *zend_print_zval_r_to_str(zval *expr, int indent); 252 ZEND_API void zend_print_flat_zval_r(zval *expr); 253 254 #define zend_print_variable(var) \ 255 zend_print_zval((var), 0) 256 257 ZEND_API ZEND_COLD void zend_output_debug_string(zend_bool trigger_break, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3); 258 259 ZEND_API void zend_activate(void); 260 ZEND_API void zend_deactivate(void); 261 ZEND_API void zend_call_destructors(void); 262 ZEND_API void zend_activate_modules(void); 263 ZEND_API void zend_deactivate_modules(void); 264 ZEND_API void zend_post_deactivate_modules(void); 265 266 ZEND_API void free_estring(char **str_p); 267 268 END_EXTERN_C() 269 270 /* output support */ 271 #define ZEND_WRITE(str, str_len) zend_write((str), (str_len)) 272 #define ZEND_WRITE_EX(str, str_len) write_func((str), (str_len)) 273 #define ZEND_PUTS(str) zend_write((str), strlen((str))) 274 #define ZEND_PUTS_EX(str) write_func((str), strlen((str))) 275 #define ZEND_PUTC(c) zend_write(&(c), 1) 276 277 BEGIN_EXTERN_C() 278 extern ZEND_API size_t (*zend_printf)(const char *format, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2); 279 extern ZEND_API zend_write_func_t zend_write; 280 extern ZEND_API FILE *(*zend_fopen)(const char *filename, zend_string **opened_path); 281 extern ZEND_API void (*zend_ticks_function)(int ticks); 282 extern ZEND_API void (*zend_interrupt_function)(zend_execute_data *execute_data); 283 extern ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 4, 0); 284 extern ZEND_API void (*zend_on_timeout)(int seconds); 285 extern ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle); 286 extern void (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_list ap); 287 extern void (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap); 288 extern ZEND_API char *(*zend_getenv)(char *name, size_t name_len); 289 extern ZEND_API zend_string *(*zend_resolve_path)(const char *filename, size_t filename_len); 290 291 /* These two callbacks are especially for opcache */ 292 extern ZEND_API int (*zend_post_startup_cb)(void); 293 extern ZEND_API void (*zend_post_shutdown_cb)(void); 294 295 /* Callback for loading of not preloaded part of the script */ 296 extern ZEND_API int (*zend_preload_autoload)(zend_string *filename); 297 298 ZEND_API ZEND_COLD void zend_error(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3); 299 ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3); 300 /* If filename is NULL the default filename is used. */ 301 ZEND_API ZEND_COLD void zend_error_at(int type, const char *filename, uint32_t lineno, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 4, 5); 302 ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_at_noreturn(int type, const char *filename, uint32_t lineno, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 4, 5); 303 304 ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3); 305 ZEND_API ZEND_COLD void zend_type_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2); 306 ZEND_API ZEND_COLD void zend_internal_type_error(zend_bool throw_exception, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3); 307 ZEND_API ZEND_COLD void zend_internal_argument_count_error(zend_bool throw_exception, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3); 308 309 ZEND_COLD void zenderror(const char *error); 310 311 /* The following #define is used for code duality in PHP for Engine 1 & 2 */ 312 #define ZEND_STANDARD_CLASS_DEF_PTR zend_standard_class_def 313 extern ZEND_API zend_class_entry *zend_standard_class_def; 314 extern ZEND_API zend_utility_values zend_uv; 315 316 /* If DTrace is available and enabled */ 317 extern ZEND_API zend_bool zend_dtrace_enabled; 318 END_EXTERN_C() 319 320 #define ZEND_UV(name) (zend_uv.name) 321 322 BEGIN_EXTERN_C() 323 ZEND_API void zend_message_dispatcher(zend_long message, const void *data); 324 325 ZEND_API zval *zend_get_configuration_directive(zend_string *name); 326 END_EXTERN_C() 327 328 /* Messages for applications of Zend */ 329 #define ZMSG_FAILED_INCLUDE_FOPEN 1L 330 #define ZMSG_FAILED_REQUIRE_FOPEN 2L 331 #define ZMSG_FAILED_HIGHLIGHT_FOPEN 3L 332 #define ZMSG_MEMORY_LEAK_DETECTED 4L 333 #define ZMSG_MEMORY_LEAK_REPEATED 5L 334 #define ZMSG_LOG_SCRIPT_NAME 6L 335 #define ZMSG_MEMORY_LEAKS_GRAND_TOTAL 7L 336 337 typedef enum { 338 EH_NORMAL = 0, 339 EH_THROW 340 } zend_error_handling_t; 341 342 typedef struct { 343 zend_error_handling_t handling; 344 zend_class_entry *exception; 345 zval user_handler; 346 } zend_error_handling; 347 348 ZEND_API void zend_save_error_handling(zend_error_handling *current); 349 ZEND_API void zend_replace_error_handling(zend_error_handling_t error_handling, zend_class_entry *exception_class, zend_error_handling *current); 350 ZEND_API void zend_restore_error_handling(zend_error_handling *saved); 351 352 #define DEBUG_BACKTRACE_PROVIDE_OBJECT (1<<0) 353 #define DEBUG_BACKTRACE_IGNORE_ARGS (1<<1) 354 355 #include "zend_object_handlers.h" 356 #include "zend_operators.h" 357 358 #endif /* ZEND_H */ 359