Coverage Report

Created: 2025-09-27 06:26

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/php-src/ext/opcache/zend_persist.c
Line
Count
Source
1
/*
2
   +----------------------------------------------------------------------+
3
   | Zend OPcache                                                         |
4
   +----------------------------------------------------------------------+
5
   | Copyright (c) The PHP Group                                          |
6
   +----------------------------------------------------------------------+
7
   | This source file is subject to version 3.01 of the PHP 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
   | https://www.php.net/license/3_01.txt                                 |
11
   | If you did not receive a copy of the PHP license and are unable to   |
12
   | obtain it through the world-wide-web, please send a note to          |
13
   | license@php.net so we can mail you a copy immediately.               |
14
   +----------------------------------------------------------------------+
15
   | Authors: Andi Gutmans <andi@php.net>                                 |
16
   |          Zeev Suraski <zeev@php.net>                                 |
17
   |          Stanislav Malyshev <stas@zend.com>                          |
18
   |          Dmitry Stogov <dmitry@php.net>                              |
19
   +----------------------------------------------------------------------+
20
*/
21
22
#include "zend.h"
23
#include "ZendAccelerator.h"
24
#include "zend_persist.h"
25
#include "zend_extensions.h"
26
#include "zend_shared_alloc.h"
27
#include "zend_vm.h"
28
#include "zend_constants.h"
29
#include "zend_operators.h"
30
#include "zend_interfaces.h"
31
#include "zend_attributes.h"
32
33
#ifdef HAVE_JIT
34
# include "Optimizer/zend_func_info.h"
35
# include "jit/zend_jit.h"
36
#endif
37
38
131k
#define zend_set_str_gc_flags(str) do { \
39
131k
  GC_SET_REFCOUNT(str, 2); \
40
131k
  uint32_t flags = GC_STRING | (ZSTR_IS_VALID_UTF8(str) ? IS_STR_VALID_UTF8 : 0); \
41
131k
  if (file_cache_only \
42
131k
   || (ZCG(current_persistent_script) && ZCG(current_persistent_script)->corrupted)) { \
43
0
    GC_TYPE_INFO(str) = GC_STRING | (IS_STR_INTERNED << GC_FLAGS_SHIFT); \
44
0
    flags |= (IS_STR_INTERNED << GC_FLAGS_SHIFT); \
45
131k
  } else { \
46
131k
    flags |= ((IS_STR_INTERNED | IS_STR_PERMANENT) << GC_FLAGS_SHIFT); \
47
131k
  } \
48
131k
  GC_TYPE_INFO(str) = flags; \
49
131k
} while (0)
50
51
203k
#define zend_accel_store_string(str) do { \
52
203k
    zend_string *new_str = zend_shared_alloc_get_xlat_entry(str); \
53
203k
    if (new_str) { \
54
72.2k
      zend_string_release_ex(str, 0); \
55
72.2k
      str = new_str; \
56
131k
    } else { \
57
131k
      new_str = zend_shared_memdup_put((void*)str, _ZSTR_STRUCT_SIZE(ZSTR_LEN(str))); \
58
131k
      zend_string_release_ex(str, 0); \
59
131k
      str = new_str; \
60
131k
      zend_string_hash_val(str); \
61
131k
      zend_set_str_gc_flags(str); \
62
131k
    } \
63
203k
  } while (0)
64
#define zend_accel_memdup_string(str) do { \
65
    zend_string *new_str = zend_shared_alloc_get_xlat_entry(str); \
66
    if (new_str) { \
67
      str = new_str; \
68
    } else { \
69
      new_str = zend_shared_memdup_put((void*)str, _ZSTR_STRUCT_SIZE(ZSTR_LEN(str))); \
70
      str = new_str; \
71
      zend_string_hash_val(str); \
72
      zend_set_str_gc_flags(str); \
73
    } \
74
  } while (0)
75
1.36M
#define zend_accel_store_interned_string(str) do { \
76
1.36M
    if (!IS_ACCEL_INTERNED(str)) { \
77
75.4k
      zend_accel_store_string(str); \
78
75.4k
    } \
79
1.36M
  } while (0)
80
#define zend_accel_memdup_interned_string(str) do { \
81
    if (!IS_ACCEL_INTERNED(str)) { \
82
      zend_accel_memdup_string(str); \
83
    } \
84
  } while (0)
85
86
typedef void (*zend_persist_func_t)(zval*);
87
88
static void zend_persist_zval(zval *z);
89
static void zend_persist_op_array(zval *zv);
90
91
static const uint32_t uninitialized_bucket[-HT_MIN_MASK] =
92
  {HT_INVALID_IDX, HT_INVALID_IDX};
93
94
static void zend_hash_persist(HashTable *ht)
95
228k
{
96
228k
  uint32_t idx, nIndex;
97
228k
  Bucket *p;
98
99
228k
  HT_FLAGS(ht) |= HASH_FLAG_STATIC_KEYS;
100
228k
  ht->pDestructor = NULL;
101
228k
  ht->nInternalPointer = 0;
102
103
228k
  if (HT_FLAGS(ht) & HASH_FLAG_UNINITIALIZED) {
104
153k
    if (EXPECTED(!ZCG(current_persistent_script)->corrupted)) {
105
153k
      HT_SET_DATA_ADDR(ht, &ZCSG(uninitialized_bucket));
106
153k
    } else {
107
0
      HT_SET_DATA_ADDR(ht, &uninitialized_bucket);
108
0
    }
109
153k
    return;
110
153k
  }
111
75.1k
  if (ht->nNumUsed == 0) {
112
4
    efree(HT_GET_DATA_ADDR(ht));
113
4
    ht->nTableMask = HT_MIN_MASK;
114
4
    if (EXPECTED(!ZCG(current_persistent_script)->corrupted)) {
115
4
      HT_SET_DATA_ADDR(ht, &ZCSG(uninitialized_bucket));
116
4
    } else {
117
0
      HT_SET_DATA_ADDR(ht, &uninitialized_bucket);
118
0
    }
119
4
    HT_FLAGS(ht) |= HASH_FLAG_UNINITIALIZED;
120
4
    return;
121
4
  }
122
75.1k
  if (HT_IS_PACKED(ht)) {
123
17.9k
    void *data = HT_GET_DATA_ADDR(ht);
124
17.9k
    if (GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) {
125
0
      data = zend_shared_memdup(data, HT_PACKED_USED_SIZE(ht));
126
17.9k
    } else {
127
17.9k
      data = zend_shared_memdup_free(data, HT_PACKED_USED_SIZE(ht));
128
17.9k
    }
129
17.9k
    HT_SET_DATA_ADDR(ht, data);
130
57.1k
  } else if (ht->nNumUsed > HT_MIN_SIZE && ht->nNumUsed < (uint32_t)(-(int32_t)ht->nTableMask) / 4) {
131
    /* compact table */
132
8
    void *old_data = HT_GET_DATA_ADDR(ht);
133
8
    Bucket *old_buckets = ht->arData;
134
8
    uint32_t hash_size;
135
136
8
    hash_size = (uint32_t)(-(int32_t)ht->nTableMask);
137
16
    while (hash_size >> 2 > ht->nNumUsed) {
138
8
      hash_size >>= 1;
139
8
    }
140
8
    ht->nTableMask = (uint32_t)(-(int32_t)hash_size);
141
8
    ZEND_ASSERT(((uintptr_t)ZCG(mem) & 0x7) == 0); /* should be 8 byte aligned */
142
8
    HT_SET_DATA_ADDR(ht, ZCG(mem));
143
8
    ZCG(mem) = (void*)((char*)ZCG(mem) + ZEND_ALIGNED_SIZE((hash_size * sizeof(uint32_t)) + (ht->nNumUsed * sizeof(Bucket))));
144
8
    HT_HASH_RESET(ht);
145
8
    memcpy(ht->arData, old_buckets, ht->nNumUsed * sizeof(Bucket));
146
8
    if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
147
8
      efree(old_data);
148
8
    }
149
150
    /* rehash */
151
128
    for (idx = 0; idx < ht->nNumUsed; idx++) {
152
120
      p = ht->arData + idx;
153
120
      if (Z_TYPE(p->val) == IS_UNDEF) continue;
154
120
      nIndex = p->h | ht->nTableMask;
155
120
      Z_NEXT(p->val) = HT_HASH(ht, nIndex);
156
120
      HT_HASH(ht, nIndex) = HT_IDX_TO_HASH(idx);
157
120
    }
158
57.1k
  } else {
159
57.1k
    void *data = ZCG(mem);
160
57.1k
    void *old_data = HT_GET_DATA_ADDR(ht);
161
162
57.1k
    ZEND_ASSERT(((uintptr_t)ZCG(mem) & 0x7) == 0); /* should be 8 byte aligned */
163
57.1k
    ZCG(mem) = (void*)((char*)data + ZEND_ALIGNED_SIZE(HT_USED_SIZE(ht)));
164
57.1k
    memcpy(data, old_data, HT_USED_SIZE(ht));
165
57.1k
    if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
166
57.1k
      efree(old_data);
167
57.1k
    }
168
57.1k
    HT_SET_DATA_ADDR(ht, data);
169
57.1k
  }
