Coverage Report

Created: 2025-09-27 06:26

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