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