170
75.1k
}
171
172
static zend_ast *zend_persist_ast(zend_ast *ast)
173
17.7k
{
174
17.7k
  uint32_t i;
175
17.7k
  zend_ast *node;
176
177
17.7k
  if (ast->kind == ZEND_AST_ZVAL || ast->kind == ZEND_AST_CONSTANT) {
178
10.5k
    zend_ast_zval *copy = zend_shared_memdup(ast, sizeof(zend_ast_zval));
179
10.5k
    zend_persist_zval(&copy->val);
180
10.5k
    node = (zend_ast *) copy;
181
10.5k
  } else if (zend_ast_is_list(ast)) {
182
862
    zend_ast_list *list = zend_ast_get_list(ast);
183
862
    zend_ast_list *copy = zend_shared_memdup(ast,
184
862
      sizeof(zend_ast_list) - sizeof(zend_ast *) + sizeof(zend_ast *) * list->children);
185
1.79k
    for (i = 0; i < list->children; i++) {
186
932
      if (copy->child[i]) {
187
932
        copy->child[i] = zend_persist_ast(copy->child[i]);
188
932
      }
189
932
    }
190
862
    node = (zend_ast *) copy;
191
6.32k
  } else if (ast->kind == ZEND_AST_OP_ARRAY) {
192
64
    zend_ast_op_array *copy = zend_shared_memdup(ast, sizeof(zend_ast_op_array));
193
64
    zval z;
194
64
    ZVAL_PTR(&z, copy->op_array);
195
64
    zend_persist_op_array(&z);
196
64
    copy->op_array = Z_PTR(z);
197
64
    node = (zend_ast *) copy;
198
6.26k
  } else if (ast->kind == ZEND_AST_CALLABLE_CONVERT) {
199
210
    zend_ast_fcc *copy = zend_shared_memdup(ast, sizeof(zend_ast_fcc));
200
210
    node = (zend_ast *) copy;
201
6.05k
  } else if (zend_ast_is_decl(ast)) {
202
    /* Not implemented. */
203
0
    ZEND_UNREACHABLE();
204
6.05k
  } else {
205
6.05k
    uint32_t children = zend_ast_get_num_children(ast);
206
6.05k
    node = zend_shared_memdup(ast, zend_ast_size(children));
207
19.3k
    for (i = 0; i < children; i++) {
208
13.3k
      if (node->child[i]) {
209
12.0k
        node->child[i] = zend_persist_ast(node->child[i]);
210
12.0k
      }
211
13.3k
    }
212
6.05k
  }
213
214
17.7k
  return node;
215
17.7k
}
216
217
static void zend_persist_zval(zval *z)
218
1.10M
{
219
1.10M
  void *new_ptr;
220
221
1.10M
  switch (Z_TYPE_P(z)) {
222
685k
    case IS_STRING:
223
685k
      zend_accel_store_interned_string(Z_STR_P(z));
224
685k
      Z_TYPE_FLAGS_P(z) = 0;
225
685k
      break;
226
21.4k
    case IS_ARRAY:
227
21.4k
      new_ptr = zend_shared_alloc_get_xlat_entry(Z_ARR_P(z));
228
21.4k
      if (new_ptr) {
229
785
        Z_ARR_P(z) = new_ptr;
230
785
        Z_TYPE_FLAGS_P(z) = 0;
231
20.6k
      } else if (!ZCG(current_persistent_script)->corrupted
232
20.6k
       && zend_accel_in_shm(Z_ARR_P(z))) {
233
        /* pass */
234
20.5k
      } else {
235
20.5k
        HashTable *ht;
236
237
20.5k
        if (!Z_REFCOUNTED_P(z)) {
238
2.91k
          ht = zend_shared_memdup_put(Z_ARR_P(z), sizeof(zend_array));
239
17.5k
        } else {
240
17.5k
          GC_REMOVE_FROM_BUFFER(Z_ARR_P(z));
241
17.5k
          ht = zend_shared_memdup_put_free(Z_ARR_P(z), sizeof(zend_array));
242
17.5k
        }
243
20.5k
        Z_ARR_P(z) = ht;
244
20.5k
        zend_hash_persist(ht);
245
20.5k
        if (HT_IS_PACKED(ht)) {
246
15.3k
          zval *zv;
247
248
492k
          ZEND_HASH_PACKED_FOREACH_VAL(ht, zv) {
249
492k
            zend_persist_zval(zv);
250
492k
          } ZEND_HASH_FOREACH_END();
251
15.3k
        } else {
252
5.13k
          Bucket *p;
253
254
26.9k
          ZEND_HASH_MAP_FOREACH_BUCKET(ht, p) {
255
26.9k
            if (p->key) {
256
2.97k
              zend_accel_store_interned_string(p->key);
257
2.97k
            }
258
26.9k
            zend_persist_zval(&p->val);
259
26.9k
          } ZEND_HASH_FOREACH_END();
260
5.13k
        }
261
        /* make immutable array */
262
20.5k
        Z_TYPE_FLAGS_P(z) = 0;
263
20.5k
        GC_SET_REFCOUNT(Z_COUNTED_P(z), 2);
264
20.5k
        GC_ADD_FLAGS(Z_COUNTED_P(z), IS_ARRAY_IMMUTABLE);
265
20.5k
      }
266
21.4k
      break;
267
21.4k
    case IS_CONSTANT_AST:
268
5.00k
      new_ptr = zend_shared_alloc_get_xlat_entry(Z_AST_P(z));
269
5.00k
      if (new_ptr) {
270
38
        Z_AST_P(z) = new_ptr;
271
38
        Z_TYPE_FLAGS_P(z) = 0;
272
4.96k
      } else if (ZCG(current_persistent_script)->corrupted
273
4.96k
       || !zend_accel_in_shm(Z_AST_P(z))) {
274
4.83k
        zend_ast_ref *old_ref = Z_AST_P(z);
275
4.83k
        Z_AST_P(z) = zend_shared_memdup_put(Z_AST_P(z), sizeof(zend_ast_ref));
276
4.83k
        zend_persist_ast(GC_AST(old_ref));
277
4.83k
        Z_TYPE_FLAGS_P(z) = 0;
278
4.83k
        GC_SET_REFCOUNT(Z_COUNTED_P(z), 1);
279
4.83k
        GC_ADD_FLAGS(Z_COUNTED_P(z), GC_IMMUTABLE);
280
4.83k
        efree(old_ref);
281
4.83k
      }
282
5.00k
      break;
283
168
    case IS_PTR:
284
168
      break;
285
390k
    default:
286
390k
      ZEND_ASSERT(Z_TYPE_P(z) < IS_STRING);
287
390k
      break;
288
1.10M
  }
289
1.10M
}
290
291
static HashTable *zend_persist_attributes(HashTable *attributes)
292
2.59k
{
293
2.59k
  uint32_t i;
294
2.59k
  zval *v;
295
296
2.59k
  if (!ZCG(current_persistent_script)->corrupted && zend_accel_in_shm(attributes)) {
297
32
    return attributes;
298
32
  }
299
300
  /* Attributes for trait properties may be shared if preloading is used. */
301
2.56k
  HashTable *xlat = zend_shared_alloc_get_xlat_entry(attributes);
302
2.56k
  if (xlat) {
303
0
    return xlat;
304
0
  }
305
306
2.56k
  zend_hash_persist(attributes);
307
308
11.7k
  ZEND_HASH_PACKED_FOREACH_VAL(attributes, v) {
309
11.7k
    zend_attribute *attr = Z_PTR_P(v);
310
11.7k
    zend_attribute *copy = zend_shared_memdup_put_free(attr, ZEND_ATTRIBUTE_SIZE(attr->argc));
311
312
11.7k
    zend_accel_store_interned_string(copy->name);
313
11.7k
    zend_accel_store_interned_string(copy->lcname);
314
11.7k
    if (copy->validation_error) {
315
64
      zend_accel_store_interned_string(copy->validation_error);
316
64
    }
317
318
11.7k
    for (i = 0; i < copy->argc; i++) {
319
1.28k
      if (copy->args[i].name) {
320
152
        zend_accel_store_interned_string(copy->args[i].name);
321
152
      }
322
1.28k
      zend_persist_zval(&copy->args[i].value);
323
1.28k
    }
324
325
11.7k
    ZVAL_PTR(v, copy);
326
11.7k
  } ZEND_HASH_FOREACH_END();
327
328
2.56k
  HashTable *ptr = zend_shared_memdup_put_free(attributes, sizeof(HashTable));
329
2.56k
  GC_SET_REFCOUNT(ptr, 2);
330
2.56k
  GC_TYPE_INFO(ptr) = GC_ARRAY | ((IS_ARRAY_IMMUTABLE|GC_NOT_COLLECTABLE) << GC_FLAGS_SHIFT);
331
332
2.56k
  return ptr;
333
2.56k
}
334
335
uint32_t zend_accel_get_class_name_map_ptr(zend_string *type_name)
336
30.8k
{
337
30.8k
  uint32_t ret;
338
339
30.8k
  if (zend_string_equals_ci(type_name, ZSTR_KNOWN(ZEND_STR_SELF)) ||
340
30.7k
      zend_string_equals_ci(type_name, ZSTR_KNOWN(ZEND_STR_PARENT))) {
341
146
    return 0;
342
146
  }
343
344
  /* We use type.name.gc.refcount to keep map_ptr of corresponding type */
345
30.7k
  if (ZSTR_HAS_CE_CACHE(type_name)) {
346
28.7k
    return GC_REFCOUNT(type_name);
347
28.7k
  }
348
349
1.92k
  if ((GC_FLAGS(type_name) & GC_IMMUTABLE)
350
1.92k
   && (GC_FLAGS(type_name) & IS_STR_PERMANENT)) {
351
1.92k
    do {
352
1.92k
      ret = ZEND_MAP_PTR_NEW_OFFSET();
353
1.92k
    } while (ret <= 2);
354
1.92k
    GC_SET_REFCOUNT(type_name, ret);
355
1.92k
    GC_ADD_FLAGS(type_name, IS_STR_CLASS_NAME_MAP_PTR);
356
1.92k
    return ret;
357
1.92k
  }
358
359
0
  return 0;
360
1.92k
}
361
362
52.8k
static void zend_persist_type(zend_type *type) {
363
52.8k
  if (ZEND_TYPE_HAS_LIST(*type)) {
364
2.05k
    zend_type_list *list = ZEND_TYPE_LIST(*type);
365
2.05k
    if (ZEND_TYPE_USES_ARENA(*type) || zend_accel_in_shm(list)) {
366
2.05k
      list = zend_shared_memdup_put(list, ZEND_TYPE_LIST_SIZE(list->num_types));
367
2.05k
      ZEND_TYPE_FULL_MASK(*type) &= ~_ZEND_TYPE_ARENA_BIT;
368
2.05k
    } else {
369
0
      list = zend_shared_memdup_put_free(list, ZEND_TYPE_LIST_SIZE(list->num_types));
370
0
    }
371
2.05k
    ZEND_TYPE_SET_PTR(*type, list);
372
2.05k
  }
373
374
52.8k
  zend_type *single_type;
375
107k
  ZEND_TYPE_FOREACH_MUTABLE(*type, single_type) {
376
107k
    if (ZEND_TYPE_HAS_LIST(*single_type)) {
377
626
      zend_persist_type(single_type);
378
626
      continue;
379
626
    }
380
54.2k
    if (ZEND_TYPE_HAS_NAME(*single_type)) {
381
7.19k
      zend_string *type_name = ZEND_TYPE_NAME(*single_type);
382
7.19k
      zend_accel_store_interned_string(type_name);
383
7.19k
      ZEND_TYPE_SET_PTR(*single_type, type_name);
384
7.19k
      if (!ZCG(current_persistent_script)->corrupted) {
385
7.19k
        zend_accel_get_class_name_map_ptr(type_name);
386
7.19k
      }
387
7.19k
    }
388
54.2k
  } ZEND_TYPE_FOREACH_END();
389
52.8k
}
390
391
static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_script* main_persistent_script)
392
108k
{
393
108k
  zend_op *persist_ptr;
394
108k
  zval *orig_literals = NULL;
395
396
108k
  if (op_array->refcount && --(*op_array->refcount) == 0) {
397
102k
    efree(op_array->refcount);
398
102k
  }
399
108k
  op_array->refcount = NULL;
400
401
108k
  if (main_persistent_script) {
402
60.4k
    zend_execute_data *orig_execute_data = EG(current_execute_data);
403
60.4k
    zend_execute_data fake_execute_data;
404
60.4k
    zval *offset;
405
406
60.4k
    memset(&fake_execute_data, 0, sizeof(fake_execute_data));
407
60.4k
    fake_execute_data.func = (zend_function*)op_array;
408
60.4k
    EG(current_execute_data) = &fake_execute_data;
409
60.4k
    if ((offset = zend_get_constant_str("__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__") - 1)) != NULL) {
410
44
      main_persistent_script->compiler_halt_offset = Z_LVAL_P(offset);
411
44
    }
412
60.4k
    EG(current_execute_data) = orig_execute_data;
413
60.4k
  }
