Coverage Report

Created: 2026-02-14 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/php-src/Zend/zend.c
Line
Count
Source
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
#include "zend.h"
21
#include "zend_extensions.h"
22
#include "zend_modules.h"
23
#include "zend_constants.h"
24
#include "zend_list.h"
25
#include "zend_API.h"
26
#include "zend_exceptions.h"
27
#include "zend_builtin_functions.h"
28
#include "zend_ini.h"
29
#include "zend_vm.h"
30
#include "zend_dtrace.h"
31
#include "zend_virtual_cwd.h"
32
#include "zend_smart_str.h"
33
#include "zend_smart_string.h"
34
#include "zend_cpuinfo.h"
35
#include "zend_attributes.h"
36
#include "zend_observer.h"
37
#include "zend_fibers.h"
38
#include "zend_call_stack.h"
39
#include "zend_max_execution_timer.h"
40
#include "zend_hrtime.h"
41
#include "zend_enum.h"
42
#include "zend_closures.h"
43
#include "Optimizer/zend_optimizer.h"
44
#include "php.h"
45
#include "php_globals.h"
46
47
// FIXME: Breaks the declaration of the function below
48
#undef zenderror
49
50
static size_t global_map_ptr_last = 0;
51
static bool startup_done = false;
52
53
#ifdef ZTS
54
ZEND_API int compiler_globals_id;
55
ZEND_API int executor_globals_id;
56
ZEND_API size_t compiler_globals_offset;
57
ZEND_API size_t executor_globals_offset;
58
static HashTable *global_function_table = NULL;
59
static HashTable *global_class_table = NULL;
60
static HashTable *global_constants_table = NULL;
61
static HashTable *global_auto_globals_table = NULL;
62
static HashTable *global_persistent_list = NULL;
63
TSRMLS_MAIN_CACHE_DEFINE()
64
# define GLOBAL_FUNCTION_TABLE    global_function_table
65
# define GLOBAL_CLASS_TABLE     global_class_table
66
# define GLOBAL_CONSTANTS_TABLE   global_constants_table
67
# define GLOBAL_AUTO_GLOBALS_TABLE  global_auto_globals_table
68
#else
69
16
# define GLOBAL_FUNCTION_TABLE    CG(function_table)
70
16
# define GLOBAL_CLASS_TABLE     CG(class_table)
71
16
# define GLOBAL_AUTO_GLOBALS_TABLE  CG(auto_globals)
72
16
# define GLOBAL_CONSTANTS_TABLE   EG(zend_constants)
73
#endif
74
75
ZEND_API zend_utility_values zend_uv;
76
ZEND_API bool zend_dtrace_enabled;
77
78
/* version information */
79
static char *zend_version_info;
80
static uint32_t zend_version_info_length;
81
32
#define ZEND_CORE_VERSION_INFO  "Zend Engine v" ZEND_VERSION ", Copyright (c) Zend Technologies\n"
82
14.4k
#define PRINT_ZVAL_INDENT 4
83
84
/* true multithread-shared globals */
85
ZEND_API zend_class_entry *zend_standard_class_def = NULL;
86
ZEND_API size_t (*zend_printf)(const char *format, ...);
87
ZEND_API zend_write_func_t zend_write;
88
ZEND_API FILE *(*zend_fopen)(zend_string *filename, zend_string **opened_path);
89
ZEND_API zend_result (*zend_stream_open_function)(zend_file_handle *handle);
90
ZEND_API void (*zend_ticks_function)(int ticks);
91
ZEND_API void (*zend_interrupt_function)(zend_execute_data *execute_data);
92
ZEND_API void (*zend_error_cb)(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message);
93
void (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_list ap);
94
void (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap);
95
ZEND_API char *(*zend_getenv)(const char *name, size_t name_len);
96
ZEND_API zend_string *(*zend_resolve_path)(zend_string *filename);
97
ZEND_API zend_result (*zend_post_startup_cb)(void) = NULL;
98
ZEND_API void (*zend_post_shutdown_cb)(void) = NULL;
99
ZEND_API void (*zend_accel_schedule_restart_hook)(int reason) = NULL;
100
ZEND_ATTRIBUTE_NONNULL ZEND_API zend_result (*zend_random_bytes)(void *bytes, size_t size, char *errstr, size_t errstr_size) = NULL;
101
ZEND_ATTRIBUTE_NONNULL ZEND_API void (*zend_random_bytes_insecure)(zend_random_bytes_insecure_state *state, void *bytes, size_t size) = NULL;
102
103
/* This callback must be signal handler safe! */
104
void (*zend_on_timeout)(int seconds);
105
106
static void (*zend_message_dispatcher_p)(zend_long message, const void *data);
107
static zval *(*zend_get_configuration_directive_p)(zend_string *name);
108
109
#if ZEND_RC_DEBUG
110
ZEND_API bool zend_rc_debug = 0;
111
#endif
112
113
static ZEND_INI_MH(OnUpdateErrorReporting) /* {{{ */
114
387
{
115
387
  if (!new_value) {
116
0
    EG(error_reporting) = E_ALL;
117
387
  } else {
118
387
    EG(error_reporting) = atoi(ZSTR_VAL(new_value));
119
387
  }
120
387
  return SUCCESS;
121
387
}
122
/* }}} */
123
124
static ZEND_INI_MH(OnUpdateGCEnabled) /* {{{ */
125
172
{
126
172
  bool val;
127
128
172
  val = zend_ini_parse_bool(new_value);
129
172
  gc_enable(val);
130
131
172
  return SUCCESS;
132
172
}
133
/* }}} */
134
135
static ZEND_INI_DISP(zend_gc_enabled_displayer_cb) /* {{{ */
136
8
{
137
8
  if (gc_enabled()) {
138
8
    ZEND_PUTS("On");
139
8
  } else {
140
0
    ZEND_PUTS("Off");
141
0
  }
142
8
}
143
/* }}} */
144
145
146
static ZEND_INI_MH(OnUpdateScriptEncoding) /* {{{ */
147
16
{
148
16
  if (!CG(multibyte)) {
149
16
    return FAILURE;
150
16
  }
151
0
  if (!zend_multibyte_get_functions()) {
152
0
    return SUCCESS;
153
0
  }
154
0
  return zend_multibyte_set_script_encoding_by_string(new_value ? ZSTR_VAL(new_value) : NULL, new_value ? ZSTR_LEN(new_value) : 0);
155
0
}
156
/* }}} */
157
158
static ZEND_INI_MH(OnUpdateAssertions) /* {{{ */
159
118
{
160
118
  zend_long *p = ZEND_INI_GET_ADDR();
161
162
118
  zend_long val = zend_ini_parse_quantity_warn(new_value, entry->name);
163
164
118
  if (stage != ZEND_INI_STAGE_STARTUP &&
165
102
      stage != ZEND_INI_STAGE_SHUTDOWN &&
166
102
      *p != val &&
167
80
      (*p < 0 || val < 0)) {
168
5
    zend_error(E_WARNING, "zend.assertions may be completely enabled or disabled only in php.ini");
169
5
    return FAILURE;
170
5
  }
171
172
113
  *p = val;
173
113
  return SUCCESS;
174
118
}
175
/* }}} */
176
177
static ZEND_INI_MH(OnSetExceptionStringParamMaxLen) /* {{{ */
178
104
{
179
104
  zend_long i = ZEND_ATOL(ZSTR_VAL(new_value));
180
104
  if (i >= 0 && i <= 1000000) {
181
68
    EG(exception_string_param_max_len) = i;
182
68
    return SUCCESS;
183
68
  } else {
184
36
    return FAILURE;
185
36
  }
186
104
}
187
/* }}} */
188
189
#ifdef ZEND_CHECK_STACK_LIMIT
190
static ZEND_INI_MH(OnUpdateMaxAllowedStackSize) /* {{{ */
191
16
{
192
16
  zend_long size = zend_ini_parse_quantity_warn(new_value, entry->name);
193
194
16
  if (size < ZEND_MAX_ALLOWED_STACK_SIZE_UNCHECKED) {
195
0
    zend_error(E_WARNING, "Invalid \"%s\" setting. Value must be >= %d, but got " ZEND_LONG_FMT,
196
0
      ZSTR_VAL(entry->name), ZEND_MAX_ALLOWED_STACK_SIZE_UNCHECKED, size);
197
0
    return FAILURE;
198
0
  }
199
200
16
  EG(max_allowed_stack_size) = size;
201
202
16
  return SUCCESS;
203
16
}
204
/* }}} */
205
206
static ZEND_INI_MH(OnUpdateReservedStackSize) /* {{{ */
207
16
{
208
16
  zend_ulong size = zend_ini_parse_uquantity_warn(new_value, entry->name);
209
210
  /* Min value accounts for alloca, PCRE2 START_FRAMES_SIZE, and some buffer
211
   * for normal function calls.
212
   * We could reduce this on systems without alloca if we also add stack size
213
   * checks before pcre2_match(). */
214
#ifdef ZEND_ALLOCA_MAX_SIZE
215
  zend_ulong min = ZEND_ALLOCA_MAX_SIZE + 16*1024;
216
#else
217
16
  zend_ulong min = 32*1024;
218
16
#endif
219
220
#if defined(__SANITIZE_ADDRESS__) || __has_feature(memory_sanitizer)
221
  /* AddressSanitizer and MemorySanitizer use more stack due to
222
   * instrumentation */
223
  min *= 10;
224
#endif
225
226
16
  if (size == 0) {
227
16
    size = min;
228
16
  } else if (size < min) {
229
0
    zend_error(E_WARNING, "Invalid \"%s\" setting. Value must be >= " ZEND_ULONG_FMT ", but got " ZEND_ULONG_FMT "\n",
230
0
      ZSTR_VAL(entry->name), min, size);
231
0
    return FAILURE;
232
0
  }
233
234
16
  EG(reserved_stack_size) = size;
235
236
16
  return SUCCESS;
237
16
}
238
/* }}} */
239
#endif /* ZEND_CHECK_STACK_LIMIT */
240
241
static ZEND_INI_MH(OnUpdateFiberStackSize) /* {{{ */
242
50
{
243
50
  if (new_value) {
244
17
    zend_long tmp = zend_ini_parse_quantity_warn(new_value, entry->name);
245
17
    if (tmp < 0) {
246
9
      zend_error(E_WARNING, "fiber.stack_size must be a positive number");
247
9
      return FAILURE;
248
9
    }
249
8
    EG(fiber_stack_size) = tmp;
250
33
  } else {
251
33
    EG(fiber_stack_size) = ZEND_FIBER_DEFAULT_C_STACK_SIZE;
252
33
  }
253
41
  return SUCCESS;
254
50
}
255
/* }}} */
256
257
#if ZEND_DEBUG
258
# define SIGNAL_CHECK_DEFAULT "1"
259
#else
260
# define SIGNAL_CHECK_DEFAULT "0"
261
#endif
262
263
ZEND_INI_BEGIN()
264
  ZEND_INI_ENTRY("error_reporting",       NULL,   ZEND_INI_ALL,   OnUpdateErrorReporting)
265
  STD_ZEND_INI_BOOLEAN("fatal_error_backtraces",      "1",  ZEND_INI_ALL,       OnUpdateBool, fatal_error_backtrace_on,      zend_executor_globals, executor_globals)
266
  STD_ZEND_INI_ENTRY("zend.assertions",       "1",    ZEND_INI_ALL,       OnUpdateAssertions,           assertions,   zend_executor_globals,  executor_globals)
267
  ZEND_INI_ENTRY3_EX("zend.enable_gc",        "1",  ZEND_INI_ALL,   OnUpdateGCEnabled, NULL, NULL, NULL, zend_gc_enabled_displayer_cb)
268
  STD_ZEND_INI_BOOLEAN("zend.multibyte", "0", ZEND_INI_PERDIR, OnUpdateBool, multibyte,      zend_compiler_globals, compiler_globals)
269
  ZEND_INI_ENTRY("zend.script_encoding",      NULL,   ZEND_INI_ALL,   OnUpdateScriptEncoding)
270
  STD_ZEND_INI_BOOLEAN("zend.detect_unicode",     "1",  ZEND_INI_ALL,   OnUpdateBool, detect_unicode, zend_compiler_globals, compiler_globals)
