Coverage Report

Created: 2026-04-01 06:49

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
15.0k
#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
409
{
115
409
  if (!new_value) {
116
0
    EG(error_reporting) = E_ALL;
117
409
  } else {
118
409
    EG(error_reporting) = atoi(ZSTR_VAL(new_value));
119
409
  }
120
409
  return SUCCESS;
121
409
}
122
/* }}} */
123
124
static ZEND_INI_MH(OnUpdateGCEnabled) /* {{{ */
125
191
{
126
191
  bool val;
127
128
191
  val = zend_ini_parse_bool(new_value);
129
191
  gc_enable(val);
130
131
191
  return SUCCESS;
132
191
}
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
129
{
160
129
  zend_long *p = ZEND_INI_GET_ADDR();
161
162
129
  zend_long val = zend_ini_parse_quantity_warn(new_value, entry->name);
163
164
129
  if (stage != ZEND_INI_STAGE_STARTUP &&
165
113
      stage != ZEND_INI_STAGE_SHUTDOWN &&
166
113
      *p != val &&
167
91
      (*p < 0 || val < 0)) {
168
6
    zend_error(E_WARNING, "zend.assertions may be completely enabled or disabled only in php.ini");
169
6
    return FAILURE;
170
6
  }
171
172
123
  *p = val;
173
123
  return SUCCESS;
174
129
}
175
/* }}} */
176
177
static ZEND_INI_MH(OnSetExceptionStringParamMaxLen) /* {{{ */
178
86
{
179
86
  zend_long i = ZEND_ATOL(ZSTR_VAL(new_value));
180
86
  if (i >= 0 && i <= 1000000) {
181
56
    EG(exception_string_param_max_len) = i;
182
56
    return SUCCESS;
183
56
  } else {
184
30
    return FAILURE;
185
30
  }
186
86
}
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
52
{
243
52
  if (new_value) {
244
18
    zend_long tmp = zend_ini_parse_quantity_warn(new_value, entry->name);
245
18
    if (tmp < 0) {
246
12
      zend_error(E_WARNING, "fiber.stack_size must be a positive number");
247
12
      return FAILURE;
248
12
    }
249
6
    EG(fiber_stack_size) = tmp;
250
34
  } else {
251
34
    EG(fiber_stack_size) = ZEND_FIBER_DEFAULT_C_STACK_SIZE;
252
34
  }
253
40
  return SUCCESS;
254
52
}
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
17.7M
{
288
17.7M
  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
17.7M
  if (!pbuf) {
293
0
    return 0;
294
0
  }
295
296
17.7M
  zend_printf_to_smart_string(&buf, format, ap);
297
298
17.7M
  if (max_len && buf.len > max_len) {
299
0
    buf.len = max_len;
300
0
  }
301
302
17.7M
  smart_string_0(&buf);
303
304
17.7M
  if (buf.c) {
305
17.7M
    *pbuf = buf.c;
306
17.7M
    return buf.len;
307
17.7M
  } else {
308
0
    *pbuf = estrndup("", 0);
309
0
    return 0;
310
0
  }
311
17.7M
}
312
/* }}} */
313
314
ZEND_API size_t zend_spprintf(char **message, size_t max_len, const char *format, ...) /* {{{ */
315
40.0k
{
316
40.0k
  va_list arg;
317
40.0k
  size_t len;
318
319
40.0k
  va_start(arg, format);
320
40.0k
  len = zend_vspprintf(message, max_len, format, arg);
321
40.0k
  va_end(arg);
322
40.0k
  return len;
323
40.0k
}
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
4.19M
{
340
4.19M
  smart_str buf = {0};
341
342
4.19M
  zend_printf_to_smart_str(&buf, format, ap);
343
344
4.19M
  if (!buf.s) {
345
0
    return ZSTR_EMPTY_ALLOC();
346
0
  }
347
348
4.19M
  if (max_len && ZSTR_LEN(buf.s) > max_len) {
349
0
    ZSTR_LEN(buf.s) = max_len;
350
0
  }
351
352
4.19M
  return smart_str_extract(&buf);
353
4.19M
}
354
/* }}} */
355
356
ZEND_API zend_string *zend_strpprintf(size_t max_len, const char *format, ...) /* {{{ */
357
150k
{
358
150k
  va_list arg;
359
150k
  zend_string *str;
360
361
150k
  va_start(arg, format);
362
150k
  str = zend_vstrpprintf(max_len, format, arg);
363
150k
  va_end(arg);
364
150k
  return str;
365
150k
}
366
/* }}} */
367
368
ZEND_API zend_string *zend_strpprintf_unchecked(size_t max_len, const char *format, ...) /* {{{ */
369
1.22M
{
370
1.22M
  va_list arg;
371
1.22M
  zend_string *str;
372
373
1.22M
  va_start(arg, format);
374
1.22M
  str = zend_vstrpprintf(max_len, format, arg);
375
1.22M
  va_end(arg);
376
1.22M
  return str;
377
1.22M
}
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.79k
{
384
3.79k
  zval *tmp;
385
3.79k
  zend_string *string_key;
386
3.79k
  zend_ulong num_key;
387
3.79k
  int i;
388
389
29.0k
  for (i = 0; i < indent; i++) {
390
25.2k
    smart_str_appendc(buf, ' ');
391
25.2k
  }
392
3.79k
  smart_str_appends(buf, "(\n");
393
3.79k
  indent += PRINT_ZVAL_INDENT;
394
19.0k
  ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) {
395
72.3k
    for (i = 0; i < indent; i++) {
396
64.9k
      smart_str_appendc(buf, ' ');
397
64.9k
    }
398
19.0k
    smart_str_appendc(buf, '[');
399
19.0k
    if (string_key) {
400
3.04k
      if (is_object) {
401
1.50k
        const char *prop_name, *class_name;
402
1.50k
        size_t prop_len;
403
1.50k
        int mangled = zend_unmangle_property_name_ex(string_key, &class_name, &prop_name, &prop_len);
404
405
1.50k
        smart_str_appendl(buf, prop_name, prop_len);
406
1.50k
        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.53k
      } else {
416
1.53k
        smart_str_append(buf, string_key);
417
1.53k
      }
418
4.43k
    } else {
419
4.43k
      smart_str_append_long(buf, num_key);
420
4.43k
    }
421
19.0k
    smart_str_appends(buf, "] => ");
422
19.0k
    zend_print_zval_r_to_buf(buf, tmp, indent+PRINT_ZVAL_INDENT);
423
19.0k
    smart_str_appends(buf, "\n");
424
19.0k
  } ZEND_HASH_FOREACH_END();
425
3.79k
  indent -= PRINT_ZVAL_INDENT;
426
29.0k
  for (i = 0; i < indent; i++) {
427
25.2k
    smart_str_appendc(buf, ' ');
428
25.2k
  }
429
3.79k
  smart_str_appends(buf, ")\n");