414
415
108k
  if (op_array->function_name) {
416
47.7k
    zend_string *old_name = op_array->function_name;
417
47.7k
    zend_accel_store_interned_string(op_array->function_name);
418
    /* Remember old function name, so it can be released multiple times if shared. */
419
47.7k
    if (op_array->function_name != old_name
420
816
        && !zend_shared_alloc_get_xlat_entry(&op_array->function_name)) {
421
816
      zend_shared_alloc_register_xlat_entry(&op_array->function_name, old_name);
422
816
    }
423
47.7k
  }
424
425
108k
  if (op_array->scope) {
426
26.7k
    zend_class_entry *scope = zend_shared_alloc_get_xlat_entry(op_array->scope);
427
428
26.7k
    if (scope) {
429
26.7k
      op_array->scope = scope;
430
26.7k
    }
431
432
26.7k
    if (op_array->prototype) {
433
3.45k
      zend_function *ptr = zend_shared_alloc_get_xlat_entry(op_array->prototype);
434
435
3.45k
      if (ptr) {
436
851
        op_array->prototype = ptr;
437
851
      }
438
3.45k
    }
439
440
26.7k
    persist_ptr = zend_shared_alloc_get_xlat_entry(op_array->opcodes);
441
26.7k
    if (persist_ptr) {
442
0
      op_array->opcodes = persist_ptr;
443
0
      if (op_array->static_variables) {
444
0
        op_array->static_variables = zend_shared_alloc_get_xlat_entry(op_array->static_variables);
445
0
        ZEND_ASSERT(op_array->static_variables != NULL);
446
0
      }
447
0
      if (op_array->literals) {
448
0
        op_array->literals = zend_shared_alloc_get_xlat_entry(op_array->literals);
449
0
        ZEND_ASSERT(op_array->literals != NULL);
450
0
      }
451
0
      if (op_array->filename) {
452
0
        op_array->filename = zend_shared_alloc_get_xlat_entry(op_array->filename);
453
0
        ZEND_ASSERT(op_array->filename != NULL);
454
0
      }
455
0
      if (op_array->arg_info) {
456
0
        zend_arg_info *arg_info = op_array->arg_info;
457
0
        if (op_array->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
458
0
          arg_info--;
459
0
        }
460
0
        arg_info = zend_shared_alloc_get_xlat_entry(arg_info);
461
0
        ZEND_ASSERT(arg_info != NULL);
462
0
        if (op_array->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
463
0
          arg_info++;
464
0
        }
465
0
        op_array->arg_info = arg_info;
466
0
      }
467
0
      if (op_array->live_range) {
468
0
        op_array->live_range = zend_shared_alloc_get_xlat_entry(op_array->live_range);
469
0
        ZEND_ASSERT(op_array->live_range != NULL);
470
0
      }
471
0
      if (op_array->doc_comment) {
472
0
        if (ZCG(accel_directives).save_comments) {
473
0
          op_array->doc_comment = zend_shared_alloc_get_xlat_entry(op_array->doc_comment);
474
0
          ZEND_ASSERT(op_array->doc_comment != NULL);
475
0
        } else {
476
0
          op_array->doc_comment = NULL;
477
0
        }
478
0
      }
479
0
      if (op_array->attributes) {
480
0
        op_array->attributes = zend_shared_alloc_get_xlat_entry(op_array->attributes);
481
0
        ZEND_ASSERT(op_array->attributes != NULL);
482
0
      }
483
484
0
      if (op_array->try_catch_array) {
485
0
        op_array->try_catch_array = zend_shared_alloc_get_xlat_entry(op_array->try_catch_array);
486
0
        ZEND_ASSERT(op_array->try_catch_array != NULL);
487
0
      }
488
0
      if (op_array->vars) {
489
0
        op_array->vars = zend_shared_alloc_get_xlat_entry(op_array->vars);
490
0
        ZEND_ASSERT(op_array->vars != NULL);
491
0
      }
492
0
      if (op_array->dynamic_func_defs) {
493
0
        op_array->dynamic_func_defs = zend_shared_alloc_get_xlat_entry(op_array->dynamic_func_defs);
494
0
        ZEND_ASSERT(op_array->dynamic_func_defs != NULL);
495
0
      }
496
0
      ZCG(mem) = (void*)((char*)ZCG(mem) + ZEND_ALIGNED_SIZE(zend_extensions_op_array_persist(op_array, ZCG(mem))));
497
0
      return;
498
0
    }
499
81.4k
  } else {
500
    /* "prototype" may be undefined if "scope" isn't set */
501
81.4k
    op_array->prototype = NULL;
502
81.4k
  }
503
504
108k
  if (op_array->scope
505
26.7k
   && !(op_array->fn_flags & ZEND_ACC_CLOSURE)
506
26.7k
   && (op_array->scope->ce_flags & ZEND_ACC_CACHED)) {
507
4.46k
    return;
508
4.46k
  }
509
510
103k
  if (op_array->static_variables && !zend_accel_in_shm(op_array->static_variables)) {
511
2.07k
    Bucket *p;
512
513
2.07k
    zend_hash_persist(op_array->static_variables);
514
17.3k
    ZEND_HASH_MAP_FOREACH_BUCKET(op_array->static_variables, p) {
515
17.3k
      ZEND_ASSERT(p->key != NULL);
516
17.3k
      zend_accel_store_interned_string(p->key);
517
6.57k
      zend_persist_zval(&p->val);
518
6.57k
    } ZEND_HASH_FOREACH_END();
519
2.07k
    op_array->static_variables = zend_shared_memdup_put_free(op_array->static_variables, sizeof(HashTable));
520
    /* make immutable array */
521
2.07k
    GC_SET_REFCOUNT(op_array->static_variables, 2);
522
2.07k
    GC_TYPE_INFO(op_array->static_variables) = GC_ARRAY | ((IS_ARRAY_IMMUTABLE|GC_NOT_COLLECTABLE) << GC_FLAGS_SHIFT);
523
2.07k
  }
524
525
103k
  if (op_array->literals) {
526
101k
    zval *p, *end;
527
528
101k
    orig_literals = op_array->literals;
529
#if ZEND_USE_ABS_CONST_ADDR
530
    p = zend_shared_memdup_put_free(op_array->literals, sizeof(zval) * op_array->last_literal);
531
#else
532
101k
    p = zend_shared_memdup_put(op_array->literals, sizeof(zval) * op_array->last_literal);
533
101k
#endif
534
101k
    end = p + op_array->last_literal;
535
101k
    op_array->literals = p;
536
925k
    while (p < end) {
537
823k
      zend_persist_zval(p);
538
823k
      p++;
539
823k
    }
540
101k
  }