271
#ifdef ZEND_SIGNALS
272
  STD_ZEND_INI_BOOLEAN("zend.signal_check", SIGNAL_CHECK_DEFAULT, ZEND_INI_SYSTEM, OnUpdateBool, check, zend_signal_globals_t, zend_signal_globals)
273
#endif
274
  STD_ZEND_INI_BOOLEAN("zend.exception_ignore_args",  "0",  ZEND_INI_ALL,   OnUpdateBool, exception_ignore_args, zend_executor_globals, executor_globals)
275
  STD_ZEND_INI_ENTRY("zend.exception_string_param_max_len", "15", ZEND_INI_ALL, OnSetExceptionStringParamMaxLen,  exception_string_param_max_len,   zend_executor_globals,  executor_globals)
276
  STD_ZEND_INI_ENTRY("fiber.stack_size",    NULL,     ZEND_INI_ALL,   OnUpdateFiberStackSize,   fiber_stack_size, zend_executor_globals,    executor_globals)
277
#ifdef ZEND_CHECK_STACK_LIMIT
278
  /* The maximum allowed call stack size. 0: auto detect, -1: no limit. For fibers, this is fiber.stack_size. */
279
  STD_ZEND_INI_ENTRY("zend.max_allowed_stack_size", "0",  ZEND_INI_SYSTEM,  OnUpdateMaxAllowedStackSize,  max_allowed_stack_size,   zend_executor_globals,  executor_globals)
280
  /* Subtracted from the max allowed stack size, as a buffer, when checking for overflow. 0: auto detect. */
281
  STD_ZEND_INI_ENTRY("zend.reserved_stack_size",  "0",  ZEND_INI_SYSTEM,  OnUpdateReservedStackSize,  reserved_stack_size,    zend_executor_globals,  executor_globals)
282
#endif
283
284
ZEND_INI_END()
285
286
ZEND_API size_t zend_vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) /* {{{ */
287
15.2M
{
288
15.2M
  smart_string buf = {0};
289
290
  /* since there are places where (v)spprintf called without checking for null,
291
     a bit of defensive coding here */
292
15.2M
  if (!pbuf) {
293
0
    return 0;
294
0
  }
295
296
15.2M
  zend_printf_to_smart_string(&buf, format, ap);
297
298
15.2M
  if (max_len && buf.len > max_len) {
299
0
    buf.len = max_len;
300
0
  }
301
302
15.2M
  smart_string_0(&buf);
303
304
15.2M
  if (buf.c) {
305
15.2M
    *pbuf = buf.c;
306
15.2M
    return buf.len;
307
15.2M
  } else {
308
0
    *pbuf = estrndup("", 0);
309
0
    return 0;
310
0
  }
311
15.2M
}
312
/* }}} */
313
314
ZEND_API size_t zend_spprintf(char **message, size_t max_len, const char *format, ...) /* {{{ */
315
25.8k
{
316
25.8k
  va_list arg;
317
25.8k
  size_t len;
318
319
25.8k
  va_start(arg, format);
320
25.8k
  len = zend_vspprintf(message, max_len, format, arg);
321
25.8k
  va_end(arg);
322
25.8k
  return len;
323
25.8k
}
324
/* }}} */
325
326
ZEND_API size_t zend_spprintf_unchecked(char **message, size_t max_len, const char *format, ...) /* {{{ */
327
0
{
328
0
  va_list arg;
329
0
  size_t len;
330
331
0
  va_start(arg, format);
332
0
  len = zend_vspprintf(message, max_len, format, arg);
333
0
  va_end(arg);
334
0
  return len;
335
0
}
336
/* }}} */
337
338
ZEND_API zend_string *zend_vstrpprintf(size_t max_len, const char *format, va_list ap) /* {{{ */
339
3.52M
{
340
3.52M
  smart_str buf = {0};
341
342
3.52M
  zend_printf_to_smart_str(&buf, format, ap);
343
344
3.52M
  if (!buf.s) {
345
0
    return ZSTR_EMPTY_ALLOC();
346
0
  }
347
348
3.52M
  if (max_len && ZSTR_LEN(buf.s) > max_len) {
349
0
    ZSTR_LEN(buf.s) = max_len;
350
0
  }
351
352
3.52M
  return smart_str_extract(&buf);
353
3.52M
}
354
/* }}} */
355
356
ZEND_API zend_string *zend_strpprintf(size_t max_len, const char *format, ...) /* {{{ */
357
123k
{
358
123k
  va_list arg;
359
123k
  zend_string *str;
360
361
123k
  va_start(arg, format);
362
123k
  str = zend_vstrpprintf(max_len, format, arg);
363
123k
  va_end(arg);
364
123k
  return str;
365
123k
}
366
/* }}} */
367
368
ZEND_API zend_string *zend_strpprintf_unchecked(size_t max_len, const char *format, ...) /* {{{ */
369
777k
{
370
777k
  va_list arg;
371
777k
  zend_string *str;
372
373
777k
  va_start(arg, format);
374
777k
  str = zend_vstrpprintf(max_len, format, arg);
375
777k
  va_end(arg);
376
777k
  return str;
377
777k
}
378
/* }}} */
379
380
static void zend_print_zval_r_to_buf(smart_str *buf, zval *expr, int indent);
381
382
static void print_hash(smart_str *buf, HashTable *ht, int indent, bool is_object) /* {{{ */
383
3.62k
{
384
3.62k
  zval *tmp;
385
3.62k
  zend_string *string_key;
386
3.62k
  zend_ulong num_key;
387
3.62k
  int i;
388
389
28.1k
  for (i = 0; i < indent; i++) {
390
24.5k
    smart_str_appendc(buf, ' ');
391
24.5k
  }
392
3.62k
  smart_str_appends(buf, "(\n");
393
3.62k
  indent += PRINT_ZVAL_INDENT;
394
18.2k
  ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) {
395
69.8k
    for (i = 0; i < indent; i++) {
396
62.6k
      smart_str_appendc(buf, ' ');
397
62.6k
    }
398
18.2k
    smart_str_appendc(buf, '[');
399
18.2k
    if (string_key) {
400
2.89k
      if (is_object) {
401
1.45k
        const char *prop_name, *class_name;
402
1.45k
        size_t prop_len;
403
1.45k
        int mangled = zend_unmangle_property_name_ex(string_key, &class_name, &prop_name, &prop_len);
404
405
1.45k
        smart_str_appendl(buf, prop_name, prop_len);
406
1.45k
        if (class_name && mangled == SUCCESS) {
407
0
          if (class_name[0] == '*') {
408
0
            smart_str_appends(buf, ":protected");
409
0
          } else {
410
0
            smart_str_appends(buf, ":");
411
0
            smart_str_appends(buf, class_name);
412
0
            smart_str_appends(buf, ":private");
413
0
          }
414
0
        }
415
1.45k
      } else {
416
1.44k
        smart_str_append(buf, string_key);
417
1.44k
      }
418
4.30k
    } else {
419
4.30k
      smart_str_append_long(buf, num_key);
420
4.30k
    }
421
18.2k
    smart_str_appends(buf, "] => ");
422
18.2k
    zend_print_zval_r_to_buf(buf, tmp, indent+PRINT_ZVAL_INDENT);
423
18.2k
    smart_str_appends(buf, "\n");
424
18.2k
  } ZEND_HASH_FOREACH_END();
425
3.62k
  indent -= PRINT_ZVAL_INDENT;
426
28.1k
  for (i = 0; i < indent; i++) {
427
24.5k
    smart_str_appendc(buf, ' ');
428
24.5k
  }
429
3.62k
  smart_str_appends(buf, ")\n");
430
3.62k
}
431
/* }}} */
432
433
static void print_flat_hash(smart_str *buf, HashTable *ht) /* {{{ */
434
0
{
435
0
  zval *tmp;
436
0
  zend_string *string_key;
437
0
  zend_ulong num_key;
438
0
  int i = 0;
439
440
0
  ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) {
441
0
    if (i++ > 0) {
442
0
      smart_str_appendc(buf, ',');
443
0
    }
444
0
    smart_str_appendc(buf, '[');
445
0
    if (string_key) {
446
0
      smart_str_append(buf, string_key);
447
0
    } else {
448
0
      smart_str_append_unsigned(buf, num_key);
449
0
    }
450
0
    smart_str_appends(buf, "] => ");
451
0
    zend_print_flat_zval_r_to_buf(buf, tmp);
452
0
  } ZEND_HASH_FOREACH_END();
453
0
}
454
/* }}} */
455
456
ZEND_API bool zend_make_printable_zval(zval *expr, zval *expr_copy) /* {{{ */
457
0
{
458
0
  if (Z_TYPE_P(expr) == IS_STRING) {
459
0
    return 0;
460
0
  } else {
461
0
    ZVAL_STR(expr_copy, zval_get_string_func(expr));
462
0
    return 1;
463
0
  }
464
0
}
465
/* }}} */
466
467
ZEND_API size_t zend_print_zval(zval *expr, int indent) /* {{{ */
468
0
{
469
0
  zend_string *tmp_str;
470
0
  zend_string *str = zval_get_tmp_string(expr, &tmp_str);
471
0
  size_t len = ZSTR_LEN(str);
472
473
0
  if (len != 0) {
474
0
    zend_write(ZSTR_VAL(str), len);
475
0
  }
476
477
0
  zend_tmp_string_release(tmp_str);
478
0
  return len;
479
0
}
480
/* }}} */
481
482
void zend_print_flat_zval_r_to_buf(smart_str *buf, zval *expr) /* {{{ */
483
0
{
484
0
  switch (Z_TYPE_P(expr)) {
485
0
    case IS_ARRAY:
486
0
      smart_str_appends(buf, "Array (");
487
0
      if (!(GC_FLAGS(Z_ARRVAL_P(expr)) & GC_IMMUTABLE)) {
488
0
        if (GC_IS_RECURSIVE(Z_ARRVAL_P(expr))) {
489
0
          smart_str_appends(buf, " *RECURSION*");
490
0
          return;
491
0
        }
492
0
        GC_PROTECT_RECURSION(Z_ARRVAL_P(expr));
493
0
      }
494
0
      print_flat_hash(buf, Z_ARRVAL_P(expr));
495
0
      smart_str_appendc(buf, ')');
496
0
      GC_TRY_UNPROTECT_RECURSION(Z_ARRVAL_P(expr));
497
0
      break;
498
0
    case IS_OBJECT:
499
0
    {
500
0
      HashTable *properties;
501
0
      zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr));
502
0
      smart_str_append(buf, class_name);
503
0
      smart_str_appends(buf, " Object (");
504
0
      zend_string_release_ex(class_name, 0);
505
506
0
      if (GC_IS_RECURSIVE(Z_COUNTED_P(expr))) {
507
0
        smart_str_appends(buf, " *RECURSION*");
508
0
        return;
509
0
      }
510
511
0
      properties = Z_OBJPROP_P(expr);
512
0
      if (properties) {
513
0
        GC_PROTECT_RECURSION(Z_OBJ_P(expr));
514
0
        print_flat_hash(buf, properties);
515
0
        GC_UNPROTECT_RECURSION(Z_OBJ_P(expr));
516
0
      }
517
0
      smart_str_appendc(buf, ')');
518
0
      break;
519
0
    }
520
0
    case IS_REFERENCE:
521
0
      zend_print_flat_zval_r_to_buf(buf, Z_REFVAL_P(expr));
522
0
      break;
523
0
    case IS_STRING:
524
0
      smart_str_append(buf, Z_STR_P(expr));
525
0
      break;
526
0
    default:
527
0
    {
528
0
      zend_string *str = zval_get_string_func(expr);
529
0
      smart_str_append(buf, str);
530
0
      zend_string_release_ex(str, 0);
531
0
      break;
532
0
    }
533
0
  }