430
3.79k
}
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.65k
{
548
9.65k
  switch (Z_TYPE_P(expr)) {
549
2.38k
    case IS_ARRAY:
550
2.38k
      smart_str_appends(buf, "Array\n");
551
2.38k
      if (!(GC_FLAGS(Z_ARRVAL_P(expr)) & GC_IMMUTABLE)) {
552
1.75k
        if (GC_IS_RECURSIVE(Z_ARRVAL_P(expr))) {
553
7
          smart_str_appends(buf, " *RECURSION*");
554
7
          return;
555
7
        }
556
1.74k
        GC_PROTECT_RECURSION(Z_ARRVAL_P(expr));
557
1.74k
      }
558
2.38k
      print_hash(buf, Z_ARRVAL_P(expr), indent, false);
559
2.38k
      GC_TRY_UNPROTECT_RECURSION(Z_ARRVAL_P(expr));
560
2.38k
      break;
561
1.41k
    case IS_OBJECT:
562
1.41k
      {
563
1.41k
        HashTable *properties;
564
565
1.41k
        zend_object *zobj = Z_OBJ_P(expr);
566
1.41k
        uint32_t *guard = zend_get_recursion_guard(zobj);
567
1.41k
        zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(zobj);
568
        /* cut off on NULL byte ... class@anonymous */
569
1.41k
        smart_str_appends(buf, ZSTR_VAL(class_name));
570
1.41k
        zend_string_release_ex(class_name, 0);
571
572
1.41k
        if (!(zobj->ce->ce_flags & ZEND_ACC_ENUM)) {
573
1.39k
          smart_str_appends(buf, " Object\n");
574
1.39k
        } else {
575
21
          smart_str_appends(buf, " Enum");
576
21
          if (zobj->ce->enum_backing_type != IS_UNDEF) {
577
13
            smart_str_appendc(buf, ':');
578
13
            smart_str_appends(buf, zend_get_type_by_const(zobj->ce->enum_backing_type));
579
13
          }
580
21
          smart_str_appendc(buf, '\n');
581
21
        }
582
583
1.41k
        if (ZEND_GUARD_OR_GC_IS_RECURSIVE(guard, DEBUG, zobj)) {
584
0
          smart_str_appends(buf, " *RECURSION*");
585
0
          return;
586
0
        }
587
588
1.41k
        if ((properties = zend_get_properties_for(expr, ZEND_PROP_PURPOSE_DEBUG)) == NULL) {
589
5
          print_hash(buf, (HashTable*) &zend_empty_array, indent, true);
590
5
          break;
591
5
        }
592
593
1.41k
        ZEND_GUARD_OR_GC_PROTECT_RECURSION(guard, DEBUG, zobj);
594
1.41k
        print_hash(buf, properties, indent, true);
595
1.41k
        ZEND_GUARD_OR_GC_UNPROTECT_RECURSION(guard, DEBUG, zobj);
596
597
1.41k
        zend_release_properties(properties);
598
1.41k
        break;
599
1.41k
      }
600
1.16k
    case IS_LONG:
601
1.16k
      smart_str_append_long(buf, Z_LVAL_P(expr));
602
1.16k
      break;
603
114
    case IS_REFERENCE:
604
114
      zend_print_zval_r_to_buf(buf, Z_REFVAL_P(expr), indent);
605
114
      break;
606
1.79k
    case IS_STRING:
607
1.79k
      smart_str_append(buf, Z_STR_P(expr));
608
1.79k
      break;
609
2.77k
    default:
610
2.77k
      {
611
2.77k
        zend_string *str = zval_get_string_func(expr);
612
2.77k
        smart_str_append(buf, str);
613
2.77k
        zend_string_release_ex(str, 0);
614
2.77k
      }
615
2.77k
      break;
616
9.65k
  }
617
9.65k
}
618
/* }}} */
619
620
ZEND_API zend_string *zend_print_zval_r_to_str(zval *expr, int indent) /* {{{ */
621
2.06k
{
622
2.06k
  smart_str buf = {0};
623
2.06k
  zend_print_zval_r_to_buf(&buf, expr, indent);
624
2.06k
  smart_str_0(&buf);
625
2.06k
  return buf.s;
626
2.06k
}
627
/* }}} */
628
629
ZEND_API void zend_print_zval_r(zval *expr, int indent) /* {{{ */
630
2.03k
{
631
2.03k
  zend_string *str = zend_print_zval_r_to_str(expr, indent);
632
2.03k
  zend_write(ZSTR_VAL(str), ZSTR_LEN(str));
633
2.03k
  zend_string_release_ex(str, 0);
634
2.03k
}
635
/* }}} */
636
637
static FILE *zend_fopen_wrapper(zend_string *filename, zend_string **opened_path) /* {{{ */
638
0
{
639
0
  if (opened_path) {
640
0
    *opened_path = zend_string_copy(filename);
641
0
  }
642
0
  return fopen(ZSTR_VAL(filename), "rb");
643
0
}
644
/* }}} */
645
646
#ifdef ZTS
647
static bool short_tags_default = true;
648
static uint32_t compiler_options_default = ZEND_COMPILE_DEFAULT;
649
#else
650
16
# define short_tags_default     1
651
16
# define compiler_options_default ZEND_COMPILE_DEFAULT
652
#endif
653
654
static void zend_set_default_compile_time_values(void) /* {{{ */
655
16
{
656
  /* default compile-time values */
657
16
  CG(short_tags) = short_tags_default;
658
16
  CG(compiler_options) = compiler_options_default;
659
660
16
  CG(rtd_key_counter) = 0;
661
16
}
662
/* }}} */
663
664
#ifdef ZEND_WIN32
665
static void zend_get_windows_version_info(OSVERSIONINFOEX *osvi) /* {{{ */
666
{
667
  ZeroMemory(osvi, sizeof(OSVERSIONINFOEX));
668
  osvi->dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
669
  if(!GetVersionEx((OSVERSIONINFO *) osvi)) {
670
    ZEND_UNREACHABLE(); /* Should not happen as sizeof is used. */
671
  }
672
}
673
/* }}} */
674
#endif
675
676
static void zend_init_exception_op(void) /* {{{ */
677
16
{
678
16
  memset(EG(exception_op), 0, sizeof(EG(exception_op)));
679
16
  EG(exception_op)[0].opcode = ZEND_HANDLE_EXCEPTION;
680
16
  ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op));
681
16
  EG(exception_op)[1].opcode = ZEND_HANDLE_EXCEPTION;
682
16
  ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op)+1);
683
16
  EG(exception_op)[2].opcode = ZEND_HANDLE_EXCEPTION;
684
16
  ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op)+2);
