Coverage Report

Created: 2022-02-19 20:29

/src/php-src/Zend/zend.h
Line
Count
Source (jump to first uncovered line)
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.0.0-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
43
#define zend_sprintf sprintf
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
120k
#define INTERNAL_FUNCTION_PARAM_PASSTHRU execute_data, return_value
50
51
#define USED_RET() \
52
4.85k
  (!EX(prev_execute_data) || \
53
4.85k
   !ZEND_USER_CODE(EX(prev_execute_data)->func->common.type) || \
54
4.85k
   (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_TSRMG_FAST TSRMG_FAST_STATIC
59
#define ZEND_TSRMLS_CACHE_EXTERN() TSRMLS_CACHE_EXTERN()
60
#define ZEND_TSRMLS_CACHE_DEFINE() TSRMLS_CACHE_DEFINE()
61
#define ZEND_TSRMLS_CACHE_UPDATE() TSRMLS_CACHE_UPDATE()
62
#define ZEND_TSRMLS_CACHE TSRMLS_CACHE
63
#else
64
#define ZEND_TSRMG TSRMG
65
#define ZEND_TSRMG_FAST TSRMG_FAST
66
#define ZEND_TSRMLS_CACHE_EXTERN()
67
#define ZEND_TSRMLS_CACHE_DEFINE()
68
#define ZEND_TSRMLS_CACHE_UPDATE()
69
#define ZEND_TSRMLS_CACHE
70
#endif
71
72
ZEND_TSRMLS_CACHE_EXTERN()
73
74
struct _zend_serialize_data;
75
struct _zend_unserialize_data;
76
77
typedef struct _zend_serialize_data zend_serialize_data;
78
typedef struct _zend_unserialize_data zend_unserialize_data;
79
80
typedef struct _zend_class_name {
81
  zend_string *name;
82
  zend_string *lc_name;
83
} zend_class_name;
84
85
typedef struct _zend_trait_method_reference {
86
  zend_string *method_name;
87
  zend_string *class_name;
88
} zend_trait_method_reference;
89
90
typedef struct _zend_trait_precedence {
91
  zend_trait_method_reference trait_method;
92
  uint32_t num_excludes;
93
  zend_string *exclude_class_names[1];
94
} zend_trait_precedence;
95
96
typedef struct _zend_trait_alias {
97
  zend_trait_method_reference trait_method;
98
99
  /**
100
  * name for method to be added
101
  */
102
  zend_string *alias;
103
104
  /**
105
  * modifiers to be set on trait method
106
  */
107
  uint32_t modifiers;
108
} zend_trait_alias;
109
110
struct _zend_class_entry {
111
  char type;
112
  zend_string *name;
113
  /* class_entry or string depending on ZEND_ACC_LINKED */
114
  union {
115
    zend_class_entry *parent;
116
    zend_string *parent_name;
117
  };
118
  int refcount;
119
  uint32_t ce_flags;
120
121
  int default_properties_count;
122
  int default_static_members_count;
123
  zval *default_properties_table;
124
  zval *default_static_members_table;
125
  ZEND_MAP_PTR_DEF(zval *, static_members_table);
126
  HashTable function_table;
127
  HashTable properties_info;
128
  HashTable constants_table;
129
130
  struct _zend_property_info **properties_info_table;
131
132
  zend_function *constructor;
133
  zend_function *destructor;
134
  zend_function *clone;
135
  zend_function *__get;
136
  zend_function *__set;
137
  zend_function *__unset;
138
  zend_function *__isset;
139
  zend_function *__call;
140
  zend_function *__callstatic;
141
  zend_function *__tostring;
142
  zend_function *__debugInfo;
143
  zend_function *__serialize;
144
  zend_function *__unserialize;
145
146
  /* allocated only if class implements Iterator or IteratorAggregate interface */
147
  zend_class_iterator_funcs *iterator_funcs_ptr;
148
149
  /* handlers */
150
  union {
151
    zend_object* (*create_object)(zend_class_entry *class_type);
152
    int (*interface_gets_implemented)(zend_class_entry *iface, zend_class_entry *class_type); /* a class implements this interface */
153
  };
154
  zend_object_iterator *(*get_iterator)(zend_class_entry *ce, zval *object, int by_ref);
155
  zend_function *(*get_static_method)(zend_class_entry *ce, zend_string* method);
156
157
  /* serializer callbacks */
158
  int (*serialize)(zval *object, unsigned char **buffer, size_t *buf_len, zend_serialize_data *data);
159
  int (*unserialize)(zval *object, zend_class_entry *ce, const unsigned char *buf, size_t buf_len, zend_unserialize_data *data);
160
161
  uint32_t num_interfaces;
162
  uint32_t num_traits;
163
164
  /* class_entry or string(s) depending on ZEND_ACC_LINKED */
165
  union {
166
    zend_class_entry **interfaces;
167
    zend_class_name *interface_names;
168
  };
169
170
  zend_class_name *trait_names;
171
  zend_trait_alias **trait_aliases;
172
  zend_trait_precedence **trait_precedences;
173
  HashTable *attributes;
174
175
  union {
176
    struct {
177
      zend_string *filename;
178
      uint32_t line_start;
179
      uint32_t line_end;
180
      zend_string *doc_comment;
181
    } user;
182
    struct {
183
      const struct _zend_function_entry *builtin_functions;
184
      struct _zend_module_entry *module;
185
    } internal;
186
  } info;
187
};
188
189
typedef struct _zend_utility_functions {
190
  void (*error_function)(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message);
191
  size_t (*printf_function)(const char *format, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2);
192
  size_t (*write_function)(const char *str, size_t str_length);
193
  FILE *(*fopen_function)(const char *filename, zend_string **opened_path);
194
  void (*message_handler)(zend_long message, const void *data);
195
  zval *(*get_configuration_directive)(zend_string *name);
196
  void (*ticks_function)(int ticks);
197
  void (*on_timeout)(int seconds);
198
  zend_result (*stream_open_function)(const char *filename, zend_file_handle *handle);
199
  void (*printf_to_smart_string_function)(smart_string *buf, const char *format, va_list ap);
200
  void (*printf_to_smart_str_function)(smart_str *buf, const char *format, va_list ap);
201
  char *(*getenv_function)(const char *name, size_t name_len);
202
  zend_string *(*resolve_path_function)(const char *filename, size_t filename_len);
203
} zend_utility_functions;
204
205
typedef struct _zend_utility_values {
206
  zend_bool html_errors;
207
} zend_utility_values;
208
209
typedef size_t (*zend_write_func_t)(const char *str, size_t str_length);
210
211
27.1k
#define zend_bailout()    _zend_bailout(__FILE__, __LINE__)
212
213
#define zend_try                        \
214
12.8M
  {                             \
215
12.8M
    JMP_BUF *__orig_bailout = EG(bailout);          \
216
12.8M
    JMP_BUF __bailout;                   \
217
12.8M
                                \
218
12.8M
    EG(bailout) = &__bailout;               \
219
12.8M
    if (SETJMP(__bailout)==0) {
220
#define zend_catch                        \
221
1.23M
    } else {                       \
222
0
      EG(bailout) = __orig_bailout;
223
#define zend_end_try()                      \
224
11.6M
    }                            \
225
12.8M
    EG(bailout) = __orig_bailout;             \
226
736
  }
227
613k
#define zend_first_try    EG(bailout)=NULL; zend_try
228
229
BEGIN_EXTERN_C()
230
void zend_startup(zend_utility_functions *utility_functions);
231
void zend_shutdown(void);
232
void zend_register_standard_ini_entries(void);
233
zend_result zend_post_startup(void);
234
void zend_set_utility_values(zend_utility_values *utility_values);
235
236
ZEND_API ZEND_COLD ZEND_NORETURN void _zend_bailout(const char *filename, uint32_t lineno);
237
238
ZEND_API size_t zend_vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap);
239
ZEND_API size_t zend_spprintf(char **message, size_t max_len, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 3, 4);
240
ZEND_API zend_string *zend_vstrpprintf(size_t max_len, const char *format, va_list ap);
241
ZEND_API zend_string *zend_strpprintf(size_t max_len, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
242
243
/* Same as zend_spprintf and zend_strpprintf, without checking of format validity.
244
 * For use with custom printf specifiers such as %H. */
245
ZEND_API size_t zend_spprintf_unchecked(char **message, size_t max_len, const char *format, ...);
246
ZEND_API zend_string *zend_strpprintf_unchecked(size_t max_len, const char *format, ...);
247
248
ZEND_API const char *get_zend_version(void);
249
ZEND_API bool zend_make_printable_zval(zval *expr, zval *expr_copy);
250
ZEND_API size_t zend_print_zval(zval *expr, int indent);
251
ZEND_API void zend_print_zval_r(zval *expr, int indent);
252
ZEND_API zend_string *zend_print_zval_r_to_str(zval *expr, int indent);
253
ZEND_API void zend_print_flat_zval_r(zval *expr);
254
255
#define zend_print_variable(var) \
256
  zend_print_zval((var), 0)
257
258
ZEND_API ZEND_COLD void zend_output_debug_string(zend_bool trigger_break, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
259
260
ZEND_API void zend_activate(void);
261
ZEND_API void zend_deactivate(void);
262
ZEND_API void zend_call_destructors(void);
263
ZEND_API void zend_activate_modules(void);
264
ZEND_API void zend_deactivate_modules(void);
265
ZEND_API void zend_post_deactivate_modules(void);
266
267
ZEND_API void free_estring(char **str_p);
268
269
END_EXTERN_C()
270
271
/* output support */
272
0
#define ZEND_WRITE(str, str_len)    zend_write((str), (str_len))
273
#define ZEND_WRITE_EX(str, str_len)   write_func((str), (str_len))
274
266k
#define ZEND_PUTS(str)          zend_write((str), strlen((str)))
275
#define ZEND_PUTS_EX(str)       write_func((str), strlen((str)))
276
1.18M
#define ZEND_PUTC(c)          zend_write(&(c), 1)
277
278
BEGIN_EXTERN_C()
279
extern ZEND_API size_t (*zend_printf)(const char *format, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2);
280
extern ZEND_API zend_write_func_t zend_write;
281
extern ZEND_API FILE *(*zend_fopen)(const char *filename, zend_string **opened_path);
282
extern ZEND_API void (*zend_ticks_function)(int ticks);
283
extern ZEND_API void (*zend_interrupt_function)(zend_execute_data *execute_data);
284
extern ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message);
285
extern ZEND_API void (*zend_on_timeout)(int seconds);
286
extern ZEND_API zend_result (*zend_stream_open_function)(const char *filename, zend_file_handle *handle);
287
extern void (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_list ap);
288
extern void (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap);
289
extern ZEND_API char *(*zend_getenv)(const char *name, size_t name_len);
290
extern ZEND_API zend_string *(*zend_resolve_path)(const char *filename, size_t filename_len);
291
292
/* These two callbacks are especially for opcache */
293
extern ZEND_API zend_result (*zend_post_startup_cb)(void);
294
extern ZEND_API void (*zend_post_shutdown_cb)(void);
295
296
/* Callback for loading of not preloaded part of the script */
297
extern ZEND_API zend_result (*zend_preload_autoload)(zend_string *filename);
298
299
ZEND_API ZEND_COLD void zend_error(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
300
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
301
/* If filename is NULL the default filename is used. */
302
ZEND_API ZEND_COLD void zend_error_at(int type, const char *filename, uint32_t lineno, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 4, 5);
303
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_at_noreturn(int type, const char *filename, uint32_t lineno, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 4, 5);
304
ZEND_API ZEND_COLD void zend_error_zstr(int type, zend_string *message);
305
306
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
307
ZEND_API ZEND_COLD void zend_type_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
308
ZEND_API ZEND_COLD void zend_argument_count_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
309
ZEND_API ZEND_COLD void zend_value_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
310
311
ZEND_COLD void zenderror(const char *error);
312
313
/* The following #define is used for code duality in PHP for Engine 1 & 2 */
314
#define ZEND_STANDARD_CLASS_DEF_PTR zend_standard_class_def
315
extern ZEND_API zend_class_entry *zend_standard_class_def;
316
extern ZEND_API zend_utility_values zend_uv;
317
318
/* If DTrace is available and enabled */
319
extern ZEND_API zend_bool zend_dtrace_enabled;
320
END_EXTERN_C()
321
322
#define ZEND_UV(name) (zend_uv.name)
323
324
BEGIN_EXTERN_C()
325
ZEND_API void zend_message_dispatcher(zend_long message, const void *data);
326
327
ZEND_API zval *zend_get_configuration_directive(zend_string *name);
328
END_EXTERN_C()
329
330
/* Messages for applications of Zend */
331
35.6k
#define ZMSG_FAILED_INCLUDE_FOPEN   1L
332
3.94k
#define ZMSG_FAILED_REQUIRE_FOPEN   2L
333
0
#define ZMSG_FAILED_HIGHLIGHT_FOPEN   3L
334
0
#define ZMSG_MEMORY_LEAK_DETECTED   4L
335
0
#define ZMSG_MEMORY_LEAK_REPEATED   5L
336
0
#define ZMSG_LOG_SCRIPT_NAME      6L
337
0
#define ZMSG_MEMORY_LEAKS_GRAND_TOTAL 7L
338
339
typedef enum {
340
  EH_NORMAL = 0,
341
  EH_THROW
342
} zend_error_handling_t;
343
344
typedef struct {
345
  zend_error_handling_t  handling;
346
  zend_class_entry       *exception;
347
  zval                   user_handler;
348
} zend_error_handling;
349
350
ZEND_API void zend_save_error_handling(zend_error_handling *current);
351
ZEND_API void zend_replace_error_handling(zend_error_handling_t error_handling, zend_class_entry *exception_class, zend_error_handling *current);
352
ZEND_API void zend_restore_error_handling(zend_error_handling *saved);
353
354
typedef void (*zend_error_notify_cb)(int type, const char *error_filename, uint32_t error_lineno, zend_string *message);
355
356
BEGIN_EXTERN_C()
357
ZEND_API void zend_register_error_notify_callback(zend_error_notify_cb callback);
358
void zend_startup_error_notify_callbacks(void);
359
void zend_shutdown_error_notify_callbacks(void);
360
void zend_error_notify_all_callbacks(int type, const char *error_filename, uint32_t error_lineno, zend_string *message);
361
END_EXTERN_C()
362
363
472k
#define DEBUG_BACKTRACE_PROVIDE_OBJECT (1<<0)
364
628k
#define DEBUG_BACKTRACE_IGNORE_ARGS    (1<<1)
365
366
#include "zend_object_handlers.h"
367
#include "zend_operators.h"
368
369
#endif /* ZEND_H */