Coverage Report

Created: 2026-06-02 06:36

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/php-src/ext/opcache/zend_file_cache.c
Line
Count
Source
1
/*
2
   +----------------------------------------------------------------------+
3
   | Zend OPcache                                                         |
4
   +----------------------------------------------------------------------+
5
   | Copyright © The PHP Group and Contributors.                          |
6
   +----------------------------------------------------------------------+
7
   | This source file is subject to the Modified BSD License that is      |
8
   | bundled with this package in the file LICENSE, and is available      |
9
   | through the World Wide Web at <https://www.php.net/license/>.        |
10
   |                                                                      |
11
   | SPDX-License-Identifier: BSD-3-Clause                                |
12
   +----------------------------------------------------------------------+
13
   | Authors: Dmitry Stogov <dmitry@php.net>                              |
14
   +----------------------------------------------------------------------+
15
*/
16
17
#include "zend.h"
18
#include "zend_virtual_cwd.h"
19
#include "zend_compile.h"
20
#include "zend_vm.h"
21
#include "zend_interfaces.h"
22
#include "zend_attributes.h"
23
#include "zend_system_id.h"
24
#include "zend_enum.h"
25
26
#include "php.h"
27
#ifdef ZEND_WIN32
28
#include "ext/standard/md5.h"
29
#endif
30
#include "ext/standard/php_filestat.h"
31
32
#include "ZendAccelerator.h"
33
#include "zend_file_cache.h"
34
#include "zend_shared_alloc.h"
35
#include "zend_accelerator_util_funcs.h"
36
#include "zend_accelerator_hash.h"
37
38
#ifdef HAVE_JIT
39
#include "jit/zend_jit.h"
40
#endif
41
42
#include <sys/types.h>
43
#include <sys/stat.h>
44
#include <fcntl.h>
45
46
#ifdef HAVE_UNISTD_H
47
#include <unistd.h>
48
#endif
49
50
#ifdef HAVE_SYS_UIO_H
51
# include <sys/uio.h>
52
#endif
53
54
#ifdef HAVE_SYS_FILE_H
55
# include <sys/file.h>
56
#endif
57
58
#if __has_feature(memory_sanitizer)
59
# include <sanitizer/msan_interface.h>
60
#endif
61
62
#ifndef ZEND_WIN32
63
0
#define zend_file_cache_unlink unlink
64
0
#define zend_file_cache_open open
65
#else
66
#define zend_file_cache_unlink php_win32_ioutil_unlink
67
#define zend_file_cache_open php_win32_ioutil_open
68
#endif
69
70
#ifdef ZEND_WIN32
71
# define LOCK_SH 0
72
# define LOCK_EX 1
73
# define LOCK_UN 2
74
static int zend_file_cache_flock(int fd, int op)
75
{
76
  OVERLAPPED offset = {0, 0, {{0}}, NULL};
77
  if (op == LOCK_EX) {
78
    if (LockFileEx((HANDLE)_get_osfhandle(fd),
79
                   LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 0, &offset) == TRUE) {
80
      return 0;
81
    }
82
  } else if (op == LOCK_SH) {
83
    if (LockFileEx((HANDLE)_get_osfhandle(fd),
84
                   0, 0, 1, 0, &offset) == TRUE) {
85
      return 0;
86
    }
87
  } else if (op == LOCK_UN) {
88
    if (UnlockFileEx((HANDLE)_get_osfhandle(fd),
89
                     0, 1, 0, &offset) == TRUE) {
90
      return 0;
91
    }
92
  }
93
  return -1;
94
}
95
#elif defined(HAVE_FLOCK)
96
0
# define zend_file_cache_flock flock
97
#else
98
# define LOCK_SH 0
99
# define LOCK_EX 1
100
# define LOCK_UN 2
101
static int zend_file_cache_flock(int fd, int type)
102
{
103
  return 0;
104
}
105
#endif
106
107
#ifndef O_BINARY
108
0
#  define O_BINARY 0
109
#endif
110
111
0
#define SUFFIX ".bin"
112
113
#define IS_SERIALIZED_INTERNED(ptr) \
114
0
  ((size_t)(ptr) & Z_UL(1))
115
116
/* Allowing == on the upper bound accounts for a potential empty allocation at the end of the
117
 * memory region. This can also happen for a return-type-only arg_info, where &arg_info[1] is
118
 * stored, which may point to the end of the region. */
119
#define IS_SERIALIZED(ptr) \
120
0
  ((char*)(ptr) <= (char*)script->size)
121
#define IS_UNSERIALIZED(ptr) \
122
0
  (((char*)(ptr) >= (char*)script->mem && (char*)(ptr) <= (char*)script->mem + script->size) || \
123
0
   IS_ACCEL_INTERNED(ptr))
124
0
#define SERIALIZE_PTR(ptr) do { \
125
0
    if (ptr) { \
126
0
      ZEND_ASSERT(IS_UNSERIALIZED(ptr)); \
127
0
      (ptr) = (void*)((char*)(ptr) - (char*)script->mem); \
128
0
    } \
129
0
  } while (0)
130
0
#define UNSERIALIZE_PTR(ptr) do { \
131
0
    if (ptr) { \
132
0
      ZEND_ASSERT(IS_SERIALIZED(ptr)); \
133
0
      (ptr) = (void*)((char*)buf + (size_t)(ptr)); \
134
0
    } \
135
0
  } while (0)
136
137
0
#define SERIALIZE_STR(ptr) do { \
138
0
    if (ptr) { \
139
0
      if (IS_ACCEL_INTERNED(ptr)) { \
140
0
        (ptr) = zend_file_cache_serialize_interned((zend_string*)(ptr), info); \
141
0
      } else { \
142
0
        ZEND_ASSERT(IS_UNSERIALIZED(ptr)); \
143
0
        (ptr) = (void*)((char*)(ptr) - (char*)script->mem); \
144
0
      } \
145
0
    } \
146
0
  } while (0)
147
0
#define UNSERIALIZE_STR(ptr) do { \
148
0
    if (ptr) { \
149
0
      if (IS_SERIALIZED_INTERNED(ptr)) { \
150
0
        (ptr) = (void*)zend_file_cache_unserialize_interned((zend_string*)(ptr), !script->corrupted); \
151
0
      } else { \
152
0
        ZEND_ASSERT(IS_SERIALIZED(ptr)); \
153
0
        (ptr) = (void*)((char*)buf + (size_t)(ptr)); \
154
0
        /* script->corrupted shows if the script in SHM or not */ \
155
0
        if (EXPECTED(!script->corrupted)) { \
156
0
          GC_ADD_FLAGS(ptr, IS_STR_INTERNED | IS_STR_PERMANENT); \
157
0
        } else { \
158
0
          GC_ADD_FLAGS(ptr, IS_STR_INTERNED); \
159
0
          GC_DEL_FLAGS(ptr, IS_STR_PERMANENT); \
160
0
        } \
161
0
        GC_DEL_FLAGS(ptr, IS_STR_CLASS_NAME_MAP_PTR); \
162
0
      } \
163
0
    } \
164
0
  } while (0)
165
166
0
#define SERIALIZE_ATTRIBUTES(attributes) do { \
167
0
  if ((attributes) && !IS_SERIALIZED(attributes)) { \
168
0
    HashTable *ht; \
169
0
    SERIALIZE_PTR(attributes); \
170
0
    ht = (attributes); \
171
0
    UNSERIALIZE_PTR(ht); \
172
0
    zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_attribute); \
173
0
  } \
174
0
} while (0)
175
176
0
#define UNSERIALIZE_ATTRIBUTES(attributes) do { \
177
0
  if ((attributes) && !IS_UNSERIALIZED(attributes)) { \
178
0
    HashTable *ht; \
179
0
    UNSERIALIZE_PTR(attributes); \
180
0
    ht = (attributes); \
181
0
    zend_file_cache_unserialize_hash(ht, script, buf, zend_file_cache_unserialize_attribute, NULL); \
182
0
  } \
183
0
} while (0)
184
185
0
#define HOOKED_ITERATOR_PLACEHOLDER ((void*)1)
186
187
static const uint32_t uninitialized_bucket[-HT_MIN_MASK] =
188
  {HT_INVALID_IDX, HT_INVALID_IDX};