685
16
}
686
/* }}} */
687
688
static void zend_init_call_trampoline_op(void) /* {{{ */
689
16
{
690
16
  memset(&EG(call_trampoline_op), 0, sizeof(EG(call_trampoline_op)));
691
16
  EG(call_trampoline_op).opcode = ZEND_CALL_TRAMPOLINE;
692
16
  ZEND_VM_SET_OPCODE_HANDLER(&EG(call_trampoline_op));
693
16
}
694
/* }}} */
695
696
static void auto_global_dtor(zval *zv) /* {{{ */
697
0
{
698
0
  free(Z_PTR_P(zv));
699
0
}
700
/* }}} */
701
702
#ifdef ZTS
703
static void auto_global_copy_ctor(zval *zv) /* {{{ */
704
{
705
  zend_auto_global *old_ag = (zend_auto_global *) Z_PTR_P(zv);
706
  zend_auto_global *new_ag = pemalloc(sizeof(zend_auto_global), 1);
707
708
  new_ag->name = old_ag->name;
709
  new_ag->auto_global_callback = old_ag->auto_global_callback;
710
  new_ag->jit = old_ag->jit;
711
712
  Z_PTR_P(zv) = new_ag;
713
}
714
/* }}} */
715
716
static void compiler_globals_ctor(zend_compiler_globals *compiler_globals) /* {{{ */
717
{
718
  compiler_globals->compiled_filename = NULL;
719
  compiler_globals->zend_lineno = 0;
720
721
  compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
722
  zend_hash_init(compiler_globals->function_table, 1024, NULL, ZEND_FUNCTION_DTOR, 1);
723
  zend_hash_copy(compiler_globals->function_table, global_function_table, NULL);
724
  compiler_globals->copied_functions_count = zend_hash_num_elements(compiler_globals->function_table);
725
726
  compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
727
  zend_hash_init(compiler_globals->class_table, 64, NULL, ZEND_CLASS_DTOR, 1);
728
  zend_hash_copy(compiler_globals->class_table, global_class_table, zend_class_add_ref);
729
730
  zend_set_default_compile_time_values();
731
732
  compiler_globals->auto_globals = (HashTable *) malloc(sizeof(HashTable));
733
  zend_hash_init(compiler_globals->auto_globals, 8, NULL, auto_global_dtor, 1);
734
  zend_hash_copy(compiler_globals->auto_globals, global_auto_globals_table, auto_global_copy_ctor);
735
736
  compiler_globals->script_encoding_list = NULL;
737
  compiler_globals->current_linking_class = NULL;
738
739
  /* Map region is going to be created and resized at run-time. */
740
  compiler_globals->map_ptr_real_base = NULL;
741
  compiler_globals->map_ptr_base = ZEND_MAP_PTR_BIASED_BASE(NULL);
742
  compiler_globals->map_ptr_size = 0;
743
  compiler_globals->map_ptr_last = global_map_ptr_last;
744
  compiler_globals->internal_run_time_cache = NULL;
745
  if (compiler_globals->map_ptr_last || zend_map_ptr_static_size) {
746
    /* Allocate map_ptr table */
747
    compiler_globals->map_ptr_size = ZEND_MM_ALIGNED_SIZE_EX(compiler_globals->map_ptr_last, 4096);
748
    void *base = pemalloc((zend_map_ptr_static_size + compiler_globals->map_ptr_size) * sizeof(void*), 1);
749
    compiler_globals->map_ptr_real_base = base;
750
    compiler_globals->map_ptr_base = ZEND_MAP_PTR_BIASED_BASE(base);
751
    memset(base, 0, (zend_map_ptr_static_size + compiler_globals->map_ptr_last) * sizeof(void*));
752
  }
753
  zend_init_internal_run_time_cache();
754
}
755
/* }}} */
756
757
static void compiler_globals_dtor(zend_compiler_globals *compiler_globals) /* {{{ */
758
{
759
  if (compiler_globals->function_table != GLOBAL_FUNCTION_TABLE) {
760
    uint32_t n = compiler_globals->copied_functions_count;
761
762
      /* Prevent destruction of functions copied from the main process context */
763
    if (zend_hash_num_elements(compiler_globals->function_table) <= n) {
764
      compiler_globals->function_table->nNumUsed = 0;
765
    } else {
766
      Bucket *p = compiler_globals->function_table->arData;
767
768
      compiler_globals->function_table->nNumOfElements -= n;
769
      while (n != 0) {
770
        ZVAL_UNDEF(&p->val);
771
        p++;
772
        n--;
773
      }
774
    }
775
    zend_hash_destroy(compiler_globals->function_table);
776
    free(compiler_globals->function_table);
777
  }
778
  if (compiler_globals->class_table != GLOBAL_CLASS_TABLE) {
779
    /* Child classes may reuse structures from parent classes, so destroy in reverse order. */
780
    zend_hash_graceful_reverse_destroy(compiler_globals->class_table);
781
    free(compiler_globals->class_table);
782
  }
783
  if (compiler_globals->auto_globals != GLOBAL_AUTO_GLOBALS_TABLE) {
784
    zend_hash_destroy(compiler_globals->auto_globals);
785
    free(compiler_globals->auto_globals);
786
  }
787
  if (compiler_globals->script_encoding_list) {
788
    pefree((char*)compiler_globals->script_encoding_list, 1);
789
  }
790
  if (compiler_globals->map_ptr_real_base) {
791
    free(compiler_globals->map_ptr_real_base);
792
    compiler_globals->map_ptr_real_base = NULL;
793
    compiler_globals->map_ptr_base = ZEND_MAP_PTR_BIASED_BASE(NULL);
794
    compiler_globals->map_ptr_size = 0;
795
  }
796
  if (compiler_globals->internal_run_time_cache) {
797
    pefree(compiler_globals->internal_run_time_cache, 1);
798
    compiler_globals->internal_run_time_cache = NULL;
799
  }
800
}
801
/* }}} */
802
803
static void executor_globals_ctor(zend_executor_globals *executor_globals) /* {{{ */
804
{
805
  zend_startup_constants();
806
  zend_copy_constants(executor_globals->zend_constants, GLOBAL_CONSTANTS_TABLE);
807
  zend_init_rsrc_plist();
808
  zend_init_exception_op();
809
  zend_init_call_trampoline_op();
810
  memset(&executor_globals->trampoline, 0, sizeof(zend_op_array));
811
  executor_globals->capture_warnings_during_sccp = 0;
812
  executor_globals->user_error_handler_error_reporting = 0;
813
  ZVAL_UNDEF(&executor_globals->user_error_handler);
814
  ZVAL_UNDEF(&executor_globals->user_exception_handler);
815
  executor_globals->current_execute_data = NULL;
816
  executor_globals->current_module = NULL;
817
  executor_globals->exit_status = 0;
818
#if XPFPA_HAVE_CW
819
  executor_globals->saved_fpu_cw = 0;
820
#endif
821
  executor_globals->saved_fpu_cw_ptr = NULL;
822
  executor_globals->active = false;
823
  executor_globals->bailout = NULL;
824
  executor_globals->error_handling  = EH_NORMAL;
825
  executor_globals->exception_class = NULL;
826
  executor_globals->exception = NULL;
827
  executor_globals->objects_store.object_buckets = NULL;
828
  executor_globals->current_fiber_context = NULL;
829
  executor_globals->main_fiber_context = NULL;
830
  executor_globals->active_fiber = NULL;
831
#ifdef ZEND_WIN32
832
  zend_get_windows_version_info(&executor_globals->windows_version_info);
833
#endif
834
  executor_globals->flags = EG_FLAGS_INITIAL;
835
  executor_globals->record_errors = false;
836
  memset(&executor_globals->errors, 0, sizeof(executor_globals->errors));
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
68
{
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
68
  return false;
915
68
}
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
32.2k
{
1248
32.2k
  CG(parse_error) = 0;
1249
1250
32.2k
  if (EG(exception)) {
1251
    /* An exception was thrown in the lexer, don't throw another in the parser. */
1252
5.66k
    return;
1253
5.66k
  }
1254
1255
26.5k
  zend_throw_exception(zend_ce_parse_error, error, 0);
1256
26.5k
}
1257
/* }}} */
1258
1259
ZEND_API ZEND_COLD ZEND_NORETURN void _zend_bailout(const char *filename, uint32_t lineno) /* {{{ */
1260
26.0k
{
1261
1262
26.0k
  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
26.0k
  gc_protect(1);
1267
26.0k
  CG(unclean_shutdown) = 1;
1268
26.0k
  CG(active_class_entry) = NULL;
1269
26.0k
  CG(in_compilation) = 0;
1270
26.0k
  CG(memoize_mode) = 0;
1271
26.0k
  EG(current_execute_data) = NULL;
1272
26.0k
  LONGJMP(*EG(bailout), FAILURE);
1273
26.0k
}
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
224k
{
1322
#ifdef ZTS
1323
  virtual_cwd_activate();
1324
#endif
1325
224k
  gc_reset();
1326
224k
  init_compiler();
1327
224k
  init_executor();
1328
224k
  startup_scanner();
1329
224k
  if (CG(map_ptr_last)) {
1330
224k
    memset((void **)CG(map_ptr_real_base) + zend_map_ptr_static_size, 0, CG(map_ptr_last) * sizeof(void*));
1331
224k
  }
1332
224k
  zend_reset_internal_run_time_cache();
1333
224k
  zend_observer_activate();
1334
224k
}
1335
/* }}} */
1336
1337
void zend_call_destructors(void) /* {{{ */
1338
224k
{
1339
224k
  zend_try {
1340
224k
    shutdown_destructors();
1341
224k
  } zend_end_try();
1342
224k
}
1343
/* }}} */
1344
1345
ZEND_API void zend_deactivate(void) /* {{{ */
1346
224k
{
1347
  /* we're no longer executing anything */
1348
224k
  EG(current_execute_data) = NULL;
1349
1350
224k
  zend_try {
1351
224k
    shutdown_scanner();
1352
224k
  } zend_end_try();
1353
1354
  /* shutdown_executor() takes care of its own bailout handling */
1355
224k
  shutdown_executor();
1356
1357
224k
  zend_try {
1358
224k
    zend_ini_deactivate();
1359
224k
  } zend_end_try();
1360
1361
224k
  zend_try {
1362
224k
    shutdown_compiler();
1363
224k
  } zend_end_try();
1364
1365
224k
  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
224k
  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
224k
}
1399
/* }}} */
1400
1401
ZEND_API void zend_message_dispatcher(zend_long message, const void *data) /* {{{ */
1402
2.03k
{
1403
2.03k
  if (zend_message_dispatcher_p) {
1404
2.03k
    zend_message_dispatcher_p(message, data);
1405
2.03k
  }
1406
2.03k
}
1407
/* }}} */
1408
1409
ZEND_API zval *zend_get_configuration_directive(zend_string *name) /* {{{ */
1410
2.85k
{
1411
2.85k
  if (zend_get_configuration_directive_p) {
1412
2.85k
    return zend_get_configuration_directive_p(name);
1413
2.85k
  } else {
1414
0
    return NULL;
1415
0
  }
1416
2.85k
}
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.52M
{
1439
2.52M
  zval params[4];
1440
2.52M
  zval retval;
1441
2.52M
  zval orig_user_error_handler;
1442
2.52M
  bool in_compilation;
1443
2.52M
  zend_class_entry *saved_class_entry = NULL;
1444
2.52M
  zend_stack loop_var_stack;
1445
2.52M
  zend_stack delayed_oplines_stack;
1446
2.52M
  int type = orig_type & E_ALL;
1447
2.52M
  bool orig_record_errors;
1448
2.52M
  zend_err_buf orig_errors_buf;
1449
2.52M
  zend_result res;
1450
1451
  /* If we're executing a function during SCCP, count any warnings that may be emitted,
1452
   * but don't perform any other error handling. */
1453
2.52M
  if (EG(capture_warnings_during_sccp)) {
1454
0
    ZEND_ASSERT(!(type & E_FATAL_ERRORS) && "Fatal error during SCCP");
1455
0
    EG(capture_warnings_during_sccp)++;
1456
0
    return;
1457
0
  }
1458
1459
  /* Emit any delayed error before handling fatal error */
1460
2.52M
  if ((type & E_FATAL_ERRORS) && !(type & E_DONT_BAIL) && EG(errors).size) {
1461
236
    zend_err_buf errors_buf = EG(errors);
1462
236
    EG(errors).size = 0;
1463
1464
236
    bool orig_record_errors = EG(record_errors);
1465
236
    EG(record_errors) = false;
1466
1467
    /* Disable user error handler before emitting delayed errors, as
1468
     * it's unsafe to execute user code after a fatal error. */
1469
236
    int orig_user_error_handler_error_reporting = EG(user_error_handler_error_reporting);
1470
236
    EG(user_error_handler_error_reporting) = 0;
1471
1472
236
    zend_emit_recorded_errors_ex(errors_buf.size, errors_buf.errors);
1473
1474
236
    EG(user_error_handler_error_reporting) = orig_user_error_handler_error_reporting;
1475
236
    EG(record_errors) = orig_record_errors;
1476
236
    EG(errors) = errors_buf;
1477
236
  }
1478
1479
2.52M
  if (EG(record_errors)) {
1480
63.4k
    zend_error_info *info = emalloc(sizeof(zend_error_info));
1481
63.4k
    info->type = type;
1482
63.4k
    info->lineno = error_lineno;
1483
63.4k
    info->filename = zend_string_copy(error_filename);
1484
63.4k
    info->message = zend_string_copy(message);
1485
63.4k
    EG(errors).size++;
1486
63.4k
    if (EG(errors).size > EG(errors).capacity) {
1487
11.9k
      uint32_t capacity = EG(errors).capacity ? EG(errors).capacity + (EG(errors).capacity >> 1) : 2;
1488
11.9k
      EG(errors).errors = erealloc(EG(errors).errors, sizeof(zend_error_info *) * capacity);
1489
11.9k
      EG(errors).capacity = capacity;
1490
11.9k
    }
1491
63.4k
    EG(errors).errors[EG(errors).size - 1] = info;
1492
1493
    /* Do not process non-fatal recorded error */
1494
63.4k
    if (!(type & E_FATAL_ERRORS) || (type & E_DONT_BAIL)) {
1495
57.2k
      return;
1496
57.2k
    }
1497
63.4k
  }
1498
1499
  // Always clear the last backtrace.
1500
2.46M
  zval_ptr_dtor(&EG(last_fatal_error_backtrace));
1501
2.46M
  ZVAL_UNDEF(&EG(last_fatal_error_backtrace));
1502
1503
  /* Report about uncaught exception in case of fatal errors */
1504
2.46M
  if (EG(exception)) {
1505
2.97k
    if (type & E_FATAL_ERRORS) {
1506
12
      zend_execute_data *ex = EG(current_execute_data);
1507
12
      const zend_op *opline = NULL;
1508
1509
15
      while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
1510
3
        ex = ex->prev_execute_data;
1511
3
      }
1512
12
      if (ex && ex->opline->opcode == ZEND_HANDLE_EXCEPTION &&
1513
9
          EG(opline_before_exception)) {
1514
9
        opline = EG(opline_before_exception);
1515
9
      }
1516
12
      zend_exception_error(EG(exception), E_WARNING);
1517
12
      EG(exception) = NULL;
1518
12
      if (opline) {
1519
9
        ex->opline = opline;
1520
9
      }
1521
12
    }
1522
2.46M
  } else if (EG(fatal_error_backtrace_on) && (type & E_FATAL_ERRORS)) {
1523
7.17k
    zend_fetch_debug_backtrace(&EG(last_fatal_error_backtrace), 0, EG(exception_ignore_args) ? DEBUG_BACKTRACE_IGNORE_ARGS : 0, 0);
1524
7.17k
  }
1525
1526
2.46M
  zend_observer_error_notify(type, error_filename, error_lineno, message);
1527
1528
  /* if we don't have a user defined error handler */
1529
2.46M
  if (Z_TYPE(EG(user_error_handler)) == IS_UNDEF
1530
0
    || !(EG(user_error_handler_error_reporting) & type)
1531
2.46M
    || EG(error_handling) != EH_NORMAL) {
1532
2.46M
    zend_error_cb(orig_type, error_filename, error_lineno, message);
1533
2.46M
  } else switch (type) {
1534
0
    case E_ERROR:
1535
0
    case E_PARSE:
1536
0
    case E_CORE_ERROR:
1537
0
    case E_CORE_WARNING:
1538
0
    case E_COMPILE_ERROR:
1539
0
    case E_COMPILE_WARNING:
1540
      /* The error may not be safe to handle in user-space */
1541
0
      zend_error_cb(orig_type, error_filename, error_lineno, message);
1542
0
      break;
1543
0
    default:
1544
      /* Handle the error in user space */
1545
0
      ZVAL_STR_COPY(&params[1], message);
1546
0
      ZVAL_LONG(&params[0], type);
1547
1548
0
      if (error_filename) {
1549
0
        ZVAL_STR_COPY(&params[2], error_filename);
1550
0
      } else {
1551
0
        ZVAL_NULL(&params[2]);
1552
0
      }
1553
1554
0
      ZVAL_LONG(&params[3], error_lineno);
1555
1556
0
      ZVAL_COPY_VALUE(&orig_user_error_handler, &EG(user_error_handler));
1557
0
      ZVAL_UNDEF(&EG(user_error_handler));
1558
1559
      /* User error handler may include() additional PHP files.
1560
       * If an error was generated during compilation PHP will compile
1561
       * such scripts recursively, but some CG() variables may be
1562
       * inconsistent. */
1563
1564
0
      in_compilation = CG(in_compilation);
1565
0
      if (in_compilation) {
1566
0
        saved_class_entry = CG(active_class_entry);
1567
0
        CG(active_class_entry) = NULL;
1568
0
        SAVE_STACK(loop_var_stack);
1569
0
        SAVE_STACK(delayed_oplines_stack);
1570
0
        CG(in_compilation) = 0;
1571
0
      }
1572
1573
0
      orig_record_errors = EG(record_errors);
1574
0
      EG(record_errors) = false;
1575
1576
0
      orig_errors_buf = EG(errors);
1577
0
      memset(&EG(errors), 0, sizeof(EG(errors)));
1578
1579
0
      res = call_user_function(CG(function_table), NULL, &orig_user_error_handler, &retval, 4, params);
1580
1581
0
      EG(record_errors) = orig_record_errors;
1582
0
      EG(errors) = orig_errors_buf;
1583
1584
0
      if (res == SUCCESS) {
1585
0
        if (Z_TYPE(retval) != IS_UNDEF) {
1586
0
          if (Z_TYPE(retval) == IS_FALSE) {
1587
0
            zend_error_cb(orig_type, error_filename, error_lineno, message);
1588
0
          }
1589
0
          zval_ptr_dtor(&retval);
1590
0
        }
1591
0
      } else if (!EG(exception)) {
1592
        /* The user error handler failed, use built-in error handler */
1593
0
        zend_error_cb(orig_type, error_filename, error_lineno, message);
1594
0
      }
1595
1596
0
      if (in_compilation) {
1597
0
        CG(active_class_entry) = saved_class_entry;
1598
0
        RESTORE_STACK(loop_var_stack);
1599
0
        RESTORE_STACK(delayed_oplines_stack);
1600
0
        CG(in_compilation) = 1;
1601
0
      }
1602
1603
0
      zval_ptr_dtor(&params[2]);
1604
0
      zval_ptr_dtor(&params[1]);
1605
1606
0
      if (Z_TYPE(EG(user_error_handler)) == IS_UNDEF) {
1607
0
        ZVAL_COPY_VALUE(&EG(user_error_handler), &orig_user_error_handler);
1608
0
      } else {
1609
0
        zval_ptr_dtor(&orig_user_error_handler);
1610
0
      }
1611
0
      break;
1612
4
  }
1613
1614
2.46M
  if (type == E_PARSE) {
1615
    /* eval() errors do not affect exit_status */
1616
0
    if (!(EG(current_execute_data) &&
1617
0
      EG(current_execute_data)->func &&
1618
0
      ZEND_USER_CODE(EG(current_execute_data)->func->type) &&
1619
0
      EG(current_execute_data)->opline->opcode == ZEND_INCLUDE_OR_EVAL &&
1620
0
      EG(current_execute_data)->opline->extended_value == ZEND_EVAL)) {
1621
0
      EG(exit_status) = 255;
1622
0
    }
1623
0
  }
1624
2.46M
}
1625
/* }}} */
1626
1627
static ZEND_COLD void zend_error_va_list(
1628
    int orig_type, zend_string *error_filename, uint32_t error_lineno,
1629
    const char *format, va_list args)