534
0
}
535
/* }}} */
536
537
ZEND_API void zend_print_flat_zval_r(zval *expr)
538
0
{
539
0
  smart_str buf = {0};
540
0
  zend_print_flat_zval_r_to_buf(&buf, expr);
541
0
  smart_str_0(&buf);
542
0
  zend_write(ZSTR_VAL(buf.s), ZSTR_LEN(buf.s));
543
0
  smart_str_free(&buf);
544
0
}
545
546
static void zend_print_zval_r_to_buf(smart_str *buf, zval *expr, int indent) /* {{{ */
547
9.17k
{
548
9.17k
  switch (Z_TYPE_P(expr)) {
549
2.24k
    case IS_ARRAY:
550
2.24k
      smart_str_appends(buf, "Array\n");
551
2.24k
      if (!(GC_FLAGS(Z_ARRVAL_P(expr)) & GC_IMMUTABLE)) {
552
1.63k
        if (GC_IS_RECURSIVE(Z_ARRVAL_P(expr))) {
553
8
          smart_str_appends(buf, " *RECURSION*");
554
8
          return;
555
8
        }
556
1.63k
        GC_PROTECT_RECURSION(Z_ARRVAL_P(expr));
557
1.63k
      }
558
2.24k
      print_hash(buf, Z_ARRVAL_P(expr), indent, false);
559
2.24k
      GC_TRY_UNPROTECT_RECURSION(Z_ARRVAL_P(expr));
560
2.24k
      break;
561
1.38k
    case IS_OBJECT:
562
1.38k
      {
563
1.38k
        HashTable *properties;
564
565
1.38k
        zend_object *zobj = Z_OBJ_P(expr);
566
1.38k
        uint32_t *guard = zend_get_recursion_guard(zobj);
567
1.38k
        zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(zobj);
568
1.38k
        smart_str_appends(buf, ZSTR_VAL(class_name));
569
1.38k
        zend_string_release_ex(class_name, 0);
570
571
1.38k
        if (!(zobj->ce->ce_flags & ZEND_ACC_ENUM)) {
572
1.36k
          smart_str_appends(buf, " Object\n");
573
1.36k
        } else {
574
19
          smart_str_appends(buf, " Enum");
575
19
          if (zobj->ce->enum_backing_type != IS_UNDEF) {
576
12
            smart_str_appendc(buf, ':');
577
12
            smart_str_appends(buf, zend_get_type_by_const(zobj->ce->enum_backing_type));
578
12
          }
579
19
          smart_str_appendc(buf, '\n');
580
19
        }
581
582
1.38k
        if (ZEND_GUARD_OR_GC_IS_RECURSIVE(guard, DEBUG, zobj)) {
583
0
          smart_str_appends(buf, " *RECURSION*");
584
0
          return;
585
0
        }
586
587
1.38k
        if ((properties = zend_get_properties_for(expr, ZEND_PROP_PURPOSE_DEBUG)) == NULL) {
588
8
          print_hash(buf, (HashTable*) &zend_empty_array, indent, true);
589
8
          break;
590
8
        }
591
592
1.37k
        ZEND_GUARD_OR_GC_PROTECT_RECURSION(guard, DEBUG, zobj);
593
1.37k
        print_hash(buf, properties, indent, true);
594
1.37k
        ZEND_GUARD_OR_GC_UNPROTECT_RECURSION(guard, DEBUG, zobj);
595
596
1.37k
        zend_release_properties(properties);
597
1.37k
        break;
598
1.38k
      }
599
1.06k
    case IS_LONG:
600
1.06k
      smart_str_append_long(buf, Z_LVAL_P(expr));
601
1.06k
      break;
602
82
    case IS_REFERENCE:
603
82
      zend_print_zval_r_to_buf(buf, Z_REFVAL_P(expr), indent);
604
82
      break;
605
1.69k
    case IS_STRING:
606
1.69k
      smart_str_append(buf, Z_STR_P(expr));
607
1.69k
      break;
608
2.69k
    default:
609
2.69k
      {
610
2.69k
        zend_string *str = zval_get_string_func(expr);
611
2.69k
        smart_str_append(buf, str);
612
2.69k
        zend_string_release_ex(str, 0);
613
2.69k
      }
614
2.69k
      break;
615
9.17k
  }
616
9.17k
}
617
/* }}} */
618
619
ZEND_API zend_string *zend_print_zval_r_to_str(zval *expr, int indent) /* {{{ */
620
1.90k
{
621
1.90k
  smart_str buf = {0};
622
1.90k
  zend_print_zval_r_to_buf(&buf, expr, indent);
623
1.90k
  smart_str_0(&buf);
624
1.90k
  return buf.s;
625
1.90k
}
626
/* }}} */
627
628
ZEND_API void zend_print_zval_r(zval *expr, int indent) /* {{{ */
629
1.87k
{
630
1.87k
  zend_string *str = zend_print_zval_r_to_str(expr, indent);
631
1.87k
  zend_write(ZSTR_VAL(str), ZSTR_LEN(str));
632
1.87k
  zend_string_release_ex(str, 0);
633
1.87k
}
634
/* }}} */
635
636
static FILE *zend_fopen_wrapper(zend_string *filename, zend_string **opened_path) /* {{{ */
637
0
{
638
0
  if (opened_path) {
639
0
    *opened_path = zend_string_copy(filename);
640
0
  }
641
0
  return fopen(ZSTR_VAL(filename), "rb");
642
0
}
643
/* }}} */
644
645
#ifdef ZTS
646
static bool short_tags_default = true;
647
static uint32_t compiler_options_default = ZEND_COMPILE_DEFAULT;
648
#else
649
16
# define short_tags_default     1
650
16
# define compiler_options_default ZEND_COMPILE_DEFAULT
651
#endif
652
653
static void zend_set_default_compile_time_values(void) /* {{{ */
654
16
{
655
  /* default compile-time values */
656
16
  CG(short_tags) = short_tags_default;
657
16
  CG(compiler_options) = compiler_options_default;
658
659
16
  CG(rtd_key_counter) = 0;
660
16
}
661
/* }}} */
662
663
#ifdef ZEND_WIN32
664
static void zend_get_windows_version_info(OSVERSIONINFOEX *osvi) /* {{{ */
665
{
666
  ZeroMemory(osvi, sizeof(OSVERSIONINFOEX));
667
  osvi->dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
668
  if(!GetVersionEx((OSVERSIONINFO *) osvi)) {
669
    ZEND_UNREACHABLE(); /* Should not happen as sizeof is used. */
670
  }
671
}
672
/* }}} */
673
#endif
674
675
static void zend_init_exception_op(void) /* {{{ */
676
16
{
677
16
  memset(EG(exception_op), 0, sizeof(EG(exception_op)));
678
16
  EG(exception_op)[0].opcode = ZEND_HANDLE_EXCEPTION;
679
16
  ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op));
680
16
  EG(exception_op)[1].opcode = ZEND_HANDLE_EXCEPTION;
681
16
  ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op)+1);
682
16
  EG(exception_op)[2].opcode = ZEND_HANDLE_EXCEPTION;
683
16
  ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op)+2);
