Coverage Report

Created: 2026-10-28 06:20

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