1630
2.17M
{
1631
2.17M
  zend_string *message = zend_vstrpprintf(0, format, args);
1632
2.17M
  zend_error_zstr_at(orig_type, error_filename, error_lineno, message);
1633
2.17M
  zend_string_release(message);
1634
2.17M
}
1635
1636
2.46M
static ZEND_COLD void get_filename_lineno(int type, zend_string **filename, uint32_t *lineno) {
1637
  /* Obtain relevant filename and lineno */
1638
2.46M
  switch (type) {
1639
8
    case E_CORE_ERROR:
1640
8
    case E_CORE_WARNING:
1641
8
      *filename = NULL;
1642
8
      *lineno = 0;
1643
8
      break;
1644
0
    case E_PARSE:
1645
5.27k
    case E_COMPILE_ERROR:
1646
24.8k
    case E_COMPILE_WARNING:
1647
25.7k
    case E_ERROR:
1648
35.6k
    case E_NOTICE:
1649
733k
    case E_DEPRECATED:
1650
2.46M
    case E_WARNING:
1651
2.46M
    case E_USER_ERROR:
1652
2.46M
    case E_USER_WARNING:
1653
2.46M
    case E_USER_NOTICE:
1654
2.46M
    case E_USER_DEPRECATED:
1655
2.46M
    case E_RECOVERABLE_ERROR:
1656
2.46M
      if (zend_is_compiling()) {
1657
61.7k
        *filename = zend_get_compiled_filename();
1658
61.7k
        *lineno = zend_get_compiled_lineno();
1659
2.39M
      } else if (zend_is_executing()) {
1660
2.34M
        *filename = zend_get_executed_filename_ex();
1661
2.34M
        *lineno = zend_get_executed_lineno();
1662
2.34M
      } else {
1663
55.8k
        *filename = NULL;
1664
55.8k
        *lineno = 0;
1665
55.8k
      }
1666
2.46M
      break;
1667
0
    default:
1668
0
      *filename = NULL;
1669
0
      *lineno = 0;
1670
0
      break;
1671
2.46M
  }
1672
2.46M
  if (!*filename) {
1673
776k
    *filename = ZSTR_KNOWN(ZEND_STR_UNKNOWN_CAPITALIZED);
1674
776k
  }
1675
2.46M
}
1676
1677
ZEND_API ZEND_COLD void zend_error_at(
1678
1.16k
    int type, zend_string *filename, uint32_t lineno, const char *format, ...) {
1679
1.16k
  va_list args;
1680
1681
1.16k
  if (!filename) {
1682
0
    uint32_t dummy_lineno;
1683
0
    get_filename_lineno(type, &filename, &dummy_lineno);
1684
0
  }
1685
1686
1.16k
  va_start(args, format);
1687
1.16k
  zend_error_va_list(type, filename, lineno, format, args);
1688
1.16k
  va_end(args);
1689
1.16k
}
1690
1691
2.16M
#define zend_error_impl(type, format) do { \
1692
2.16M
    zend_string *filename; \