541
542
103k
  {
543
103k
    zend_op *new_opcodes = zend_shared_memdup_put(op_array->opcodes, sizeof(zend_op) * op_array->last);
544
103k
    zend_op *opline = new_opcodes;
545
103k
    zend_op *end = new_opcodes + op_array->last;
546
103k
    int offset = 0;
547
548
2.59M
    for (; opline < end ; opline++, offset++) {
549
#if ZEND_USE_ABS_CONST_ADDR
550
      if (opline->op1_type == IS_CONST) {
551
        opline->op1.zv = (zval*)((char*)opline->op1.zv + ((char*)op_array->literals - (char*)orig_literals));
552
        if (opline->opcode == ZEND_SEND_VAL
553
         || opline->opcode == ZEND_SEND_VAL_EX
554
         || opline->opcode == ZEND_QM_ASSIGN) {
555
          /* Update handlers to eliminate REFCOUNTED check */
556
          zend_vm_set_opcode_handler_ex(opline, 1 << Z_TYPE_P(opline->op1.zv), 0, 0);
557
        }
558
      }
559
      if (opline->op2_type == IS_CONST) {
560
        opline->op2.zv = (zval*)((char*)opline->op2.zv + ((char*)op_array->literals - (char*)orig_literals));
561
      }
562
#else
563
2.49M
      if (opline->op1_type == IS_CONST) {
564
444k
        opline->op1.constant =
565
444k
          (char*)(op_array->literals +
566
444k
            ((zval*)((char*)(op_array->opcodes + (opline - new_opcodes)) +
567
444k
            (int32_t)opline->op1.constant) - orig_literals)) -
568
444k
          (char*)opline;
569
444k
        if (opline->opcode == ZEND_SEND_VAL
570
402k
         || opline->opcode == ZEND_SEND_VAL_EX
571
380k
         || opline->opcode == ZEND_QM_ASSIGN) {
572
71.1k
          zend_vm_set_opcode_handler_ex(opline, 0, 0, 0);
573
71.1k
        }
574
444k
      }
575
2.49M
      if (opline->op2_type == IS_CONST) {
576
616k
        opline->op2.constant =
577
616k
          (char*)(op_array->literals +
578
616k
            ((zval*)((char*)(op_array->opcodes + (opline - new_opcodes)) +
579
616k
            (int32_t)opline->op2.constant) - orig_literals)) -
580
616k
          (char*)opline;
581
616k
      }
582
2.49M
#endif
583
#if ZEND_USE_ABS_JMP_ADDR
584
      if (op_array->fn_flags & ZEND_ACC_DONE_PASS_TWO) {
585
        /* fix jumps to point to new array */
586
        switch (opline->opcode) {
587
          case ZEND_JMP:
588
          case ZEND_FAST_CALL:
589
            opline->op1.jmp_addr = &new_opcodes[opline->op1.jmp_addr - op_array->opcodes];
590
            break;
591
          case ZEND_JMPZ:
592
          case ZEND_JMPNZ:
593
          case ZEND_JMPZ_EX:
594
          case ZEND_JMPNZ_EX:
595
          case ZEND_JMP_SET:
596
          case ZEND_COALESCE:
597
          case ZEND_FE_RESET_R:
598
          case ZEND_FE_RESET_RW:
599
          case ZEND_ASSERT_CHECK:
600
          case ZEND_JMP_NULL:
601
          case ZEND_BIND_INIT_STATIC_OR_JMP:
602
          case ZEND_JMP_FRAMELESS:
603
            opline->op2.jmp_addr = &new_opcodes[opline->op2.jmp_addr - op_array->opcodes];
604
            break;
605
          case ZEND_CATCH:
606
            if (!(opline->extended_value & ZEND_LAST_CATCH)) {
607
              opline->op2.jmp_addr = &new_opcodes[opline->op2.jmp_addr - op_array->opcodes];
608
            }
609
            break;
610
          case ZEND_FE_FETCH_R:
611
          case ZEND_FE_FETCH_RW:
612
          case ZEND_SWITCH_LONG:
613
          case ZEND_SWITCH_STRING:
614
          case ZEND_MATCH:
615
            /* relative extended_value don't have to be changed */
616
            break;
617
        }
618
      }
619
#endif
620
2.49M
      if (opline->opcode == ZEND_OP_DATA && (opline-1)->opcode == ZEND_DECLARE_ATTRIBUTED_CONST) {
621
168
        zval *literal = RT_CONSTANT(opline, opline->op1);
622
168
        HashTable *attributes = Z_PTR_P(literal);
623
168
        attributes = zend_persist_attributes(attributes);
624
168
        ZVAL_PTR(literal, attributes);
625
168
      }
626
2.49M
    }
627
628
103k
    efree(op_array->opcodes);
629
103k
    op_array->opcodes = new_opcodes;
630
103k
  }
631
632
103k
  if (op_array->filename) {
633
103k
    zend_accel_store_string(op_array->filename);
634
103k
  }
635
636
103k
  if (op_array->arg_info) {
637
22.0k
    zend_arg_info *arg_info = op_array->arg_info;
638
22.0k
    uint32_t num_args = op_array->num_args;
639
22.0k
    uint32_t i;
640
641
22.0k
    if (op_array->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
642
7.21k
      arg_info--;
643
7.21k
      num_args++;
644
7.21k
    }
645
22.0k
    if (op_array->fn_flags & ZEND_ACC_VARIADIC) {
646
398
      num_args++;
647
398
    }
648
22.0k
    arg_info = zend_shared_memdup_put_free(arg_info, sizeof(zend_arg_info) * num_args);
649
54.1k
    for (i = 0; i < num_args; i++) {
650
32.0k
      if (arg_info[i].name) {
651
24.8k
        zend_accel_store_interned_string(arg_info[i].name);
652
24.8k
      }
653
32.0k
      zend_persist_type(&arg_info[i].type);
654
32.0k
    }
655
22.0k
    if (op_array->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
656
7.21k
      arg_info++;
657
7.21k
    }
658
22.0k
    op_array->arg_info = arg_info;
659
22.0k
  }
660
661
103k
  if (op_array->live_range) {
662
53.8k
    op_array->live_range = zend_shared_memdup_put_free(op_array->live_range, sizeof(zend_live_range) * op_array->last_live_range);
663
53.8k
  }
664
665
103k
  if (op_array->doc_comment) {
666
118
    if (ZCG(accel_directives).save_comments) {
667
118
      zend_accel_store_interned_string(op_array->doc_comment);
668
118
    } else {
669
0
      zend_string_release_ex(op_array->doc_comment, 0);
670
0
      op_array->doc_comment = NULL;
671
0
    }
672
118
  }
673
674
103k
  if (op_array->attributes) {
675
1.09k
    op_array->attributes = zend_persist_attributes(op_array->attributes);
676
1.09k
  }
677
678
103k
  if (op_array->try_catch_array) {
679
25.9k
    op_array->try_catch_array = zend_shared_memdup_put_free(op_array->try_catch_array, sizeof(zend_try_catch_element) * op_array->last_try_catch);
680
25.9k
  }
681
682
103k
  if (op_array->vars) {
683
68.5k
    int i;
684
68.5k
    op_array->vars = zend_shared_memdup_put_free(op_array->vars, sizeof(zend_string*) * op_array->last_var);
685
435k
    for (i = 0; i < op_array->last_var; i++) {
686
366k
      zend_accel_store_interned_string(op_array->vars[i]);
687
366k
    }
688
68.5k
  }
689
690
103k
  if (op_array->num_dynamic_func_defs) {
691
5.01k
    op_array->dynamic_func_defs = zend_shared_memdup_put_free(
692
5.01k
      op_array->dynamic_func_defs, sizeof(zend_function *) * op_array->num_dynamic_func_defs);
693
12.7k
    for (uint32_t i = 0; i < op_array->num_dynamic_func_defs; i++) {
694
7.76k
      zval tmp;
695
7.76k
      ZVAL_PTR(&tmp, op_array->dynamic_func_defs[i]);
696
7.76k
      zend_persist_op_array(&tmp);
697
7.76k
      op_array->dynamic_func_defs[i] = Z_PTR(tmp);
698
7.76k
    }
699
5.01k
  }
700
701
103k
  ZCG(mem) = (void*)((char*)ZCG(mem) + ZEND_ALIGNED_SIZE(zend_extensions_op_array_persist(op_array, ZCG(mem))));