684
16
}
685
/* }}} */
686
687
static void zend_init_call_trampoline_op(void) /* {{{ */
688
16
{
689
16
  memset(&EG(call_trampoline_op), 0, sizeof(EG(call_trampoline_op)));
690
16
  EG(call_trampoline_op).opcode = ZEND_CALL_TRAMPOLINE;
691
16
  ZEND_VM_SET_OPCODE_HANDLER(&EG(call_trampoline_op));
692
16
}
693
/* }}} */
694
695
static void auto_global_dtor(zval *zv) /* {{{ */
696
0
{
697
0
  free(Z_PTR_P(zv));
698
0
}
699
/* }}} */
700
701
#ifdef ZTS
702
static void auto_global_copy_ctor(zval *zv) /* {{{ */
703
{
704
  zend_auto_global *old_ag = (zend_auto_global *) Z_PTR_P(zv);
705
  zend_auto_global *new_ag = pemalloc(sizeof(zend_auto_global), 1);
706
707
  new_ag->name = old_ag->name;
708
  new_ag->auto_global_callback = old_ag->auto_global_callback;
709
  new_ag->jit = old_ag->jit;
710
711
  Z_PTR_P(zv) = new_ag;
712
}
713
/* }}} */
714
715
static void compiler_globals_ctor(zend_compiler_globals *compiler_globals) /* {{{ */
716
{
717
  compiler_globals->compiled_filename = NULL;
718
  compiler_globals->zend_lineno = 0;
719
720
  compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
721
  zend_hash_init(compiler_globals->function_table, 1024, NULL, ZEND_FUNCTION_DTOR, 1);
722
  zend_hash_copy(compiler_globals->function_table, global_function_table, NULL);
723
  compiler_globals->copied_functions_count = zend_hash_num_elements(compiler_globals->function_table);
724
725
  compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
726
  zend_hash_init(compiler_globals->class_table, 64, NULL, ZEND_CLASS_DTOR, 1);
727
  zend_hash_copy(compiler_globals->class_table, global_class_table, zend_class_add_ref);
728
729
  zend_set_default_compile_time_values();
730
731
  compiler_globals->auto_globals = (HashTable *) malloc(sizeof(HashTable));
732
  zend_hash_init(compiler_globals->auto_globals, 8, NULL, auto_global_dtor, 1);
733
  zend_hash_copy(compiler_globals->auto_globals, global_auto_globals_table, auto_global_copy_ctor);
734
735
  compiler_globals->script_encoding_list = NULL;
736
  compiler_globals->current_linking_class = NULL;
737
738
  /* Map region is going to be created and resized at run-time. */
739
  compiler_globals->map_ptr_real_base = NULL;
740
  compiler_globals->map_ptr_base = ZEND_MAP_PTR_BIASED_BASE(NULL);
741
  compiler_globals->map_ptr_size = 0;
742
  compiler_globals->map_ptr_last = global_map_ptr_last;
743
  compiler_globals->internal_run_time_cache = NULL;
744
  if (compiler_globals->map_ptr_last || zend_map_ptr_static_size) {
745
    /* Allocate map_ptr table */
746
    compiler_globals->map_ptr_size = ZEND_MM_ALIGNED_SIZE_EX(compiler_globals->map_ptr_last, 4096);
747
    void *base = pemalloc((zend_map_ptr_static_size + compiler_globals->map_ptr_size) * sizeof(void*), 1);
748
    compiler_globals->map_ptr_real_base = base;
749
    compiler_globals->map_ptr_base = ZEND_MAP_PTR_BIASED_BASE(base);
750
    memset(base, 0, (zend_map_ptr_static_size + compiler_globals->map_ptr_last) * sizeof(void*));
751
  }
752
  zend_init_internal_run_time_cache();
753
}
754
/* }}} */
755
756
static void compiler_globals_dtor(zend_compiler_globals *compiler_globals) /* {{{ */
757
{
758
  if (compiler_globals->function_table != GLOBAL_FUNCTION_TABLE) {
759
    uint32_t n = compiler_globals->copied_functions_count;
760
761
      /* Prevent destruction of functions copied from the main process context */
762
    if (zend_hash_num_elements(compiler_globals->function_table) <= n) {
763
      compiler_globals->function_table->nNumUsed = 0;
764
    } else {
765
      Bucket *p = compiler_globals->function_table->arData;
766
767
      compiler_globals->function_table->nNumOfElements -= n;
768
      while (n != 0) {
769
        ZVAL_UNDEF(&p->val);
770
        p++;
771
        n--;
772
      }
773
    }
774
    zend_hash_destroy(compiler_globals->function_table);
775
    free(compiler_globals->function_table);
776
  }
777
  if (compiler_globals->class_table != GLOBAL_CLASS_TABLE) {
778
    /* Child classes may reuse structures from parent classes, so destroy in reverse order. */
779
    zend_hash_graceful_reverse_destroy(compiler_globals->class_table);
780
    free(compiler_globals->class_table);
781
  }
782
  if (compiler_globals->auto_globals != GLOBAL_AUTO_GLOBALS_TABLE) {
783
    zend_hash_destroy(compiler_globals->auto_globals);
784
    free(compiler_globals->auto_globals);
785
  }
786
  if (compiler_globals->script_encoding_list) {
787
    pefree((char*)compiler_globals->script_encoding_list, 1);
788
  }
789
  if (compiler_globals->map_ptr_real_base) {
790
    free(compiler_globals->map_ptr_real_base);
791
    compiler_globals->map_ptr_real_base = NULL;
792
    compiler_globals->map_ptr_base = ZEND_MAP_PTR_BIASED_BASE(NULL);
793
    compiler_globals->map_ptr_size = 0;
794
  }
795
  if (compiler_globals->internal_run_time_cache) {
796
    pefree(compiler_globals->internal_run_time_cache, 1);
797
    compiler_globals->internal_run_time_cache = NULL;
798
  }
799
}
800
/* }}} */
801
802
static void executor_globals_ctor(zend_executor_globals *executor_globals) /* {{{ */
803
{
804
  zend_startup_constants();
805
  zend_copy_constants(executor_globals->zend_constants, GLOBAL_CONSTANTS_TABLE);
806
  zend_init_rsrc_plist();
807
  zend_init_exception_op();
808
  zend_init_call_trampoline_op();
809
  memset(&executor_globals->trampoline, 0, sizeof(zend_op_array));
810
  executor_globals->capture_warnings_during_sccp = 0;
811
  executor_globals->user_error_handler_error_reporting = 0;
812
  ZVAL_UNDEF(&executor_globals->user_error_handler);
813
  ZVAL_UNDEF(&executor_globals->user_exception_handler);
814
  executor_globals->current_execute_data = NULL;
815
  executor_globals->current_module = NULL;
816
  executor_globals->exit_status = 0;
817
#if XPFPA_HAVE_CW
818
  executor_globals->saved_fpu_cw = 0;
819
#endif
820
  executor_globals->saved_fpu_cw_ptr = NULL;
821
  executor_globals->active = false;
822
  executor_globals->bailout = NULL;
823
  executor_globals->error_handling  = EH_NORMAL;
824
  executor_globals->exception_class = NULL;
825
  executor_globals->exception = NULL;
826
  executor_globals->objects_store.object_buckets = NULL;
827
  executor_globals->current_fiber_context = NULL;
828
  executor_globals->main_fiber_context = NULL;
829
  executor_globals->active_fiber = NULL;
830
#ifdef ZEND_WIN32
831
  zend_get_windows_version_info(&executor_globals->windows_version_info);
832
#endif
833
  executor_globals->flags = EG_FLAGS_INITIAL;
834
  executor_globals->record_errors = false;
835
  executor_globals->num_errors = 0;
836
  executor_globals->errors = NULL;
837
  executor_globals->filename_override = NULL;
838
  executor_globals->lineno_override = -1;
839
#ifdef ZEND_CHECK_STACK_LIMIT
840
  executor_globals->stack_limit = (void*)0;
841
  executor_globals->stack_base = (void*)0;
842
#endif
843
#ifdef ZEND_MAX_EXECUTION_TIMERS
844
  executor_globals->pid = 0;
845
  executor_globals->oldact = (struct sigaction){0};
846
#endif
847
  memset(executor_globals->strtod_state.freelist, 0,
848
      sizeof(executor_globals->strtod_state.freelist));
849
  executor_globals->strtod_state.p5s = NULL;
850
  executor_globals->strtod_state.result = NULL;
851
}
852
/* }}} */
853
854
static void executor_globals_persistent_list_dtor(void *storage)
855
{
856
  zend_executor_globals *executor_globals = storage;
857
858
  if (&executor_globals->persistent_list != global_persistent_list) {
859
    zend_destroy_rsrc_list(&executor_globals->persistent_list);
860
  }
861
}
862
863
static void executor_globals_dtor(zend_executor_globals *executor_globals) /* {{{ */
864
{
865
  zend_ini_dtor(executor_globals->ini_directives);
866
867
  if (executor_globals->zend_constants != GLOBAL_CONSTANTS_TABLE) {
868
    zend_hash_destroy(executor_globals->zend_constants);
869
    free(executor_globals->zend_constants);
870
  }
871
}
872
/* }}} */
873
874
static void zend_new_thread_end_handler(THREAD_T thread_id) /* {{{ */
875
{
876
  zend_copy_ini_directives();
877
  zend_ini_refresh_caches(ZEND_INI_STAGE_STARTUP);
878
#ifdef ZEND_CHECK_STACK_LIMIT
879
  zend_call_stack_init();
880
#endif
881
  zend_max_execution_timer_init();
882
}
883
/* }}} */
884
#endif
885
886
#if defined(__FreeBSD__) || defined(__DragonFly__)
887
/* FreeBSD and DragonFly floating point precision fix */
888
#include <floatingpoint.h>
889
#endif
890
891
static void ini_scanner_globals_ctor(zend_ini_scanner_globals *scanner_globals_p) /* {{{ */
892
16
{
893
16
  memset(scanner_globals_p, 0, sizeof(*scanner_globals_p));
894
16
}
895
/* }}} */
896
897
static void php_scanner_globals_ctor(zend_php_scanner_globals *scanner_globals_p) /* {{{ */
898
16
{
899
16
  memset(scanner_globals_p, 0, sizeof(*scanner_globals_p));
900
16
}
901
/* }}} */
902
903
static void module_destructor_zval(zval *zv) /* {{{ */
904
0
{
905
0
  zend_module_entry *module = (zend_module_entry*)Z_PTR_P(zv);
906
0
  module_destructor(module);
907
0
}
908
/* }}} */
909
910
static bool php_auto_globals_create_globals(zend_string *name) /* {{{ */
911
60
{
912
  /* While we keep registering $GLOBALS as an auto-global, we do not create an
913
   * actual variable for it. Access to it handled specially by the compiler. */
914
60
  return false;
915
60
}
916
/* }}} */
917
918
void zend_startup(zend_utility_functions *utility_functions) /* {{{ */
919
16
{
920
#ifdef ZTS
921
  zend_compiler_globals *compiler_globals;
922
  zend_executor_globals *executor_globals;
923
  extern ZEND_API ts_rsrc_id ini_scanner_globals_id;
924
  extern ZEND_API ts_rsrc_id language_scanner_globals_id;
925
#else
926
16
  extern zend_ini_scanner_globals ini_scanner_globals;
927
16
  extern zend_php_scanner_globals language_scanner_globals;
928
16
#endif
929
930
16
  zend_cpu_startup();
931
932
#ifdef ZEND_WIN32
933
  php_win32_cp_set_by_id(65001);
934
#endif
935
936
  /* Set up early utility functions. zend_mm depends on
937
   * zend_random_bytes_insecure */
938
16
  zend_random_bytes = utility_functions->random_bytes_function;
939
16
  zend_random_bytes_insecure = utility_functions->random_bytes_insecure_function;
940
941
16
  start_memory_manager();
942
943
16
  virtual_cwd_startup(); /* Could use shutdown to free the main cwd but it would just slow it down for CGI */
944
945
#if defined(__FreeBSD__) || defined(__DragonFly__)
946
  /* FreeBSD and DragonFly floating point precision fix */
947
  fpsetmask(0);
948
#endif
949
950
16
  zend_startup_hrtime();
951
16
  zend_startup_extensions_mechanism();
952
953
  /* Set up utility functions and values */
954
16
  zend_error_cb = utility_functions->error_function;
955
16
  zend_printf = utility_functions->printf_function;
956
16
  zend_write = utility_functions->write_function;
957
16
  zend_fopen = utility_functions->fopen_function;
958
16
  if (!zend_fopen) {
959
0
    zend_fopen = zend_fopen_wrapper;
960
0
  }
961
16
  zend_stream_open_function = utility_functions->stream_open_function;
962
16
  zend_message_dispatcher_p = utility_functions->message_handler;
963
16
  zend_get_configuration_directive_p = utility_functions->get_configuration_directive;
964
16
  zend_ticks_function = utility_functions->ticks_function;
965
16
  zend_on_timeout = utility_functions->on_timeout;
966
16
  zend_printf_to_smart_string = utility_functions->printf_to_smart_string_function;
967
16
  zend_printf_to_smart_str = utility_functions->printf_to_smart_str_function;
968
16
  zend_getenv = utility_functions->getenv_function;
969
16
  zend_resolve_path = utility_functions->resolve_path_function;
970
971
16
  zend_interrupt_function = NULL;
972
973
#ifdef HAVE_DTRACE
974
/* build with dtrace support */
975
  {
976
    char *tmp = getenv("USE_ZEND_DTRACE");
977
978
    if (tmp && ZEND_ATOL(tmp)) {
979
      zend_dtrace_enabled = 1;
980
      zend_compile_file = dtrace_compile_file;
981
      zend_execute_ex = dtrace_execute_ex;
982
      zend_execute_internal = dtrace_execute_internal;
983
984
      zend_observer_error_register(dtrace_error_notify_cb);
985
    } else {
986
      zend_compile_file = compile_file;
987
      zend_execute_ex = execute_ex;
988
      zend_execute_internal = NULL;
989
    }
990
  }
991
#else
992
16
  zend_compile_file = compile_file;
993
16
  zend_execute_ex = execute_ex;
994
16
  zend_execute_internal = NULL;
995
16
#endif /* HAVE_DTRACE */
996
16
  zend_compile_string = compile_string;
997
16
  zend_throw_exception_hook = NULL;
998
999
  /* Set up the default garbage collection implementation. */
1000
16
  gc_collect_cycles = zend_gc_collect_cycles;
1001
1002
16
  zend_vm_init();
1003
1004
  /* set up version */
1005
16
  zend_version_info = strdup(ZEND_CORE_VERSION_INFO);
1006
16
  zend_version_info_length = sizeof(ZEND_CORE_VERSION_INFO) - 1;
1007
1008
16
  GLOBAL_FUNCTION_TABLE = (HashTable *) malloc(sizeof(HashTable));
1009
16
  GLOBAL_CLASS_TABLE = (HashTable *) malloc(sizeof(HashTable));
1010
16
  GLOBAL_AUTO_GLOBALS_TABLE = (HashTable *) malloc(sizeof(HashTable));
1011
16
  GLOBAL_CONSTANTS_TABLE = (HashTable *) malloc(sizeof(HashTable));
1012
1013
16
  zend_hash_init(GLOBAL_FUNCTION_TABLE, 1024, NULL, ZEND_FUNCTION_DTOR, 1);
1014
16
  zend_hash_init(GLOBAL_CLASS_TABLE, 64, NULL, ZEND_CLASS_DTOR, 1);
1015
16
  zend_hash_init(GLOBAL_AUTO_GLOBALS_TABLE, 8, NULL, auto_global_dtor, 1);
1016
16
  zend_hash_init(GLOBAL_CONSTANTS_TABLE, 128, NULL, ZEND_CONSTANT_DTOR, 1);
1017
1018
16
  zend_hash_init(&module_registry, 32, NULL, module_destructor_zval, 1);
1019
16
  zend_init_rsrc_list_dtors();
1020
1021
#ifdef ZTS
1022
  ts_allocate_fast_id(&compiler_globals_id, &compiler_globals_offset, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor);
1023
  ts_allocate_fast_id(&executor_globals_id, &executor_globals_offset, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor);
1024
  ts_allocate_fast_id(&language_scanner_globals_id, &language_scanner_globals_offset, sizeof(zend_php_scanner_globals), (ts_allocate_ctor) php_scanner_globals_ctor, NULL);
1025
  ts_allocate_fast_id(&ini_scanner_globals_id, &ini_scanner_globals_offset, sizeof(zend_ini_scanner_globals), (ts_allocate_ctor) ini_scanner_globals_ctor, NULL);
1026
  compiler_globals = ts_resource(compiler_globals_id);
1027
  executor_globals = ts_resource(executor_globals_id);
1028
1029
  compiler_globals_dtor(compiler_globals);
1030
  compiler_globals->in_compilation = false;
1031
  compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
1032
  compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
1033
1034
  *compiler_globals->function_table = *GLOBAL_FUNCTION_TABLE;
1035
  *compiler_globals->class_table = *GLOBAL_CLASS_TABLE;
1036
  compiler_globals->auto_globals = GLOBAL_AUTO_GLOBALS_TABLE;
1037
1038
  zend_hash_destroy(executor_globals->zend_constants);
1039
  *executor_globals->zend_constants = *GLOBAL_CONSTANTS_TABLE;
1040
#else
1041
16
  ini_scanner_globals_ctor(&ini_scanner_globals);
1042
16
  php_scanner_globals_ctor(&language_scanner_globals);
1043
16
  zend_set_default_compile_time_values();
1044
#ifdef ZEND_WIN32
1045
  zend_get_windows_version_info(&EG(windows_version_info));
1046
#endif
1047
  /* Map region is going to be created and resized at run-time. */
1048
16
  CG(map_ptr_real_base) = NULL;
1049
16
  CG(map_ptr_base) = ZEND_MAP_PTR_BIASED_BASE(NULL);
1050
16
  CG(map_ptr_size) = 0;
1051
16
  CG(map_ptr_last) = 0;
1052
16
#endif /* ZTS */
1053
16
  EG(error_reporting) = E_ALL & ~E_NOTICE;
1054
16
  EG(fatal_error_backtrace_on) = false;
1055
16
  ZVAL_UNDEF(&EG(last_fatal_error_backtrace));
1056
1057
16
  zend_interned_strings_init();
1058
16
  zend_object_handlers_startup();
1059
16
  zend_startup_builtin_functions();
1060
16
  zend_register_standard_constants();
1061
16
  zend_register_auto_global(zend_string_init_interned("GLOBALS", sizeof("GLOBALS") - 1, 1), 1, php_auto_globals_create_globals);
1062
1063
16
#ifndef ZTS
1064
16
  zend_init_rsrc_plist();
1065
16
  zend_init_exception_op();
1066
16
  zend_init_call_trampoline_op();
1067
16
#endif
1068
1069
16
  zend_ini_startup();
1070
1071
#ifdef ZEND_WIN32
1072
  /* Uses INI settings, so needs to be run after it. */
1073
  php_win32_cp_setup();
1074
#endif
1075
1076
16
  zend_optimizer_startup();
1077
1078
#ifdef ZTS
1079
  tsrm_set_new_thread_end_handler(zend_new_thread_end_handler);
1080
  tsrm_set_shutdown_handler(zend_interned_strings_dtor);
1081
#endif
1082
1083
16
    zend_enum_startup();
1084
16
}
1085
/* }}} */
1086
1087
void zend_register_standard_ini_entries(void) /* {{{ */
1088
16
{
1089
16
  zend_register_ini_entries_ex(ini_entries, 0, MODULE_PERSISTENT);
1090
16
}
1091
/* }}} */
1092
1093
1094
/* Unlink the global (r/o) copies of the class, function and constant tables,
1095
 * and use a fresh r/w copy for the startup thread
1096
 */