1693
2.16M
    uint32_t lineno; \
1694
2.16M
    va_list args; \
1695
2.16M
    get_filename_lineno(type, &filename, &lineno); \
1696
2.16M
    va_start(args, format); \
1697
2.16M
    zend_error_va_list(type, filename, lineno, format, args); \
1698
2.16M
    va_end(args); \
1699
2.16M
  } while (0)
1700
1701
680k
ZEND_API ZEND_COLD void zend_error(int type, const char *format, ...) {
1702
680k
  zend_error_impl(type, format);
1703
680k
}
1704
1705
1.48M
ZEND_API ZEND_COLD void zend_error_unchecked(int type, const char *format, ...) {
1706
1.48M
  zend_error_impl(type, format);
1707
1.48M
}
1708
1709
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_at_noreturn(
1710
    int type, zend_string *filename, uint32_t lineno, const char *format, ...)
1711
89
{
1712
89
  va_list args;
1713
1714
89
  if (!filename) {
1715
0
    uint32_t dummy_lineno;
1716
0
    get_filename_lineno(type, &filename, &dummy_lineno);
1717
0
  }
1718
1719
89
  va_start(args, format);
1720
89
  zend_error_va_list(type, filename, lineno, format, args);
1721
89
  va_end(args);
1722
  /* Should never reach this. */
1723
89
  abort();
1724
89
}
1725
1726
5.64k
#define zend_error_noreturn_impl(type, format) do { \
1727
5.64k
    zend_string *filename; \
