zend.h 13 KB

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