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