1728
5.64k
    uint32_t lineno; \
1729
5.64k
    va_list args; \
1730
5.64k
    get_filename_lineno(type, &filename, &lineno); \
1731
5.64k
    va_start(args, format); \
1732
5.64k
    zend_error_va_list(type, filename, lineno, format, args); \
1733
5.64k
    va_end(args); \
1734
5.64k
    /* Should never reach this. */ \
1735
5.64k
    abort(); \
1736
5.64k
  } while (0)
1737
1738
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...)
1739
5.61k
{
1740
5.61k
  zend_error_noreturn_impl(type, format);
1741
5.61k
}
1742
1743
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn_unchecked(int type, const char *format, ...)
1744
28
{
1745
28
  zend_error_noreturn_impl(type, format);
1746
28
}
1747
1748
ZEND_API ZEND_COLD ZEND_NORETURN void zend_strerror_noreturn(int type, int errn, const char *message)
1749
0
{
1750
0
#ifdef HAVE_STRERROR_R
1751
0
  char b[1024];
1752
1753
0
# ifdef STRERROR_R_CHAR_P
1754
0
  char *buf = strerror_r(errn, b, sizeof(b));
1755
# else
1756
  strerror_r(errn, b, sizeof(b));
1757
  char *buf = b;
1758
# endif
1759
#else
1760
  char *buf = strerror(errn);
1761
#endif
1762
1763
0
  zend_error_noreturn(type, "%s: %s (%d)", message, buf, errn);
1764
0
}
1765
1766
285k
ZEND_API ZEND_COLD void zend_error_zstr(int type, zend_string *message) {
1767
285k
  zend_string *filename;
1768
285k
  uint32_t lineno;
1769
285k
  get_filename_lineno(type, &filename, &lineno);
1770
285k
  zend_error_zstr_at(type, filename, lineno, message);
1771
285k
}
1772
1773
ZEND_API void zend_begin_record_errors(void)
1774
115k
{
1775
115k
  ZEND_ASSERT(!EG(record_errors) && "Error recording already enabled");
1776
115k
  EG(record_errors) = true;
1777
115k
  EG(errors).size = 0;
1778
115k
}
1779
1780
ZEND_API void zend_emit_recorded_errors_ex(uint32_t num_errors, zend_error_info **errors)
1781
222k
{
1782
283k
  for (uint32_t i = 0; i < num_errors; i++) {
1783
60.7k
    zend_error_info *error = errors[i];
1784
60.7k
    zend_error_zstr_at(error->type, error->filename, error->lineno, error->message);
1785
60.7k
  }
1786
222k
}
1787
1788
ZEND_API void zend_emit_recorded_errors(void)
1789
109k
{
1790
109k
  EG(record_errors) = false;
1791
109k
  zend_emit_recorded_errors_ex(EG(errors).size, EG(errors).errors);
1792
109k
}
1793
1794
ZEND_API void zend_free_recorded_errors(void)
1795
112k
{
1796
112k
  if (!EG(errors).size) {
1797
107k
    return;
1798
107k
  }
1799
1800
52.7k
  for (uint32_t i = 0; i < EG(errors).size; i++) {
1801
47.4k
    zend_error_info *info = EG(errors).errors[i];
1802
47.4k
    zend_string_release(info->filename);
1803
47.4k
    zend_string_release(info->message);
1804
47.4k
    efree_size(info, sizeof(zend_error_info));
1805
47.4k
  }
1806
5.27k
  efree(EG(errors).errors);
1807
5.27k
  memset(&EG(errors), 0, sizeof(EG(errors)));
1808
5.27k
}
1809
1810
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format, ...) /* {{{ */
1811
96.3k
{
1812
96.3k
  va_list va;
1813
96.3k
  char *message = NULL;
1814
1815
96.3k
  if (!exception_ce) {
1816
94.3k
    exception_ce = zend_ce_error;
1817
94.3k
  }
1818
1819
  /* Marker used to disable exception generation during preloading. */
1820
96.3k
  if (EG(exception) == (void*)(uintptr_t)-1) {
1821
0
    return;
1822
0
  }
1823
1824
96.3k
  va_start(va, format);
1825
96.3k
  zend_vspprintf(&message, 0, format, va);
1826
1827
  //TODO: we can't convert compile-time errors to exceptions yet???
1828
96.3k
  if (EG(current_execute_data) && !CG(in_compilation)) {
1829
96.3k
    zend_throw_exception(exception_ce, message, 0);
1830
96.3k
  } else {
1831
9
    zend_error_noreturn(E_ERROR, "%s", message);
1832
9
  }
1833
1834
96.3k
  efree(message);
1835
96.3k
  va_end(va);
1836
96.3k
}
1837
/* }}} */
1838
1839
/* type should be one of the BP_VAR_* constants, only special messages happen for isset/empty and unset */
1840
ZEND_API ZEND_COLD void zend_illegal_container_offset(const zend_string *container, const zval *offset, int type)
1841
443
{
1842
443
  switch (type) {
1843
33
    case BP_VAR_IS:
1844
33
      zend_type_error("Cannot access offset of type %s in isset or empty",
1845
33
        zend_zval_type_name(offset));
1846
33
      return;
1847
13
    case BP_VAR_UNSET:
1848
      /* Consistent error for when trying to unset a string offset */
1849
13
      if (zend_string_equals(container, ZSTR_KNOWN(ZEND_STR_STRING))) {
1850
7
        zend_throw_error(NULL, "Cannot unset string offsets");
1851
7
      } else {
1852
6
        zend_type_error("Cannot unset offset of type %s on %s", zend_zval_type_name(offset), ZSTR_VAL(container));
1853
6
      }
1854
13
      return;
1855
397
    default:
1856
397
      zend_type_error("Cannot access offset of type %s on %s",
1857
397
        zend_zval_type_name(offset), ZSTR_VAL(container));
1858
397
      return;
1859
443
  }
1860
443
}
1861
1862
ZEND_API ZEND_COLD void zend_type_error(const char *format, ...) /* {{{ */
1863
5.24k
{
1864
5.24k
  va_list va;
1865
5.24k
  char *message = NULL;
1866
1867
5.24k
  va_start(va, format);
1868
5.24k
  zend_vspprintf(&message, 0, format, va);
1869
5.24k
  zend_throw_exception(zend_ce_type_error, message, 0);
1870
5.24k
  efree(message);
1871
5.24k
  va_end(va);
1872
5.24k
} /* }}} */
1873
1874
ZEND_API ZEND_COLD void zend_argument_count_error(const char *format, ...) /* {{{ */
1875
458
{
1876
458
  va_list va;
1877
458
  char *message = NULL;
1878
1879
458
  va_start(va, format);
1880
458
  zend_vspprintf(&message, 0, format, va);
1881
458
  zend_throw_exception(zend_ce_argument_count_error, message, 0);
1882
458
  efree(message);
1883
1884
458
  va_end(va);
1885
458
} /* }}} */
1886
1887
ZEND_API ZEND_COLD void zend_value_error(const char *format, ...) /* {{{ */
1888
91
{
1889
91
  va_list va;
1890
91
  char *message = NULL;
1891
1892
91
  va_start(va, format);
1893
91
  zend_vspprintf(&message, 0, format, va);
1894
91
  zend_throw_exception(zend_ce_value_error, message, 0);
1895
91
  efree(message);
1896
91
  va_end(va);
1897
91
} /* }}} */
1898
1899
ZEND_API ZEND_COLD void zend_output_debug_string(bool trigger_break, const char *format, ...) /* {{{ */
1900
0
{
1901
0
#if ZEND_DEBUG
1902
0
  va_list args;
1903
1904
0
  va_start(args, format);
1905
# ifdef ZEND_WIN32
1906
  {
1907
    char output_buf[1024];
1908
1909
    vsnprintf(output_buf, 1024, format, args);
1910
    OutputDebugString(output_buf);
1911
    OutputDebugString("\n");
1912
    if (trigger_break && IsDebuggerPresent()) {
1913
      DebugBreak();
1914
    }
1915
  }
1916
# else
1917
0
  vfprintf(stderr, format, args);
1918
0
  fprintf(stderr, "\n");
1919
0
# endif
1920
0
  va_end(args);
1921
0
#endif
1922
0
}
1923
/* }}} */
1924
1925
ZEND_API ZEND_COLD void zend_user_exception_handler(void) /* {{{ */
1926
14
{
1927
14
  zval orig_user_exception_handler;
1928
14
  zval params[1], retval2;
1929
14
  zend_object *old_exception;
1930
1931
14
  if (zend_is_unwind_exit(EG(exception))) {
1932
0
    return;
1933
0
  }
1934
1935
14
  old_exception = EG(exception);
1936
14
  EG(exception) = NULL;
1937
14
  ZVAL_OBJ(&params[0], old_exception);
1938
1939
14
  ZVAL_COPY_VALUE(&orig_user_exception_handler, &EG(user_exception_handler));
1940
14
  zend_stack_push(&EG(user_exception_handlers), &orig_user_exception_handler);
1941
14
  ZVAL_UNDEF(&EG(user_exception_handler));
1942
1943
14
  if (call_user_function(CG(function_table), NULL, &orig_user_exception_handler, &retval2, 1, params) == SUCCESS) {
1944
6
    zval_ptr_dtor(&retval2);
1945
6
    if (EG(exception)) {
1946
0
      OBJ_RELEASE(EG(exception));
1947
0
      EG(exception) = NULL;
1948
0
    }
1949
6
    OBJ_RELEASE(old_exception);
1950
8
  } else {
1951
8
    EG(exception) = old_exception;
1952
8
  }
1953
1954
14
  if (Z_TYPE(EG(user_exception_handler)) == IS_UNDEF) {
1955
6
    zval *tmp = zend_stack_top(&EG(user_exception_handlers));
1956
6
    if (tmp) {
1957
6
      ZVAL_COPY_VALUE(&EG(user_exception_handler), tmp);
1958
6
      zend_stack_del_top(&EG(user_exception_handlers));
1959
6
    }
1960
6
  }
1961
14
} /* }}} */
1962
1963
ZEND_API zend_result zend_execute_script(int type, zval *retval, zend_file_handle *file_handle)
1964
0
{
1965
0
  zend_op_array *op_array = zend_compile_file(file_handle, type);
1966
0
  if (file_handle->opened_path) {
1967
0
    zend_hash_add_empty_element(&EG(included_files), file_handle->opened_path);
1968
0
  }
1969
1970
0
  zend_result ret = SUCCESS;
1971
0
  if (op_array) {
1972
0
    zend_execute(op_array, retval);
1973
0
    if (UNEXPECTED(EG(exception))) {
1974
0
      if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) {
1975
0
        zend_user_exception_handler();
1976
0
      }
1977
0
      if (EG(exception)) {
1978
0
        ret = zend_exception_error(EG(exception), E_ERROR);
1979
0
      }
1980
0
    }
1981
0
    zend_destroy_static_vars(op_array);
1982
0
    destroy_op_array(op_array);
1983
0
    efree_size(op_array, sizeof(zend_op_array));
1984
0
  } else if (type == ZEND_REQUIRE) {
1985
0
    ret = FAILURE;
1986
0
  }