189
190
typedef struct _zend_file_cache_metainfo {
191
  char         magic[8];
192
  char         system_id[32];
193
  size_t       mem_size;
194
  size_t       str_size;
195
  size_t       script_offset;
196
  accel_time_t timestamp;
197
  uint32_t     checksum;
198
} zend_file_cache_metainfo;
199
200
static int zend_file_cache_mkdir(char *filename, size_t start)
201
0
{
202
0
  char *s = filename + start;
203
204
0
  while (*s) {
205
0
    if (IS_SLASH(*s)) {
206
0
      char old = *s;
207
0
      *s = '\000';
208
0
#ifndef ZEND_WIN32
209
0
      if (mkdir(filename, S_IRWXU) < 0 && errno != EEXIST) {
210
#else
211
      if (php_win32_ioutil_mkdir(filename, 0700) < 0 && errno != EEXIST) {
212
#endif
213
0
        *s = old;
214
0
        return FAILURE;
215
0
      }
216
0
      *s = old;
217
0
    }
218
0
    s++;
219
0
  }
220
0
  return SUCCESS;
221
0
}
222
223
typedef void (*serialize_callback_t)(zval                     *zv,
224
                                     zend_persistent_script   *script,
225
                                     zend_file_cache_metainfo *info,
226
                                     void                     *buf);
227
228
typedef void (*unserialize_callback_t)(zval                    *zv,
229
                                       zend_persistent_script  *script,
230
                                       void                    *buf);
231
232
static void zend_file_cache_serialize_zval(zval                     *zv,
233
                                           zend_persistent_script   *script,
234
                                           zend_file_cache_metainfo *info,
235
                                           void                     *buf);
236
static void zend_file_cache_unserialize_zval(zval                    *zv,
237
                                             zend_persistent_script  *script,
238
                                             void                    *buf);
239
240
static void zend_file_cache_serialize_func(zval                     *zv,
241
                                           zend_persistent_script   *script,
242
                                           zend_file_cache_metainfo *info,
243
                                           void                     *buf);
244
245
static void zend_file_cache_unserialize_func(zval                    *zv,
246
                                             zend_persistent_script  *script,
247
                                             void                    *buf);
248
249
static void zend_file_cache_serialize_attribute(zval                     *zv,
250
                                                zend_persistent_script   *script,
251
                                                zend_file_cache_metainfo *info,
252
                                                void                     *buf);
253
254
static void zend_file_cache_unserialize_attribute(zval *zv, zend_persistent_script *script, void *buf);
255
256
static void *zend_file_cache_serialize_interned(zend_string              *str,
257
                                                zend_file_cache_metainfo *info)
258
0
{
259
0
  size_t len;
260
0
  void *ret;
261
262
  /* check if the same interned string was already stored */
263
0
  ret = zend_shared_alloc_get_xlat_entry(str);
264
0
  if (ret) {
265
0
    return ret;
266
0
  }
267
268
0
  len = ZEND_MM_ALIGNED_SIZE(_ZSTR_STRUCT_SIZE(ZSTR_LEN(str)));
269
0
  ret = (void*)(info->str_size | Z_UL(1));
270
0
  zend_shared_alloc_register_xlat_entry(str, ret);
271
272
0
  zend_string *s = (zend_string*)ZCG(mem);
273
0
  if (info->str_size + len > ZSTR_LEN(s)) {
274
0
    size_t new_len = info->str_size + len;
275
0
    s = zend_string_realloc(
276
0
      s,
277
0
      ((_ZSTR_HEADER_SIZE + 1 + new_len + 4095) & ~0xfff) - (_ZSTR_HEADER_SIZE + 1),
278
0
      0);
279
0
    ZCG(mem) = (void*)s;
280
0
  }
281
282
0
  zend_string *new_str = (zend_string *) (ZSTR_VAL(s) + info->str_size);
283
0
  memcpy(new_str, str, len);
284
0
  GC_ADD_FLAGS(new_str, IS_STR_INTERNED);
285
0
  GC_DEL_FLAGS(new_str, IS_STR_PERMANENT|IS_STR_CLASS_NAME_MAP_PTR);
286
0
  info->str_size += len;
287
0
  return ret;
288
0
}
289
290
static void *zend_file_cache_unserialize_interned(zend_string *str, bool in_shm)
291
0
{
292
0
  str = (zend_string*)((char*)ZCG(mem) + ((size_t)(str) & ~Z_UL(1)));
293
0
  if (!in_shm) {
294
0
    return str;
295
0
  }
296
297
0
  zend_string *ret = accel_new_interned_string(str);
298
0
  if (ret == str) {
299
    /* We have to create new SHM allocated string */
300
0
    size_t size = _ZSTR_STRUCT_SIZE(ZSTR_LEN(str));
301
0
    ret = zend_shared_alloc(size);
302
0
    if (!ret) {
303
0
      zend_accel_schedule_restart_if_necessary(ACCEL_RESTART_OOM);
304
0
      LONGJMP(*EG(bailout), FAILURE);
305
0
    }
306
0
    memcpy(ret, str, size);
307
    /* String wasn't interned but we will use it as interned anyway */
308
0
    GC_SET_REFCOUNT(ret, 1);
309
0
    GC_TYPE_INFO(ret) = GC_STRING | ((IS_STR_INTERNED | IS_STR_PERSISTENT | IS_STR_PERMANENT) << GC_FLAGS_SHIFT);
310
0
  }
311
0
  return ret;
312
0
}
313
314
static void zend_file_cache_serialize_hash(HashTable                *ht,
315
                                           zend_persistent_script   *script,
316
                                           zend_file_cache_metainfo *info,
317
                                           void                     *buf,
318
                                           serialize_callback_t      func)
319
0
{
320
0
  if (HT_FLAGS(ht) & HASH_FLAG_UNINITIALIZED) {
321
0
    ht->arData = NULL;
322
0
    return;
323
0
  }
324
0
  if (IS_SERIALIZED(ht->arData)) {
325
0
    return;
326
0
  }
327
0
  if (HT_IS_PACKED(ht)) {
328
0
    zval *p, *end;
329
330
0
    SERIALIZE_PTR(ht->arPacked);
331
0
    p = ht->arPacked;
332
0
    UNSERIALIZE_PTR(p);
333
0
    end = p + ht->nNumUsed;
334
0
    while (p < end) {
335
0
      if (Z_TYPE_P(p) != IS_UNDEF) {
336
0
        func(p, script, info, buf);
337
0
      }
338
0
      p++;
339
0
    }
340
0
  } else {
341
0
    Bucket *p, *end;
342
343
0
    SERIALIZE_PTR(ht->arData);
344
0
    p = ht->arData;
345
0
    UNSERIALIZE_PTR(p);
346
0
    end = p + ht->nNumUsed;
347
0
    while (p < end) {
348
0
      if (Z_TYPE(p->val) != IS_UNDEF) {
349
0
        SERIALIZE_STR(p->key);
350
0
        func(&p->val, script, info, buf);
351
0
      }
352
0
      p++;
353
0
    }
354
0
  }
355
0
}
356
357
static void zend_file_cache_serialize_ast(zend_ast                 *ast,
358
                                          zend_persistent_script   *script,
359
                                          zend_file_cache_metainfo *info,
360
                                          void                     *buf)
361
0
{
362
0
  uint32_t i;
363
0
  zend_ast *tmp;
364
365
0
  if (ast->kind == ZEND_AST_ZVAL || ast->kind == ZEND_AST_CONSTANT) {
366
0
    zend_file_cache_serialize_zval(&((zend_ast_zval*)ast)->val, script, info, buf);
367
0
  } else if (zend_ast_is_list(ast)) {
368
0
    zend_ast_list *list = zend_ast_get_list(ast);
369
0
    for (i = 0; i < list->children; i++) {
370
0
      if (list->child[i] && !IS_SERIALIZED(list->child[i])) {
371
0
        SERIALIZE_PTR(list->child[i]);
372
0
        tmp = list->child[i];
373
0
        UNSERIALIZE_PTR(tmp);
374
0
        zend_file_cache_serialize_ast(tmp, script, info, buf);
375
0
      }
376
0
    }
377
0
  } else if (ast->kind == ZEND_AST_OP_ARRAY) {
378
0
    zval z;
379
0
    ZVAL_PTR(&z, zend_ast_get_op_array(ast)->op_array);
380
0
    zend_file_cache_serialize_func(&z, script, info, buf);
381
0
    zend_ast_get_op_array(ast)->op_array = Z_PTR(z);
382
0
  } else if (ast->kind == ZEND_AST_CALLABLE_CONVERT) {
383
0
    zend_ast_fcc *fcc = (zend_ast_fcc*)ast;
384
0
    ZEND_MAP_PTR_INIT(fcc->fptr, NULL);
385
0
    if (!IS_SERIALIZED(fcc->args)) {
386
0
      SERIALIZE_PTR(fcc->args);
387
0
      tmp = fcc->args;
388
0
      UNSERIALIZE_PTR(tmp);
389
0
      zend_file_cache_serialize_ast(tmp, script, info, buf);
390
0
    }
391
0
  } else if (zend_ast_is_decl(ast)) {
392
    /* Not implemented. */
393
0
    ZEND_UNREACHABLE();
394
0
  } else {
395
0
    uint32_t children = zend_ast_get_num_children(ast);
396
0
    for (i = 0; i < children; i++) {
397
0
      if (ast->child[i] && !IS_SERIALIZED(ast->child[i])) {
398
0
        SERIALIZE_PTR(ast->child[i]);
399
0
        tmp = ast->child[i];
400
0
        UNSERIALIZE_PTR(tmp);
401
0
        zend_file_cache_serialize_ast(tmp, script, info, buf);
402
0
      }
403
0
    }
404
0
  }
405
0
}
406
407
static void zend_file_cache_serialize_zval(zval                     *zv,
408
                                           zend_persistent_script   *script,
409
                                           zend_file_cache_metainfo *info,
410
                                           void                     *buf)
411
0
{
412
0
  switch (Z_TYPE_P(zv)) {
413
0
    case IS_STRING:
414
0
      if (!IS_SERIALIZED(Z_STR_P(zv))) {
415
0
        SERIALIZE_STR(Z_STR_P(zv));
416
0
      }
417
0
      break;
418
0
    case IS_ARRAY:
419
0
      if (!IS_SERIALIZED(Z_ARR_P(zv))) {
420
0
        HashTable *ht;
421
422
0
        SERIALIZE_PTR(Z_ARR_P(zv));
423
0
        ht = Z_ARR_P(zv);
424
0
        UNSERIALIZE_PTR(ht);
425
0
        zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_zval);
426
0
      }
427
0
      break;
428
0
    case IS_CONSTANT_AST:
429
0
      if (!IS_SERIALIZED(Z_AST_P(zv))) {
430
0
        zend_ast_ref *ast;
431
432
0
        SERIALIZE_PTR(Z_AST_P(zv));
433
0
        ast = Z_AST_P(zv);
434
0
        UNSERIALIZE_PTR(ast);
435
0
        zend_file_cache_serialize_ast(GC_AST(ast), script, info, buf);
436
0
      }
437
0
      break;
438
0
    case IS_INDIRECT:
439
      /* Used by static properties. */
440
0
      SERIALIZE_PTR(Z_INDIRECT_P(zv));
441
0
      break;
442
0
    case IS_PTR:
443
      /* Used by attributes on constants, will be handled separately */
444
0
      break;
445
0
    default:
446
0
      ZEND_ASSERT(Z_TYPE_P(zv) < IS_STRING);
447
0
      break;
448
0
  }
449
0
}
450
451
static void zend_file_cache_serialize_attribute(zval                     *zv,
452
                                                zend_persistent_script   *script,
453
                                                zend_file_cache_metainfo *info,
454
                                                void                     *buf)
455
0
{
456
0
  zend_attribute *attr = Z_PTR_P(zv);
457
0
  uint32_t i;
458
459
0
  SERIALIZE_PTR(Z_PTR_P(zv));
460
0
  attr = Z_PTR_P(zv);
461
0
  UNSERIALIZE_PTR(attr);
462
463
0
  SERIALIZE_STR(attr->name);
464
0
  SERIALIZE_STR(attr->lcname);
465
0
  SERIALIZE_STR(attr->validation_error);
466
467
0
  for (i = 0; i < attr->argc; i++) {
468
0
    SERIALIZE_STR(attr->args[i].name);
469
0
    zend_file_cache_serialize_zval(&attr->args[i].value, script, info, buf);
470
0
  }
471
0
}
472
473
static void zend_file_cache_serialize_type(
474
    zend_type *type, zend_persistent_script *script, zend_file_cache_metainfo *info, void *buf)
475
0
{
476
0
  if (ZEND_TYPE_HAS_LIST(*type)) {
477
0
    zend_type_list *list = ZEND_TYPE_LIST(*type);
478
0
    SERIALIZE_PTR(list);
479
0
    ZEND_TYPE_SET_PTR(*type, list);
480
0
    UNSERIALIZE_PTR(list);
481
482
0
    zend_type *list_type;
483
0
    ZEND_TYPE_LIST_FOREACH_MUTABLE(list, list_type) {
484
0
      zend_file_cache_serialize_type(list_type, script, info, buf);
485
0
    } ZEND_TYPE_LIST_FOREACH_END();
486
0
  } else if (ZEND_TYPE_HAS_NAME(*type)) {
487
0
    zend_string *type_name = ZEND_TYPE_NAME(*type);
488
0
    SERIALIZE_STR(type_name);
489
0
    ZEND_TYPE_SET_PTR(*type, type_name);
490
0
  }
491
0
}
492
493
static void zend_file_cache_serialize_op_array(zend_op_array            *op_array,
494
                                               zend_persistent_script   *script,
495
                                               zend_file_cache_metainfo *info,
496
                                               void                     *buf)
497
0
{
498
0
  ZEND_MAP_PTR_INIT(op_array->static_variables_ptr, NULL);
499
0
  ZEND_MAP_PTR_INIT(op_array->run_time_cache, NULL);
500
501
  /* Check whether this op_array has already been serialized. */
502
0
  if (IS_SERIALIZED(op_array->opcodes)) {
503
0
    ZEND_ASSERT(op_array->scope && "Only method op_arrays should be shared");
504
0
    return;
505
0
  }
506
507
0
  if (op_array->scope) {
508
0
    if (UNEXPECTED(zend_shared_alloc_get_xlat_entry(op_array->opcodes))) {
509
0
      op_array->refcount = (uint32_t*)(intptr_t)-1;
510
0
      SERIALIZE_PTR(op_array->static_variables);
511
0
      SERIALIZE_PTR(op_array->literals);
512
0
      SERIALIZE_PTR(op_array->opcodes);
513
0
      SERIALIZE_PTR(op_array->arg_info);
514
0
      SERIALIZE_PTR(op_array->vars);
515
0
      SERIALIZE_STR(op_array->function_name);
516
0
      SERIALIZE_STR(op_array->filename);
517
0
      SERIALIZE_PTR(op_array->live_range);
518
0
      SERIALIZE_PTR(op_array->scope);
519
0
      SERIALIZE_STR(op_array->doc_comment);
520
0
      SERIALIZE_ATTRIBUTES(op_array->attributes);
521
0
      SERIALIZE_PTR(op_array->try_catch_array);
522
0
      SERIALIZE_PTR(op_array->prototype);
523
0
      SERIALIZE_PTR(op_array->prop_info);
524
0
      return;
525
0
    }
526
0
    zend_shared_alloc_register_xlat_entry(op_array->opcodes, op_array->opcodes);
527
0
  }
528
529
0
  if (op_array->static_variables) {
530
0
    HashTable *ht;
531
532
0
    SERIALIZE_PTR(op_array->static_variables);
533
0
    ht = op_array->static_variables;
534
0
    UNSERIALIZE_PTR(ht);
535
0
    zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_zval);
536
0
  }
537
538
0
  if (op_array->literals) {
539
0
    zval *p, *end;
540
541
0
    SERIALIZE_PTR(op_array->literals);
542
0
    p = op_array->literals;
543
0
    UNSERIALIZE_PTR(p);
544
0
    end = p + op_array->last_literal;
545
0
    while (p < end) {
546
0
      zend_file_cache_serialize_zval(p, script, info, buf);
547
0
      p++;
548
0
    }
549
0
  }
