xref: /PHP-7.1/Zend/zend.h (revision ccd4716e)
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@zend.com>                                |
16    |          Zeev Suraski <zeev@zend.com>                                |
17    +----------------------------------------------------------------------+
18 */
19 
20 /* $Id$ */
21 
22 #ifndef ZEND_H
23 #define ZEND_H
24 
25 #define ZEND_VERSION "3.1.0"
26 
27 #define ZEND_ENGINE_3
28 
29 #define ZEND_MAX_RESERVED_RESOURCES	4
30 
31 #include "zend_types.h"
32 #include "zend_errors.h"
33 #include "zend_alloc.h"
34 #include "zend_llist.h"
35 #include "zend_string.h"
36 #include "zend_hash.h"
37 #include "zend_ast.h"
38 #include "zend_gc.h"
39 #include "zend_variables.h"
40 #include "zend_iterators.h"
41 #include "zend_stream.h"
42 #include "zend_smart_str_public.h"
43 #include "zend_signal.h"
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_TSRMLS_CACHE_EXTERN() TSRMLS_CACHE_EXTERN()
59 #define ZEND_TSRMLS_CACHE_DEFINE() TSRMLS_CACHE_DEFINE()
60 #define ZEND_TSRMLS_CACHE_UPDATE() TSRMLS_CACHE_UPDATE()
61 #define ZEND_TSRMLS_CACHE TSRMLS_CACHE
62 #else
63 #define ZEND_TSRMG TSRMG
64 #define ZEND_TSRMLS_CACHE_EXTERN()
65 #define ZEND_TSRMLS_CACHE_DEFINE()
66 #define ZEND_TSRMLS_CACHE_UPDATE()
67 #define ZEND_TSRMLS_CACHE
68 #endif
69 
70 ZEND_TSRMLS_CACHE_EXTERN()
71 
72 #ifdef HAVE_NORETURN
73 # ifdef ZEND_NORETURN_ALIAS
74 ZEND_COLD void zend_error_noreturn(int type, const char *format, ...) ZEND_NORETURN ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
75 # else
76 ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
77 # endif
78 #else
79 # define zend_error_noreturn zend_error
80 #endif
81 
82 struct _zend_serialize_data;
83 struct _zend_unserialize_data;
84 
85 typedef struct _zend_serialize_data zend_serialize_data;
86 typedef struct _zend_unserialize_data zend_unserialize_data;
87 
88 typedef struct _zend_trait_method_reference {
89 	zend_string *method_name;
90 	zend_class_entry *ce;
91 	zend_string *class_name;
92 } zend_trait_method_reference;
93 
94 typedef struct _zend_trait_precedence {
95 	zend_trait_method_reference *trait_method;
96 	union {
97 		zend_class_entry  *ce;
98 		zend_string       *class_name;
99 	} *exclude_from_classes;
100 } zend_trait_precedence;
101 
102 typedef struct _zend_trait_alias {
103 	zend_trait_method_reference *trait_method;
104 
105 	/**
106 	* name for method to be added
107 	*/
108 	zend_string *alias;
109 
110 	/**
111 	* modifiers to be set on trait method
112 	*/
113 	uint32_t modifiers;
114 } zend_trait_alias;
115 
116 struct _zend_class_entry {
117 	char type;
118 	zend_string *name;
119 	struct _zend_class_entry *parent;
120 	int refcount;
121 	uint32_t ce_flags;
122 
123 	int default_properties_count;
124 	int default_static_members_count;
125 	zval *default_properties_table;
126 	zval *default_static_members_table;
127 	zval *static_members_table;
128 	HashTable function_table;
129 	HashTable properties_info;
130 	HashTable constants_table;
131 
132 	union _zend_function *constructor;
133 	union _zend_function *destructor;
134 	union _zend_function *clone;
135 	union _zend_function *__get;
136 	union _zend_function *__set;
137 	union _zend_function *__unset;
138 	union _zend_function *__isset;
139 	union _zend_function *__call;
140 	union _zend_function *__callstatic;
141 	union _zend_function *__tostring;
142 	union _zend_function *__debugInfo;
143 	union _zend_function *serialize_func;
144 	union _zend_function *unserialize_func;
145 
146 	zend_class_iterator_funcs iterator_funcs;
147 
148 	/* handlers */
149 	zend_object* (*create_object)(zend_class_entry *class_type);
150 	zend_object_iterator *(*get_iterator)(zend_class_entry *ce, zval *object, int by_ref);
151 	int (*interface_gets_implemented)(zend_class_entry *iface, zend_class_entry *class_type); /* a class implements this interface */
152 	union _zend_function *(*get_static_method)(zend_class_entry *ce, zend_string* method);
153 
154 	/* serializer callbacks */
155 	int (*serialize)(zval *object, unsigned char **buffer, size_t *buf_len, zend_serialize_data *data);
156 	int (*unserialize)(zval *object, zend_class_entry *ce, const unsigned char *buf, size_t buf_len, zend_unserialize_data *data);
157 
158 	uint32_t num_interfaces;
159 	uint32_t num_traits;
160 	zend_class_entry **interfaces;
161 
162 	zend_class_entry **traits;
163 	zend_trait_alias **trait_aliases;
164 	zend_trait_precedence **trait_precedences;
165 
166 	union {
167 		struct {
168 			zend_string *filename;
169 			uint32_t line_start;
170 			uint32_t line_end;
171 			zend_string *doc_comment;
172 		} user;
173 		struct {
174 			const struct _zend_function_entry *builtin_functions;
175 			struct _zend_module_entry *module;
176 		} internal;
177 	} info;
178 };
179 
180 typedef struct _zend_utility_functions {
181 	void (*error_function)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 4, 0);
182 	size_t (*printf_function)(const char *format, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2);
183 	size_t (*write_function)(const char *str, size_t str_length);
184 	FILE *(*fopen_function)(const char *filename, zend_string **opened_path);
185 	void (*message_handler)(zend_long message, const void *data);
186 	zval *(*get_configuration_directive)(zend_string *name);
187 	void (*ticks_function)(int ticks);
188 	void (*on_timeout)(int seconds);
189 	int (*stream_open_function)(const char *filename, zend_file_handle *handle);
190 	size_t (*vspprintf_function)(char **pbuf, size_t max_len, const char *format, va_list ap);
191 	zend_string *(*vstrpprintf_function)(size_t max_len, const char *format, va_list ap);
192 	char *(*getenv_function)(char *name, size_t name_len);
193 	zend_string *(*resolve_path_function)(const char *filename, int filename_len);
194 } zend_utility_functions;
195 
196 typedef struct _zend_utility_values {
197 	char *import_use_extension;
198 	uint import_use_extension_length;
199 	zend_bool html_errors;
200 } zend_utility_values;
201 
202 typedef int (*zend_write_func_t)(const char *str, size_t str_length);
203 
204 #define zend_bailout()		_zend_bailout(__FILE__, __LINE__)
205 
206 #define zend_try												\
207 	{															\
208 		JMP_BUF *__orig_bailout = EG(bailout);					\
209 		JMP_BUF __bailout;										\
210 																\
211 		EG(bailout) = &__bailout;								\
212 		if (SETJMP(__bailout)==0) {
213 #define zend_catch												\
214 		} else {												\
215 			EG(bailout) = __orig_bailout;
216 #define zend_end_try()											\
217 		}														\
218 		EG(bailout) = __orig_bailout;							\
219 	}
220 #define zend_first_try		EG(bailout)=NULL;	zend_try
221 
222 BEGIN_EXTERN_C()
223 int zend_startup(zend_utility_functions *utility_functions, char **extensions);
224 void zend_shutdown(void);
225 void zend_register_standard_ini_entries(void);
226 void zend_post_startup(void);
227 void zend_set_utility_values(zend_utility_values *utility_values);
228 
229 ZEND_API ZEND_COLD void _zend_bailout(char *filename, uint lineno);
230 
231 ZEND_API char *get_zend_version(void);
232 ZEND_API int zend_make_printable_zval(zval *expr, zval *expr_copy);
233 ZEND_API size_t zend_print_zval(zval *expr, int indent);
234 ZEND_API void zend_print_zval_r(zval *expr, int indent);
235 ZEND_API zend_string *zend_print_zval_r_to_str(zval *expr, int indent);
236 ZEND_API void zend_print_flat_zval_r(zval *expr);
237 ZEND_API ZEND_COLD void zend_output_debug_string(zend_bool trigger_break, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
238 
239 ZEND_API void zend_activate(void);
240 ZEND_API void zend_deactivate(void);
241 ZEND_API void zend_call_destructors(void);
242 ZEND_API void zend_activate_modules(void);
243 ZEND_API void zend_deactivate_modules(void);
244 ZEND_API void zend_post_deactivate_modules(void);
245 
246 ZEND_API void free_estring(char **str_p);
247 END_EXTERN_C()
248 
249 /* output support */
250 #define ZEND_WRITE(str, str_len)		zend_write((str), (str_len))
251 #define ZEND_WRITE_EX(str, str_len)		write_func((str), (str_len))
252 #define ZEND_PUTS(str)					zend_write((str), strlen((str)))
253 #define ZEND_PUTS_EX(str)				write_func((str), strlen((str)))
254 #define ZEND_PUTC(c)					zend_write(&(c), 1)
255 
256 BEGIN_EXTERN_C()
257 extern ZEND_API size_t (*zend_printf)(const char *format, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2);
258 extern ZEND_API zend_write_func_t zend_write;
259 extern ZEND_API FILE *(*zend_fopen)(const char *filename, zend_string **opened_path);
260 extern ZEND_API void (*zend_ticks_function)(int ticks);
261 extern ZEND_API void (*zend_interrupt_function)(zend_execute_data *execute_data);
262 extern ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 4, 0);
263 extern ZEND_API void (*zend_on_timeout)(int seconds);
264 extern ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle);
265 extern size_t (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap);
266 extern zend_string *(*zend_vstrpprintf)(size_t max_len, const char *format, va_list ap);
267 extern ZEND_API char *(*zend_getenv)(char *name, size_t name_len);
268 extern ZEND_API zend_string *(*zend_resolve_path)(const char *filename, int filename_len);
269 
270 ZEND_API ZEND_COLD void zend_error(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
271 ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
272 ZEND_API ZEND_COLD void zend_type_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
273 ZEND_API ZEND_COLD void zend_internal_type_error(zend_bool throw_exception, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
274 ZEND_API ZEND_COLD void zend_internal_argument_count_error(zend_bool throw_exception, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
275 
276 ZEND_COLD void zenderror(const char *error);
277 
278 /* The following #define is used for code duality in PHP for Engine 1 & 2 */
279 #define ZEND_STANDARD_CLASS_DEF_PTR zend_standard_class_def
280 extern ZEND_API zend_class_entry *zend_standard_class_def;
281 extern ZEND_API zend_utility_values zend_uv;
282 
283 /* If DTrace is available and enabled */
284 extern ZEND_API zend_bool zend_dtrace_enabled;
285 END_EXTERN_C()
286 
287 #define ZEND_UV(name) (zend_uv.name)
288 
289 BEGIN_EXTERN_C()
290 ZEND_API void zend_message_dispatcher(zend_long message, const void *data);
291 
292 ZEND_API zval *zend_get_configuration_directive(zend_string *name);
293 END_EXTERN_C()
294 
295 /* Messages for applications of Zend */
296 #define ZMSG_FAILED_INCLUDE_FOPEN		1L
297 #define ZMSG_FAILED_REQUIRE_FOPEN		2L
298 #define ZMSG_FAILED_HIGHLIGHT_FOPEN		3L
299 #define ZMSG_MEMORY_LEAK_DETECTED		4L
300 #define ZMSG_MEMORY_LEAK_REPEATED		5L
301 #define ZMSG_LOG_SCRIPT_NAME			6L
302 #define ZMSG_MEMORY_LEAKS_GRAND_TOTAL	7L
303 
304 typedef enum {
305 	EH_NORMAL = 0,
306 	EH_SUPPRESS,
307 	EH_THROW
308 } zend_error_handling_t;
309 
310 typedef struct {
311 	zend_error_handling_t  handling;
312 	zend_class_entry       *exception;
313 	zval                   user_handler;
314 } zend_error_handling;
315 
316 ZEND_API void zend_save_error_handling(zend_error_handling *current);
317 ZEND_API void zend_replace_error_handling(zend_error_handling_t error_handling, zend_class_entry *exception_class, zend_error_handling *current);
318 ZEND_API void zend_restore_error_handling(zend_error_handling *saved);
319 
320 #define DEBUG_BACKTRACE_PROVIDE_OBJECT (1<<0)
321 #define DEBUG_BACKTRACE_IGNORE_ARGS    (1<<1)
322 
323 #include "zend_object_handlers.h"
324 #include "zend_operators.h"
325 
326 #endif /* ZEND_H */
327 
328 /*
329  * Local variables:
330  * tab-width: 4
331  * c-basic-offset: 4
332  * indent-tabs-mode: t
333  * End:
334  */
335