1097
zend_result zend_post_startup(void) /* {{{ */
1098
16
{
1099
#ifdef ZTS
1100
  zend_encoding **script_encoding_list;
1101
1102
  zend_compiler_globals *compiler_globals = ts_resource(compiler_globals_id);
1103
  zend_executor_globals *executor_globals = ts_resource(executor_globals_id);
1104
#endif
1105
1106
16
  startup_done = true;
1107
1108
16
  if (zend_post_startup_cb) {
1109
16
    zend_result (*cb)(void) = zend_post_startup_cb;
1110
1111
16
    zend_post_startup_cb = NULL;
1112
16
    if (cb() != SUCCESS) {
1113
0
      return FAILURE;
1114
0
    }
1115
16
  }
1116
1117
#ifdef ZTS
1118
  *GLOBAL_FUNCTION_TABLE = *compiler_globals->function_table;
1119
  *GLOBAL_CLASS_TABLE = *compiler_globals->class_table;
1120
  *GLOBAL_CONSTANTS_TABLE = *executor_globals->zend_constants;
1121
  global_map_ptr_last = compiler_globals->map_ptr_last;
1122
1123
  short_tags_default = CG(short_tags);
1124
  compiler_options_default = CG(compiler_options);
1125
1126
  zend_destroy_rsrc_list(&EG(persistent_list));
1127
  free(compiler_globals->function_table);
1128
  compiler_globals->function_table = NULL;
1129
  free(compiler_globals->class_table);
1130
  compiler_globals->class_table = NULL;
1131
  if (compiler_globals->map_ptr_real_base) {
1132
    free(compiler_globals->map_ptr_real_base);
1133
  }
1134
  compiler_globals->map_ptr_real_base = NULL;
1135
  compiler_globals->map_ptr_base = ZEND_MAP_PTR_BIASED_BASE(NULL);
1136
  if (compiler_globals->internal_run_time_cache) {
1137
    pefree(compiler_globals->internal_run_time_cache, 1);
1138
  }
1139
  compiler_globals->internal_run_time_cache = NULL;
1140
  if ((script_encoding_list = (zend_encoding **)compiler_globals->script_encoding_list)) {
1141
    compiler_globals_ctor(compiler_globals);
1142
    compiler_globals->script_encoding_list = (const zend_encoding **)script_encoding_list;
1143
  } else {
1144
    compiler_globals_ctor(compiler_globals);
1145
  }
1146
  free(EG(zend_constants));
1147
  EG(zend_constants) = NULL;
1148
1149
  executor_globals_ctor(executor_globals);
1150
  global_persistent_list = &EG(persistent_list);
1151
  zend_copy_ini_directives();
1152
#else
1153
16
  global_map_ptr_last = CG(map_ptr_last);
1154
16
#endif
1155
1156
16
#ifdef ZEND_CHECK_STACK_LIMIT
1157
16
  zend_call_stack_init();
1158
16
#endif
1159
16
  gc_init();
1160
1161
16
  return SUCCESS;
1162
16
}
1163
/* }}} */
1164
1165
void zend_shutdown(void) /* {{{ */
1166
0
{
1167
0
  zend_vm_dtor();
1168
1169
0
  zend_destroy_rsrc_list(&EG(persistent_list));
1170
#ifdef ZTS
1171
  ts_apply_for_id(executor_globals_id, executor_globals_persistent_list_dtor);
1172
#endif
1173
0
  zend_destroy_modules();
1174
1175
0
  virtual_cwd_deactivate();
1176
0
  virtual_cwd_shutdown();
1177
1178
0
  zend_hash_destroy(GLOBAL_FUNCTION_TABLE);
1179
  /* Child classes may reuse structures from parent classes, so destroy in reverse order. */
1180
0
  zend_hash_graceful_reverse_destroy(GLOBAL_CLASS_TABLE);
1181
1182
0
  zend_flf_capacity = 0;
1183
0
  zend_flf_count = 0;
1184
0
  free(zend_flf_functions);
1185
0
  free(zend_flf_handlers);
1186
0
  zend_flf_functions = NULL;
1187
0
  zend_flf_handlers = NULL;
1188
1189
0
  zend_hash_destroy(GLOBAL_AUTO_GLOBALS_TABLE);
1190
0
  free(GLOBAL_AUTO_GLOBALS_TABLE);
1191
1192
0
  zend_shutdown_extensions();
1193
0
  free(zend_version_info);
1194
1195
0
  free(GLOBAL_FUNCTION_TABLE);
1196
0
  free(GLOBAL_CLASS_TABLE);
1197
1198
0
  zend_hash_destroy(GLOBAL_CONSTANTS_TABLE);
1199
0
  free(GLOBAL_CONSTANTS_TABLE);
1200
0
  zend_shutdown_strtod();
1201
0
  zend_attributes_shutdown();
1202
1203
#ifdef ZTS
1204
  GLOBAL_FUNCTION_TABLE = NULL;
1205
  GLOBAL_CLASS_TABLE = NULL;
1206
  GLOBAL_AUTO_GLOBALS_TABLE = NULL;
1207
  GLOBAL_CONSTANTS_TABLE = NULL;
1208
  ts_free_id(executor_globals_id);
1209
  ts_free_id(compiler_globals_id);
1210
#else
1211
0
  if (CG(map_ptr_real_base)) {
1212
0
    free(CG(map_ptr_real_base));
1213
0
    CG(map_ptr_real_base) = NULL;
1214
0
    CG(map_ptr_base) = ZEND_MAP_PTR_BIASED_BASE(NULL);
1215
0
    CG(map_ptr_size) = 0;
1216
0
  }
1217
0
  if (CG(script_encoding_list)) {
1218
0
    free(ZEND_VOIDP(CG(script_encoding_list)));
1219
0
    CG(script_encoding_list) = NULL;
1220
0
    CG(script_encoding_list_size) = 0;
1221
0
  }
1222
0
  if (CG(internal_run_time_cache)) {
1223
0
    pefree(CG(internal_run_time_cache), 1);
1224
0
    CG(internal_run_time_cache) = NULL;
1225
0
  }
1226
0
#endif
1227
0
  zend_map_ptr_static_last = 0;
1228
0
  zend_map_ptr_static_size = 0;
1229
1230
0
  zend_destroy_rsrc_list_dtors();
1231
1232
0
  zend_unload_modules();
1233
1234
0
  zend_optimizer_shutdown();
1235
0
  startup_done = false;
1236
0
}
1237
/* }}} */
1238
1239
void zend_set_utility_values(zend_utility_values *utility_values) /* {{{ */
1240
16
{
1241
16
  zend_uv = *utility_values;
1242
16
}
1243
/* }}} */
1244
1245
/* this should be compatible with the standard zenderror */
1246
ZEND_COLD void zenderror(const char *error) /* {{{ */
1247
27.0k
{
1248
27.0k
  CG(parse_error) = 0;
1249
1250
27.0k
  if (EG(exception)) {
1251
    /* An exception was thrown in the lexer, don't throw another in the parser. */
1252
5.55k
    return;
1253
5.55k
  }
1254
1255
21.4k
  zend_throw_exception(zend_ce_parse_error, error, 0);
1256
21.4k
}
1257
/* }}} */
1258
1259
ZEND_API ZEND_COLD ZEND_NORETURN void _zend_bailout(const char *filename, uint32_t lineno) /* {{{ */
1260
24.3k
{
1261
1262
24.3k
  if (!EG(bailout)) {
1263
0
    zend_output_debug_string(1, "%s(%d) : Bailed out without a bailout address!", filename, lineno);
1264
0
    exit(-1);
1265
0
  }
1266
24.3k
  gc_protect(1);
1267
24.3k
  CG(unclean_shutdown) = 1;
1268
24.3k
  CG(active_class_entry) = NULL;
1269
24.3k
  CG(in_compilation) = 0;
1270
24.3k
  CG(memoize_mode) = 0;
1271
24.3k
  EG(current_execute_data) = NULL;
1272
24.3k
  LONGJMP(*EG(bailout), FAILURE);
1273
24.3k
}
1274
/* }}} */
1275
1276
ZEND_API size_t zend_get_page_size(void)
1277
3
{
1278
#ifdef _WIN32
1279
  SYSTEM_INFO system_info;
1280
  GetSystemInfo(&system_info);
1281
  return system_info.dwPageSize;
1282
#elif defined(__FreeBSD__) || defined(__APPLE__)
1283
  /* This returns the value obtained from
1284
   * the auxv vector, avoiding a
1285
   * syscall (on FreeBSD)/function call (on macOS). */
1286
  return getpagesize();
1287
#else
1288
3
  return (size_t) sysconf(_SC_PAGESIZE);
1289
3
#endif
1290
3
}
1291
1292
ZEND_API void zend_append_version_info(const zend_extension *extension) /* {{{ */
1293
16
{
1294
16
  char *new_info;
1295
16
  uint32_t new_info_length;
1296
1297
16
  new_info_length = (uint32_t)(sizeof("    with  v, , by \n")
1298
16
            + strlen(extension->name)
1299
16
            + strlen(extension->version)
1300
16
            + strlen(extension->copyright)
1301
16
            + strlen(extension->author));
1302
1303
16
  new_info = (char *) malloc(new_info_length + 1);
1304
1305
16
  snprintf(new_info, new_info_length, "    with %s v%s, %s, by %s\n", extension->name, extension->version, extension->copyright, extension->author);
1306
1307
16
  zend_version_info = (char *) realloc(zend_version_info, zend_version_info_length+new_info_length + 1);
1308
16
  strncat(zend_version_info, new_info, new_info_length);
1309
16
  zend_version_info_length += new_info_length;
1310
16
  free(new_info);
1311
16
}
1312
/* }}} */
1313
1314
ZEND_API const char *get_zend_version(void) /* {{{ */
1315
4
{
1316
4
  return zend_version_info;
1317
4
}
1318
/* }}} */
1319
1320
ZEND_API void zend_activate(void) /* {{{ */
1321
191k
{
1322
#ifdef ZTS
1323
  virtual_cwd_activate();
1324
#endif
1325
191k
  gc_reset();
1326
191k
  init_compiler();
1327
191k
  init_executor();
1328
191k
  startup_scanner();
1329
191k
  if (CG(map_ptr_last)) {
1330
191k
    memset((void **)CG(map_ptr_real_base) + zend_map_ptr_static_size, 0, CG(map_ptr_last) * sizeof(void*));
1331
191k
  }
1332
191k
  zend_reset_internal_run_time_cache();
1333
191k
  zend_observer_activate();
1334
191k
}
1335
/* }}} */
1336
1337
void zend_call_destructors(void) /* {{{ */
1338
191k
{
1339
191k
  zend_try {
1340
191k
    shutdown_destructors();
1341
191k
  } zend_end_try();
1342
191k
}
1343
/* }}} */
1344
1345
ZEND_API void zend_deactivate(void) /* {{{ */
1346
191k
{
1347
  /* we're no longer executing anything */
1348
191k
  EG(current_execute_data) = NULL;
1349
1350
191k
  zend_try {
1351
191k
    shutdown_scanner();
1352
191k
  } zend_end_try();
1353
1354
  /* shutdown_executor() takes care of its own bailout handling */
1355
191k
  shutdown_executor();
1356
1357
191k
  zend_try {
1358
191k
    zend_ini_deactivate();
1359
191k
  } zend_end_try();
1360
1361
191k
  zend_try {
1362
191k
    shutdown_compiler();
1363
191k
  } zend_end_try();
1364
1365
191k
  zend_destroy_rsrc_list(&EG(regular_list));
1366
1367
  /* See GH-8646: https://github.com/php/php-src/issues/8646
1368
   *
1369
   * Interned strings that hold class entries can get a corresponding slot in map_ptr for the CE cache.
1370
   * map_ptr works like a bump allocator: there is a counter which increases to allocate the next slot in the map.
1371
   *
1372
   * For class name strings in non-opcache we have:
1373
   *   - on startup: permanent + interned
1374
   *   - on request: interned
1375
   * For class name strings in opcache we have:
1376
   *   - on startup: permanent + interned
1377
   *   - on request: either not interned at all, which we can ignore because they won't get a CE cache entry
1378
   *                 or they were already permanent + interned
1379
   *                 or we get a new permanent + interned string in the opcache persistence code
1380
   *
1381
   * Notice that the map_ptr layout always has the permanent strings first, and the request strings after.
1382
   * In non-opcache, a request string may get a slot in map_ptr, and that interned request string
1383
   * gets destroyed at the end of the request. The corresponding map_ptr slot can thereafter never be used again.
1384
   * This causes map_ptr to keep reallocating to larger and larger sizes.
1385
   *
1386
   * We solve it as follows:
1387
   * We can check whether we had any interned request strings, which only happens in non-opcache.
1388
   * If we have any, we reset map_ptr to the last permanent string.
1389
   * We can't lose any permanent strings because of map_ptr's layout.
1390
   */
1391
191k
  if (zend_hash_num_elements(&CG(interned_strings)) > 0) {
1392
0
    zend_map_ptr_reset();
1393
0
  }
1394
1395
#if GC_BENCH
1396
  gc_bench_print();
1397
#endif
1398
191k
}
1399
/* }}} */
1400
1401
ZEND_API void zend_message_dispatcher(zend_long message, const void *data) /* {{{ */
1402
1.87k
{
1403
1.87k
  if (zend_message_dispatcher_p) {
1404
1.87k
    zend_message_dispatcher_p(message, data);
1405
1.87k
  }
1406
1.87k
}
1407
/* }}} */
1408
1409
ZEND_API zval *zend_get_configuration_directive(zend_string *name) /* {{{ */
1410
2.84k
{
1411
2.84k
  if (zend_get_configuration_directive_p) {
1412
2.84k
    return zend_get_configuration_directive_p(name);
1413
2.84k
  } else {
1414
0
    return NULL;
1415
0
  }
1416
2.84k
}
1417
/* }}} */
1418
1419
0
#define SAVE_STACK(stack) do { \
1420
0
    if (CG(stack).top) { \
1421
0
      memcpy(&stack, &CG(stack), sizeof(zend_stack)); \
1422
0
      CG(stack).top = CG(stack).max = 0; \
1423
0
      CG(stack).elements = NULL; \
1424
0
    } else { \
1425
0
      stack.top = 0; \
1426
0
    } \