550
551
0
  {
552
0
    zend_op *opline, *end;
553
554
0
#if !ZEND_USE_ABS_CONST_ADDR
555
0
    zval *literals = op_array->literals;
556
0
    UNSERIALIZE_PTR(literals);
557
0
#endif
558
559
0
    SERIALIZE_PTR(op_array->opcodes);
560
0
    opline = op_array->opcodes;
561
0
    UNSERIALIZE_PTR(opline);
562
0
    end = opline + op_array->last;
563
0
    while (opline < end) {
564
0
      if (opline->opcode == ZEND_OP_DATA
565
0
        && (opline-1)->opcode == ZEND_DECLARE_ATTRIBUTED_CONST
566
0
      ) {
567
0
        zval *literal = RT_CONSTANT(opline, opline->op1);
568
0
        SERIALIZE_ATTRIBUTES(Z_PTR_P(literal));
569
0
      }
570
571
#if ZEND_USE_ABS_CONST_ADDR
572
      if (opline->op1_type == IS_CONST) {
573
        SERIALIZE_PTR(opline->op1.zv);
574
      }
575
      if (opline->op2_type == IS_CONST) {
576
        SERIALIZE_PTR(opline->op2.zv);
577
578
        /* See GH-17733. Reset Z_EXTRA_P(op2) of ZEND_INIT_FCALL, which
579
         * is an offset into the global function table, to avoid calling
580
         * incorrect functions when environment changes. This, and the
581
         * equivalent code below, can be removed once proper system ID
582
         * validation is implemented. */
583
        if (opline->opcode == ZEND_INIT_FCALL) {
584
          zval *op2 = opline->op2.zv;
585
          UNSERIALIZE_PTR(op2);
586
          Z_EXTRA_P(op2) = 0;
587
          ZEND_VM_SET_OPCODE_HANDLER(opline);
588
        }
589
      }
590
#else
591
0
      if (opline->op1_type == IS_CONST) {
592
0
        opline->op1.constant = RT_CONSTANT(opline, opline->op1) - literals;
593
0
      }
594
0
      if (opline->op2_type == IS_CONST) {
595
0
        zval *op2 = RT_CONSTANT(opline, opline->op2);
596
0
        opline->op2.constant = op2 - literals;
597
598
        /* See GH-17733 and comment above. */
599
0
        if (opline->opcode == ZEND_INIT_FCALL) {
600
0
          Z_EXTRA_P(op2) = 0;
601
0
          ZEND_VM_SET_OPCODE_HANDLER(opline);
602
0
        }
603
0
      }
604
0
#endif
605
#if ZEND_USE_ABS_JMP_ADDR
606
      switch (opline->opcode) {
607
        case ZEND_JMP:
608
        case ZEND_FAST_CALL:
609
          SERIALIZE_PTR(opline->op1.jmp_addr);
610
          break;
611
        case ZEND_JMPZ:
612
        case ZEND_JMPNZ:
613
        case ZEND_JMPZ_EX:
614
        case ZEND_JMPNZ_EX:
615
        case ZEND_JMP_SET:
616
        case ZEND_COALESCE:
617
        case ZEND_FE_RESET_R:
618
        case ZEND_FE_RESET_RW:
619
        case ZEND_ASSERT_CHECK:
620
        case ZEND_JMP_NULL:
621
        case ZEND_BIND_INIT_STATIC_OR_JMP:
622
        case ZEND_JMP_FRAMELESS:
623
          SERIALIZE_PTR(opline->op2.jmp_addr);
624
          break;
625
        case ZEND_CATCH:
626
          if (!(opline->extended_value & ZEND_LAST_CATCH)) {
627
            SERIALIZE_PTR(opline->op2.jmp_addr);
628
          }
629
          break;
630
        case ZEND_FE_FETCH_R:
631
        case ZEND_FE_FETCH_RW:
632
        case ZEND_SWITCH_LONG:
633
        case ZEND_SWITCH_STRING:
634
        case ZEND_MATCH:
635
          /* relative extended_value don't have to be changed */
636
          break;
637
      }
638
#endif
639
0
      zend_serialize_opcode_handler(opline);
640
0
      opline++;
641
0
    }
642
643
0
    if (op_array->arg_info) {
644
0
      zend_arg_info *p, *end;
645
0
      SERIALIZE_PTR(op_array->arg_info);
646
0
      p = op_array->arg_info;
647
0
      UNSERIALIZE_PTR(p);
648
0
      end = p + op_array->num_args;
649
0
      if (op_array->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
650
0
        p--;
651
0
      }
652
0
      if (op_array->fn_flags & ZEND_ACC_VARIADIC) {
653
0
        end++;
654
0
      }
655
0
      while (p < end) {
656
0
        if (!IS_SERIALIZED(p->name)) {
657
0
          SERIALIZE_STR(p->name);
658
0
        }
659
0
        zend_file_cache_serialize_type(&p->type, script, info, buf);
660
0
        SERIALIZE_STR(p->doc_comment);
661
0
        p++;
662
0
      }
663
0
    }
664
665
0
    if (op_array->vars) {
666
0
      zend_string **p, **end;
667
668
0
      SERIALIZE_PTR(op_array->vars);
669
0
      p = op_array->vars;
670
0
      UNSERIALIZE_PTR(p);
671
0
      end = p + op_array->last_var;
672
0
      while (p < end) {
673
0
        if (!IS_SERIALIZED(*p)) {
674
0
          SERIALIZE_STR(*p);
675
0
        }
676
0
        p++;
677
0
      }
678
0
    }
679
680
0
    if (op_array->num_dynamic_func_defs) {
681
0
      zend_op_array **defs;
682
0
      SERIALIZE_PTR(op_array->dynamic_func_defs);
683
0
      defs = op_array->dynamic_func_defs;
684
0
      UNSERIALIZE_PTR(defs);
685
0
      for (uint32_t i = 0; i < op_array->num_dynamic_func_defs; i++) {
686
0
        zend_op_array *def;
687
0
        SERIALIZE_PTR(defs[i]);
688
0
        def = defs[i];
689
0
        UNSERIALIZE_PTR(def);
690
0
        zend_file_cache_serialize_op_array(def, script, info, buf);
691
0
      }
692
0
    }
693
694
0
    SERIALIZE_STR(op_array->function_name);
695
0
    SERIALIZE_STR(op_array->filename);
696
0
    SERIALIZE_PTR(op_array->live_range);
697
0
    SERIALIZE_PTR(op_array->scope);
698
0
    SERIALIZE_STR(op_array->doc_comment);
699
0
    SERIALIZE_ATTRIBUTES(op_array->attributes);
700
0
    SERIALIZE_PTR(op_array->try_catch_array);
701
0
    SERIALIZE_PTR(op_array->prototype);
702
0
    SERIALIZE_PTR(op_array->prop_info);
703
0
  }
704
0
}
705
706
static void zend_file_cache_serialize_func(zval                     *zv,
707
                                           zend_persistent_script   *script,
708
                                           zend_file_cache_metainfo *info,
709
                                           void                     *buf)
710
0
{
711
0
  zend_function *func;
712
0
  SERIALIZE_PTR(Z_PTR_P(zv));
713
0
  func = Z_PTR_P(zv);
714
0
  UNSERIALIZE_PTR(func);
715
0
  ZEND_ASSERT(func->type == ZEND_USER_FUNCTION);
716
0
  zend_file_cache_serialize_op_array(&func->op_array, script, info, buf);
717
0
}
718
719
static void zend_file_cache_serialize_prop_info(zval                     *zv,
720
                                                zend_persistent_script   *script,
721
                                                zend_file_cache_metainfo *info,
722
                                                void                     *buf)
723
0
{
724
0
  if (!IS_SERIALIZED(Z_PTR_P(zv))) {
725
0
    zend_property_info *prop;
726
727
0
    SERIALIZE_PTR(Z_PTR_P(zv));
728
0
    prop = Z_PTR_P(zv);
729
0
    UNSERIALIZE_PTR(prop);
730
731
0
    ZEND_ASSERT(prop->ce != NULL && prop->name != NULL);
732
0
    if (!IS_SERIALIZED(prop->ce)) {
733
0
      SERIALIZE_PTR(prop->ce);
734
0
      SERIALIZE_STR(prop->name);
735
0
      if (prop->doc_comment) {
736
0
        SERIALIZE_STR(prop->doc_comment);
737
0
      }
738
0
      SERIALIZE_ATTRIBUTES(prop->attributes);
739
0
      SERIALIZE_PTR(prop->prototype);
740
0
      if (prop->hooks) {
741
0
        SERIALIZE_PTR(prop->hooks);
742
0
        zend_function **hooks = prop->hooks;
743
0
        UNSERIALIZE_PTR(hooks);
744
0
        for (uint32_t i = 0; i < ZEND_PROPERTY_HOOK_COUNT; i++) {
745
0
          if (hooks[i]) {
746
0
            SERIALIZE_PTR(hooks[i]);
747
0
            zend_function *hook = hooks[i];
748
0
            UNSERIALIZE_PTR(hook);
749
0
            zend_file_cache_serialize_op_array(&hook->op_array, script, info, buf);
750
0
          }
751
0
        }
752
0
      }
753
0
      zend_file_cache_serialize_type(&prop->type, script, info, buf);
754
0
    }
755
0
  }
756
0
}
757
758
static void zend_file_cache_serialize_class_constant(zval                     *zv,
759
                                                     zend_persistent_script   *script,
760
                                                     zend_file_cache_metainfo *info,
761
                                                     void                     *buf)
762
0
{
763
0
  if (!IS_SERIALIZED(Z_PTR_P(zv))) {
764
0
    zend_class_constant *c;
765
766
0
    SERIALIZE_PTR(Z_PTR_P(zv));
767
0
    c = Z_PTR_P(zv);
768
0
    UNSERIALIZE_PTR(c);
769
770
0
    ZEND_ASSERT(c->ce != NULL);
771
0
    if (!IS_SERIALIZED(c->ce)) {
772
0
      SERIALIZE_PTR(c->ce);
773
774
0
      zend_file_cache_serialize_zval(&c->value, script, info, buf);
775
0
      if (c->doc_comment) {
776
0
        SERIALIZE_STR(c->doc_comment);
777
0
      }
778
779
0
      SERIALIZE_ATTRIBUTES(c->attributes);
780
0
      zend_file_cache_serialize_type(&c->type, script, info, buf);
781
0
    }
782
0
  }
783
0
}
784
785
static void zend_file_cache_serialize_class(zval                     *zv,
786
                                            zend_persistent_script   *script,
787
                                            zend_file_cache_metainfo *info,
788
                                            void                     *buf)