702
103k
}
703
704
static void zend_persist_op_array(zval *zv)
705
21.0k
{
706
21.0k
  zend_op_array *op_array = Z_PTR_P(zv);
707
21.0k
  zend_op_array *old_op_array;
708
21.0k
  ZEND_ASSERT(op_array->type == ZEND_USER_FUNCTION);
709
710
21.0k
  old_op_array = zend_shared_alloc_get_xlat_entry(op_array);
711
21.0k
  if (!old_op_array) {
712
21.0k
    op_array = Z_PTR_P(zv) = zend_shared_memdup_put(Z_PTR_P(zv), sizeof(zend_op_array));
713
21.0k
    zend_persist_op_array_ex(op_array, NULL);
714
21.0k
    if (!ZCG(current_persistent_script)->corrupted) {
715
21.0k
      op_array->fn_flags |= ZEND_ACC_IMMUTABLE;
716
21.0k
      ZEND_MAP_PTR_NEW(op_array->run_time_cache);
717
21.0k
      if (op_array->static_variables) {
718
1.91k
        ZEND_MAP_PTR_NEW(op_array->static_variables_ptr);
719
1.91k
      }
720
21.0k
    }
721
21.0k
#ifdef HAVE_JIT
722
21.0k
    if (JIT_G(on)
723
0
     && JIT_G(opt_level) <= ZEND_JIT_LEVEL_OPT_FUNCS
724
0
     && (!ZCG(current_persistent_script)
725
0
      || !ZCG(current_persistent_script)->corrupted)) {
726
0
      zend_jit_op_array(op_array, ZCG(current_persistent_script) ? &ZCG(current_persistent_script)->script : NULL);
727
0
    }
728
21.0k
#endif
729
21.0k
  } else {
730
    /* This can happen during preloading, if a dynamic function definition is declared. */
731
0
    Z_PTR_P(zv) = old_op_array;
732
0
  }
733
21.0k
}
734
735
static zend_op_array *zend_persist_class_method(zend_op_array *op_array, zend_class_entry *ce)
736
34.3k
{
737
34.3k
  zend_op_array *old_op_array;
738
739
34.3k
  if (op_array->type != ZEND_USER_FUNCTION) {
740
5.55k
    ZEND_ASSERT(op_array->type == ZEND_INTERNAL_FUNCTION);
741
5.55k
    if (op_array->fn_flags & ZEND_ACC_ARENA_ALLOCATED) {
742
5.55k
      old_op_array = zend_shared_alloc_get_xlat_entry(op_array);
743
5.55k
      if (old_op_array) {
744
0
        return old_op_array;
745
5.55k
      } else {
746
5.55k
        op_array = zend_shared_memdup_put(op_array, sizeof(zend_internal_function));
747
5.55k
        if (op_array->scope) {
748
5.55k
          void *persist_ptr;
749
750
5.55k
          if ((persist_ptr = zend_shared_alloc_get_xlat_entry(op_array->scope))) {
751
0
            op_array->scope = (zend_class_entry*)persist_ptr;
752
0
          }
753
5.55k
          if (op_array->prototype) {
754
2.43k
            if ((persist_ptr = zend_shared_alloc_get_xlat_entry(op_array->prototype))) {
755
0
              op_array->prototype = (zend_function*)persist_ptr;
756
0
            }
757
2.43k
          }
758
5.55k
        }
759
        // Real dynamically created internal functions like enum methods must have their own run_time_cache pointer. They're always on the same scope as their defining class.
760
        // However, copies - as caused by inheritance of internal methods - must retain the original run_time_cache pointer, shared with the source function.
761
5.55k
        if (!op_array->scope || (op_array->scope == ce && !(op_array->fn_flags & ZEND_ACC_TRAIT_CLONE))) {
762
0
          if (op_array->fn_flags & ZEND_ACC_PRELOADED) {
763
0
            ZEND_MAP_PTR_NEW_STATIC(op_array->run_time_cache);
764
0
          } else {
765
0
            ZEND_MAP_PTR_NEW(op_array->run_time_cache);
766
0
          }
767
0
        }
768
5.55k
      }
769
5.55k
    }
770
5.55k
    return op_array;
771
5.55k
  }
772
773
28.8k
  if ((op_array->fn_flags & ZEND_ACC_IMMUTABLE)
774
470
   && !ZCG(current_persistent_script)->corrupted
775
470
   && zend_accel_in_shm(op_array)) {
776
462
    zend_shared_alloc_register_xlat_entry(op_array, op_array);
777
462
    return op_array;
778
462
  }
779
780
28.3k
  old_op_array = zend_shared_alloc_get_xlat_entry(op_array);
781
28.3k
  if (old_op_array) {
782
1.63k
    if (op_array->refcount && --(*op_array->refcount) == 0) {
783
1.38k
      efree(op_array->refcount);
784
1.38k
    }
785
786
    /* If op_array is shared, the function name refcount is still incremented for each use,
787
     * so we need to release it here. We remembered the original function name in xlat. */
788
1.63k
    zend_string *old_function_name =
789
1.63k
      zend_shared_alloc_get_xlat_entry(&old_op_array->function_name);
790
1.63k
    if (old_function_name) {
791
60
      zend_string_release_ex(old_function_name, 0);
792
60
    }
793
1.63k
    return old_op_array;
794
1.63k
  }
795
796
26.7k
  op_array = zend_shared_memdup_put(op_array, sizeof(zend_op_array));
797
26.7k
  zend_persist_op_array_ex(op_array, NULL);
798
26.7k
  if (ce->ce_flags & ZEND_ACC_IMMUTABLE) {
799
26.7k
    op_array->fn_flags |= ZEND_ACC_IMMUTABLE;
800
26.7k
    if (ce->ce_flags & ZEND_ACC_LINKED) {
801
22.6k
      ZEND_MAP_PTR_NEW(op_array->run_time_cache);
802
22.6k
      if (op_array->static_variables) {
803
161
        ZEND_MAP_PTR_NEW(op_array->static_variables_ptr);
804
161
      }
805
22.6k
    } else {
806
4.05k
      ZEND_MAP_PTR_INIT(op_array->run_time_cache, NULL);
807
4.05k
      ZEND_MAP_PTR_INIT(op_array->static_variables_ptr, NULL);
808
4.05k
    }
809
26.7k
  }
810
26.7k
  return op_array;
811
28.3k
}
812
813
static zend_property_info *zend_persist_property_info(zend_property_info *prop)
814
15.2k
{
815
15.2k
  zend_class_entry *ce;
816
15.2k
  prop = zend_shared_memdup_put(prop, sizeof(zend_property_info));
817
15.2k
  ce = zend_shared_alloc_get_xlat_entry(prop->ce);
818
15.2k
  if (ce) {
819
15.2k
    prop->ce = ce;
820
15.2k
  }
821
15.2k
  zend_accel_store_interned_string(prop->name);
822
15.2k
  if (prop->doc_comment) {
823
200
    if (ZCG(accel_directives).save_comments) {
824
200
      zend_accel_store_interned_string(prop->doc_comment);
825
200
    } else {
826
0
      if (!zend_shared_alloc_get_xlat_entry(prop->doc_comment)) {
827
0
        zend_shared_alloc_register_xlat_entry(prop->doc_comment, prop->doc_comment);
828
0
      }
829
0
      zend_string_release_ex(prop->doc_comment, 0);
830
0
      prop->doc_comment = NULL;
831
0
    }
832
200
  }
833
15.2k
  if (prop->attributes) {
834
188
    prop->attributes = zend_persist_attributes(prop->attributes);
835
188
  }
836
15.2k
  if (prop->prototype) {
837
15.2k
    zend_property_info *new_prototype = (zend_property_info *) zend_shared_alloc_get_xlat_entry(prop->prototype);
838
15.2k
    if (new_prototype) {
839
15.1k
      prop->prototype = new_prototype;
840
15.1k
    }
841
15.2k
  }
842
15.2k
  if (prop->hooks) {
843
1.55k
    prop->hooks = zend_shared_memdup_put(prop->hooks, ZEND_PROPERTY_HOOK_STRUCT_SIZE);
844
4.65k
    for (uint32_t i = 0; i < ZEND_PROPERTY_HOOK_COUNT; i++) {
845
3.10k
      if (prop->hooks[i]) {
846
2.05k
        zend_op_array *hook = zend_persist_class_method(&prop->hooks[i]->op_array, ce);
847
2.05k
#ifdef HAVE_JIT
848
2.05k
        if (JIT_G(on)
849
0
         && JIT_G(opt_level) <= ZEND_JIT_LEVEL_OPT_FUNCS
850
0
         && (!ZCG(current_persistent_script)
851
0
          || !ZCG(current_persistent_script)->corrupted)) {
852
0
          if (hook->scope == ce && !(hook->fn_flags & ZEND_ACC_TRAIT_CLONE)) {
853
0
            zend_jit_op_array(hook, ZCG(current_persistent_script) ? &ZCG(current_persistent_script)->script : NULL);
854
0
          }
855
0
        }
856
2.05k
#endif
857
2.05k
        zend_property_info *new_prop_info = (zend_property_info *) zend_shared_alloc_get_xlat_entry(hook->prop_info);
858
2.05k
        if (new_prop_info) {
859
2.00k
          hook->prop_info = new_prop_info;
860
2.00k
        }
861
2.05k
        prop->hooks[i] = (zend_function *) hook;
862
2.05k
      }
863
3.10k
    }
864
1.55k
  }
865
15.2k
  zend_persist_type(&prop->type);
866
15.2k
  return prop;
867
15.2k
}
868
869
static void zend_persist_class_constant(zval *zv)
870
6.98k
{
871
6.98k
  zend_class_constant *orig_c = Z_PTR_P(zv);
872
6.98k
  zend_class_constant *c = zend_shared_alloc_get_xlat_entry(orig_c);
873
6.98k
  zend_class_entry *ce;
874
875
6.98k
  if (c) {
876
144
    Z_PTR_P(zv) = c;
877
144
    return;
878
6.84k
  } else if (((orig_c->ce->ce_flags & ZEND_ACC_IMMUTABLE) && !(Z_CONSTANT_FLAGS(orig_c->value) & CONST_OWNED))
879
6.71k
   || orig_c->ce->type == ZEND_INTERNAL_CLASS) {
880
    /* Class constant comes from a different file in shm or internal class, keep existing pointer. */
881
2.02k
    return;
882
4.82k
  } else if (!ZCG(current_persistent_script)->corrupted
883
4.82k
   && zend_accel_in_shm(Z_PTR_P(zv))) {
884
0
    return;
885
0
  }
886
4.82k
  c = Z_PTR_P(zv) = zend_shared_memdup_put(Z_PTR_P(zv), sizeof(zend_class_constant));
887
4.82k
  zend_persist_zval(&c->value);
888
4.82k
  ce = zend_shared_alloc_get_xlat_entry(c->ce);
889
4.82k
  if (ce) {
890
4.81k
    c->ce = ce;
891
4.81k
  }
892
4.82k
  if (c->doc_comment) {
893
22
    if (ZCG(accel_directives).save_comments) {
894
22
      zend_string *doc_comment = zend_shared_alloc_get_xlat_entry(c->doc_comment);
895
22
      if (doc_comment) {
896
0
        c->doc_comment = doc_comment;
897
22
      } else {
898
22
        zend_accel_store_interned_string(c->doc_comment);
899
22
      }
900
22
    } else {
901
0
      zend_string *doc_comment = zend_shared_alloc_get_xlat_entry(c->doc_comment);
902
0
      if (!doc_comment) {
903
0
        zend_shared_alloc_register_xlat_entry(c->doc_comment, c->doc_comment);
904
0
        zend_string_release_ex(c->doc_comment, 0);
905
0
      }
906
0
      c->doc_comment = NULL;
907
0
    }
908
22
  }
909
4.82k
  if (c->attributes) {
910
168
    c->attributes = zend_persist_attributes(c->attributes);
911
168
  }
912
4.82k
  zend_persist_type(&c->type);
913
4.82k
}
914
915
zend_class_entry *zend_persist_class_entry(zend_class_entry *orig_ce)
916
27.3k
{
917
27.3k
  Bucket *p;
918
27.3k
  zend_class_entry *ce = orig_ce;
919
920
27.3k
  if (ce->type == ZEND_USER_CLASS) {
921
    /* The same zend_class_entry may be reused by class_alias */
922
27.3k
    zend_class_entry *new_ce = zend_shared_alloc_get_xlat_entry(ce);
923
27.3k
    if (new_ce) {
924
0
      return new_ce;
925
0
    }
926
27.3k
    ce = zend_shared_memdup_put(ce, sizeof(zend_class_entry));
927
27.3k
    if (EXPECTED(!ZCG(current_persistent_script)->corrupted)) {
928
27.3k
      ce->ce_flags |= ZEND_ACC_IMMUTABLE;
929
27.3k
      if ((ce->ce_flags & ZEND_ACC_LINKED)
930
22.0k
       && !(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
931
716
        ZEND_MAP_PTR_NEW(ce->mutable_data);
932
26.6k
      } else {
933
26.6k
        ZEND_MAP_PTR_INIT(ce->mutable_data, NULL);
934
26.6k
      }
935
27.3k
    } else {
936
0
      ce->ce_flags |= ZEND_ACC_FILE_CACHED;
937
0
    }
938
27.3k
    ce->inheritance_cache = NULL;
939
940
27.3k
    if (!(ce->ce_flags & ZEND_ACC_CACHED)) {
941
24.4k
      if (ZSTR_HAS_CE_CACHE(ce->name)) {
942
22.0k
        ZSTR_SET_CE_CACHE_EX(ce->name, NULL, 0);
943
22.0k
      }
944
24.4k
      zend_accel_store_interned_string(ce->name);
945
24.4k
      if (!(ce->ce_flags & ZEND_ACC_ANON_CLASS)
946
23.6k
       && !ZCG(current_persistent_script)->corrupted) {
947
23.6k
        zend_accel_get_class_name_map_ptr(ce->name);
948
23.6k
      }
949
24.4k
      if (ce->parent_name && !(ce->ce_flags & ZEND_ACC_LINKED)) {
950
1.29k
        zend_accel_store_interned_string(ce->parent_name);
951
1.29k
      }
952
24.4k
    }
953
954
27.3k
    zend_hash_persist(&ce->function_table);
955
119k
    ZEND_HASH_MAP_FOREACH_BUCKET(&ce->function_table, p) {
956
119k
      ZEND_ASSERT(p->key != NULL);
957
119k
      zend_accel_store_interned_string(p->key);
958
32.3k
      Z_PTR(p->val) = zend_persist_class_method(Z_PTR(p->val), ce);
959
32.3k
    } ZEND_HASH_FOREACH_END();
960
27.3k
    HT_FLAGS(&ce->function_table) &= (HASH_FLAG_UNINITIALIZED | HASH_FLAG_STATIC_KEYS);
961
27.3k
    if (ce->default_properties_table) {
962
8.66k
        int i;
963
964
8.66k
      ce->default_properties_table = zend_shared_memdup_free(ce->default_properties_table, sizeof(zval) * ce->default_properties_count);
965
22.6k
      for (i = 0; i < ce->default_properties_count; i++) {
966
14.0k
        zend_persist_zval(&ce->default_properties_table[i]);
967
14.0k
      }
968
8.66k
    }
969
27.3k
    if (ce->default_static_members_table) {
970
1.52k
      int i;
971
1.52k
      ce->default_static_members_table = zend_shared_memdup_free(ce->default_static_members_table, sizeof(zval) * ce->default_static_members_count);
972
973
      /* Persist only static properties in this class.
974
       * Static properties from parent classes will be handled in class_copy_ctor and are marked with IS_INDIRECT */
975
4.67k
      for (i = 0; i < ce->default_static_members_count; i++) {
976
3.15k
        if (Z_TYPE(ce->default_static_members_table[i]) != IS_INDIRECT) {
977
2.76k
          zend_persist_zval(&ce->default_static_members_table[i]);
978
2.76k
        }
979
3.15k
      }
980
1.52k
      if (ce->ce_flags & ZEND_ACC_IMMUTABLE) {
981
1.52k
        if (ce->ce_flags & ZEND_ACC_LINKED) {
982
1.47k
          ZEND_MAP_PTR_NEW(ce->static_members_table);
983
1.47k
        } else {
984
48
          ZEND_MAP_PTR_INIT(ce->static_members_table, NULL);
985
48
        }
986
1.52k
      }
987
1.52k
    }
988
989
27.3k
    zend_hash_persist(&ce->constants_table);
990
68.7k
    ZEND_HASH_MAP_FOREACH_BUCKET(&ce->constants_table, p) {
991
68.7k
      ZEND_ASSERT(p->key != NULL);
992
68.7k
      zend_accel_store_interned_string(p->key);
993
6.98k
      zend_persist_class_constant(&p->val);
994
6.98k
    } ZEND_HASH_FOREACH_END();
995
27.3k
    HT_FLAGS(&ce->constants_table) &= (HASH_FLAG_UNINITIALIZED | HASH_FLAG_STATIC_KEYS);
996
997
27.3k
    zend_hash_persist(&ce->properties_info);
998
90.0k
    ZEND_HASH_MAP_FOREACH_BUCKET(&ce->properties_info, p) {
999
90.0k
      zend_property_info *prop = Z_PTR(p->val);
1000
90.0k
      ZEND_ASSERT(p->key != NULL);
1001
90.0k
      zend_accel_store_interned_string(p->key);
1002
17.6k
      if (prop->ce == orig_ce) {
1003
15.2k
        Z_PTR(p->val) = zend_persist_property_info(prop);
1004
15.2k
      } else {
1005
2.38k
        prop = zend_shared_alloc_get_xlat_entry(prop);
1006
2.38k
        if (prop) {
1007
1.14k
          Z_PTR(p->val) = prop;
1008
1.24k
        } else {
1009
          /* This can happen if preloading is used and we inherit a property from an
1010
           * internal class. In that case we should keep pointing to the internal
1011
           * property, without any adjustments. */
1012
1.24k
        }
1013
2.38k
      }
1014
17.6k
    } ZEND_HASH_FOREACH_END();
1015
27.3k
    HT_FLAGS(&ce->properties_info) &= (HASH_FLAG_UNINITIALIZED | HASH_FLAG_STATIC_KEYS);
1016
1017
27.3k
    if (ce->properties_info_table) {
1018
6.99k
      int i;
1019
1020
6.99k
      size_t size = sizeof(zend_property_info *) * ce->default_properties_count;
1021
6.99k
      ZEND_ASSERT(ce->ce_flags & ZEND_ACC_LINKED);
1022
6.99k
      ce->properties_info_table = zend_shared_memdup(
1023
6.99k
        ce->properties_info_table, size);
1024
1025
18.8k
      for (i = 0; i < ce->default_properties_count; i++) {
1026
11.8k
        if (ce->properties_info_table[i]) {
1027
11.4k
          zend_property_info *prop_info = zend_shared_alloc_get_xlat_entry(
1028
11.4k
            ce->properties_info_table[i]);
1029
11.4k
          if (prop_info) {
1030
10.3k
            ce->properties_info_table[i] = prop_info;
1031
10.3k
          }
1032
11.4k
        }
1033
11.8k
      }
1034
6.99k
    }
1035
1036
27.3k
    if (ce->iterator_funcs_ptr) {
1037
247
      ce->iterator_funcs_ptr = zend_shared_memdup(ce->iterator_funcs_ptr, sizeof(zend_class_iterator_funcs));
1038
247
    }
1039
27.3k
    if (ce->arrayaccess_funcs_ptr) {
1040
290
      ce->arrayaccess_funcs_ptr = zend_shared_memdup(ce->arrayaccess_funcs_ptr, sizeof(zend_class_arrayaccess_funcs));
1041
290
    }
1042
1043
27.3k
    if (ce->ce_flags & ZEND_ACC_CACHED) {
1044
2.96k
      return ce;
1045
2.96k
    }
1046
1047
24.4k
    ce->ce_flags |= ZEND_ACC_CACHED;
1048
1049
24.4k
    if (ce->info.user.filename) {
1050
24.4k
      zend_accel_store_string(ce->info.user.filename);
1051
24.4k
    }
1052
1053
24.4k
    if (ce->doc_comment) {
1054
28
      if (ZCG(accel_directives).save_comments) {
1055
28
        zend_accel_store_interned_string(ce->doc_comment);
1056
28
      } else {
1057
0
        if (!zend_shared_alloc_get_xlat_entry(ce->doc_comment)) {
1058
0
          zend_shared_alloc_register_xlat_entry(ce->doc_comment, ce->doc_comment);
1059
0
          zend_string_release_ex(ce->doc_comment, 0);
1060
0
        }
1061
0
        ce->doc_comment = NULL;
1062
0
      }
1063
28
    }
1064
1065
24.4k
    if (ce->attributes) {
1066
978
      ce->attributes = zend_persist_attributes(ce->attributes);
1067
978
    }
1068
1069
24.4k
    if (ce->num_interfaces && !(ce->ce_flags & ZEND_ACC_LINKED)) {
1070
3.16k
      uint32_t i = 0;
1071
1072
7.11k
      for (i = 0; i < ce->num_interfaces; i++) {
1073
3.95k
        zend_accel_store_interned_string(ce->interface_names[i].name);
1074
3.95k
        zend_accel_store_interned_string(ce->interface_names[i].lc_name);
1075
3.95k
      }
1076
3.16k
      ce->interface_names = zend_shared_memdup_free(ce->interface_names, sizeof(zend_class_name) * ce->num_interfaces);
1077
3.16k
    }
1078
1079
24.4k
    if (ce->num_traits) {
1080
1.45k
      uint32_t i = 0;
1081
1082
3.26k
      for (i = 0; i < ce->num_traits; i++) {
1083
1.80k
        zend_accel_store_interned_string(ce->trait_names[i].name);
1084
1.80k
        zend_accel_store_interned_string(ce->trait_names[i].lc_name);
1085
1.80k
      }
1086
1.45k
      ce->trait_names = zend_shared_memdup_free(ce->trait_names, sizeof(zend_class_name) * ce->num_traits);
1087
1088
1.45k
      i = 0;
1089
1.45k
      if (ce->trait_aliases) {
1090
654
        while (ce->trait_aliases[i]) {
1091
432
          if (ce->trait_aliases[i]->trait_method.method_name) {
1092
432
            zend_accel_store_interned_string(ce->trait_aliases[i]->trait_method.method_name);
1093
432
          }
1094
432
          if (ce->trait_aliases[i]->trait_method.class_name) {
1095
184
            zend_accel_store_interned_string(ce->trait_aliases[i]->trait_method.class_name);
1096
184
          }
1097
1098
432
          if (ce->trait_aliases[i]->alias) {
1099
284
            zend_accel_store_interned_string(ce->trait_aliases[i]->alias);
1100
284
          }
1101
1102
432
          ce->trait_aliases[i] = zend_shared_memdup_free(ce->trait_aliases[i], sizeof(zend_trait_alias));
1103
432
          i++;
1104
432
        }
1105
1106
222
        ce->trait_aliases = zend_shared_memdup_free(ce->trait_aliases, sizeof(zend_trait_alias*) * (i + 1));
1107
222
      }
1108
1109
1.45k
      if (ce->trait_precedences) {
1110
72
        uint32_t j;
1111
1112
72
        i = 0;
1113
162
        while (ce->trait_precedences[i]) {
1114
90
          zend_accel_store_interned_string(ce->trait_precedences[i]->trait_method.method_name);
1115
90
          zend_accel_store_interned_string(ce->trait_precedences[i]->trait_method.class_name);
1116
1117
184
          for (j = 0; j < ce->trait_precedences[i]->num_excludes; j++) {
1118
94
            zend_accel_store_interned_string(ce->trait_precedences[i]->exclude_class_names[j]);
1119
94
          }
1120
1121
90
          ce->trait_precedences[i] = zend_shared_memdup_free(ce->trait_precedences[i], sizeof(zend_trait_precedence) + (ce->trait_precedences[i]->num_excludes - 1) * sizeof(zend_string*));
1122
90
          i++;
1123
90
        }
1124
72
        ce->trait_precedences = zend_shared_memdup_free(
1125
72
          ce->trait_precedences, sizeof(zend_trait_precedence*) * (i + 1));
1126
72
      }
1127
1.45k
    }
1128
1129
24.4k
    ZEND_ASSERT(ce->backed_enum_table == NULL);
1130
24.4k
  }
1131
1132
24.4k
  return ce;
1133
27.3k
}
1134
1135
void zend_update_parent_ce(zend_class_entry *ce)
1136
27.3k
{
1137
27.3k
  if (ce->ce_flags & ZEND_ACC_LINKED) {
1138
22.0k
    if (ce->parent) {
1139
3.29k
      int i, end;
1140
3.29k
      zend_class_entry *parent = ce->parent;
1141
1142
3.29k
      if (parent->type == ZEND_USER_CLASS) {
1143
2.88k
        zend_class_entry *p = zend_shared_alloc_get_xlat_entry(parent);
1144
1145
2.88k
        if (p) {
1146
2.24k
          ce->parent = parent = p;
1147
2.24k
        }
1148
2.88k
      }
1149
1150
      /* Create indirections to static properties from parent classes */
1151
3.29k
      i = parent->default_static_members_count - 1;
1152
3.56k
      while (parent && parent->default_static_members_table) {
1153
266
        end = parent->parent ? parent->parent->default_static_members_count : 0;
1154
648
        for (; i >= end; i--) {
1155
382
          zval *p = &ce->default_static_members_table[i];
1156
          /* The static property may have been overridden by a trait
1157
           * during inheritance. In that case, the property default
1158
           * value is replaced by zend_declare_typed_property() at the
1159
           * property index of the parent property. Make sure we only
1160
           * point to the parent property value if the child value was
1161
           * already indirect. */
1162
382
          if (Z_TYPE_P(p) == IS_INDIRECT) {
1163
382
            ZVAL_INDIRECT(p, &parent->default_static_members_table[i]);
1164
382
          }
1165
382
        }
1166
1167
266
        parent = parent->parent;
1168
266
      }
1169
3.29k
    }
1170
1171
22.0k
    if (ce->num_interfaces) {
1172
2.05k
      uint32_t i = 0;
1173
1174
2.05k
      ce->interfaces = zend_shared_memdup_free(ce->interfaces, sizeof(zend_class_entry*) * ce->num_interfaces);
1175
4.96k
      for (i = 0; i < ce->num_interfaces; i++) {
1176
2.90k
        if (ce->interfaces[i]->type == ZEND_USER_CLASS) {
1177
1.15k
          zend_class_entry *tmp = zend_shared_alloc_get_xlat_entry(ce->interfaces[i]);
1178
1.15k
          if (tmp != NULL) {
1179
0
            ce->interfaces[i] = tmp;
1180
0
          }
1181
1.15k
        }
1182
2.90k
      }
1183
2.05k
    }
1184
1185
22.0k
    if (ce->iterator_funcs_ptr) {
1186
247
      memset(ce->iterator_funcs_ptr, 0, sizeof(zend_class_iterator_funcs));
1187
247
      if (zend_class_implements_interface(ce, zend_ce_aggregate)) {
1188
160
        ce->iterator_funcs_ptr->zf_new_iterator = zend_hash_str_find_ptr(&ce->function_table, "getiterator", sizeof("getiterator") - 1);
1189
160
      }
1190
247
      if (zend_class_implements_interface(ce, zend_ce_iterator)) {
1191
87
        ce->iterator_funcs_ptr->zf_rewind = zend_hash_str_find_ptr(&ce->function_table, "rewind", sizeof("rewind") - 1);
1192
87
        ce->iterator_funcs_ptr->zf_valid = zend_hash_str_find_ptr(&ce->function_table, "valid", sizeof("valid") - 1);
1193
87
        ce->iterator_funcs_ptr->zf_key = zend_hash_find_ptr(&ce->function_table, ZSTR_KNOWN(ZEND_STR_KEY));
1194
87
        ce->iterator_funcs_ptr->zf_current = zend_hash_str_find_ptr(&ce->function_table, "current", sizeof("current") - 1);
1195
87
        ce->iterator_funcs_ptr->zf_next = zend_hash_str_find_ptr(&ce->function_table, "next", sizeof("next") - 1);
1196
87
      }
1197
247
    }
1198
1199
22.0k
    if (ce->arrayaccess_funcs_ptr) {
1200
290
      ZEND_ASSERT(zend_class_implements_interface(ce, zend_ce_arrayaccess));
1201
290
      ce->arrayaccess_funcs_ptr->zf_offsetget = zend_hash_str_find_ptr(&ce->function_table, "offsetget", sizeof("offsetget") - 1);
1202
290
      ce->arrayaccess_funcs_ptr->zf_offsetexists = zend_hash_str_find_ptr(&ce->function_table, "offsetexists", sizeof("offsetexists") - 1);
1203
290
      ce->arrayaccess_funcs_ptr->zf_offsetset = zend_hash_str_find_ptr(&ce->function_table, "offsetset", sizeof("offsetset") - 1);
1204
290
      ce->arrayaccess_funcs_ptr->zf_offsetunset = zend_hash_str_find_ptr(&ce->function_table, "offsetunset", sizeof("offsetunset") - 1);
1205
290
    }
1206
22.0k
  }
1207
1208
  /* update methods */
1209
27.3k
  if (ce->constructor) {
1210
3.58k
    zend_function *tmp = zend_shared_alloc_get_xlat_entry(ce->constructor);
1211
3.58k
    if (tmp != NULL) {
1212
3.32k
      ce->constructor = tmp;
1213
3.32k
    }
1214
3.58k
  }
1215
27.3k
  if (ce->destructor) {
1216
2.28k
    zend_function *tmp = zend_shared_alloc_get_xlat_entry(ce->destructor);
1217
2.28k
    if (tmp != NULL) {
1218
2.28k
      ce->destructor = tmp;
1219
2.28k
    }
1220
2.28k
  }
1221
27.3k
  if (ce->clone) {
1222
318
    zend_function *tmp = zend_shared_alloc_get_xlat_entry(ce->clone);
1223
318
    if (tmp != NULL) {
1224
190
      ce->clone = tmp;
1225
190
    }
1226
318
  }
1227
27.3k
  if (ce->__get) {
1228
671
    zend_function *tmp = zend_shared_alloc_get_xlat_entry(ce->__get);
1229
671
    if (tmp != NULL) {
1230
671
      ce->__get = tmp;
1231
671
    }
1232
671
  }
1233
27.3k
  if (ce->__set) {
1234
452
    zend_function *tmp = zend_shared_alloc_get_xlat_entry(ce->__set);
1235
452
    if (tmp != NULL) {
1236
452
      ce->__set = tmp;
1237
452
    }
1238
452
  }
1239
27.3k
  if (ce->__call) {
1240
547
    zend_function *tmp = zend_shared_alloc_get_xlat_entry(ce->__call);
1241
547
    if (tmp != NULL) {
1242
547
      ce->__call = tmp;
1243
547
    }
1244
547
  }
1245
27.3k
  if (ce->__serialize) {
1246
220
    zend_function *tmp = zend_shared_alloc_get_xlat_entry(ce->__serialize);
1247
220
    if (tmp != NULL) {
1248
36
      ce->__serialize = tmp;
1249
36
    }
1250
220
  }
1251
27.3k
  if (ce->__unserialize) {
1252
216
    zend_function *tmp = zend_shared_alloc_get_xlat_entry(ce->__unserialize);
1253
216
    if (tmp != NULL) {
1254
32
      ce->__unserialize = tmp;
1255
32
    }
1256
216
  }
1257
27.3k
  if (ce->__isset) {
1258
204
    zend_function *tmp = zend_shared_alloc_get_xlat_entry(ce->__isset);
1259
204
    if (tmp != NULL) {
1260
204
      ce->__isset = tmp;
1261
204
    }
1262
204
  }
1263
27.3k
  if (ce->__unset) {
1264
126
    zend_function *tmp = zend_shared_alloc_get_xlat_entry(ce->__unset);
1265
126
    if (tmp != NULL) {
1266
126
      ce->__unset = tmp;
1267
126
    }
1268
126
  }
1269
27.3k
  if (ce->__tostring) {
1270
964
    zend_function *tmp = zend_shared_alloc_get_xlat_entry(ce->__tostring);
1271
964
    if (tmp != NULL) {
1272
844
      ce->__tostring = tmp;
1273
844
    }
1274
964
  }
1275
27.3k
  if (ce->__callstatic) {
1276
353
    zend_function *tmp = zend_shared_alloc_get_xlat_entry(ce->__callstatic);
1277
353
    if (tmp != NULL) {
1278
353
      ce->__callstatic = tmp;
1279
353
    }
1280
353
  }
1281
27.3k
  if (ce->__debugInfo) {
1282
130
    zend_function *tmp = zend_shared_alloc_get_xlat_entry(ce->__debugInfo);
1283
130
    if (tmp != NULL) {
1284
90
      ce->__debugInfo = tmp;
1285
90
    }
1286
130
  }
1287
27.3k
}
1288
1289
#ifdef HAVE_JIT
1290
static void zend_accel_persist_jit_op_array(zend_op_array *op_array, zend_class_entry *ce)
1291
0
{
1292
0
  if (op_array->type == ZEND_USER_FUNCTION) {
1293
0
    if (op_array->scope == ce
1294
0
     && !(op_array->fn_flags & ZEND_ACC_ABSTRACT)
1295
0
     && !(op_array->fn_flags & ZEND_ACC_TRAIT_CLONE)) {
1296
0
      zend_jit_op_array(op_array, ZCG(current_persistent_script) ? &ZCG(current_persistent_script)->script : NULL);
1297
0
      for (uint32_t i = 0; i < op_array->num_dynamic_func_defs; i++) {
1298
0
        zend_jit_op_array(op_array->dynamic_func_defs[i], ZCG(current_persistent_script) ? &ZCG(current_persistent_script)->script : NULL);
1299
0
      }
1300
0
    }
1301
0
  }
1302
0
}
1303
1304
static void zend_accel_persist_link_func_info(zend_op_array *op_array, zend_class_entry *ce)
1305
0
{
1306
0
  if (op_array->type == ZEND_USER_FUNCTION
1307
0
   && !(op_array->fn_flags & ZEND_ACC_ABSTRACT)) {
1308
0
    if ((op_array->scope != ce
1309
0
     || (op_array->fn_flags & ZEND_ACC_TRAIT_CLONE))
1310
0
      && (JIT_G(trigger) == ZEND_JIT_ON_FIRST_EXEC
1311
0
      || JIT_G(trigger) == ZEND_JIT_ON_PROF_REQUEST
1312
0
      || JIT_G(trigger) == ZEND_JIT_ON_HOT_COUNTERS
1313
0
      || JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE)) {
1314
0
      void *jit_extension = zend_shared_alloc_get_xlat_entry(op_array->opcodes);
1315
1316
0
      if (jit_extension) {
1317
0
        ZEND_SET_FUNC_INFO(op_array, jit_extension);
1318
0
      }
1319
0
    }
1320
0
  }
1321
0
}
1322
#endif
1323
1324
static void zend_accel_persist_class_table(HashTable *class_table)
1325
60.4k
{
1326
60.4k
  Bucket *p;
1327
60.4k
  zend_class_entry *ce;
1328
60.4k
#ifdef HAVE_JIT
1329
60.4k
  bool orig_jit_on = JIT_G(on);
1330
1331
60.4k
  JIT_G(on) = 0;
1332
60.4k
#endif
1333
60.4k
  zend_hash_persist(class_table);
1334
169k
  ZEND_HASH_MAP_FOREACH_BUCKET(class_table, p) {
1335
169k
    ZEND_ASSERT(p->key != NULL);
1336
169k
    zend_accel_store_interned_string(p->key);
1337
24.4k
    Z_CE(p->val) = zend_persist_class_entry(Z_CE(p->val));
1338
24.4k
  } ZEND_HASH_FOREACH_END();
1339
169k
  ZEND_HASH_MAP_FOREACH_BUCKET(class_table, p) {
1340
169k
    if (EXPECTED(Z_TYPE(p->val) != IS_ALIAS_PTR)) {
1341
24.4k
      ce = Z_PTR(p->val);
1342
24.4k
      zend_update_parent_ce(ce);
1343
24.4k
    }
1344
169k
  } ZEND_HASH_FOREACH_END();
1345
60.4k
#ifdef HAVE_JIT
1346
60.4k
  JIT_G(on) = orig_jit_on;
1347
60.4k
  if (JIT_G(on) && JIT_G(opt_level) <= ZEND_JIT_LEVEL_OPT_FUNCS &&
1348
0
      !ZCG(current_persistent_script)->corrupted) {
1349
0
      zend_op_array *op_array;
1350
0
    zend_property_info *prop;
1351
1352
0
      ZEND_HASH_MAP_FOREACH_BUCKET(class_table, p) {
1353
0
      if (EXPECTED(Z_TYPE(p->val) != IS_ALIAS_PTR)) {
1354
0
        ce = Z_PTR(p->val);
1355
0
        ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, op_array) {
1356
0
          zend_accel_persist_jit_op_array(op_array, ce);
1357
0
        } ZEND_HASH_FOREACH_END();
1358
1359
0
        if (ce->num_hooked_props > 0) {
1360
0
          ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, prop) {
1361
0
            if (prop->hooks) {
1362
0
              for (uint32_t i = 0; i < ZEND_PROPERTY_HOOK_COUNT; i++) {
1363
0
                if (prop->hooks[i]) {
1364
0
                  op_array = &prop->hooks[i]->op_array;
1365
0
                  zend_accel_persist_jit_op_array(op_array, ce);
1366
0
                }
1367
0
              }
1368
0
            }
1369
0
          } ZEND_HASH_FOREACH_END();
1370
0
        }
1371
0
      }
1372
0
    } ZEND_HASH_FOREACH_END();
1373
0
      ZEND_HASH_MAP_FOREACH_BUCKET(class_table, p) {
1374
0
      if (EXPECTED(Z_TYPE(p->val) != IS_ALIAS_PTR)) {
1375
0
        ce = Z_PTR(p->val);
1376
0
        ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, op_array) {
1377
0
          zend_accel_persist_link_func_info(op_array, ce);
1378
0
        } ZEND_HASH_FOREACH_END();
1379
1380
0
        if (ce->num_hooked_props > 0) {
1381
0
          ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, prop) {
1382
0
            if (prop->hooks) {
1383
0
              for (uint32_t i = 0; i < ZEND_PROPERTY_HOOK_COUNT; i++) {
1384
0
                if (prop->hooks[i]) {
1385
0
                  op_array = &prop->hooks[i]->op_array;
1386
0
                  zend_accel_persist_link_func_info(op_array, ce);
1387
0
                }
1388
0
              }
1389
0
            }
1390
0
          } ZEND_HASH_FOREACH_END();
1391
0
        }
1392
0
      }
