zend.h 15 KB

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