789
0
{
790
0
  zend_class_entry *ce;
791
792
0
  SERIALIZE_PTR(Z_PTR_P(zv));
793
0
  ce = Z_PTR_P(zv);
794
0
  UNSERIALIZE_PTR(ce);
795
796
0
  SERIALIZE_STR(ce->name);
797
0
  if (ce->parent) {
798
0
    if (!(ce->ce_flags & ZEND_ACC_LINKED)) {
799
0
      SERIALIZE_STR(ce->parent_name);
800
0
    } else {
801
0
      SERIALIZE_PTR(ce->parent);
802
0
    }
803
0
  }
804
0
  zend_file_cache_serialize_hash(&ce->function_table, script, info, buf, zend_file_cache_serialize_func);
805
0
  if (ce->default_properties_table) {
806
0
    zval *p, *end;
807
808
0
    SERIALIZE_PTR(ce->default_properties_table);
809
0
    p = ce->default_properties_table;
810
0
    UNSERIALIZE_PTR(p);
811
0
    end = p + ce->default_properties_count;
812
0
    while (p < end) {
813
0
      zend_file_cache_serialize_zval(p, script, info, buf);
814
0
      p++;
815
0
    }
816
0
  }
817
0
  if (ce->default_static_members_table) {
818
0
    zval *p, *end;
819
820
0
    SERIALIZE_PTR(ce->default_static_members_table);
821
0
    p = ce->default_static_members_table;
822
0
    UNSERIALIZE_PTR(p);
823
824
0
    end = p + ce->default_static_members_count;
825
0
    while (p < end) {
826
0
      zend_file_cache_serialize_zval(p, script, info, buf);
827
0
      p++;
828
0
    }
829
0
  }
830
0
  zend_file_cache_serialize_hash(&ce->constants_table, script, info, buf, zend_file_cache_serialize_class_constant);
831
0
  SERIALIZE_STR(ce->info.user.filename);
832
0
  SERIALIZE_STR(ce->doc_comment);
833
0
  SERIALIZE_ATTRIBUTES(ce->attributes);
834
0
  zend_file_cache_serialize_hash(&ce->properties_info, script, info, buf, zend_file_cache_serialize_prop_info);
835
836
0
  if (ce->properties_info_table) {
837
0
    uint32_t i;
838
0
    zend_property_info **table;
839
840
0
    SERIALIZE_PTR(ce->properties_info_table);
841
0
    table = ce->properties_info_table;
842
0
    UNSERIALIZE_PTR(table);
843
844
0
    for (i = 0; i < ce->default_properties_count; i++) {
845
0
      SERIALIZE_PTR(table[i]);
846
0
    }
847
0
  }
848
849
0
  if (ce->num_interfaces) {
850
0
    uint32_t i;
851
0
    zend_class_name *interface_names;
852
853
0
    ZEND_ASSERT(!(ce->ce_flags & ZEND_ACC_LINKED));
854
855
0
    SERIALIZE_PTR(ce->interface_names);
856
0
    interface_names = ce->interface_names;
857
0
    UNSERIALIZE_PTR(interface_names);
858
859
0
    for (i = 0; i < ce->num_interfaces; i++) {
860
0
      SERIALIZE_STR(interface_names[i].name);
861
0
      SERIALIZE_STR(interface_names[i].lc_name);
862
0
    }
863
0
  }
864
865
0
  if (ce->num_traits) {
866
0
    uint32_t i;
867
0
    zend_class_name *trait_names;
868
869
0
    SERIALIZE_PTR(ce->trait_names);
870
0
    trait_names = ce->trait_names;
871
0
    UNSERIALIZE_PTR(trait_names);
872
873
0
    for (i = 0; i < ce->num_traits; i++) {
874
0
      SERIALIZE_STR(trait_names[i].name);
875
0
      SERIALIZE_STR(trait_names[i].lc_name);
876
0
    }
877
878
0
    if (ce->trait_aliases) {
879
0
      zend_trait_alias **p, *q;
880
881
0
      SERIALIZE_PTR(ce->trait_aliases);
882
0
      p = ce->trait_aliases;
883
0
      UNSERIALIZE_PTR(p);
884
885
0
      while (*p) {
886
0
        SERIALIZE_PTR(*p);
887
0
        q = *p;
888
0
        UNSERIALIZE_PTR(q);
889
890
0
        if (q->trait_method.method_name) {
891
0
          SERIALIZE_STR(q->trait_method.method_name);
892
0
        }
893
0
        if (q->trait_method.class_name) {
894
0
          SERIALIZE_STR(q->trait_method.class_name);
895
0
        }
896
897
0
        if (q->alias) {
898
0
          SERIALIZE_STR(q->alias);
899
0
        }
900
0
        p++;
901
0
      }
902
0
    }
903
904
0
    if (ce->trait_precedences) {
905
0
      zend_trait_precedence **p, *q;
906
0
      uint32_t j;
907
908
0
      SERIALIZE_PTR(ce->trait_precedences);
909
0
      p = ce->trait_precedences;
910
0
      UNSERIALIZE_PTR(p);
911
912
0
      while (*p) {
913
0
        SERIALIZE_PTR(*p);
914
0
        q = *p;
915
0
        UNSERIALIZE_PTR(q);
916
917
0
        if (q->trait_method.method_name) {
918
0
          SERIALIZE_STR(q->trait_method.method_name);
919
0
        }
920
0
        if (q->trait_method.class_name) {
921
0
          SERIALIZE_STR(q->trait_method.class_name);
922
0
        }
923
924
0
        for (j = 0; j < q->num_excludes; j++) {
925
0
          SERIALIZE_STR(q->exclude_class_names[j]);
926
0
        }
927
0
        p++;
928
0
      }
929
0
    }
930
0
  }
931
932
0
  SERIALIZE_PTR(ce->constructor);
933
0
  SERIALIZE_PTR(ce->destructor);
934
0
  SERIALIZE_PTR(ce->clone);
935
0
  SERIALIZE_PTR(ce->__get);
936
0
  SERIALIZE_PTR(ce->__set);
937
0
  SERIALIZE_PTR(ce->__call);
938
0
  SERIALIZE_PTR(ce->__serialize);
939
0
  SERIALIZE_PTR(ce->__unserialize);
940
0
  SERIALIZE_PTR(ce->__isset);
941
0
  SERIALIZE_PTR(ce->__unset);
942
0
  SERIALIZE_PTR(ce->__tostring);
943
0
  SERIALIZE_PTR(ce->__callstatic);
944
0
  SERIALIZE_PTR(ce->__debugInfo);
945
946
0
  if (ce->iterator_funcs_ptr) {
947
0
    SERIALIZE_PTR(ce->iterator_funcs_ptr->zf_new_iterator);
948
0
    SERIALIZE_PTR(ce->iterator_funcs_ptr->zf_rewind);
949
0
    SERIALIZE_PTR(ce->iterator_funcs_ptr->zf_valid);
950
0
    SERIALIZE_PTR(ce->iterator_funcs_ptr->zf_key);
951
0
    SERIALIZE_PTR(ce->iterator_funcs_ptr->zf_current);
952
0
    SERIALIZE_PTR(ce->iterator_funcs_ptr->zf_next);
953
0
    SERIALIZE_PTR(ce->iterator_funcs_ptr);
954
0
  }
955
956
0
  if (ce->arrayaccess_funcs_ptr) {
957
0
    SERIALIZE_PTR(ce->arrayaccess_funcs_ptr->zf_offsetget);
958
0
    SERIALIZE_PTR(ce->arrayaccess_funcs_ptr->zf_offsetexists);
959
0
    SERIALIZE_PTR(ce->arrayaccess_funcs_ptr->zf_offsetset);
960
0
    SERIALIZE_PTR(ce->arrayaccess_funcs_ptr->zf_offsetunset);
961
0
    SERIALIZE_PTR(ce->arrayaccess_funcs_ptr);
962
0
  }
963
964
0
  ZEND_MAP_PTR_INIT(ce->static_members_table, NULL);
965
0
  ZEND_MAP_PTR_INIT(ce->mutable_data, NULL);
966
967
0
  ce->inheritance_cache = NULL;
968
969
0
  if (ce->get_iterator) {
970
0
    ZEND_ASSERT(ce->get_iterator == zend_hooked_object_get_iterator);
971
0
    ce->get_iterator = HOOKED_ITERATOR_PLACEHOLDER;
972
0
  }
973
0
}
974
975
static void zend_file_cache_serialize_warnings(
976
    zend_persistent_script *script, zend_file_cache_metainfo *info, void *buf)
977
0
{
978
0
  if (script->warnings) {
979
0
    zend_error_info **warnings;
980
0
    SERIALIZE_PTR(script->warnings);
981
0
    warnings = script->warnings;
982
0
    UNSERIALIZE_PTR(warnings);
983
984
0
    for (uint32_t i = 0; i < script->num_warnings; i++) {
985
0
      zend_error_info *warning;
986
0
      SERIALIZE_PTR(warnings[i]);
987
0
      warning = warnings[i];
988
0
      UNSERIALIZE_PTR(warning);
989
0
      SERIALIZE_STR(warning->filename);
990
0
      SERIALIZE_STR(warning->message);
991
0
    }
992
0
  }
993
0
}
994
995
static void zend_file_cache_serialize_early_bindings(
996
    zend_persistent_script *script, zend_file_cache_metainfo *info, void *buf)
997
0
{
998
0
  if (script->early_bindings) {
999
0
    SERIALIZE_PTR(script->early_bindings);
1000
0
    zend_early_binding *early_bindings = script->early_bindings;
1001
0
    UNSERIALIZE_PTR(early_bindings);
1002
0
    for (uint32_t i = 0; i < script->num_early_bindings; i++) {
1003
0
      SERIALIZE_STR(early_bindings[i].lcname);
1004
0
      SERIALIZE_STR(early_bindings[i].rtd_key);
1005
0
      SERIALIZE_STR(early_bindings[i].lc_parent_name);
1006
0
    }
1007
0
  }
1008
0
}
1009
1010
static void zend_file_cache_serialize(zend_persistent_script   *script,
1011
                                      zend_file_cache_metainfo *info,
1012
                                      void                     *buf)
1013
0
{
1014
0
  zend_persistent_script *new_script;
1015
1016
0
  memcpy(info->magic, "OPCACHE", 8);
1017
0
  memcpy(info->system_id, zend_system_id, 32);
1018
0
  info->mem_size = script->size;
1019
0
  info->str_size = 0;
1020
0
  info->script_offset = (char*)script - (char*)script->mem;
1021
0
  info->timestamp = script->timestamp;
1022
1023
0
  memcpy(buf, script->mem, script->size);
1024
1025
0
  new_script = (zend_persistent_script*)((char*)buf + info->script_offset);
1026
0
  SERIALIZE_STR(new_script->script.filename);
1027
1028
0
  zend_file_cache_serialize_hash(&new_script->script.class_table, script, info, buf, zend_file_cache_serialize_class);
1029
0
  zend_file_cache_serialize_hash(&new_script->script.function_table, script, info, buf, zend_file_cache_serialize_func);
1030
0
  zend_file_cache_serialize_op_array(&new_script->script.main_op_array, script, info, buf);
1031
0
  zend_file_cache_serialize_warnings(new_script, info, buf);
1032
0
  zend_file_cache_serialize_early_bindings(new_script, info, buf);
1033
1034
0
  new_script->mem = NULL;
1035
0
}
1036
1037
static char *zend_file_cache_get_bin_file_path(zend_string *script_path)
1038
0
{
1039
0
  size_t len;
1040
0
  char *filename;
1041
1042
0
#ifndef ZEND_WIN32
1043
0
  len = strlen(ZCG(accel_directives).file_cache);
1044
0
  filename = emalloc(len + 33 + ZSTR_LEN(script_path) + sizeof(SUFFIX));
1045
0
  memcpy(filename, ZCG(accel_directives).file_cache, len);
1046
0
  filename[len] = '/';
1047
0
  memcpy(filename + len + 1, zend_system_id, 32);
1048
0
  memcpy(filename + len + 33, ZSTR_VAL(script_path), ZSTR_LEN(script_path));
1049
0
  memcpy(filename + len + 33 + ZSTR_LEN(script_path), SUFFIX, sizeof(SUFFIX));
1050
#else
1051
  len = strlen(ZCG(accel_directives).file_cache);
1052
1053
  filename = emalloc(len + 33 + 33 + ZSTR_LEN(script_path) + sizeof(SUFFIX));
1054
1055
  memcpy(filename, ZCG(accel_directives).file_cache, len);
1056
  filename[len] = '\\';
1057
  memcpy(filename + 1 + len, accel_uname_id, 32);
1058
  len += 1 + 32;
1059
  filename[len] = '\\';
1060
1061
  memcpy(filename + len + 1, zend_system_id, 32);
1062
1063
  if (ZSTR_LEN(script_path) >= 7 && ':' == ZSTR_VAL(script_path)[4] && '/' == ZSTR_VAL(script_path)[5]  && '/' == ZSTR_VAL(script_path)[6]) {
1064
    /* phar:// or file:// */
1065
    *(filename + len + 33) = '\\';
1066
    memcpy(filename + len + 34, ZSTR_VAL(script_path), 4);
1067
    if (ZSTR_LEN(script_path) - 7 >= 2 && ':' == ZSTR_VAL(script_path)[8]) {
1068
      *(filename + len + 38) = '\\';
1069
      *(filename + len + 39) = ZSTR_VAL(script_path)[7];
1070
      memcpy(filename + len + 40, ZSTR_VAL(script_path) + 9, ZSTR_LEN(script_path) - 9);
1071
      memcpy(filename + len + 40 + ZSTR_LEN(script_path) - 9, SUFFIX, sizeof(SUFFIX));
1072
    } else {
1073
      memcpy(filename + len + 38, ZSTR_VAL(script_path) + 7, ZSTR_LEN(script_path) - 7);
1074
      memcpy(filename + len + 38 + ZSTR_LEN(script_path) - 7, SUFFIX, sizeof(SUFFIX));
1075
    }
1076
  } else if (ZSTR_LEN(script_path) >= 2 && ':' == ZSTR_VAL(script_path)[1]) {
1077
    /* local fs */
1078
    *(filename + len + 33) = '\\';
1079
    *(filename + len + 34) = ZSTR_VAL(script_path)[0];
1080
    memcpy(filename + len + 35, ZSTR_VAL(script_path) + 2, ZSTR_LEN(script_path) - 2);
1081
    memcpy(filename + len + 35 + ZSTR_LEN(script_path) - 2, SUFFIX, sizeof(SUFFIX));
1082
  } else {
1083
    /* network path */
1084
    memcpy(filename + len + 33, ZSTR_VAL(script_path), ZSTR_LEN(script_path));
1085
    memcpy(filename + len + 33 + ZSTR_LEN(script_path), SUFFIX, sizeof(SUFFIX));
1086
  }
1087
#endif
1088
1089
0
  return filename;
1090
0
}
1091
1092
/**
1093
 * Helper function for zend_file_cache_script_store().
1094
 *
1095
 * @return true on success, false on error and errno is set to indicate the cause of the error
1096
 */