1393
0
    } ZEND_HASH_FOREACH_END();
1394
0
  }
1395
60.4k
#endif
1396
60.4k
}
1397
1398
63.4k
zend_error_info **zend_persist_warnings(uint32_t num_warnings, zend_error_info **warnings) {
1399
63.4k
  if (warnings) {
1400
36
    warnings = zend_shared_memdup(warnings, num_warnings * sizeof(zend_error_info *));
1401
74
    for (uint32_t i = 0; i < num_warnings; i++) {
1402
38
      zend_accel_store_string(warnings[i]->filename);
1403
38
      zend_accel_store_string(warnings[i]->message);
1404
38
      warnings[i] = zend_shared_memdup(warnings[i], sizeof(zend_error_info));
1405
38
    }
1406
36
  }
1407
63.4k
  return warnings;
1408
63.4k
}
1409
1410
static zend_early_binding *zend_persist_early_bindings(
1411
60.4k
    uint32_t num_early_bindings, zend_early_binding *early_bindings) {
1412
60.4k
  if (early_bindings) {
1413
556
    early_bindings = zend_shared_memdup_free(
1414
556
      early_bindings, num_early_bindings * sizeof(zend_early_binding));
1415
1.93k
    for (uint32_t i = 0; i < num_early_bindings; i++) {
1416
1.38k
      zend_accel_store_interned_string(early_bindings[i].lcname);
1417
1.38k
      zend_accel_store_interned_string(early_bindings[i].rtd_key);
1418
1.38k
      zend_accel_store_interned_string(early_bindings[i].lc_parent_name);
1419
1.38k
    }
1420
556
  }
1421
60.4k
  return early_bindings;
1422
60.4k
}
1423
1424
zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script, int for_shm)
1425
60.4k
{
1426
60.4k
  Bucket *p;
1427
1428
60.4k
  script->mem = ZCG(mem);
1429
1430
60.4k
  ZEND_ASSERT(((uintptr_t)ZCG(mem) & 0x7) == 0); /* should be 8 byte aligned */
1431
1432
60.4k
  script = zend_shared_memdup_free(script, sizeof(zend_persistent_script));
1433
60.4k
  script->corrupted = false;
1434
60.4k
  ZCG(current_persistent_script) = script;
1435
1436
60.4k
  if (!for_shm) {
1437
    /* script is not going to be saved in SHM */
1438
0
    script->corrupted = true;
1439
0
  }
1440
1441
60.4k
  zend_accel_store_interned_string(script->script.filename);
1442
1443
60.4k
#if defined(__AVX__) || defined(__SSE2__)
1444
  /* Align to 64-byte boundary */
1445
60.4k
  ZCG(mem) = (void*)(((uintptr_t)ZCG(mem) + 63L) & ~63L);
1446
#else
1447
  ZEND_ASSERT(((uintptr_t)ZCG(mem) & 0x7) == 0); /* should be 8 byte aligned */
1448
#endif
1449
1450
60.4k
#ifdef HAVE_JIT
1451
60.4k
  if (JIT_G(on) && for_shm) {
1452
0
    zend_jit_unprotect();
1453
0
  }
1454
60.4k
#endif
1455
1456
60.4k
  zend_map_ptr_extend(ZCSG(map_ptr_last));
1457
1458
60.4k
  zend_accel_persist_class_table(&script->script.class_table);
1459
60.4k
  zend_hash_persist(&script->script.function_table);
1460
147k
  ZEND_HASH_MAP_FOREACH_BUCKET(&script->script.function_table, p) {
1461
147k
    ZEND_ASSERT(p->key != NULL);
1462
147k
    zend_accel_store_interned_string(p->key);
1463
13.1k
    zend_persist_op_array(&p->val);
1464
13.1k
  } ZEND_HASH_FOREACH_END();
1465
60.4k
  zend_persist_op_array_ex(&script->script.main_op_array, script);
1466
60.4k
  if (!script->corrupted) {
1467
60.4k
    ZEND_MAP_PTR_INIT(script->script.main_op_array.run_time_cache, NULL);
1468
60.4k
    if (script->script.main_op_array.static_variables) {
1469
52
      ZEND_MAP_PTR_NEW(script->script.main_op_array.static_variables_ptr);
1470
52
    }
1471
60.4k
#ifdef HAVE_JIT
1472
60.4k
    if (JIT_G(on) && JIT_G(opt_level) <= ZEND_JIT_LEVEL_OPT_FUNCS) {
1473
0
      zend_jit_op_array(&script->script.main_op_array, &script->script);
1474
0
    }
1475
60.4k
#endif
1476
60.4k
  }
1477
60.4k
  script->warnings = zend_persist_warnings(script->num_warnings, script->warnings);
1478
60.4k
  script->early_bindings = zend_persist_early_bindings(
1479
60.4k
    script->num_early_bindings, script->early_bindings);
1480
1481
60.4k
  if (for_shm) {
1482
60.4k
    ZCSG(map_ptr_last) = CG(map_ptr_last);
1483
60.4k
    ZCSG(map_ptr_static_last) = zend_map_ptr_static_last;
1484
60.4k
  }
1485
1486
60.4k
#ifdef HAVE_JIT
1487
60.4k
  if (JIT_G(on) && for_shm) {
1488
0
    if (JIT_G(opt_level) >= ZEND_JIT_LEVEL_OPT_SCRIPT) {
1489
0
      zend_jit_script(&script->script);
1490
0
    }
1491
0
    zend_jit_protect();
1492
0
  }
1493
60.4k
#endif
1494
1495
60.4k
  script->corrupted = false;
1496
60.4k
  ZCG(current_persistent_script) = NULL;
1497
1498
60.4k
  return script;
1499
60.4k
}