Coverage Report

Created: 2023-12-13 20:06

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