1097
static bool zend_file_cache_script_write(int fd, const zend_persistent_script *script, const zend_file_cache_metainfo *info, const void *buf, const zend_string *s)
1098
0
{
1099
0
  ssize_t written;
1100
0
  const ssize_t total_size = (ssize_t)(sizeof(*info) + script->size + info->str_size);
1101
1102
0
#ifdef HAVE_SYS_UIO_H
1103
0
  const struct iovec vec[] = {
1104
0
    { .iov_base = (void *)info, .iov_len = sizeof(*info) },
1105
0
    { .iov_base = (void *)buf, .iov_len = script->size },
1106
0
    { .iov_base = (void *)ZSTR_VAL(s), .iov_len = info->str_size },
1107
0
  };
1108
1109
0
  written = writev(fd, vec, sizeof(vec) / sizeof(vec[0]));
1110
0
  if (EXPECTED(written == total_size)) {
1111
0
    return true;
1112
0
  }
1113
1114
0
  errno = written == -1 ? errno : EAGAIN;
1115
0
  return false;
1116
#else
1117
  if (UNEXPECTED(ZEND_LONG_MAX < (zend_long)total_size)) {
1118
# ifdef EFBIG
1119
    errno = EFBIG;
1120
# else
1121
    errno = ERANGE;
1122
# endif
1123
    return false;
1124
  }
1125
1126
  written = write(fd, info, sizeof(*info));
1127
  if (UNEXPECTED(written != sizeof(*info))) {
1128
    errno = written == -1 ? errno : EAGAIN;
1129
    return false;
1130
  }
1131
1132
  written = write(fd, buf, script->size);
1133
  if (UNEXPECTED(written != script->size)) {
1134
    errno = written == -1 ? errno : EAGAIN;
1135
    return false;
1136
  }
1137
1138
  written = write(fd, ZSTR_VAL(s), info->str_size);
1139
  if (UNEXPECTED(written != info->str_size)) {
1140
    errno = written == -1 ? errno : EAGAIN;
1141
    return false;
1142
  }
1143
1144
  return true;
1145
#endif
1146
0
}
1147
1148
int zend_file_cache_script_store(zend_persistent_script *script, bool in_shm)
1149
0
{
1150
0
  int fd;
1151
0
  char *filename;
1152
0
  zend_file_cache_metainfo info;
1153
0
  void *mem, *buf;
1154
1155
0
#ifdef HAVE_JIT
1156
  /* FIXME: dump jited codes out to file cache? */
1157
0
  if (JIT_G(on)) {
1158
0
    return FAILURE;
1159
0
  }
1160
0
#endif
1161
1162
0
  if (ZCG(accel_directives).file_cache_read_only) {
1163
0
    return FAILURE;
1164
0
  }
1165
1166
0
  filename = zend_file_cache_get_bin_file_path(script->script.filename);
1167
1168
0
  if (zend_file_cache_mkdir(filename, strlen(ZCG(accel_directives).file_cache)) != SUCCESS) {
1169
0
    zend_accel_error(ACCEL_LOG_WARNING, "opcache cannot create directory for file '%s', %s\n", filename, strerror(errno));
1170
0
    efree(filename);
1171
0
    return FAILURE;
1172
0
  }
1173
1174
0
  fd = zend_file_cache_open(filename, O_CREAT | O_EXCL | O_RDWR | O_BINARY, S_IRUSR | S_IWUSR);
1175
0
  if (fd < 0) {
1176
0
    if (errno != EEXIST) {
1177
0
      zend_accel_error(ACCEL_LOG_WARNING, "opcache cannot create file '%s', %s\n", filename, strerror(errno));
1178
0
    }
1179
0
    efree(filename);
1180
0
    return FAILURE;
1181
0
  }
1182
1183
0
  if (zend_file_cache_flock(fd, LOCK_EX) != 0) {
1184
0
    close(fd);
1185
0
    efree(filename);
1186
0
    return FAILURE;
1187
0
  }
1188
1189
0
#if defined(__AVX__) || defined(__SSE2__)
1190
  /* Align to 64-byte boundary */
1191
0
  mem = emalloc(script->size + 64);
1192
0
  buf = (void*)(((uintptr_t)mem + 63L) & ~63L);
1193
#else
1194
  mem = buf = emalloc(script->size);
1195
#endif
1196
1197
0
  ZCG(mem) = zend_string_alloc(4096 - (_ZSTR_HEADER_SIZE + 1), 0);
1198
1199
0
  zend_shared_alloc_init_xlat_table();
1200
0
  if (!in_shm) {
1201
0
    script->corrupted = true; /* used to check if script restored to SHM or process memory */
1202
0
  }
1203
0
  zend_file_cache_serialize(script, &info, buf);
1204
0
  if (!in_shm) {
1205
0
    script->corrupted = false;
1206
0
  }
1207
0
  zend_shared_alloc_destroy_xlat_table();
1208
1209
0
  zend_string *const s = (zend_string*)ZCG(mem);
1210
1211
#if __has_feature(memory_sanitizer)
1212
  /* The buffer may contain uninitialized regions. However, the uninitialized parts will not be
1213
   * used when reading the cache. We should probably still try to get things fully initialized
1214
   * for reproducibility, but for now ignore this issue. */
1215
  __msan_unpoison(&info, sizeof(info));
1216
  __msan_unpoison(buf, script->size);
1217
#endif
1218
1219
0
  info.checksum = zend_adler32(ADLER32_INIT, buf, script->size);
1220
0
  info.checksum = zend_adler32(info.checksum, (unsigned char*)ZSTR_VAL(s), info.str_size);
1221
1222
0
  if (!zend_file_cache_script_write(fd, script, &info, buf, s)) {
1223
0
    zend_accel_error(ACCEL_LOG_WARNING, "opcache cannot write to file '%s': %s\n", filename, strerror(errno));
1224
0
    zend_string_release_ex(s, 0);
1225
0
    close(fd);
1226
0
    efree(mem);
1227
0
    zend_file_cache_unlink(filename);
1228
0
    efree(filename);
1229
0
    return FAILURE;
1230
0
  }
1231
1232
0
  zend_string_release_ex(s, 0);
1233
0
  efree(mem);
1234
0
  if (zend_file_cache_flock(fd, LOCK_UN) != 0) {
1235
0
    zend_accel_error(ACCEL_LOG_WARNING, "opcache cannot unlock file '%s': %s\n", filename, strerror(errno));
1236
0
  }
1237
0
  close(fd);
1238
0
  efree(filename);
1239
1240
0
  return SUCCESS;
1241
0
}
1242
1243
static void zend_file_cache_unserialize_hash(HashTable               *ht,
1244
                                             zend_persistent_script  *script,
1245
                                             void                    *buf,
1246
                                             unserialize_callback_t   func,
1247
                                             dtor_func_t              dtor)
1248
0
{
1249
0
  ht->pDestructor = dtor;
1250
0
  if (HT_FLAGS(ht) & HASH_FLAG_UNINITIALIZED) {
1251
0
    if (EXPECTED(!file_cache_only)) {
1252
0
      HT_SET_DATA_ADDR(ht, &ZCSG(uninitialized_bucket));
1253
0
    } else {
1254
0
      HT_SET_DATA_ADDR(ht, &uninitialized_bucket);
1255
0
    }
1256
0
    return;
1257
0
  }
1258
0
  if (IS_UNSERIALIZED(ht->arData)) {
1259
0
    return;
1260
0
  }
1261
0
  UNSERIALIZE_PTR(ht->arData);
1262
0
  if (HT_IS_PACKED(ht)) {
1263
0
    zval *p, *end;
1264
1265
0
    p = ht->arPacked;
1266
0
    end = p + ht->nNumUsed;
1267
0
    while (p < end) {
1268
0
      if (Z_TYPE_P(p) != IS_UNDEF) {
1269
0
        func(p, script, buf);
1270
0
      }
1271
0
      p++;
1272
0
    }
1273
0
  } else {
1274
0
    Bucket *p, *end;
1275
1276
0
    p = ht->arData;
1277
0
    end = p + ht->nNumUsed;
1278
0
    while (p < end) {
1279
0
      if (Z_TYPE(p->val) != IS_UNDEF) {
1280
0
        UNSERIALIZE_STR(p->key);
1281
0
        func(&p->val, script, buf);
1282
0
      }
1283
0
      p++;
1284
0
    }
1285
0
  }
1286
0
}
1287
1288
static void zend_file_cache_unserialize_ast(zend_ast                *ast,
1289
                                            zend_persistent_script  *script,
1290
                                            void                    *buf)
1291
0
{
1292
0
  uint32_t i;
1293
1294
0
  if (ast->kind == ZEND_AST_ZVAL || ast->kind == ZEND_AST_CONSTANT) {
1295
0
    zend_file_cache_unserialize_zval(&((zend_ast_zval*)ast)->val, script, buf);
1296
0
  } else if (zend_ast_is_list(ast)) {
1297
0
    zend_ast_list *list = zend_ast_get_list(ast);
1298
0
    for (i = 0; i < list->children; i++) {
1299
0
      if (list->child[i] && !IS_UNSERIALIZED(list->child[i])) {
1300
0
        UNSERIALIZE_PTR(list->child[i]);
1301
0
        zend_file_cache_unserialize_ast(list->child[i], script, buf);
1302
0
      }
1303
0
    }
1304
0
  } else if (ast->kind == ZEND_AST_OP_ARRAY) {
1305
0
    zval z;
1306
0
    ZVAL_PTR(&z, zend_ast_get_op_array(ast)->op_array);
1307
0
    zend_file_cache_unserialize_func(&z, script, buf);
1308
0
    zend_ast_get_op_array(ast)->op_array = Z_PTR(z);
1309
0
  } else if (ast->kind == ZEND_AST_CALLABLE_CONVERT) {
1310
0
    zend_ast_fcc *fcc = (zend_ast_fcc*)ast;
1311
0
    ZEND_MAP_PTR_NEW(fcc->fptr);
1312
0
    if (!IS_UNSERIALIZED(fcc->args)) {
1313
0
      UNSERIALIZE_PTR(fcc->args);
1314
0
      zend_file_cache_unserialize_ast(fcc->args, script, buf);
1315
0
    }
1316
0
  } else if (zend_ast_is_decl(ast)) {
1317
    /* Not implemented. */
1318
0
    ZEND_UNREACHABLE();
1319
0
  } else {
1320
0
    uint32_t children = zend_ast_get_num_children(ast);
1321
0
    for (i = 0; i < children; i++) {
1322
0
      if (ast->child[i] && !IS_UNSERIALIZED(ast->child[i])) {
1323
0
        UNSERIALIZE_PTR(ast->child[i]);
1324
0
        zend_file_cache_unserialize_ast(ast->child[i], script, buf);
1325
0
      }
1326
0
    }
1327
0
  }
1328
0
}
1329
1330
static void zend_file_cache_unserialize_zval(zval                    *zv,
1331
                                             zend_persistent_script  *script,
1332
                                             void                    *buf)
1333
0
{
1334
0
  switch (Z_TYPE_P(zv)) {
1335
0
    case IS_STRING:
1336
      /* We can't use !IS_UNSERIALIZED here, because that does not recognize unserialized
1337
       * interned strings in non-shm mode. */
1338
0
      if (IS_SERIALIZED(Z_STR_P(zv)) || IS_SERIALIZED_INTERNED(Z_STR_P(zv))) {
1339
0
        UNSERIALIZE_STR(Z_STR_P(zv));
1340
0
      }
1341
0
      break;
1342
0
    case IS_ARRAY:
1343
0
      if (!IS_UNSERIALIZED(Z_ARR_P(zv))) {
1344
0
        HashTable *ht;
1345
1346
0
        UNSERIALIZE_PTR(Z_ARR_P(zv));
1347
0
        ht = Z_ARR_P(zv);
1348
0
        zend_file_cache_unserialize_hash(ht,
1349
0
            script, buf, zend_file_cache_unserialize_zval, ZVAL_PTR_DTOR);
1350
0
      }
1351
0
      break;
1352
0
    case IS_CONSTANT_AST:
1353
0
      if (!IS_UNSERIALIZED(Z_AST_P(zv))) {
1354
0
        UNSERIALIZE_PTR(Z_AST_P(zv));
1355
0
        zend_file_cache_unserialize_ast(Z_ASTVAL_P(zv), script, buf);
1356
0
      }
1357
0
      break;
1358
0
    case IS_INDIRECT:
1359
      /* Used by static properties. */
1360
0
      UNSERIALIZE_PTR(Z_INDIRECT_P(zv));
1361
0
      break;
1362
0
    case IS_PTR:
1363
      /* Used by attributes on constants, will be handled separately */
1364
0
      break;
1365
0
    default:
1366
0
      ZEND_ASSERT(Z_TYPE_P(zv) < IS_STRING);
1367
0
      break;
1368
0
  }
1369
0
}
1370
1371
static void zend_file_cache_unserialize_attribute(zval *zv, zend_persistent_script *script, void *buf)
1372
0
{
1373
0
  zend_attribute *attr;
1374
0
  uint32_t i;
1375
1376
0
  UNSERIALIZE_PTR(Z_PTR_P(zv));
1377
0
  attr = Z_PTR_P(zv);
1378
1379
0
  UNSERIALIZE_STR(attr->name);
1380
0
  UNSERIALIZE_STR(attr->lcname);
1381
0
  UNSERIALIZE_STR(attr->validation_error);
1382
1383
0
  for (i = 0; i < attr->argc; i++) {
1384
0
    UNSERIALIZE_STR(attr->args[i].name);
1385
0
    zend_file_cache_unserialize_zval(&attr->args[i].value, script, buf);
1386
0
  }
1387
0
}
1388
1389
static void zend_file_cache_unserialize_type(
1390
    zend_type *type, zend_class_entry *scope, zend_persistent_script *script, void *buf)
