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