1427
0
  } while (0)
1428
1429
0
#define RESTORE_STACK(stack) do { \
1430
0
    if (stack.top) { \
1431
0
      zend_stack_destroy(&CG(stack)); \
1432
0
      memcpy(&CG(stack), &stack, sizeof(zend_stack)); \
1433
0
    } \
1434
0
  } while (0)
1435
1436
ZEND_API ZEND_COLD void zend_error_zstr_at(
1437
    int orig_type, zend_string *error_filename, uint32_t error_lineno, zend_string *message)
1438
2.40M
{
1439
2.40M
  zval params[4];
1440
2.40M
  zval retval;
1441
2.40M
  zval orig_user_error_handler;
1442
2.40M
  bool in_compilation;
1443
2.40M
  zend_class_entry *saved_class_entry = NULL;
1444
2.40M
  zend_stack loop_var_stack;
1445
2.40M
  zend_stack delayed_oplines_stack;
1446
2.40M
  int type = orig_type & E_ALL;
1447
2.40M
  bool orig_record_errors;
1448
2.40M
  uint32_t orig_num_errors;
1449
2.40M
  zend_error_info **orig_errors;
1450
2.40M
  zend_result res;
1451
1452
  /* If we're executing a function during SCCP, count any warnings that may be emitted,
1453
   * but don't perform any other error handling. */
1454
2.40M
  if (EG(capture_warnings_during_sccp)) {
1455
0
    ZEND_ASSERT(!(type & E_FATAL_ERRORS) && "Fatal error during SCCP");
1456
0
    EG(capture_warnings_during_sccp)++;
1457
0
    return;
1458
0
  }
1459
1460
  /* Emit any delayed error before handling fatal error */
1461
2.40M
  if ((type & E_FATAL_ERRORS) && !(type & E_DONT_BAIL) && EG(num_errors)) {
1462
191
    uint32_t num_errors = EG(num_errors);
1463
191
    zend_error_info **errors = EG(errors);
1464
191
    EG(num_errors) = 0;
1465
191
    EG(errors) = NULL;
1466
1467
191
    bool orig_record_errors = EG(record_errors);
1468
191
    EG(record_errors) = false;
1469
1470
    /* Disable user error handler before emitting delayed errors, as
1471
     * it's unsafe to execute user code after a fatal error. */
1472
191
    int orig_user_error_handler_error_reporting = EG(user_error_handler_error_reporting);
1473
191
    EG(user_error_handler_error_reporting) = 0;
1474
1475
191
    zend_emit_recorded_errors_ex(num_errors, errors);
1476
1477
191
    EG(user_error_handler_error_reporting) = orig_user_error_handler_error_reporting;
1478
191
    EG(record_errors) = orig_record_errors;
1479
191
    EG(num_errors) = num_errors;
1480
191
    EG(errors) = errors;
1481
191
  }
1482
1483
2.40M
  if (EG(record_errors)) {
1484
133k
    zend_error_info *info = emalloc(sizeof(zend_error_info));
1485
133k
    info->type = type;
1486
133k
    info->lineno = error_lineno;
1487
133k
    info->filename = zend_string_copy(error_filename);
1488
133k
    info->message = zend_string_copy(message);
1489
1490
    /* This is very inefficient for a large number of errors.
1491
     * Use pow2 realloc if it becomes a problem. */
1492
133k
    EG(num_errors)++;
1493
133k
    EG(errors) = erealloc(EG(errors), sizeof(zend_error_info*) * EG(num_errors));
1494
133k
    EG(errors)[EG(num_errors)-1] = info;
1495
1496
    /* Do not process non-fatal recorded error */
1497
133k
    if (!(type & E_FATAL_ERRORS) || (type & E_DONT_BAIL)) {
1498
127k
      return;
1499
127k
    }
1500
133k
  }
1501
1502
  // Always clear the last backtrace.
1503
2.27M
  zval_ptr_dtor(&EG(last_fatal_error_backtrace));
1504
2.27M
  ZVAL_UNDEF(&EG(last_fatal_error_backtrace));
1505
1506
  /* Report about uncaught exception in case of fatal errors */
1507
2.27M
  if (EG(exception)) {
1508
1.21k
    if (type & E_FATAL_ERRORS) {
1509
11
      zend_execute_data *ex = EG(current_execute_data);
1510
11
      const zend_op *opline = NULL;
1511
1512
14
      while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
1513
3
        ex = ex->prev_execute_data;
1514
3
      }
1515
11
      if (ex && ex->opline->opcode == ZEND_HANDLE_EXCEPTION &&
1516
8
          EG(opline_before_exception)) {
1517
8
        opline = EG(opline_before_exception);
1518
8
      }
1519
11
      zend_exception_error(EG(exception), E_WARNING);
1520
11
      EG(exception) = NULL;
1521
11
      if (opline) {
1522
8
        ex->opline = opline;
1523
8
      }
1524
11
    }
1525
2.27M
  } else if (EG(fatal_error_backtrace_on) && (type & E_FATAL_ERRORS)) {
1526
6.65k
    zend_fetch_debug_backtrace(&EG(last_fatal_error_backtrace), 0, EG(exception_ignore_args) ? DEBUG_BACKTRACE_IGNORE_ARGS : 0, 0);
1527
6.65k
  }
1528
1529
2.27M
  zend_observer_error_notify(type, error_filename, error_lineno, message);
1530
1531
  /* if we don't have a user defined error handler */
1532
2.27M
  if (Z_TYPE(EG(user_error_handler)) == IS_UNDEF
1533
0
    || !(EG(user_error_handler_error_reporting) & type)
1534
2.27M
    || EG(error_handling) != EH_NORMAL) {
1535
2.27M
    zend_error_cb(orig_type, error_filename, error_lineno, message);
1536
2.27M
  } else switch (type) {
1537
0
    case E_ERROR:
1538
0
    case E_PARSE:
1539
0
    case E_CORE_ERROR:
1540
0
    case E_CORE_WARNING:
1541
0
    case E_COMPILE_ERROR:
1542
0
    case E_COMPILE_WARNING:
1543
      /* The error may not be safe to handle in user-space */
1544
0
      zend_error_cb(orig_type, error_filename, error_lineno, message);
1545
0
      break;
1546
0
    default:
1547
      /* Handle the error in user space */
1548
0
      ZVAL_STR_COPY(&params[1], message);
1549
0
      ZVAL_LONG(&params[0], type);
1550
1551
0
      if (error_filename) {
1552
0
        ZVAL_STR_COPY(&params[2], error_filename);
1553
0
      } else {
1554
0
        ZVAL_NULL(&params[2]);
1555
0
      }
1556
1557
0
      ZVAL_LONG(&params[3], error_lineno);
1558
1559
0
      ZVAL_COPY_VALUE(&orig_user_error_handler, &EG(user_error_handler));
1560
0
      ZVAL_UNDEF(&EG(user_error_handler));
1561
1562
      /* User error handler may include() additional PHP files.
1563
       * If an error was generated during compilation PHP will compile
1564
       * such scripts recursively, but some CG() variables may be
1565
       * inconsistent. */
1566
1567
0
      in_compilation = CG(in_compilation);
1568
0
      if (in_compilation) {
1569
0
        saved_class_entry = CG(active_class_entry);
1570
0
        CG(active_class_entry) = NULL;
1571
0
        SAVE_STACK(loop_var_stack);
1572
0
        SAVE_STACK(delayed_oplines_stack);
1573
0
        CG(in_compilation) = 0;
1574
0
      }
1575
1576
0
      orig_record_errors = EG(record_errors);
1577
0
      orig_num_errors = EG(num_errors);
1578
0
      orig_errors = EG(errors);
1579
0
      EG(record_errors) = false;
1580
0
      EG(num_errors) = 0;
1581
0
      EG(errors) = NULL;
1582
1583
0
      res = call_user_function(CG(function_table), NULL, &orig_user_error_handler, &retval, 4, params);
1584
1585
0
      EG(record_errors) = orig_record_errors;
1586
0
      EG(num_errors) = orig_num_errors;
1587
0
      EG(errors) = orig_errors;
1588
1589
0
      if (res == SUCCESS) {
1590
0
        if (Z_TYPE(retval) != IS_UNDEF) {
1591
0
          if (Z_TYPE(retval) == IS_FALSE) {
1592
0
            zend_error_cb(orig_type, error_filename, error_lineno, message);
1593
0
          }
1594
0
          zval_ptr_dtor(&retval);
1595
0
        }
1596
0
      } else if (!EG(exception)) {
1597
        /* The user error handler failed, use built-in error handler */
1598
0
        zend_error_cb(orig_type, error_filename, error_lineno, message);
1599
0
      }
1600
1601
0
      if (in_compilation) {
1602
0
        CG(active_class_entry) = saved_class_entry;
1603
0
        RESTORE_STACK(loop_var_stack);
1604
0
        RESTORE_STACK(delayed_oplines_stack);
1605
0
        CG(in_compilation) = 1;
1606
0
      }
1607
1608
0
      zval_ptr_dtor(&params[2]);
1609
0
      zval_ptr_dtor(&params[1]);
1610
1611
0
      if (Z_TYPE(EG(user_error_handler)) == IS_UNDEF) {
1612
0
        ZVAL_COPY_VALUE(&EG(user_error_handler), &orig_user_error_handler);
1613
0
      } else {
1614
0
        zval_ptr_dtor(&orig_user_error_handler);
1615
0
      }
1616
0
      break;
1617
0
  }