1391
0
{
1392
0
  if (ZEND_TYPE_HAS_LIST(*type)) {
1393
0
    zend_type_list *list = ZEND_TYPE_LIST(*type);
1394
0
    UNSERIALIZE_PTR(list);
1395
0
    ZEND_TYPE_SET_PTR(*type, list);
1396
1397
0
    zend_type *list_type;
1398
0
    ZEND_TYPE_LIST_FOREACH_MUTABLE(list, list_type) {
1399
0
      zend_file_cache_unserialize_type(list_type, scope, script, buf);
1400
0
    } ZEND_TYPE_LIST_FOREACH_END();
1401
0
  } else if (ZEND_TYPE_HAS_NAME(*type)) {
1402
0
    zend_string *type_name = ZEND_TYPE_NAME(*type);
1403
0
    UNSERIALIZE_STR(type_name);
1404
0
    ZEND_TYPE_SET_PTR(*type, type_name);
1405
0
    if (!script->corrupted) {
1406
0
      zend_accel_get_class_name_map_ptr(type_name);
1407
0
    } else {
1408
0
      zend_alloc_ce_cache(type_name);
1409
0
    }
1410
0
  }
1411
0
}
1412
1413
static void zend_file_cache_unserialize_op_array(zend_op_array           *op_array,
1414
                                                 zend_persistent_script  *script,
1415
                                                 void                    *buf)
1416
0
{
1417
0
  if (!script->corrupted) {
1418
0
    if (op_array != &script->script.main_op_array) {
1419
0
      op_array->fn_flags |= ZEND_ACC_IMMUTABLE;
1420
0
      ZEND_MAP_PTR_NEW(op_array->run_time_cache);
1421
0
    } else {
1422
0
      ZEND_ASSERT(!(op_array->fn_flags & ZEND_ACC_IMMUTABLE));
1423
0
      ZEND_MAP_PTR_INIT(op_array->run_time_cache, NULL);
1424
0
    }
1425
0
    if (op_array->static_variables) {
1426
0
      ZEND_MAP_PTR_NEW(op_array->static_variables_ptr);
1427
0
    }
1428
0
  } else {
1429
0
    op_array->fn_flags &= ~ZEND_ACC_IMMUTABLE;
1430
0
    ZEND_MAP_PTR_INIT(op_array->static_variables_ptr, NULL);
1431
0
    ZEND_MAP_PTR_INIT(op_array->run_time_cache, NULL);
1432
0
  }
1433
1434
  /* Check whether this op_array has already been unserialized. */
1435
0
  if (IS_UNSERIALIZED(op_array->opcodes)) {
1436
0
    ZEND_ASSERT(op_array->scope && "Only method op_arrays should be shared");
1437
0
    return;
1438
0
  }
1439
1440
0
  if (op_array->refcount) {
1441
0
    op_array->refcount = NULL;
1442
0
    UNSERIALIZE_PTR(op_array->static_variables);
1443
0
    UNSERIALIZE_PTR(op_array->literals);
1444
0
    UNSERIALIZE_PTR(op_array->opcodes);
1445
0
    UNSERIALIZE_PTR(op_array->arg_info);
1446
0
    UNSERIALIZE_PTR(op_array->vars);
1447
0
    UNSERIALIZE_STR(op_array->function_name);
1448
0
    UNSERIALIZE_STR(op_array->filename);
1449
0
    UNSERIALIZE_PTR(op_array->live_range);
1450
0
    UNSERIALIZE_PTR(op_array->scope);
1451
0
    UNSERIALIZE_STR(op_array->doc_comment);
1452
0
    UNSERIALIZE_ATTRIBUTES(op_array->attributes);
1453
0
    UNSERIALIZE_PTR(op_array->try_catch_array);
1454
0
    UNSERIALIZE_PTR(op_array->prototype);
1455
0
    UNSERIALIZE_PTR(op_array->prop_info);
1456
0
    return;
1457
0
  }
1458
1459
0
  if (op_array->static_variables) {
1460
0
    HashTable *ht;
1461
1462
0
    UNSERIALIZE_PTR(op_array->static_variables);
1463
0
    ht = op_array->static_variables;
1464
0
    zend_file_cache_unserialize_hash(ht,
1465
0
        script, buf, zend_file_cache_unserialize_zval, ZVAL_PTR_DTOR);
1466
0
  }
1467
1468
0
  if (op_array->literals) {
1469
0
    zval *p, *end;
1470
1471
0
    UNSERIALIZE_PTR(op_array->literals);
1472
0
    p = op_array->literals;
1473
0
    end = p + op_array->last_literal;
1474
0
    while (p < end) {
1475
0
      zend_file_cache_unserialize_zval(p, script, buf);
1476
0
      p++;
1477
0
    }
1478
0
  }
1479
1480
0
  {
1481
0
    zend_op *opline, *end;
1482
1483
0
    UNSERIALIZE_PTR(op_array->opcodes);
1484
0
    opline = op_array->opcodes;
1485
0
    end = opline + op_array->last;
1486
0
    while (opline < end) {
1487
#if ZEND_USE_ABS_CONST_ADDR
1488
      if (opline->op1_type == IS_CONST) {
1489
        UNSERIALIZE_PTR(opline->op1.zv);
1490
      }
1491
      if (opline->op2_type == IS_CONST) {
1492
        UNSERIALIZE_PTR(opline->op2.zv);
1493
      }
1494
#else
1495
0
      if (opline->op1_type == IS_CONST) {
1496
0
        ZEND_PASS_TWO_UPDATE_CONSTANT(op_array, opline, opline->op1);
1497
0
      }
1498
0
      if (opline->op2_type == IS_CONST) {
1499
0
        ZEND_PASS_TWO_UPDATE_CONSTANT(op_array, opline, opline->op2);
1500
0
      }
1501
0
#endif
1502
#if ZEND_USE_ABS_JMP_ADDR
1503
      switch (opline->opcode) {
1504
        case ZEND_JMP:
1505
        case ZEND_FAST_CALL:
1506
          UNSERIALIZE_PTR(opline->op1.jmp_addr);
1507
          break;
1508
        case ZEND_JMPZ:
1509
        case ZEND_JMPNZ:
1510
        case ZEND_JMPZ_EX:
1511
        case ZEND_JMPNZ_EX:
1512
        case ZEND_JMP_SET:
1513
        case ZEND_COALESCE:
1514
        case ZEND_FE_RESET_R:
1515
        case ZEND_FE_RESET_RW:
1516
        case ZEND_ASSERT_CHECK:
1517
        case ZEND_JMP_NULL:
1518
        case ZEND_BIND_INIT_STATIC_OR_JMP:
1519
        case ZEND_JMP_FRAMELESS:
1520
          UNSERIALIZE_PTR(opline->op2.jmp_addr);
1521
          break;
1522
        case ZEND_CATCH:
1523
          if (!(opline->extended_value & ZEND_LAST_CATCH)) {
1524
            UNSERIALIZE_PTR(opline->op2.jmp_addr);
1525
          }
1526
          break;
1527
        case ZEND_FE_FETCH_R:
1528
        case ZEND_FE_FETCH_RW:
1529
        case ZEND_SWITCH_LONG:
1530
        case ZEND_SWITCH_STRING:
1531
          /* relative extended_value don't have to be changed */
1532
          break;
1533
      }
1534
#endif
1535
1536
0
      if (opline->opcode == ZEND_OP_DATA
1537
0
        && (opline-1)->opcode == ZEND_DECLARE_ATTRIBUTED_CONST
1538
0
      ) {
1539
0
        zval *literal = RT_CONSTANT(opline, opline->op1);
1540
0
        UNSERIALIZE_ATTRIBUTES(Z_PTR_P(literal));
1541
0
      }
1542
0
      zend_deserialize_opcode_handler(opline);
1543
0
      opline++;
1544
0
    }
1545
1546
0
    UNSERIALIZE_PTR(op_array->scope);
1547
1548
0
    if (op_array->arg_info) {
1549
0
      zend_arg_info *p, *end;
1550
0
      UNSERIALIZE_PTR(op_array->arg_info);
1551
0
      p = op_array->arg_info;
1552
0
      end = p + op_array->num_args;
1553
0
      if (op_array->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
1554
0
        p--;
1555
0
      }
1556
0
      if (op_array->fn_flags & ZEND_ACC_VARIADIC) {
1557
0
        end++;
1558
0
      }
1559
0
      while (p < end) {
1560
0
        if (!IS_UNSERIALIZED(p->name)) {
1561
0
          UNSERIALIZE_STR(p->name);
1562
0
        }
1563
0
        zend_file_cache_unserialize_type(&p->type, (op_array->fn_flags & ZEND_ACC_CLOSURE) ? NULL : op_array->scope, script, buf);
1564
0
        UNSERIALIZE_STR(p->doc_comment);
1565
0
        p++;
1566
0
      }
1567
0
    }
1568
1569
0
    if (op_array->vars) {
1570
0
      zend_string **p, **end;
1571
1572
0
      UNSERIALIZE_PTR(op_array->vars);
1573
0
      p = op_array->vars;
1574
0
      end = p + op_array->last_var;
1575
0
      while (p < end) {
1576
0
        if (!IS_UNSERIALIZED(*p)) {
1577
0
          UNSERIALIZE_STR(*p);
1578
0
        }
1579
0
        p++;
1580
0
      }
1581
0
    }
1582
1583
0
    if (op_array->num_dynamic_func_defs) {
1584
0
      UNSERIALIZE_PTR(op_array->dynamic_func_defs);
1585
0
      for (uint32_t i = 0; i < op_array->num_dynamic_func_defs; i++) {
1586
0
        UNSERIALIZE_PTR(op_array->dynamic_func_defs[i]);
1587
0
        zend_file_cache_unserialize_op_array(op_array->dynamic_func_defs[i], script, buf);
1588
0
      }
1589
0
    }
1590
1591
0
    UNSERIALIZE_STR(op_array->function_name);
1592
0
    UNSERIALIZE_STR(op_array->filename);
1593
0
    UNSERIALIZE_PTR(op_array->live_range);
1594
0
    UNSERIALIZE_STR(op_array->doc_comment);
1595
0
    UNSERIALIZE_ATTRIBUTES(op_array->attributes);
1596
0
    UNSERIALIZE_PTR(op_array->try_catch_array);
1597
0
    UNSERIALIZE_PTR(op_array->prototype);
1598
0
    UNSERIALIZE_PTR(op_array->prop_info);
1599
0
  }
1600
0
}
1601
1602
static void zend_file_cache_unserialize_func(zval                    *zv,
1603
                                             zend_persistent_script  *script,
1604
                                             void                    *buf)
1605
0
{
1606
0
  zend_function *func;
1607
0
  UNSERIALIZE_PTR(Z_PTR_P(zv));
1608
0
  func = Z_PTR_P(zv);
1609
0
  ZEND_ASSERT(func->type == ZEND_USER_FUNCTION);
1610
0
  zend_file_cache_unserialize_op_array(&func->op_array, script, buf);
1611
0
}
1612
1613
static void zend_file_cache_unserialize_prop_info(zval                    *zv,
1614
                                                  zend_persistent_script  *script,
1615
                                                  void                    *buf)