1987
1988
0
  return ret;
1989
0
}
1990
1991
ZEND_API zend_result zend_execute_scripts(int type, zval *retval, int file_count, ...) /* {{{ */
1992
0
{
1993
0
  va_list files;
1994
0
  int i;
1995
0
  zend_file_handle *file_handle;
1996
0
  zend_result ret = SUCCESS;
1997
1998
0
  va_start(files, file_count);
1999
0
  for (i = 0; i < file_count; i++) {
2000
0
    file_handle = va_arg(files, zend_file_handle *);
2001
0
    if (!file_handle) {
2002
0
      continue;
2003
0
    }
2004
0
    if (ret == FAILURE) {
2005
0
      continue;
2006
0
    }
2007
0
    ret = zend_execute_script(type, retval, file_handle);
2008
0
  }
2009
0
  va_end(files);
2010
2011
0
  return ret;
2012
0
}
2013
/* }}} */
2014
2015
37.4k
#define COMPILED_STRING_DESCRIPTION_FORMAT "%s(%d) : %s"
2016
2017
ZEND_API char *zend_make_compiled_string_description(const char *name) /* {{{ */
2018
37.4k
{
2019
37.4k
  const char *cur_filename;
2020
37.4k
  int cur_lineno;
2021
37.4k
  char *compiled_string_description;
2022
2023
37.4k
  if (zend_is_compiling()) {
2024
0
    cur_filename = ZSTR_VAL(zend_get_compiled_filename());
2025
0
    cur_lineno = zend_get_compiled_lineno();
2026
37.4k
  } else if (zend_is_executing()) {
2027
37.4k
    cur_filename = zend_get_executed_filename();
2028
37.4k
    cur_lineno = zend_get_executed_lineno();
2029
37.4k
  } else {
2030
0
    cur_filename = "Unknown";
2031
0
    cur_lineno = 0;
2032
0
  }
2033
2034
37.4k
  zend_spprintf(&compiled_string_description, 0, COMPILED_STRING_DESCRIPTION_FORMAT, cur_filename, cur_lineno, name);
2035
37.4k
  return compiled_string_description;
2036
37.4k
}
2037
/* }}} */
2038
2039
void free_estring(char **str_p) /* {{{ */
2040
0
{
2041
0
  efree(*str_p);
2042
0
}
2043
/* }}} */
2044
2045
ZEND_API size_t zend_map_ptr_static_size;
2046
ZEND_API size_t zend_map_ptr_static_last;
2047
2048
ZEND_API void zend_map_ptr_reset(void)
2049
0
{
2050
0
  CG(map_ptr_last) = global_map_ptr_last;
2051
0
}
2052
2053
ZEND_API void *zend_map_ptr_new(void)
2054
50.4k
{
2055
50.4k
  void **ptr;
2056
2057
50.4k
  if (CG(map_ptr_last) >= CG(map_ptr_size)) {
2058
    /* Grow map_ptr table */
2059
26
    CG(map_ptr_size) = ZEND_MM_ALIGNED_SIZE_EX(CG(map_ptr_last) + 1, 4096);
2060
26
    CG(map_ptr_real_base) = perealloc(CG(map_ptr_real_base), (zend_map_ptr_static_size + CG(map_ptr_size)) * sizeof(void*), 1);
2061
26
    CG(map_ptr_base) = ZEND_MAP_PTR_BIASED_BASE(CG(map_ptr_real_base));
2062
26
  }
2063
50.4k
  ptr = (void**)CG(map_ptr_real_base) + zend_map_ptr_static_size + CG(map_ptr_last);
2064
50.4k
  *ptr = NULL;
2065
50.4k
  CG(map_ptr_last)++;
2066
50.4k
  return ZEND_MAP_PTR_PTR2OFFSET(ptr);
2067
50.4k
}
2068
2069
ZEND_API void *zend_map_ptr_new_static(void)
2070
0
{
2071
0
  void **ptr;
2072
2073
0
  if (zend_map_ptr_static_last >= zend_map_ptr_static_size) {
2074
0
    zend_map_ptr_static_size += 4096;
2075
    /* Grow map_ptr table */
2076
0
    void *new_base = pemalloc((zend_map_ptr_static_size + CG(map_ptr_size)) * sizeof(void*), 1);
2077
0
    if (CG(map_ptr_real_base)) {
2078
0
      memcpy((void **)new_base + 4096, CG(map_ptr_real_base), (CG(map_ptr_last) + zend_map_ptr_static_size - 4096) * sizeof(void *));
2079
0
      pefree(CG(map_ptr_real_base), 1);
2080
0
    }
2081
0
    CG(map_ptr_real_base) = new_base;
2082
0
    CG(map_ptr_base) = ZEND_MAP_PTR_BIASED_BASE(new_base);
2083
0
  }
2084
0
  ptr = (void**)CG(map_ptr_real_base) + (zend_map_ptr_static_last & 4095);
2085
0
  *ptr = NULL;
2086
0
  zend_map_ptr_static_last++;
2087
0
  return ZEND_MAP_PTR_PTR2OFFSET(ptr);
2088
0
}
2089
2090
ZEND_API void zend_map_ptr_extend(size_t last)
2091
54.5k
{
2092
54.5k
  if (last > CG(map_ptr_last)) {
2093
0
    void **ptr;
2094
2095
0
    if (last >= CG(map_ptr_size)) {
2096
      /* Grow map_ptr table */
2097
0
      CG(map_ptr_size) = ZEND_MM_ALIGNED_SIZE_EX(last, 4096);
2098
0
      CG(map_ptr_real_base) = perealloc(CG(map_ptr_real_base), (zend_map_ptr_static_size + CG(map_ptr_size)) * sizeof(void*), 1);
2099
0
      CG(map_ptr_base) = ZEND_MAP_PTR_BIASED_BASE(CG(map_ptr_real_base));
2100
0
    }
2101
0
    ptr = (void**)CG(map_ptr_real_base) + zend_map_ptr_static_size + CG(map_ptr_last);
2102
0
    memset(ptr, 0, (last - CG(map_ptr_last)) * sizeof(void*));
2103
0
    CG(map_ptr_last) = last;
2104
0
  }
2105
54.5k
}
2106
2107
ZEND_API void zend_alloc_ce_cache(zend_string *type_name)
2108
371k
{
2109
371k
  if (ZSTR_HAS_CE_CACHE(type_name) || !ZSTR_IS_INTERNED(type_name)) {
2110
352k
    return;
2111
352k
  }
2112
2113
19.3k
  if ((GC_FLAGS(type_name) & IS_STR_PERMANENT) && startup_done) {
2114
    /* Don't allocate slot on permanent interned string outside module startup.
2115
     * The cache slot would no longer be valid on the next request. */
2116
16.7k
    return;
2117
16.7k
  }
2118
2119
2.64k
  if (zend_string_equals_ci(type_name, ZSTR_KNOWN(ZEND_STR_SELF))
2120
2.64k
      || zend_string_equals_ci(type_name, ZSTR_KNOWN(ZEND_STR_PARENT))) {
2121
0
    return;
2122
0
  }
2123
2124
  /* We use the refcount to keep map_ptr of corresponding type */
2125
2.64k
  uint32_t ret;
2126
2.65k
  do {
2127
2.65k
    ret = ZEND_MAP_PTR_NEW_OFFSET();
2128
2.65k
  } while (ret <= 2);
2129
2.64k
  GC_ADD_FLAGS(type_name, IS_STR_CLASS_NAME_MAP_PTR);
2130
2.64k
  GC_SET_REFCOUNT(type_name, ret);
2131
2.64k
}