1618
1619
2.27M
  if (type == E_PARSE) {
1620
    /* eval() errors do not affect exit_status */
1621
0
    if (!(EG(current_execute_data) &&
1622
0
      EG(current_execute_data)->func &&
1623
0
      ZEND_USER_CODE(EG(current_execute_data)->func->type) &&
1624
0
      EG(current_execute_data)->opline->opcode == ZEND_INCLUDE_OR_EVAL &&
1625
0
      EG(current_execute_data)->opline->extended_value == ZEND_EVAL)) {
1626
0
      EG(exit_status) = 255;
1627
0
    }
1628
0
  }
1629
2.27M
}
1630
/* }}} */
1631
1632
static ZEND_COLD void zend_error_va_list(
1633
    int orig_type, zend_string *error_filename, uint32_t error_lineno,
1634
    const char *format, va_list args)
1635
1.99M
{
1636
1.99M
  zend_string *message = zend_vstrpprintf(0, format, args);
1637
1.99M
  zend_error_zstr_at(orig_type, error_filename, error_lineno, message);
1638
1.99M
  zend_string_release(message);
1639
1.99M
}
1640
1641
2.27M
static ZEND_COLD void get_filename_lineno(int type, zend_string **filename, uint32_t *lineno) {
1642
  /* Obtain relevant filename and lineno */
1643
2.27M
  switch (type) {
1644
8
    case E_CORE_ERROR:
1645
8
    case E_CORE_WARNING:
1646
8
      *filename = NULL;
1647
8
      *lineno = 0;
1648
8
      break;
1649
0
    case E_PARSE:
1650
4.85k
    case E_COMPILE_ERROR:
1651
11.9k
    case E_COMPILE_WARNING:
1652
12.7k
    case E_ERROR:
1653
19.8k
    case E_NOTICE:
1654
741k
    case E_DEPRECATED:
1655
2.27M
    case E_WARNING:
1656
2.27M
    case E_USER_ERROR:
1657
2.27M
    case E_USER_WARNING:
1658
2.27M
    case E_USER_NOTICE:
1659
2.27M
    case E_USER_DEPRECATED:
1660
2.27M
    case E_RECOVERABLE_ERROR:
1661
2.27M
      if (zend_is_compiling()) {
1662
132k
        *filename = zend_get_compiled_filename();
1663
132k
        *lineno = zend_get_compiled_lineno();
1664
2.14M
      } else if (zend_is_executing()) {
1665
2.09M
        *filename = zend_get_executed_filename_ex();
1666
2.09M
        *lineno = zend_get_executed_lineno();
1667
2.09M
      } else {
1668
50.8k
        *filename = NULL;
1669
50.8k
        *lineno = 0;
1670
50.8k
      }
1671
2.27M
      break;
1672
0
    default:
1673
0
      *filename = NULL;
1674
0
      *lineno = 0;
1675
0
      break;
1676
2.27M
  }
1677
2.27M
  if (!*filename) {
1678
690k
    *filename = ZSTR_KNOWN(ZEND_STR_UNKNOWN_CAPITALIZED);
1679
690k
  }
1680
2.27M
}
1681
1682
ZEND_API ZEND_COLD void zend_error_at(
1683
1.03k
    int type, zend_string *filename, uint32_t lineno, const char *format, ...) {
1684
1.03k
  va_list args;
1685
1686
1.03k
  if (!filename) {
1687
0
    uint32_t dummy_lineno;
1688
0
    get_filename_lineno(type, &filename, &dummy_lineno);
1689
0
  }
1690
1691
1.03k
  va_start(args, format);
1692
1.03k
  zend_error_va_list(type, filename, lineno, format, args);
1693
1.03k
  va_end(args);
1694
1.03k
}
1695
1696
1.98M
#define zend_error_impl(type, format) do { \
1697
1.98M
    zend_string *filename; \
1698
1.98M
    uint32_t lineno; \
1699
1.98M
    va_list args; \
1700
1.98M
    get_filename_lineno(type, &filename, &lineno); \
1701
1.98M
    va_start(args, format); \
1702
1.98M
    zend_error_va_list(type, filename, lineno, format, args); \
1703
1.98M
    va_end(args); \
1704
1.98M
  } while (0)
1705
1706
644k
ZEND_API ZEND_COLD void zend_error(int type, const char *format, ...) {
1707
644k
  zend_error_impl(type, format);
1708
644k
}
1709
1710
1.34M
ZEND_API ZEND_COLD void zend_error_unchecked(int type, const char *format, ...) {
1711
1.34M
  zend_error_impl(type, format);
1712
1.34M
}
1713
1714
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_at_noreturn(
1715
    int type, zend_string *filename, uint32_t lineno, const char *format, ...)
1716
91
{
1717
91
  va_list args;
1718
1719
91
  if (!filename) {
1720
0
    uint32_t dummy_lineno;
1721
0
    get_filename_lineno(type, &filename, &dummy_lineno);
1722
0
  }
1723
1724
91
  va_start(args, format);
1725
91
  zend_error_va_list(type, filename, lineno, format, args);
1726
91
  va_end(args);
1727
  /* Should never reach this. */
1728
91
  abort();
1729
91
}
1730
1731
5.18k
#define zend_error_noreturn_impl(type, format) do { \
1732
5.18k
    zend_string *filename; \
1733
5.18k
    uint32_t lineno; \
1734
5.18k
    va_list args; \
1735
5.18k
    get_filename_lineno(type, &filename, &lineno); \
1736
5.18k
    va_start(args, format); \
1737
5.18k
    zend_error_va_list(type, filename, lineno, format, args); \
1738
5.18k
    va_end(args); \
1739
5.18k
    /* Should never reach this. */ \
1740
5.18k
    abort(); \
1741
5.18k
  } while (0)
1742
1743
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...)
1744
5.16k
{
1745
5.16k
  zend_error_noreturn_impl(type, format);
1746
5.16k
}
1747
1748
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn_unchecked(int type, const char *format, ...)
1749
22
{
1750
22
  zend_error_noreturn_impl(type, format);
1751
22
}
1752
1753
ZEND_API ZEND_COLD ZEND_NORETURN void zend_strerror_noreturn(int type, int errn, const char *message)
1754
0
{
1755
0
#ifdef HAVE_STRERROR_R
1756
0
  char b[1024];
1757
1758
0
# ifdef STRERROR_R_CHAR_P
1759
0
  char *buf = strerror_r(errn, b, sizeof(b));
1760
# else
1761
  strerror_r(errn, b, sizeof(b));
1762
  char *buf = b;
1763
# endif
1764
#else
1765
  char *buf = strerror(errn);
1766
#endif
1767
1768
0
  zend_error_noreturn(type, "%s: %s (%d)", message, buf, errn);
1769
0
}
1770
1771
282k
ZEND_API ZEND_COLD void zend_error_zstr(int type, zend_string *message) {
1772
282k
  zend_string *filename;
1773
282k
  uint32_t lineno;
1774
282k
  get_filename_lineno(type, &filename, &lineno);
1775
282k
  zend_error_zstr_at(type, filename, lineno, message);
1776
282k
}
1777
1778
ZEND_API void zend_begin_record_errors(void)
1779
100k
{
1780
100k
  ZEND_ASSERT(!EG(record_errors) && "Error recording already enabled");
1781
100k
  EG(record_errors) = true;
1782
100k
  EG(num_errors) = 0;
1783
100k
  EG(errors) = NULL;
1784
100k
}
1785
1786
ZEND_API void zend_emit_recorded_errors_ex(uint32_t num_errors, zend_error_info **errors)
1787
220k
{
1788
348k
  for (uint32_t i = 0; i < num_errors; i++) {
1789
127k
    zend_error_info *error = errors[i];
1790
127k
    zend_error_zstr_at(error->type, error->filename, error->lineno, error->message);
1791
127k
  }
1792
220k
}
1793
1794
ZEND_API void zend_emit_recorded_errors(void)
1795
94.8k
{
1796
94.8k
  EG(record_errors) = false;
1797
94.8k
  zend_emit_recorded_errors_ex(EG(num_errors), EG(errors));
1798
94.8k
}
1799
1800
ZEND_API void zend_free_recorded_errors(void)
1801
98.0k
{
1802
98.0k
  if (!EG(num_errors)) {
1803
93.2k
    return;
1804
93.2k
  }
1805
1806
61.2k
  for (uint32_t i = 0; i < EG(num_errors); i++) {
1807
56.4k
    zend_error_info *info = EG(errors)[i];
1808
56.4k
    zend_string_release(info->filename);
1809
56.4k
    zend_string_release(info->message);
1810
56.4k
    efree(info);
1811
56.4k
  }
1812
4.85k
  efree(EG(errors));
1813
4.85k
  EG(errors) = NULL;
1814
4.85k
  EG(num_errors) = 0;
1815
4.85k
}
1816
1817
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format, ...) /* {{{ */
1818
93.3k
{
1819
93.3k
  va_list va;
1820
93.3k
  char *message = NULL;
1821
1822
93.3k
  if (!exception_ce) {
1823
91.6k
    exception_ce = zend_ce_error;
1824
91.6k
  }
1825
1826
  /* Marker used to disable exception generation during preloading. */
1827
93.3k
  if (EG(exception) == (void*)(uintptr_t)-1) {
1828
0
    return;
1829
0
  }
1830
1831
93.3k
  va_start(va, format);
1832
93.3k
  zend_vspprintf(&message, 0, format, va);
1833
1834
  //TODO: we can't convert compile-time errors to exceptions yet???
1835
93.3k
  if (EG(current_execute_data) && !CG(in_compilation)) {
1836
93.3k
    zend_throw_exception(exception_ce, message, 0);
1837
93.3k
  } else {
1838
9
    zend_error_noreturn(E_ERROR, "%s", message);
1839
9
  }
1840
1841
93.3k
  efree(message);
1842
93.3k
  va_end(va);
1843
93.3k
}
1844
/* }}} */
1845
1846
/* type should be one of the BP_VAR_* constants, only special messages happen for isset/empty and unset */
1847
ZEND_API ZEND_COLD void zend_illegal_container_offset(const zend_string *container, const zval *offset, int type)
1848
407
{
1849
407
  switch (type) {
1850
31
    case BP_VAR_IS:
1851
31
      zend_type_error("Cannot access offset of type %s in isset or empty",
1852
31
        zend_zval_type_name(offset));
1853
31
      return;
1854
12
    case BP_VAR_UNSET:
1855
      /* Consistent error for when trying to unset a string offset */
1856
12
      if (zend_string_equals(container, ZSTR_KNOWN(ZEND_STR_STRING))) {
1857
7
        zend_throw_error(NULL, "Cannot unset string offsets");
1858
7
      } else {
1859
5
        zend_type_error("Cannot unset offset of type %s on %s", zend_zval_type_name(offset), ZSTR_VAL(container));
1860
5
      }
1861
12
      return;
1862
364
    default:
1863
364
      zend_type_error("Cannot access offset of type %s on %s",
1864
364
        zend_zval_type_name(offset), ZSTR_VAL(container));
1865
364
      return;
1866
407
  }
1867
407
}
1868
1869
ZEND_API ZEND_COLD void zend_type_error(const char *format, ...) /* {{{ */
1870
4.49k
{
1871
4.49k
  va_list va;
1872
4.49k
  char *message = NULL;
1873
1874
4.49k
  va_start(va, format);
1875
4.49k
  zend_vspprintf(&message, 0, format, va);
1876
4.49k
  zend_throw_exception(zend_ce_type_error, message, 0);
1877
4.49k
  efree(message);
1878
4.49k
  va_end(va);
1879
4.49k
} /* }}} */
1880
1881
ZEND_API ZEND_COLD void zend_argument_count_error(const char *format, ...) /* {{{ */
1882
398
{
1883
398
  va_list va;
1884
398
  char *message = NULL;
1885
1886
398
  va_start(va, format);
1887
398
  zend_vspprintf(&message, 0, format, va);
1888
398
  zend_throw_exception(zend_ce_argument_count_error, message, 0);
1889
398
  efree(message);
1890
1891
398
  va_end(va);
1892
398
} /* }}} */
1893
1894
ZEND_API ZEND_COLD void zend_value_error(const char *format, ...) /* {{{ */
1895
85
{
1896
85
  va_list va;
1897
85
  char *message = NULL;
1898
1899
85
  va_start(va, format);
1900
85
  zend_vspprintf(&message, 0, format, va);
1901
85
  zend_throw_exception(zend_ce_value_error, message, 0);
1902
85
  efree(message);
1903
85
  va_end(va);
1904
85
} /* }}} */
1905
1906
ZEND_API ZEND_COLD void zend_output_debug_string(bool trigger_break, const char *format, ...) /* {{{ */
1907
0
{
1908
0
#if ZEND_DEBUG
1909
0
  va_list args;
1910
1911
0
  va_start(args, format);
1912
# ifdef ZEND_WIN32
1913
  {
1914
    char output_buf[1024];
1915
1916
    vsnprintf(output_buf, 1024, format, args);
1917
    OutputDebugString(output_buf);
1918
    OutputDebugString("\n");
1919
    if (trigger_break && IsDebuggerPresent()) {
1920
      DebugBreak();
1921
    }
1922
  }
1923
# else
1924
0
  vfprintf(stderr, format, args);
1925
0
  fprintf(stderr, "\n");
1926
0
# endif
1927
0
  va_end(args);
1928
0
#endif
1929
0
}
1930
/* }}} */
1931
1932
ZEND_API ZEND_COLD void zend_user_exception_handler(void) /* {{{ */
1933
10
{
1934
10
  zval orig_user_exception_handler;
1935
10
  zval params[1], retval2;
1936
10
  zend_object *old_exception;
1937
1938
10
  if (zend_is_unwind_exit(EG(exception))) {
1939
0
    return;
1940
0
  }
1941
1942
10
  old_exception = EG(exception);
1943
10
  EG(exception) = NULL;
1944
10
  ZVAL_OBJ(&params[0], old_exception);
1945
1946
10
  ZVAL_COPY_VALUE(&orig_user_exception_handler, &EG(user_exception_handler));
1947
10
  zend_stack_push(&EG(user_exception_handlers), &orig_user_exception_handler);
1948
10
  ZVAL_UNDEF(&EG(user_exception_handler));
1949
1950
10
  if (call_user_function(CG(function_table), NULL, &orig_user_exception_handler, &retval2, 1, params) == SUCCESS) {
1951
6
    zval_ptr_dtor(&retval2);
1952
6
    if (EG(exception)) {
1953
0
      OBJ_RELEASE(EG(exception));
1954
0
      EG(exception) = NULL;
1955
0
    }
1956
6
    OBJ_RELEASE(old_exception);
1957
6
  } else {
1958
4
    EG(exception) = old_exception;
1959
4
  }
1960
1961
10
  if (Z_TYPE(EG(user_exception_handler)) == IS_UNDEF) {
1962
6
    zval *tmp = zend_stack_top(&EG(user_exception_handlers));
1963
6
    if (tmp) {
1964
6
      ZVAL_COPY_VALUE(&EG(user_exception_handler), tmp);
1965
6
      zend_stack_del_top(&EG(user_exception_handlers));
1966
6
    }
1967
6
  }
1968
10
} /* }}} */
1969
1970
ZEND_API zend_result zend_execute_script(int type, zval *retval, zend_file_handle *file_handle)
1971
0
{
1972
0
  zend_op_array *op_array = zend_compile_file(file_handle, type);
1973
0
  if (file_handle->opened_path) {
1974
0
    zend_hash_add_empty_element(&EG(included_files), file_handle->opened_path);
1975
0
  }
1976
1977
0
  zend_result ret = SUCCESS;
1978
0
  if (op_array) {
1979
0
    zend_execute(op_array, retval);
1980
0
    if (UNEXPECTED(EG(exception))) {
1981
0
      if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) {
1982
0
        zend_user_exception_handler();
1983
0
      }
1984
0
      if (EG(exception)) {
1985
0
        ret = zend_exception_error(EG(exception), E_ERROR);
1986
0
      }
1987
0
    }
1988
0
    zend_destroy_static_vars(op_array);
1989
0
    destroy_op_array(op_array);
1990
0
    efree_size(op_array, sizeof(zend_op_array));
1991
0
  } else if (type == ZEND_REQUIRE) {
1992
0
    ret = FAILURE;
1993
0
  }