1616
0
{
1617
0
  if (!IS_UNSERIALIZED(Z_PTR_P(zv))) {
1618
0
    zend_property_info *prop;
1619
1620
0
    UNSERIALIZE_PTR(Z_PTR_P(zv));
1621
0
    prop = Z_PTR_P(zv);
1622
1623
0
    ZEND_ASSERT(prop->ce != NULL && prop->name != NULL);
1624
0
    if (!IS_UNSERIALIZED(prop->ce)) {
1625
0
      UNSERIALIZE_PTR(prop->ce);
1626
0
      UNSERIALIZE_STR(prop->name);
1627
0
      if (prop->doc_comment) {
1628
0
        UNSERIALIZE_STR(prop->doc_comment);
1629
0
      }
1630
0
      UNSERIALIZE_ATTRIBUTES(prop->attributes);
1631
0
      UNSERIALIZE_PTR(prop->prototype);
1632
0
      if (prop->hooks) {
1633
0
        UNSERIALIZE_PTR(prop->hooks);
1634
0
        for (uint32_t i = 0; i < ZEND_PROPERTY_HOOK_COUNT; i++) {
1635
0
          if (prop->hooks[i]) {
1636
0
            UNSERIALIZE_PTR(prop->hooks[i]);
1637
0
            zend_file_cache_unserialize_op_array(&prop->hooks[i]->op_array, script, buf);
1638
0
          }
1639
0
        }
1640
0
      }
1641
0
      zend_file_cache_unserialize_type(&prop->type, prop->ce, script, buf);
1642
0
    }
1643
0
  }
1644
0
}
1645
1646
static void zend_file_cache_unserialize_class_constant(zval                    *zv,
1647
                                                       zend_persistent_script  *script,
1648
                                                       void                    *buf)
1649
0
{
1650
0
  if (!IS_UNSERIALIZED(Z_PTR_P(zv))) {
1651
0
    zend_class_constant *c;
1652
1653
0
    UNSERIALIZE_PTR(Z_PTR_P(zv));
1654
0
    c = Z_PTR_P(zv);
1655
1656
0
    ZEND_ASSERT(c->ce != NULL);
1657
0
    if (!IS_UNSERIALIZED(c->ce)) {
1658
0
      UNSERIALIZE_PTR(c->ce);
1659
1660
0
      zend_file_cache_unserialize_zval(&c->value, script, buf);
1661
1662
0
      if (c->doc_comment) {
1663
0
        UNSERIALIZE_STR(c->doc_comment);
1664
0
      }
1665
0
      UNSERIALIZE_ATTRIBUTES(c->attributes);
1666
0
      zend_file_cache_unserialize_type(&c->type, c->ce, script, buf);
1667
0
    }
1668
0
  }
1669
0
}
1670
1671
static void zend_file_cache_unserialize_class(zval                    *zv,
1672
                                              zend_persistent_script  *script,
1673
                                              void                    *buf)
1674
0
{
1675
0
  zend_class_entry *ce;
1676
1677
0
  UNSERIALIZE_PTR(Z_PTR_P(zv));
1678
0
  ce = Z_PTR_P(zv);
1679
1680
0
  UNSERIALIZE_STR(ce->name);
1681
0
  if (!(ce->ce_flags & ZEND_ACC_ANON_CLASS)) {
1682
0
    if (!script->corrupted) {
1683
0
      zend_accel_get_class_name_map_ptr(ce->name);
1684
0
    } else {
1685
0
      zend_alloc_ce_cache(ce->name);
1686
0
    }
1687
0
  }
1688
0
  if (ce->parent) {
1689
0
    if (!(ce->ce_flags & ZEND_ACC_LINKED)) {
1690
0
      UNSERIALIZE_STR(ce->parent_name);
1691
0
    } else {
1692
0
      UNSERIALIZE_PTR(ce->parent);
1693
0
    }
1694
0
  }
1695
0
  zend_file_cache_unserialize_hash(&ce->function_table,
1696
0
      script, buf, zend_file_cache_unserialize_func, ZEND_FUNCTION_DTOR);
1697
0
  if (ce->default_properties_table) {
1698
0
    zval *p, *end;
1699
1700
0
    UNSERIALIZE_PTR(ce->default_properties_table);
1701
0
    p = ce->default_properties_table;
1702
0
    end = p + ce->default_properties_count;
1703
0
    while (p < end) {
1704
0
      zend_file_cache_unserialize_zval(p, script, buf);
1705
0
      p++;
1706
0
    }
1707
0
  }
1708
0
  if (ce->default_static_members_table) {
1709
0
    zval *p, *end;
1710
0
    UNSERIALIZE_PTR(ce->default_static_members_table);
1711
0
    p = ce->default_static_members_table;
1712
0
    end = p + ce->default_static_members_count;
1713
0
    while (p < end) {
1714
0
      zend_file_cache_unserialize_zval(p, script, buf);
1715
0
      p++;
1716
0
    }
1717
0
  }
1718
0
  zend_file_cache_unserialize_hash(&ce->constants_table,
1719
0
      script, buf, zend_file_cache_unserialize_class_constant, NULL);
1720
0
  UNSERIALIZE_STR(ce->info.user.filename);
1721
0
  UNSERIALIZE_STR(ce->doc_comment);
1722
0
  UNSERIALIZE_ATTRIBUTES(ce->attributes);
1723
0
  zend_file_cache_unserialize_hash(&ce->properties_info,
1724
0
      script, buf, zend_file_cache_unserialize_prop_info, NULL);
1725
1726
0
  if (ce->properties_info_table) {
1727
0
    uint32_t i;
1728
0
    UNSERIALIZE_PTR(ce->properties_info_table);
1729
1730
0
    for (i = 0; i < ce->default_properties_count; i++) {
1731
0
      UNSERIALIZE_PTR(ce->properties_info_table[i]);
1732
0
    }
1733
0
  }
1734
1735
0
  if (ce->num_interfaces) {
1736
0
    uint32_t i;
1737
1738
0
    ZEND_ASSERT(!(ce->ce_flags & ZEND_ACC_LINKED));
1739
0
    UNSERIALIZE_PTR(ce->interface_names);
1740
1741
0
    for (i = 0; i < ce->num_interfaces; i++) {
1742
0
      UNSERIALIZE_STR(ce->interface_names[i].name);
1743
0
      UNSERIALIZE_STR(ce->interface_names[i].lc_name);
1744
0
    }
1745
0
  }
1746
1747
0
  if (ce->num_traits) {
1748
0
    uint32_t i;
1749
1750
0
    UNSERIALIZE_PTR(ce->trait_names);
1751
1752
0
    for (i = 0; i < ce->num_traits; i++) {
1753
0
      UNSERIALIZE_STR(ce->trait_names[i].name);
1754
0
      UNSERIALIZE_STR(ce->trait_names[i].lc_name);
1755
0
    }
1756
1757
0
    if (ce->trait_aliases) {
1758
0
      zend_trait_alias **p, *q;
1759
1760
0
      UNSERIALIZE_PTR(ce->trait_aliases);
1761
0
      p = ce->trait_aliases;
1762
1763
0
      while (*p) {
1764
0
        UNSERIALIZE_PTR(*p);
1765
0
        q = *p;
1766
1767
0
        if (q->trait_method.method_name) {
1768
0
          UNSERIALIZE_STR(q->trait_method.method_name);
1769
0
        }
1770
0
        if (q->trait_method.class_name) {
1771
0
          UNSERIALIZE_STR(q->trait_method.class_name);
1772
0
        }
1773
1774
0
        if (q->alias) {
1775
0
          UNSERIALIZE_STR(q->alias);
1776
0
        }
1777
0
        p++;
1778
0
      }
1779
0
    }
1780
1781
0
    if (ce->trait_precedences) {
1782
0
      zend_trait_precedence **p, *q;
1783
0
      uint32_t j;
1784
1785
0
      UNSERIALIZE_PTR(ce->trait_precedences);
1786
0
      p = ce->trait_precedences;
1787
1788
0
      while (*p) {
1789
0
        UNSERIALIZE_PTR(*p);
1790
0
        q = *p;
1791
1792
0
        if (q->trait_method.method_name) {
1793
0
          UNSERIALIZE_STR(q->trait_method.method_name);
1794
0
        }
1795
0
        if (q->trait_method.class_name) {
1796
0
          UNSERIALIZE_STR(q->trait_method.class_name);
1797
0
        }
1798
1799
0
        for (j = 0; j < q->num_excludes; j++) {
1800
0
          UNSERIALIZE_STR(q->exclude_class_names[j]);
1801
0
        }
1802
0
        p++;
1803
0
      }
1804
0
    }
1805
0
  }
1806
1807
0
  UNSERIALIZE_PTR(ce->constructor);
1808
0
  UNSERIALIZE_PTR(ce->destructor);
1809
0
  UNSERIALIZE_PTR(ce->clone);
1810
0
  UNSERIALIZE_PTR(ce->__get);
1811
0
  UNSERIALIZE_PTR(ce->__set);
1812
0
  UNSERIALIZE_PTR(ce->__call);
1813
0
  UNSERIALIZE_PTR(ce->__serialize);
1814
0
  UNSERIALIZE_PTR(ce->__unserialize);
1815
0
  UNSERIALIZE_PTR(ce->__isset);
1816
0
  UNSERIALIZE_PTR(ce->__unset);
1817
0
  UNSERIALIZE_PTR(ce->__tostring);
1818
0
  UNSERIALIZE_PTR(ce->__callstatic);
1819
0
  UNSERIALIZE_PTR(ce->__debugInfo);
1820
1821
0
  if (ce->iterator_funcs_ptr) {
1822
0
    UNSERIALIZE_PTR(ce->iterator_funcs_ptr);
1823
0
    UNSERIALIZE_PTR(ce->iterator_funcs_ptr->zf_new_iterator);
1824
0
    UNSERIALIZE_PTR(ce->iterator_funcs_ptr->zf_rewind);
1825
0
    UNSERIALIZE_PTR(ce->iterator_funcs_ptr->zf_valid);
1826
0
    UNSERIALIZE_PTR(ce->iterator_funcs_ptr->zf_key);
1827
0
    UNSERIALIZE_PTR(ce->iterator_funcs_ptr->zf_current);
1828
0
    UNSERIALIZE_PTR(ce->iterator_funcs_ptr->zf_next);
1829
0
  }
1830
0
  if (ce->arrayaccess_funcs_ptr) {
1831
0
    UNSERIALIZE_PTR(ce->arrayaccess_funcs_ptr);
1832
0
    UNSERIALIZE_PTR(ce->arrayaccess_funcs_ptr->zf_offsetget);
1833
0
    UNSERIALIZE_PTR(ce->arrayaccess_funcs_ptr->zf_offsetexists);
1834
0
    UNSERIALIZE_PTR(ce->arrayaccess_funcs_ptr->zf_offsetset);
1835
0
    UNSERIALIZE_PTR(ce->arrayaccess_funcs_ptr->zf_offsetunset);
1836
0
  }
1837
1838
0
  if (!(script->corrupted)) {
1839
0
    ce->ce_flags |= ZEND_ACC_IMMUTABLE;
1840
0
    ce->ce_flags &= ~ZEND_ACC_FILE_CACHED;
1841
0
    ZEND_MAP_PTR_NEW(ce->mutable_data);
1842
0
    if (ce->default_static_members_count) {
1843
0
      ZEND_MAP_PTR_NEW(ce->static_members_table);
1844
0
    }
1845
0
  } else {
1846
0
    ce->ce_flags &= ~ZEND_ACC_IMMUTABLE;
1847
0
    ce->ce_flags |= ZEND_ACC_FILE_CACHED;
1848
0
    ZEND_MAP_PTR_INIT(ce->mutable_data, NULL);
1849
0
    ZEND_MAP_PTR_INIT(ce->static_members_table, NULL);
1850
0
  }
1851
1852
0
  if (ce->get_iterator) {
1853
0
    ZEND_ASSERT(ce->get_iterator == HOOKED_ITERATOR_PLACEHOLDER);
1854
0
    ce->get_iterator = zend_hooked_object_get_iterator;
1855
0
  }
1856
1857
  // Memory addresses of object handlers are not stable. They can change due to ASLR or order of linking dynamic. To
1858
  // avoid pointing to invalid memory we relink default_object_handlers here.
1859
0
  ce->default_object_handlers = ce->ce_flags & ZEND_ACC_ENUM ? &zend_enum_object_handlers : &std_object_handlers;
1860
0
}
1861
1862
static void zend_file_cache_unserialize_warnings(zend_persistent_script *script, void *buf)
1863
0
{
1864
0
  if (script->warnings) {
1865
0
    UNSERIALIZE_PTR(script->warnings);
1866
0
    for (uint32_t i = 0; i < script->num_warnings; i++) {
1867
0
      UNSERIALIZE_PTR(script->warnings[i]);
1868
0
      UNSERIALIZE_STR(script->warnings[i]->filename);
1869
0
      UNSERIALIZE_STR(script->warnings[i]->message);
1870
0
    }
1871
0
  }
1872
0
}
1873
1874
static void zend_file_cache_unserialize_early_bindings(zend_persistent_script *script, void *buf)
1875
0
{
1876
0
  if (script->early_bindings) {
1877
0
    UNSERIALIZE_PTR(script->early_bindings);
1878
0
    for (uint32_t i = 0; i < script->num_early_bindings; i++) {
1879
0
      UNSERIALIZE_STR(script->early_bindings[i].lcname);
1880
0
      UNSERIALIZE_STR(script->early_bindings[i].rtd_key);
1881
0
      UNSERIALIZE_STR(script->early_bindings[i].lc_parent_name);
1882
0
    }
1883
0
  }
1884
0
}
1885
1886
static void zend_file_cache_unserialize(zend_persistent_script  *script,
1887
                                        void                    *buf)
1888
0
{
1889
0
  script->mem = buf;
1890
1891
0
  UNSERIALIZE_STR(script->script.filename);
1892
1893
0
  zend_file_cache_unserialize_hash(&script->script.class_table,
1894
0
      script, buf, zend_file_cache_unserialize_class, ZEND_CLASS_DTOR);
1895
0
  zend_file_cache_unserialize_hash(&script->script.function_table,
1896
0
      script, buf, zend_file_cache_unserialize_func, ZEND_FUNCTION_DTOR);
1897
0
  zend_file_cache_unserialize_op_array(&script->script.main_op_array, script, buf);
1898
0
  zend_file_cache_unserialize_warnings(script, buf);
1899
0
  zend_file_cache_unserialize_early_bindings(script, buf);
1900
0
}
1901
1902
static zend_persistent_script file_cache_validate_success_script;
1903
1904
zend_persistent_script *zend_file_cache_script_load(zend_file_handle *file_handle)
1905
0
{
1906
0
  return zend_file_cache_script_load_ex(file_handle, false);
1907
0
}
1908
1909
zend_persistent_script *zend_file_cache_script_load_ex(zend_file_handle *file_handle, bool validate_only)
1910
0
{
1911
0
  zend_string *full_path = file_handle->opened_path;
1912
0
  int fd;
1913
0
  char *filename;
1914
0
  zend_persistent_script *script;
1915
0
  zend_file_cache_metainfo info;
1916
0
  zend_accel_hash_entry *bucket;
1917
0
  void *mem, *checkpoint, *buf;
1918
0
  bool cache_it = true;
1919
0
  unsigned int actual_checksum;
1920
0
  bool ok;
1921
1922
0
  if (!full_path) {
1923
0
    return NULL;
1924
0
  }
1925
0
  filename = zend_file_cache_get_bin_file_path(full_path);
1926
1927
0
  fd = zend_file_cache_open(filename, O_RDONLY | O_BINARY);
1928
0
  if (fd < 0) {
1929
0
    efree(filename);
1930
0
    return NULL;
1931
0
  }
1932
1933
0
  if (zend_file_cache_flock(fd, LOCK_SH) != 0) {
1934
0
    close(fd);
1935
0
    efree(filename);
1936
0
    return NULL;
1937
0
  }
1938
1939
0
  if (read(fd, &info, sizeof(info)) != sizeof(info)) {
1940
0
    zend_accel_error(ACCEL_LOG_WARNING, "opcache cannot read from file '%s' (info)\n", filename);
1941
0
    zend_file_cache_flock(fd, LOCK_UN);
1942
0
    close(fd);
1943
0
    if (!ZCG(accel_directives).file_cache_read_only) {
1944
0
      zend_file_cache_unlink(filename);
1945
0
    }
1946
0
    efree(filename);
1947
0
    return NULL;
1948
0
  }
1949
1950
  /* verify header */
1951
0
  if (memcmp(info.magic, "OPCACHE", 8) != 0) {
1952
0
    zend_accel_error(ACCEL_LOG_WARNING, "opcache cannot read from file '%s' (wrong header)\n", filename);
1953
0
    zend_file_cache_flock(fd, LOCK_UN);
1954
0
    close(fd);
1955
0
    if (!ZCG(accel_directives).file_cache_read_only) {
1956
0
      zend_file_cache_unlink(filename);
1957
0
    }
1958
0
    efree(filename);
1959
0
    return NULL;
1960
0
  }
1961
0
  if (memcmp(info.system_id, zend_system_id, 32) != 0) {
1962
0
    zend_accel_error(ACCEL_LOG_WARNING, "opcache cannot read from file '%s' (wrong \"system_id\")\n", filename);
1963
0
    zend_file_cache_flock(fd, LOCK_UN);
1964
0
    close(fd);
1965
0
    if (!ZCG(accel_directives).file_cache_read_only) {
1966
0
      zend_file_cache_unlink(filename);
1967
0
    }
1968
0
    efree(filename);
1969
0
    return NULL;
1970
0
  }
1971
1972
  /* verify timestamp */
1973
0
  if (ZCG(accel_directives).validate_timestamps &&
1974
0
      zend_get_file_handle_timestamp(file_handle, NULL) != info.timestamp) {
1975
0
    if (zend_file_cache_flock(fd, LOCK_UN) != 0) {
1976
0
      zend_accel_error(ACCEL_LOG_WARNING, "opcache cannot unlock file '%s'\n", filename);
1977
0
    }
1978
0
    close(fd);
1979
0
    if (!ZCG(accel_directives).file_cache_read_only) {
1980
0
      zend_file_cache_unlink(filename);
1981
0
    }
1982
0
    efree(filename);
1983
0
    return NULL;
1984
0
  }
1985
1986
  /* return here if validating */
1987
0
  if (validate_only) {
1988
0
    if (zend_file_cache_flock(fd, LOCK_UN) != 0) {
1989
0
      zend_accel_error(ACCEL_LOG_WARNING, "opcache cannot unlock file '%s'\n", filename);
1990
0
    }
1991
0
    close(fd);
1992
0
    efree(filename);
1993
0
    return &file_cache_validate_success_script;
1994
0
  }
1995
1996
0
  checkpoint = zend_arena_checkpoint(CG(arena));
1997
0
#if defined(__AVX__) || defined(__SSE2__)
1998
  /* Align to 64-byte boundary */
1999
0
  mem = zend_arena_alloc(&CG(arena), info.mem_size + info.str_size + 64);
2000
0
  mem = (void*)(((uintptr_t)mem + 63L) & ~63L);
2001
#else
2002
  mem = zend_arena_alloc(&CG(arena), info.mem_size + info.str_size);
2003
#endif
2004
2005
0
  if (read(fd, mem, info.mem_size + info.str_size) != (ssize_t)(info.mem_size + info.str_size)) {
2006
0
    zend_accel_error(ACCEL_LOG_WARNING, "opcache cannot read from file '%s' (mem)\n", filename);
2007
0
    zend_file_cache_flock(fd, LOCK_UN);
2008
0
    close(fd);
2009
0
    if (!ZCG(accel_directives).file_cache_read_only) {
2010
0
      zend_file_cache_unlink(filename);
2011
0
    }
2012
0
    zend_arena_release(&CG(arena), checkpoint);
2013
0
    efree(filename);
2014
0
    return NULL;
2015
0
  }
2016
0
  if (zend_file_cache_flock(fd, LOCK_UN) != 0) {
2017
0
    zend_accel_error(ACCEL_LOG_WARNING, "opcache cannot unlock file '%s'\n", filename);
2018
0
  }
2019
0
  close(fd);
2020
2021
  /* verify checksum */
2022
0
  if (ZCG(accel_directives).file_cache_consistency_checks &&
2023
0
      (actual_checksum = zend_adler32(ADLER32_INIT, mem, info.mem_size + info.str_size)) != info.checksum) {
2024
0
    zend_accel_error(ACCEL_LOG_WARNING, "corrupted file '%s' excepted checksum: 0x%08x actual checksum: 0x%08x\n", filename, info.checksum, actual_checksum);
2025
0
    if (!ZCG(accel_directives).file_cache_read_only) {
2026
0
      zend_file_cache_unlink(filename);
2027
0
    }
2028
0
    zend_arena_release(&CG(arena), checkpoint);
2029
0
    efree(filename);
2030
0
    return NULL;
2031
0
  }
2032
2033
0
  if (!file_cache_only &&
2034
0
      !ZCSG(restart_in_progress) &&
2035
0
      !ZCSG(restart_pending) &&
2036
0
    !ZSMMG(memory_exhausted) &&
2037
0
      accelerator_shm_read_lock() == SUCCESS) {
2038
    /* exclusive lock */
2039
0
    zend_shared_alloc_lock();
2040
2041
    /* Check if we still need to put the file into the cache (may be it was
2042
     * already stored by another process. This final check is done under
2043
     * exclusive lock) */
2044
0
    bucket = zend_accel_hash_find_entry(&ZCSG(hash), full_path);
2045
0
    if (bucket) {
2046
0
      script = (zend_persistent_script *)bucket->data;
2047
0
      if (!script->corrupted) {
2048
0
        zend_shared_alloc_unlock();
2049
0
        zend_arena_release(&CG(arena), checkpoint);
2050
0
        efree(filename);
2051
0
        return script;
2052
0
      }
2053
0
    }
2054
2055
0
    if (zend_accel_hash_is_full(&ZCSG(hash))) {
2056
0
      zend_accel_error(ACCEL_LOG_DEBUG, "No more entries in hash table!");
2057
0
      ZSMMG(memory_exhausted) = 1;
2058
0
      zend_accel_schedule_restart_if_necessary(ACCEL_RESTART_HASH);
2059
0
      zend_shared_alloc_unlock();
2060
0
      goto use_process_mem;
2061
0
    }
2062
2063
0
    buf = zend_shared_alloc_aligned(info.mem_size);
2064
2065
0
    if (!buf) {
2066
0
      zend_accel_schedule_restart_if_necessary(ACCEL_RESTART_OOM);
2067
0
      zend_shared_alloc_unlock();
2068
0
      goto use_process_mem;
2069
0
    }
2070
0
    memcpy(buf, mem, info.mem_size);
2071
0
    zend_map_ptr_extend(ZCSG(map_ptr_last));
2072
0
  } else {
2073
0
use_process_mem:
2074
0
    buf = mem;
2075
0
    cache_it = false;
2076
0
  }
2077
2078
0
  ZCG(mem) = ((char*)mem + info.mem_size);
2079
0
  script = (zend_persistent_script*)((char*)buf + info.script_offset);
2080
0
  script->corrupted = !cache_it; /* used to check if script restored to SHM or process memory */
2081
2082
0
  ok = true;
2083
0
  zend_try {
2084
0
    zend_file_cache_unserialize(script, buf);
2085
0
  } zend_catch {
2086
0
    ok = false;
2087
0
  } zend_end_try();
2088
0
  if (!ok) {
2089
0
    if (cache_it) {
2090
0
      zend_shared_alloc_unlock();
2091
0
      goto use_process_mem;
2092
0
    } else {
2093
0
      zend_arena_release(&CG(arena), checkpoint);
2094
0
      efree(filename);
2095
0
      return NULL;
2096
0
    }
2097
0
  }
2098
2099
0
  script->corrupted = false;
2100
2101
0
  if (cache_it) {
2102
0
    ZCSG(map_ptr_last) = CG(map_ptr_last);
2103
0
    script->dynamic_members.last_used = ZCG(request_time);
2104
2105
0
    zend_accel_hash_update(&ZCSG(hash), script->script.filename, 0, script);
2106
2107
0
    zend_shared_alloc_unlock();
2108
0
    zend_accel_error(ACCEL_LOG_INFO, "File cached script loaded into memory '%s'", ZSTR_VAL(script->script.filename));
2109
2110
0
    zend_arena_release(&CG(arena), checkpoint);
2111
0
  }
2112
0
  efree(filename);
2113
2114
0
  return script;
2115
0
}
2116
2117
void zend_file_cache_invalidate(zend_string *full_path)
2118
0
{
2119
0
  if (ZCG(accel_directives).file_cache_read_only) {
2120
0
    return;
2121
0
  }
2122
2123
0
  char *filename;
2124
2125
0
  filename = zend_file_cache_get_bin_file_path(full_path);
2126
2127
0
  zend_file_cache_unlink(filename);
2128
  efree(filename);
2129
0
}