1994
1995
0
  return ret;
1996
0
}
1997
1998
ZEND_API zend_result zend_execute_scripts(int type, zval *retval, int file_count, ...) /* {{{ */
1999
0
{
2000
0
  va_list files;
2001
0
  int i;
2002
0
  zend_file_handle *file_handle;
2003
0
  zend_result ret = SUCCESS;
2004
2005
0
  va_start(files, file_count);
2006
0
  for (i = 0; i < file_count; i++) {
2007
0
    file_handle = va_arg(files, zend_file_handle *);
2008
0
    if (!file_handle) {
2009
0
      continue;
2010
0
    }
2011
0
    if (ret == FAILURE) {
2012
0
      continue;
2013
0
    }
2014
0
    ret = zend_execute_script(type, retval, file_handle);
2015
0
  }
2016
0
  va_end(files);
2017
2018
0
  return ret;
2019
0
}
2020
/* }}} */
2021
2022
23.9k
#define COMPILED_STRING_DESCRIPTION_FORMAT "%s(%d) : %s"
2023
2024
ZEND_API char *zend_make_compiled_string_description(const char *name) /* {{{ */
2025
23.9k
{
2026
23.9k
  const char *cur_filename;
2027
23.9k
  int cur_lineno;
2028
23.9k
  char *compiled_string_description;
2029
2030
23.9k
  if (zend_is_compiling()) {
2031
0
    cur_filename = ZSTR_VAL(zend_get_compiled_filename());
2032
0
    cur_lineno = zend_get_compiled_lineno();
2033
23.9k
  } else if (zend_is_executing()) {
2034
23.9k
    cur_filename = zend_get_executed_filename();
2035
23.9k
    cur_lineno = zend_get_executed_lineno();
2036
23.9k
  } else {
2037
0
    cur_filename = "Unknown";
2038
0
    cur_lineno = 0;
2039
0
  }
2040
2041
23.9k
  zend_spprintf(&compiled_string_description, 0, COMPILED_STRING_DESCRIPTION_FORMAT, cur_filename, cur_lineno, name);
2042
23.9k
  return compiled_string_description;
2043
23.9k
}
2044
/* }}} */
2045
2046
void free_estring(char **str_p) /* {{{ */
2047
0
{
2048
0
  efree(*str_p);
2049
0
}
2050
/* }}} */
2051
2052
ZEND_API size_t zend_map_ptr_static_size;
2053
ZEND_API size_t zend_map_ptr_static_last;
2054
2055
ZEND_API void zend_map_ptr_reset(void)
2056
0
{
2057
0
  CG(map_ptr_last) = global_map_ptr_last;
2058
0
}
2059
2060
ZEND_API void *zend_map_ptr_new(void)
2061
47.9k
{
2062
47.9k
  void **ptr;
2063
2064
47.9k
  if (CG(map_ptr_last) >= CG(map_ptr_size)) {
2065
    /* Grow map_ptr table */
2066
26
    CG(map_ptr_size) = ZEND_MM_ALIGNED_SIZE_EX(CG(map_ptr_last) + 1, 4096);
2067
26
    CG(map_ptr_real_base) = perealloc(CG(map_ptr_real_base), (zend_map_ptr_static_size + CG(map_ptr_size)) * sizeof(void*), 1);
2068
26
    CG(map_ptr_base) = ZEND_MAP_PTR_BIASED_BASE(CG(map_ptr_real_base));
2069
26
  }
2070
47.9k
  ptr = (void**)CG(map_ptr_real_base) + zend_map_ptr_static_size + CG(map_ptr_last);
2071
47.9k
  *ptr = NULL;
2072
47.9k
  CG(map_ptr_last)++;
2073
47.9k
  return ZEND_MAP_PTR_PTR2OFFSET(ptr);
2074
47.9k
}
2075
2076
ZEND_API void *zend_map_ptr_new_static(void)
2077
0
{
2078
0
  void **ptr;
2079
2080
0
  if (zend_map_ptr_static_last >= zend_map_ptr_static_size) {
2081
0
    zend_map_ptr_static_size += 4096;
2082
    /* Grow map_ptr table */
2083
0
    void *new_base = pemalloc((zend_map_ptr_static_size + CG(map_ptr_size)) * sizeof(void*), 1);
2084
0
    if (CG(map_ptr_real_base)) {
2085
0
      memcpy((void **)new_base + 4096, CG(map_ptr_real_base), (CG(map_ptr_last) + zend_map_ptr_static_size - 4096) * sizeof(void *));
2086
0
      pefree(CG(map_ptr_real_base), 1);
2087
0
    }
2088
0
    CG(map_ptr_real_base) = new_base;
2089
0
    CG(map_ptr_base) = ZEND_MAP_PTR_BIASED_BASE(new_base);
2090
0
  }
2091
0
  ptr = (void**)CG(map_ptr_real_base) + (zend_map_ptr_static_last & 4095);
2092
0
  *ptr = NULL;
2093
0
  zend_map_ptr_static_last++;
2094
0
  return ZEND_MAP_PTR_PTR2OFFSET(ptr);
2095
0
}
2096
2097
ZEND_API void zend_map_ptr_extend(size_t last)
2098
51.1k
{
2099
51.1k
  if (last > CG(map_ptr_last)) {
2100
0
    void **ptr;
2101
2102
0
    if (last >= CG(map_ptr_size)) {
2103
      /* Grow map_ptr table */
2104
0
      CG(map_ptr_size) = ZEND_MM_ALIGNED_SIZE_EX(last, 4096);
2105
0
      CG(map_ptr_real_base) = perealloc(CG(map_ptr_real_base), (zend_map_ptr_static_size + CG(map_ptr_size)) * sizeof(void*), 1);
2106
0
      CG(map_ptr_base) = ZEND_MAP_PTR_BIASED_BASE(CG(map_ptr_real_base));
2107
0
    }
2108
0
    ptr = (void**)CG(map_ptr_real_base) + zend_map_ptr_static_size + CG(map_ptr_last);
2109
0
    memset(ptr, 0, (last - CG(map_ptr_last)) * sizeof(void*));
2110
0
    CG(map_ptr_last) = last;
2111
0
  }
2112
51.1k
}
2113
2114
ZEND_API void zend_alloc_ce_cache(zend_string *type_name)
2115
269k
{
2116
269k
  if (ZSTR_HAS_CE_CACHE(type_name) || !ZSTR_IS_INTERNED(type_name)) {
2117
252k
    return;
2118
252k
  }
2119
2120
17.0k
  if ((GC_FLAGS(type_name) & IS_STR_PERMANENT) && startup_done) {
2121
    /* Don't allocate slot on permanent interned string outside module startup.
2122
     * The cache slot would no longer be valid on the next request. */
2123
14.3k
    return;
2124
14.3k
  }
2125
2126
2.64k
  if (zend_string_equals_ci(type_name, ZSTR_KNOWN(ZEND_STR_SELF))
2127
2.64k
      || zend_string_equals_ci(type_name, ZSTR_KNOWN(ZEND_STR_PARENT))) {
2128
0
    return;
2129
0
  }
2130
2131
  /* We use the refcount to keep map_ptr of corresponding type */
2132
2.64k
  uint32_t ret;
2133
2.65k
  do {
2134
2.65k
    ret = ZEND_MAP_PTR_NEW_OFFSET();
2135
2.65k
  } while (ret <= 2);
2136
2.64k
  GC_ADD_FLAGS(type_name, IS_STR_CLASS_NAME_MAP_PTR);
2137
2.64k
  GC_SET_REFCOUNT(type_name, ret);
2138
2.64k
}