Coverage Report

Created: 2026-01-18 06:46

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 (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: Dmitry Stogov <dmitry@php.net>                              |
16
   +----------------------------------------------------------------------+
17
*/
18
19
#include "zend.h"
20
#include "zend_virtual_cwd.h"
21
#include "zend_compile.h"
22
#include "zend_vm.h"
23
#include "zend_interfaces.h"
24
#include "zend_attributes.h"
25
#include "zend_system_id.h"
26
#include "zend_enum.h"
27
28
#include "php.h"
29
#ifdef ZEND_WIN32
30
#include "ext/standard/md5.h"
31
#endif
32
#include "ext/standard/php_filestat.h"
33
34
#include "ZendAccelerator.h"
35
#include "zend_file_cache.h"
36
#include "zend_shared_alloc.h"
37
#include "zend_accelerator_util_funcs.h"
38
#include "zend_accelerator_hash.h"
39
40
#ifdef HAVE_JIT
41
#include "jit/zend_jit.h"
42
#endif
43
44
#include <sys/types.h>
45
#include <sys/stat.h>
46
#include <fcntl.h>
47
48
#ifdef HAVE_UNISTD_H
49
#include <unistd.h>
50
#endif
51
52
#ifdef HAVE_SYS_UIO_H
53
# include <sys/uio.h>
54
#endif
55
56
#ifdef HAVE_SYS_FILE_H
57
# include <sys/file.h>
58
#endif
59
60
#if __has_feature(memory_sanitizer)
61
# include <sanitizer/msan_interface.h>
62
#endif
63
64
#ifndef ZEND_WIN32
65
0
#define zend_file_cache_unlink unlink
66
0
#define zend_file_cache_open open
67
#else
68
#define zend_file_cache_unlink php_win32_ioutil_unlink
69
#define zend_file_cache_open php_win32_ioutil_open
70
#endif
71
72
#ifdef ZEND_WIN32
73
# define LOCK_SH 0
74
# define LOCK_EX 1
75
# define LOCK_UN 2
76
static int zend_file_cache_flock(int fd, int op)
77
{
78
  OVERLAPPED offset = {0, 0, {{0}}, NULL};
79
  if (op == LOCK_EX) {
80
    if (LockFileEx((HANDLE)_get_osfhandle(fd),
81
                   LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 0, &offset) == TRUE) {
82
      return 0;
83
    }
84
  } else if (op == LOCK_SH) {
85
    if (LockFileEx((HANDLE)_get_osfhandle(fd),
86
                   0, 0, 1, 0, &offset) == TRUE) {
87
      return 0;
88
    }
89
  } else if (op == LOCK_UN) {
90
    if (UnlockFileEx((HANDLE)_get_osfhandle(fd),
91
                     0, 1, 0, &offset) == TRUE) {
92
      return 0;
93
    }
94
  }
95
  return -1;
96
}
97
#elif defined(HAVE_FLOCK)
98
0
# define zend_file_cache_flock flock
99
#else
100
# define LOCK_SH 0
101
# define LOCK_EX 1
102
# define LOCK_UN 2
103
static int zend_file_cache_flock(int fd, int type)
104
{
105
  return 0;
106
}
107
#endif
108
109
#ifndef O_BINARY
110
0
#  define O_BINARY 0
111
#endif
112
113
0
#define SUFFIX ".bin"
114
115
#define IS_SERIALIZED_INTERNED(ptr) \
116
0
  ((size_t)(ptr) & Z_UL(1))
117
118
/* Allowing == on the upper bound accounts for a potential empty allocation at the end of the
119
 * memory region. This can also happen for a return-type-only arg_info, where &arg_info[1] is
120
 * stored, which may point to the end of the region. */
121
#define IS_SERIALIZED(ptr) \
122
0
  ((char*)(ptr) <= (char*)script->size)
123
#define IS_UNSERIALIZED(ptr) \
124
0
  (((char*)(ptr) >= (char*)script->mem && (char*)(ptr) <= (char*)script->mem + script->size) || \
125
0
   IS_ACCEL_INTERNED(ptr))
126
0
#define SERIALIZE_PTR(ptr) do { \
127
0
    if (ptr) { \
128
0
      ZEND_ASSERT(IS_UNSERIALIZED(ptr)); \
129
0
      (ptr) = (void*)((char*)(ptr) - (char*)script->mem); \
130
0
    } \
131
0
  } while (0)
132
0
#define UNSERIALIZE_PTR(ptr) do { \
133
0
    if (ptr) { \
134
0
      ZEND_ASSERT(IS_SERIALIZED(ptr)); \
135
0
      (ptr) = (void*)((char*)buf + (size_t)(ptr)); \
136
0
    } \
137
0
  } while (0)
138
139
0
#define SERIALIZE_STR(ptr) do { \
140
0
    if (ptr) { \
141
0
      if (IS_ACCEL_INTERNED(ptr)) { \
142
0
        (ptr) = zend_file_cache_serialize_interned((zend_string*)(ptr), info); \
143
0
      } else { \
144
0
        ZEND_ASSERT(IS_UNSERIALIZED(ptr)); \
145
0
        (ptr) = (void*)((char*)(ptr) - (char*)script->mem); \
146
0
      } \
147
0
    } \
148
0
  } while (0)
149
0
#define UNSERIALIZE_STR(ptr) do { \
150
0
    if (ptr) { \
151
0
      if (IS_SERIALIZED_INTERNED(ptr)) { \
152
0
        (ptr) = (void*)zend_file_cache_unserialize_interned((zend_string*)(ptr), !script->corrupted); \
153
0
      } else { \
154
0
        ZEND_ASSERT(IS_SERIALIZED(ptr)); \
155
0
        (ptr) = (void*)((char*)buf + (size_t)(ptr)); \
156
0
        /* script->corrupted shows if the script in SHM or not */ \
157
0
        if (EXPECTED(!script->corrupted)) { \
158
0
          GC_ADD_FLAGS(ptr, IS_STR_INTERNED | IS_STR_PERMANENT); \
159
0
        } else { \
160
0
          GC_ADD_FLAGS(ptr, IS_STR_INTERNED); \
161
0
          GC_DEL_FLAGS(ptr, IS_STR_PERMANENT); \
162
0
        } \
163
0
        GC_DEL_FLAGS(ptr, IS_STR_CLASS_NAME_MAP_PTR); \
164
0
      } \
165
0
    } \
166
0
  } while (0)
167
168
0
#define SERIALIZE_ATTRIBUTES(attributes) do { \
169
0
  if ((attributes) && !IS_SERIALIZED(attributes)) { \
170
0
    HashTable *ht; \
171
0
    SERIALIZE_PTR(attributes); \
172
0
    ht = (attributes); \
173
0
    UNSERIALIZE_PTR(ht); \
174
0
    zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_attribute); \
175
0
  } \
176
0
} while (0)
177
178
0
#define UNSERIALIZE_ATTRIBUTES(attributes) do { \
179
0
  if ((attributes) && !IS_UNSERIALIZED(attributes)) { \
180
0
    HashTable *ht; \
181
0
    UNSERIALIZE_PTR(attributes); \
182
0
    ht = (attributes); \
183
0
    zend_file_cache_unserialize_hash(ht, script, buf, zend_file_cache_unserialize_attribute, NULL); \
184
0
  } \
185
0
} while (0)
186
187
0
#define HOOKED_ITERATOR_PLACEHOLDER ((void*)1)
188
189
static const uint32_t uninitialized_bucket[-HT_MIN_MASK] =
190
  {HT_INVALID_IDX, HT_INVALID_IDX};
191
192
typedef struct _zend_file_cache_metainfo {
193
  char         magic[8];
194
  char         system_id[32];
195
  size_t       mem_size;
196
  size_t       str_size;
197
  size_t       script_offset;
198
  accel_time_t timestamp;
199
  uint32_t     checksum;
200
} zend_file_cache_metainfo;
201
202
static int zend_file_cache_mkdir(char *filename, size_t start)
203
0
{
204
0
  char *s = filename + start;
205
206
0
  while (*s) {
207
0
    if (IS_SLASH(*s)) {
208
0
      char old = *s;
209
0
      *s = '\000';
210
0
#ifndef ZEND_WIN32
211
0
      if (mkdir(filename, S_IRWXU) < 0 && errno != EEXIST) {
212
#else
213
      if (php_win32_ioutil_mkdir(filename, 0700) < 0 && errno != EEXIST) {
214
#endif
215
0
        *s = old;
216
0
        return FAILURE;
217
0
      }
218
0
      *s = old;
219
0
    }
220
0
    s++;
221
0
  }
222
0
  return SUCCESS;
223
0
}
224
225
typedef void (*serialize_callback_t)(zval                     *zv,
226
                                     zend_persistent_script   *script,
227
                                     zend_file_cache_metainfo *info,
228
                                     void                     *buf);
229
230
typedef void (*unserialize_callback_t)(zval                    *zv,
231
                                       zend_persistent_script  *script,
232
                                       void                    *buf);
233
234
static void zend_file_cache_serialize_zval(zval                     *zv,
235
                                           zend_persistent_script   *script,
236
                                           zend_file_cache_metainfo *info,
237
                                           void                     *buf);
238
static void zend_file_cache_unserialize_zval(zval                    *zv,
239
                                             zend_persistent_script  *script,
240
                                             void                    *buf);
241
242
static void zend_file_cache_serialize_func(zval                     *zv,
243
                                           zend_persistent_script   *script,
244
                                           zend_file_cache_metainfo *info,
245
                                           void                     *buf);
246
247
static void zend_file_cache_unserialize_func(zval                    *zv,
248
                                             zend_persistent_script  *script,
249
                                             void                    *buf);
250
251
static void zend_file_cache_serialize_attribute(zval                     *zv,
252
                                                zend_persistent_script   *script,
253
                                                zend_file_cache_metainfo *info,
254
                                                void                     *buf);
255
256
static void zend_file_cache_unserialize_attribute(zval *zv, zend_persistent_script *script, void *buf);
257
258
static void *zend_file_cache_serialize_interned(zend_string              *str,
259
                                                zend_file_cache_metainfo *info)
260
0
{
261
0
  size_t len;
262
0
  void *ret;
263
264
  /* check if the same interned string was already stored */
265
0
  ret = zend_shared_alloc_get_xlat_entry(str);
266
0
  if (ret) {
267
0
    return ret;
268
0
  }
269
270
0
  len = ZEND_MM_ALIGNED_SIZE(_ZSTR_STRUCT_SIZE(ZSTR_LEN(str)));
271
0
  ret = (void*)(info->str_size | Z_UL(1));
272
0
  zend_shared_alloc_register_xlat_entry(str, ret);
273
274
0
  zend_string *s = (zend_string*)ZCG(mem);
275
0
  if (info->str_size + len > ZSTR_LEN(s)) {
276
0
    size_t new_len = info->str_size + len;
277
0
    s = zend_string_realloc(
278
0
      s,
279
0
      ((_ZSTR_HEADER_SIZE + 1 + new_len + 4095) & ~0xfff) - (_ZSTR_HEADER_SIZE + 1),
280
0
      0);
281
0
    ZCG(mem) = (void*)s;
282
0
  }
283
284
0
  zend_string *new_str = (zend_string *) (ZSTR_VAL(s) + info->str_size);
285
0
  memcpy(new_str, str, len);
286
0
  GC_ADD_FLAGS(new_str, IS_STR_INTERNED);
287
0
  GC_DEL_FLAGS(new_str, IS_STR_PERMANENT|IS_STR_CLASS_NAME_MAP_PTR);
288
0
  info->str_size += len;
289
0
  return ret;
290
0
}
291
292
static void *zend_file_cache_unserialize_interned(zend_string *str, bool in_shm)
293
0
{
294
0
  str = (zend_string*)((char*)ZCG(mem) + ((size_t)(str) & ~Z_UL(1)));
295
0
  if (!in_shm) {
296
0
    return str;
297
0
  }
298
299
0
  zend_string *ret = accel_new_interned_string(str);
300
0
  if (ret == str) {
301
    /* We have to create new SHM allocated string */
302
0
    size_t size = _ZSTR_STRUCT_SIZE(ZSTR_LEN(str));
303
0
    ret = zend_shared_alloc(size);
304
0
    if (!ret) {
305
0
      zend_accel_schedule_restart_if_necessary(ACCEL_RESTART_OOM);
306
0
      LONGJMP(*EG(bailout), FAILURE);
307
0
    }
308
0
    memcpy(ret, str, size);
309
    /* String wasn't interned but we will use it as interned anyway */
310
0
    GC_SET_REFCOUNT(ret, 1);
311
0
    GC_TYPE_INFO(ret) = GC_STRING | ((IS_STR_INTERNED | IS_STR_PERSISTENT | IS_STR_PERMANENT) << GC_FLAGS_SHIFT);
312
0
  }
313
0
  return ret;
314
0
}
315
316
static void zend_file_cache_serialize_hash(HashTable                *ht,
317
                                           zend_persistent_script   *script,
318
                                           zend_file_cache_metainfo *info,
319
                                           void                     *buf,
320
                                           serialize_callback_t      func)
321
0
{
322
0
  if (HT_FLAGS(ht) & HASH_FLAG_UNINITIALIZED) {
323
0
    ht->arData = NULL;
324
0
    return;
325
0
  }
326
0
  if (IS_SERIALIZED(ht->arData)) {
327
0
    return;
328
0
  }
329
0
  if (HT_IS_PACKED(ht)) {
330
0
    zval *p, *end;
331
332
0
    SERIALIZE_PTR(ht->arPacked);
333
0
    p = ht->arPacked;
334
0
    UNSERIALIZE_PTR(p);
335
0
    end = p + ht->nNumUsed;
336
0
    while (p < end) {
337
0
      if (Z_TYPE_P(p) != IS_UNDEF) {
338
0
        func(p, script, info, buf);
339
0
      }
340
0
      p++;
341
0
    }
342
0
  } else {
343
0
    Bucket *p, *end;
344
345
0
    SERIALIZE_PTR(ht->arData);
346
0
    p = ht->arData;
347
0
    UNSERIALIZE_PTR(p);
348
0
    end = p + ht->nNumUsed;
349
0
    while (p < end) {
350
0
      if (Z_TYPE(p->val) != IS_UNDEF) {
351
0
        SERIALIZE_STR(p->key);
352
0
        func(&p->val, script, info, buf);
353
0
      }
354
0
      p++;
355
0
    }
356
0
  }
357
0
}
358
359
static void zend_file_cache_serialize_ast(zend_ast                 *ast,
360
                                          zend_persistent_script   *script,
361
                                          zend_file_cache_metainfo *info,
362
                                          void                     *buf)
363
0
{
364
0
  uint32_t i;
365
0
  zend_ast *tmp;
366
367
0
  if (ast->kind == ZEND_AST_ZVAL || ast->kind == ZEND_AST_CONSTANT) {
368
0
    zend_file_cache_serialize_zval(&((zend_ast_zval*)ast)->val, script, info, buf);
369
0
  } else if (zend_ast_is_list(ast)) {
370
0
    zend_ast_list *list = zend_ast_get_list(ast);
371
0
    for (i = 0; i < list->children; i++) {
372
0
      if (list->child[i] && !IS_SERIALIZED(list->child[i])) {
373
0
        SERIALIZE_PTR(list->child[i]);
374
0
        tmp = list->child[i];
375
0
        UNSERIALIZE_PTR(tmp);
376
0
        zend_file_cache_serialize_ast(tmp, script, info, buf);
377
0
      }
378
0
    }
379
0
  } else if (ast->kind == ZEND_AST_OP_ARRAY) {
380
0
    zval z;
381
0
    ZVAL_PTR(&z, zend_ast_get_op_array(ast)->op_array);
382
0
    zend_file_cache_serialize_func(&z, script, info, buf);
383
0
    zend_ast_get_op_array(ast)->op_array = Z_PTR(z);
384
0
  } else if (ast->kind == ZEND_AST_CALLABLE_CONVERT) {
385
0
    zend_ast_fcc *fcc = (zend_ast_fcc*)ast;
386
0
    ZEND_MAP_PTR_INIT(fcc->fptr, NULL);
387
0
    if (!IS_SERIALIZED(fcc->args)) {
388
0
      SERIALIZE_PTR(fcc->args);
389
0
      tmp = fcc->args;
390
0
      UNSERIALIZE_PTR(tmp);
391
0
      zend_file_cache_serialize_ast(tmp, script, info, buf);
392
0
    }
393
0
  } else if (zend_ast_is_decl(ast)) {
394
    /* Not implemented. */
395
0
    ZEND_UNREACHABLE();
396
0
  } else {
397
0
    uint32_t children = zend_ast_get_num_children(ast);
398
0
    for (i = 0; i < children; i++) {
399
0
      if (ast->child[i] && !IS_SERIALIZED(ast->child[i])) {
400
0
        SERIALIZE_PTR(ast->child[i]);
401
0
        tmp = ast->child[i];
402
0
        UNSERIALIZE_PTR(tmp);
403
0
        zend_file_cache_serialize_ast(tmp, script, info, buf);
404
0
      }
405
0
    }
406
0
  }
407
0
}
408
409
static void zend_file_cache_serialize_zval(zval                     *zv,
410
                                           zend_persistent_script   *script,
411
                                           zend_file_cache_metainfo *info,
412
                                           void                     *buf)
413
0
{
414
0
  switch (Z_TYPE_P(zv)) {
415
0
    case IS_STRING:
416
0
      if (!IS_SERIALIZED(Z_STR_P(zv))) {
417
0
        SERIALIZE_STR(Z_STR_P(zv));
418
0
      }
419
0
      break;
420
0
    case IS_ARRAY:
421
0
      if (!IS_SERIALIZED(Z_ARR_P(zv))) {
422
0
        HashTable *ht;
423
424
0
        SERIALIZE_PTR(Z_ARR_P(zv));
425
0
        ht = Z_ARR_P(zv);
426
0
        UNSERIALIZE_PTR(ht);
427
0
        zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_zval);
428
0
      }
429
0
      break;
430
0
    case IS_CONSTANT_AST:
431
0
      if (!IS_SERIALIZED(Z_AST_P(zv))) {
432
0
        zend_ast_ref *ast;
433
434
0
        SERIALIZE_PTR(Z_AST_P(zv));
435
0
        ast = Z_AST_P(zv);
436
0
        UNSERIALIZE_PTR(ast);
437
0
        zend_file_cache_serialize_ast(GC_AST(ast), script, info, buf);
438
0
      }
439
0
      break;
440
0
    case IS_INDIRECT:
441
      /* Used by static properties. */
442
0
      SERIALIZE_PTR(Z_INDIRECT_P(zv));
443
0
      break;
444
0
    case IS_PTR:
445
      /* Used by attributes on constants, will be handled separately */
446
0
      break;
447
0
    default:
448
0
      ZEND_ASSERT(Z_TYPE_P(zv) < IS_STRING);
449
0
      break;
450
0
  }
451
0
}
452
453
static void zend_file_cache_serialize_attribute(zval                     *zv,
454
                                                zend_persistent_script   *script,
455
                                                zend_file_cache_metainfo *info,
456
                                                void                     *buf)
457
0
{
458
0
  zend_attribute *attr = Z_PTR_P(zv);
459
0
  uint32_t i;
460
461
0
  SERIALIZE_PTR(Z_PTR_P(zv));
462
0
  attr = Z_PTR_P(zv);
463
0
  UNSERIALIZE_PTR(attr);
464
465
0
  SERIALIZE_STR(attr->name);
466
0
  SERIALIZE_STR(attr->lcname);
467
0
  SERIALIZE_STR(attr->validation_error);
468
469
0
  for (i = 0; i < attr->argc; i++) {
470
0
    SERIALIZE_STR(attr->args[i].name);
471
0
    zend_file_cache_serialize_zval(&attr->args[i].value, script, info, buf);
472
0
  }
473
0
}
474
475
static void zend_file_cache_serialize_type(
476
    zend_type *type, zend_persistent_script *script, zend_file_cache_metainfo *info, void *buf)
477
0
{
478
0
  if (ZEND_TYPE_HAS_LIST(*type)) {
479
0
    zend_type_list *list = ZEND_TYPE_LIST(*type);
480
0
    SERIALIZE_PTR(list);
481
0
    ZEND_TYPE_SET_PTR(*type, list);
482
0
    UNSERIALIZE_PTR(list);
483
484
0
    zend_type *list_type;
485
0
    ZEND_TYPE_LIST_FOREACH_MUTABLE(list, list_type) {
486
0
      zend_file_cache_serialize_type(list_type, script, info, buf);
487
0
    } ZEND_TYPE_LIST_FOREACH_END();
488
0
  } else if (ZEND_TYPE_HAS_NAME(*type)) {
489
0
    zend_string *type_name = ZEND_TYPE_NAME(*type);
490
0
    SERIALIZE_STR(type_name);
491
0
    ZEND_TYPE_SET_PTR(*type, type_name);
492
0
  }
493
0
}
494
495
static void zend_file_cache_serialize_op_array(zend_op_array            *op_array,
496
                                               zend_persistent_script   *script,
497
                                               zend_file_cache_metainfo *info,
498
                                               void                     *buf)
499
0
{
500
0
  ZEND_MAP_PTR_INIT(op_array->static_variables_ptr, NULL);
501
0
  ZEND_MAP_PTR_INIT(op_array->run_time_cache, NULL);
502
503
  /* Check whether this op_array has already been serialized. */
504
0
  if (IS_SERIALIZED(op_array->opcodes)) {
505
0
    ZEND_ASSERT(op_array->scope && "Only method op_arrays should be shared");
506
0
    return;
507
0
  }
508
509
0
  if (op_array->scope) {
510
0
    if (UNEXPECTED(zend_shared_alloc_get_xlat_entry(op_array->opcodes))) {
511
0
      op_array->refcount = (uint32_t*)(intptr_t)-1;
512
0
      SERIALIZE_PTR(op_array->static_variables);
513
0
      SERIALIZE_PTR(op_array->literals);
514
0
      SERIALIZE_PTR(op_array->opcodes);
515
0
      SERIALIZE_PTR(op_array->arg_info);
516
0
      SERIALIZE_PTR(op_array->vars);
517
0
      SERIALIZE_STR(op_array->function_name);
518
0
      SERIALIZE_STR(op_array->filename);
519
0
      SERIALIZE_PTR(op_array->live_range);
520
0
      SERIALIZE_PTR(op_array->scope);
521
0
      SERIALIZE_STR(op_array->doc_comment);
522
0
      SERIALIZE_ATTRIBUTES(op_array->attributes);
523
0
      SERIALIZE_PTR(op_array->try_catch_array);
524
0
      SERIALIZE_PTR(op_array->prototype);
525
0
      SERIALIZE_PTR(op_array->prop_info);
526
0
      return;
527
0
    }
528
0
    zend_shared_alloc_register_xlat_entry(op_array->opcodes, op_array->opcodes);
529
0
  }
530
531
0
  if (op_array->static_variables) {
532
0
    HashTable *ht;
533
534
0
    SERIALIZE_PTR(op_array->static_variables);
535
0
    ht = op_array->static_variables;
536
0
    UNSERIALIZE_PTR(ht);
537
0
    zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_zval);
538
0
  }
539
540
0
  if (op_array->literals) {
541
0
    zval *p, *end;
542
543
0
    SERIALIZE_PTR(op_array->literals);
544
0
    p = op_array->literals;
545
0
    UNSERIALIZE_PTR(p);
546
0
    end = p + op_array->last_literal;
547
0
    while (p < end) {
548
0
      zend_file_cache_serialize_zval(p, script, info, buf);
549
0
      p++;
550
0
    }
551
0
  }
552
553
0
  {
554
0
    zend_op *opline, *end;
555
556
0
#if !ZEND_USE_ABS_CONST_ADDR
557
0
    zval *literals = op_array->literals;
558
0
    UNSERIALIZE_PTR(literals);
559
0
#endif
560
561
0
    SERIALIZE_PTR(op_array->opcodes);
562
0
    opline = op_array->opcodes;
563
0
    UNSERIALIZE_PTR(opline);
564
0
    end = opline + op_array->last;
565
0
    while (opline < end) {
566
0
      if (opline->opcode == ZEND_OP_DATA
567
0
        && (opline-1)->opcode == ZEND_DECLARE_ATTRIBUTED_CONST
568
0
      ) {
569
0
        zval *literal = RT_CONSTANT(opline, opline->op1);
570
0
        SERIALIZE_ATTRIBUTES(Z_PTR_P(literal));
571
0
      }
572
573
#if ZEND_USE_ABS_CONST_ADDR
574
      if (opline->op1_type == IS_CONST) {
575
        SERIALIZE_PTR(opline->op1.zv);
576
      }
577
      if (opline->op2_type == IS_CONST) {
578
        SERIALIZE_PTR(opline->op2.zv);
579
580
        /* See GH-17733. Reset Z_EXTRA_P(op2) of ZEND_INIT_FCALL, which
581
         * is an offset into the global function table, to avoid calling
582
         * incorrect functions when environment changes. This, and the
583
         * equivalent code below, can be removed once proper system ID
584
         * validation is implemented. */
585
        if (opline->opcode == ZEND_INIT_FCALL) {
586
          zval *op2 = opline->op2.zv;
587
          UNSERIALIZE_PTR(op2);
588
          Z_EXTRA_P(op2) = 0;
589
          ZEND_VM_SET_OPCODE_HANDLER(opline);
590
        }
591
      }
592
#else
593
0
      if (opline->op1_type == IS_CONST) {
594
0
        opline->op1.constant = RT_CONSTANT(opline, opline->op1) - literals;
595
0
      }
596
0
      if (opline->op2_type == IS_CONST) {
597
0
        zval *op2 = RT_CONSTANT(opline, opline->op2);
598
0
        opline->op2.constant = op2 - literals;
599
600
        /* See GH-17733 and comment above. */
601
0
        if (opline->opcode == ZEND_INIT_FCALL) {
602
0
          Z_EXTRA_P(op2) = 0;
603
0
          ZEND_VM_SET_OPCODE_HANDLER(opline);
604
0
        }
605
0
      }
606
0
#endif
607
#if ZEND_USE_ABS_JMP_ADDR
608
      switch (opline->opcode) {
609
        case ZEND_JMP:
610
        case ZEND_FAST_CALL:
611
          SERIALIZE_PTR(opline->op1.jmp_addr);
612
          break;
613
        case ZEND_JMPZ:
614
        case ZEND_JMPNZ:
615
        case ZEND_JMPZ_EX:
616
        case ZEND_JMPNZ_EX:
617
        case ZEND_JMP_SET:
618
        case ZEND_COALESCE:
619
        case ZEND_FE_RESET_R:
620
        case ZEND_FE_RESET_RW:
621
        case ZEND_ASSERT_CHECK:
622
        case ZEND_JMP_NULL:
623
        case ZEND_BIND_INIT_STATIC_OR_JMP:
624
        case ZEND_JMP_FRAMELESS:
625
          SERIALIZE_PTR(opline->op2.jmp_addr);
626
          break;
627
        case ZEND_CATCH:
628
          if (!(opline->extended_value & ZEND_LAST_CATCH)) {
629
            SERIALIZE_PTR(opline->op2.jmp_addr);
630
          }
631
          break;
632
        case ZEND_FE_FETCH_R:
633
        case ZEND_FE_FETCH_RW:
634
        case ZEND_SWITCH_LONG:
635
        case ZEND_SWITCH_STRING:
636
        case ZEND_MATCH:
637
          /* relative extended_value don't have to be changed */
638
          break;
639
      }
640
#endif
641
0
      zend_serialize_opcode_handler(opline);
642
0
      opline++;
643
0
    }
644
645
0
    if (op_array->arg_info) {
646
0
      zend_arg_info *p, *end;
647
0
      SERIALIZE_PTR(op_array->arg_info);
648
0
      p = op_array->arg_info;
649
0
      UNSERIALIZE_PTR(p);
650
0
      end = p + op_array->num_args;
651
0
      if (op_array->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
652
0
        p--;
653
0
      }
654
0
      if (op_array->fn_flags & ZEND_ACC_VARIADIC) {
655
0
        end++;
656
0
      }
657
0
      while (p < end) {
658
0
        if (!IS_SERIALIZED(p->name)) {
659
0
          SERIALIZE_STR(p->name);
660
0
        }
661
0
        zend_file_cache_serialize_type(&p->type, script, info, buf);
662
0
        p++;
663
0
      }
664
0
    }
665
666
0
    if (op_array->vars) {
667
0
      zend_string **p, **end;
668
669
0
      SERIALIZE_PTR(op_array->vars);
670
0
      p = op_array->vars;
671
0
      UNSERIALIZE_PTR(p);
672
0
      end = p + op_array->last_var;
673
0
      while (p < end) {
674
0
        if (!IS_SERIALIZED(*p)) {
675
0
          SERIALIZE_STR(*p);
676
0
        }
677
0
        p++;
678
0
      }
679
0
    }
680
681
0
    if (op_array->num_dynamic_func_defs) {
682
0
      zend_op_array **defs;
683
0
      SERIALIZE_PTR(op_array->dynamic_func_defs);
684
0
      defs = op_array->dynamic_func_defs;
685
0
      UNSERIALIZE_PTR(defs);
686
0
      for (uint32_t i = 0; i < op_array->num_dynamic_func_defs; i++) {
687
0
        zend_op_array *def;
688
0
        SERIALIZE_PTR(defs[i]);
689
0
        def = defs[i];
690
0
        UNSERIALIZE_PTR(def);
691
0
        zend_file_cache_serialize_op_array(def, script, info, buf);
692
0
      }
693
0
    }
694
695
0
    SERIALIZE_STR(op_array->function_name);
696
0
    SERIALIZE_STR(op_array->filename);
697
0
    SERIALIZE_PTR(op_array->live_range);
698
0
    SERIALIZE_PTR(op_array->scope);
699
0
    SERIALIZE_STR(op_array->doc_comment);
700
0
    SERIALIZE_ATTRIBUTES(op_array->attributes);
701
0
    SERIALIZE_PTR(op_array->try_catch_array);
702
0
    SERIALIZE_PTR(op_array->prototype);
703
0
    SERIALIZE_PTR(op_array->prop_info);
704
0
  }
705
0
}
706
707
static void zend_file_cache_serialize_func(zval                     *zv,
708
                                           zend_persistent_script   *script,
709
                                           zend_file_cache_metainfo *info,
710
                                           void                     *buf)
711
0
{
712
0
  zend_function *func;
713
0
  SERIALIZE_PTR(Z_PTR_P(zv));
714
0
  func = Z_PTR_P(zv);
715
0
  UNSERIALIZE_PTR(func);
716
0
  ZEND_ASSERT(func->type == ZEND_USER_FUNCTION);
717
0
  zend_file_cache_serialize_op_array(&func->op_array, script, info, buf);
718
0
}
719
720
static void zend_file_cache_serialize_prop_info(zval                     *zv,
721
                                                zend_persistent_script   *script,
722
                                                zend_file_cache_metainfo *info,
723
                                                void                     *buf)
724
0
{
725
0
  if (!IS_SERIALIZED(Z_PTR_P(zv))) {
726
0
    zend_property_info *prop;
727
728
0
    SERIALIZE_PTR(Z_PTR_P(zv));
729
0
    prop = Z_PTR_P(zv);
730
0
    UNSERIALIZE_PTR(prop);
731
732
0
    ZEND_ASSERT(prop->ce != NULL && prop->name != NULL);
733
0
    if (!IS_SERIALIZED(prop->ce)) {
734
0
      SERIALIZE_PTR(prop->ce);
735
0
      SERIALIZE_STR(prop->name);
736
0
      if (prop->doc_comment) {
737
0
        SERIALIZE_STR(prop->doc_comment);
738
0
      }
739
0
      SERIALIZE_ATTRIBUTES(prop->attributes);
740
0
      SERIALIZE_PTR(prop->prototype);
741
0
      if (prop->hooks) {
742
0
        SERIALIZE_PTR(prop->hooks);
743
0
        zend_function **hooks = prop->hooks;
744
0
        UNSERIALIZE_PTR(hooks);
745
0
        for (uint32_t i = 0; i < ZEND_PROPERTY_HOOK_COUNT; i++) {
746
0
          if (hooks[i]) {
747
0
            SERIALIZE_PTR(hooks[i]);
748
0
            zend_function *hook = hooks[i];
749
0
            UNSERIALIZE_PTR(hook);
750
0
            zend_file_cache_serialize_op_array(&hook->op_array, script, info, buf);
751
0
          }
752
0
        }
753
0
      }
754
0
      zend_file_cache_serialize_type(&prop->type, script, info, buf);
755
0
    }
756
0
  }
757
0
}
758
759
static void zend_file_cache_serialize_class_constant(zval                     *zv,
760
                                                     zend_persistent_script   *script,
761
                                                     zend_file_cache_metainfo *info,
762
                                                     void                     *buf)
763
0
{
764
0
  if (!IS_SERIALIZED(Z_PTR_P(zv))) {
765
0
    zend_class_constant *c;
766
767
0
    SERIALIZE_PTR(Z_PTR_P(zv));
768
0
    c = Z_PTR_P(zv);
769
0
    UNSERIALIZE_PTR(c);
770
771
0
    ZEND_ASSERT(c->ce != NULL);
772
0
    if (!IS_SERIALIZED(c->ce)) {
773
0
      SERIALIZE_PTR(c->ce);
774
775
0
      zend_file_cache_serialize_zval(&c->value, script, info, buf);
776
0
      if (c->doc_comment) {
777
0
        SERIALIZE_STR(c->doc_comment);
778
0
      }
779
780
0
      SERIALIZE_ATTRIBUTES(c->attributes);
781
0
      zend_file_cache_serialize_type(&c->type, script, info, buf);
782
0
    }
783
0
  }
784
0
}
785
786
static void zend_file_cache_serialize_class(zval                     *zv,
787
                                            zend_persistent_script   *script,
788
                                            zend_file_cache_metainfo *info,
789
                                            void                     *buf)
790
0
{
791
0
  zend_class_entry *ce;
792
793
0
  SERIALIZE_PTR(Z_PTR_P(zv));
794
0
  ce = Z_PTR_P(zv);
795
0
  UNSERIALIZE_PTR(ce);
796
797
0
  SERIALIZE_STR(ce->name);
798
0
  if (ce->parent) {
799
0
    if (!(ce->ce_flags & ZEND_ACC_LINKED)) {
800
0
      SERIALIZE_STR(ce->parent_name);
801
0
    } else {
802
0
      SERIALIZE_PTR(ce->parent);
803
0
    }
804
0
  }
805
0
  zend_file_cache_serialize_hash(&ce->function_table, script, info, buf, zend_file_cache_serialize_func);
806
0
  if (ce->default_properties_table) {
807
0
    zval *p, *end;
808
809
0
    SERIALIZE_PTR(ce->default_properties_table);
810
0
    p = ce->default_properties_table;
811
0
    UNSERIALIZE_PTR(p);
812
0
    end = p + ce->default_properties_count;
813
0
    while (p < end) {
814
0
      zend_file_cache_serialize_zval(p, script, info, buf);
815
0
      p++;
816
0
    }
817
0
  }
818
0
  if (ce->default_static_members_table) {
819
0
    zval *p, *end;
820
821
0
    SERIALIZE_PTR(ce->default_static_members_table);
822
0
    p = ce->default_static_members_table;
823
0
    UNSERIALIZE_PTR(p);
824
825
0
    end = p + ce->default_static_members_count;
826
0
    while (p < end) {
827
0
      zend_file_cache_serialize_zval(p, script, info, buf);
828
0
      p++;
829
0
    }
830
0
  }
831
0
  zend_file_cache_serialize_hash(&ce->constants_table, script, info, buf, zend_file_cache_serialize_class_constant);
832
0
  SERIALIZE_STR(ce->info.user.filename);
833
0
  SERIALIZE_STR(ce->doc_comment);
834
0
  SERIALIZE_ATTRIBUTES(ce->attributes);
835
0
  zend_file_cache_serialize_hash(&ce->properties_info, script, info, buf, zend_file_cache_serialize_prop_info);
836
837
0
  if (ce->properties_info_table) {
838
0
    uint32_t i;
839
0
    zend_property_info **table;
840
841
0
    SERIALIZE_PTR(ce->properties_info_table);
842
0
    table = ce->properties_info_table;
843
0
    UNSERIALIZE_PTR(table);
844
845
0
    for (i = 0; i < ce->default_properties_count; i++) {
846
0
      SERIALIZE_PTR(table[i]);
847
0
    }
848
0
  }
849
850
0
  if (ce->num_interfaces) {
851
0
    uint32_t i;
852
0
    zend_class_name *interface_names;
853
854
0
    ZEND_ASSERT(!(ce->ce_flags & ZEND_ACC_LINKED));
855
856
0
    SERIALIZE_PTR(ce->interface_names);
857
0
    interface_names = ce->interface_names;
858
0
    UNSERIALIZE_PTR(interface_names);
859
860
0
    for (i = 0; i < ce->num_interfaces; i++) {
861
0
      SERIALIZE_STR(interface_names[i].name);
862
0
      SERIALIZE_STR(interface_names[i].lc_name);
863
0
    }
864
0
  }
865
866
0
  if (ce->num_traits) {
867
0
    uint32_t i;
868
0
    zend_class_name *trait_names;
869
870
0
    SERIALIZE_PTR(ce->trait_names);
871
0
    trait_names = ce->trait_names;
872
0
    UNSERIALIZE_PTR(trait_names);
873
874
0
    for (i = 0; i < ce->num_traits; i++) {
875
0
      SERIALIZE_STR(trait_names[i].name);
876
0
      SERIALIZE_STR(trait_names[i].lc_name);
877
0
    }
878
879
0
    if (ce->trait_aliases) {
880
0
      zend_trait_alias **p, *q;
881
882
0
      SERIALIZE_PTR(ce->trait_aliases);
883
0
      p = ce->trait_aliases;
884
0
      UNSERIALIZE_PTR(p);
885
886
0
      while (*p) {
887
0
        SERIALIZE_PTR(*p);
888
0
        q = *p;
889
0
        UNSERIALIZE_PTR(q);
890
891
0
        if (q->trait_method.method_name) {
892
0
          SERIALIZE_STR(q->trait_method.method_name);
893
0
        }
894
0
        if (q->trait_method.class_name) {
895
0
          SERIALIZE_STR(q->trait_method.class_name);
896
0
        }
897
898
0
        if (q->alias) {
899
0
          SERIALIZE_STR(q->alias);
900
0
        }
901
0
        p++;
902
0
      }
903
0
    }
904
905
0
    if (ce->trait_precedences) {
906
0
      zend_trait_precedence **p, *q;
907
0
      uint32_t j;
908
909
0
      SERIALIZE_PTR(ce->trait_precedences);
910
0
      p = ce->trait_precedences;
911
0
      UNSERIALIZE_PTR(p);
912
913
0
      while (*p) {
914
0
        SERIALIZE_PTR(*p);
915
0
        q = *p;
916
0
        UNSERIALIZE_PTR(q);
917
918
0
        if (q->trait_method.method_name) {
919
0
          SERIALIZE_STR(q->trait_method.method_name);
920
0
        }
921
0
        if (q->trait_method.class_name) {
922
0
          SERIALIZE_STR(q->trait_method.class_name);
923
0
        }
924
925
0
        for (j = 0; j < q->num_excludes; j++) {
926
0
          SERIALIZE_STR(q->exclude_class_names[j]);
927
0
        }
928
0
        p++;
929
0
      }
930
0
    }
931
0
  }
932
933
0
  SERIALIZE_PTR(ce->constructor);
934
0
  SERIALIZE_PTR(ce->destructor);
935
0
  SERIALIZE_PTR(ce->clone);
936
0
  SERIALIZE_PTR(ce->__get);
937
0
  SERIALIZE_PTR(ce->__set);
938
0
  SERIALIZE_PTR(ce->__call);
939
0
  SERIALIZE_PTR(ce->__serialize);
940
0
  SERIALIZE_PTR(ce->__unserialize);
941
0
  SERIALIZE_PTR(ce->__isset);
942
0
  SERIALIZE_PTR(ce->__unset);
943
0
  SERIALIZE_PTR(ce->__tostring);
944
0
  SERIALIZE_PTR(ce->__callstatic);
945
0
  SERIALIZE_PTR(ce->__debugInfo);
946
947
0
  if (ce->iterator_funcs_ptr) {
948
0
    SERIALIZE_PTR(ce->iterator_funcs_ptr->zf_new_iterator);
949
0
    SERIALIZE_PTR(ce->iterator_funcs_ptr->zf_rewind);
950
0
    SERIALIZE_PTR(ce->iterator_funcs_ptr->zf_valid);
951
0
    SERIALIZE_PTR(ce->iterator_funcs_ptr->zf_key);
952
0
    SERIALIZE_PTR(ce->iterator_funcs_ptr->zf_current);
953
0
    SERIALIZE_PTR(ce->iterator_funcs_ptr->zf_next);
954
0
    SERIALIZE_PTR(ce->iterator_funcs_ptr);
955
0
  }
956
957
0
  if (ce->arrayaccess_funcs_ptr) {
958
0
    SERIALIZE_PTR(ce->arrayaccess_funcs_ptr->zf_offsetget);
959
0
    SERIALIZE_PTR(ce->arrayaccess_funcs_ptr->zf_offsetexists);
960
0
    SERIALIZE_PTR(ce->arrayaccess_funcs_ptr->zf_offsetset);
961
0
    SERIALIZE_PTR(ce->arrayaccess_funcs_ptr->zf_offsetunset);
962
0
    SERIALIZE_PTR(ce->arrayaccess_funcs_ptr);
963
0
  }
964
965
0
  ZEND_MAP_PTR_INIT(ce->static_members_table, NULL);
966
0
  ZEND_MAP_PTR_INIT(ce->mutable_data, NULL);
967
968
0
  ce->inheritance_cache = NULL;
969
970
0
  if (ce->get_iterator) {
971
0
    ZEND_ASSERT(ce->get_iterator == zend_hooked_object_get_iterator);
972
0
    ce->get_iterator = HOOKED_ITERATOR_PLACEHOLDER;
973
0
  }
974
0
}
975
976
static void zend_file_cache_serialize_warnings(
977
    zend_persistent_script *script, zend_file_cache_metainfo *info, void *buf)
978
0
{
979
0
  if (script->warnings) {
980
0
    zend_error_info **warnings;
981
0
    SERIALIZE_PTR(script->warnings);
982
0
    warnings = script->warnings;
983
0
    UNSERIALIZE_PTR(warnings);
984
985
0
    for (uint32_t i = 0; i < script->num_warnings; i++) {
986
0
      zend_error_info *warning;
987
0
      SERIALIZE_PTR(warnings[i]);
988
0
      warning = warnings[i];
989
0
      UNSERIALIZE_PTR(warning);
990
0
      SERIALIZE_STR(warning->filename);
991
0
      SERIALIZE_STR(warning->message);
992
0
    }
993
0
  }
994
0
}
995
996
static void zend_file_cache_serialize_early_bindings(
997
    zend_persistent_script *script, zend_file_cache_metainfo *info, void *buf)
998
0
{
999
0
  if (script->early_bindings) {
1000
0
    SERIALIZE_PTR(script->early_bindings);
1001
0
    zend_early_binding *early_bindings = script->early_bindings;
1002
0
    UNSERIALIZE_PTR(early_bindings);
1003
0
    for (uint32_t i = 0; i < script->num_early_bindings; i++) {
1004
0
      SERIALIZE_STR(early_bindings[i].lcname);
1005
0
      SERIALIZE_STR(early_bindings[i].rtd_key);
1006
0
      SERIALIZE_STR(early_bindings[i].lc_parent_name);
1007
0
    }
1008
0
  }
1009
0
}
1010
1011
static void zend_file_cache_serialize(zend_persistent_script   *script,
1012
                                      zend_file_cache_metainfo *info,
1013
                                      void                     *buf)
1014
0
{
1015
0
  zend_persistent_script *new_script;
1016
1017
0
  memcpy(info->magic, "OPCACHE", 8);
1018
0
  memcpy(info->system_id, zend_system_id, 32);
1019
0
  info->mem_size = script->size;
1020
0
  info->str_size = 0;
1021
0
  info->script_offset = (char*)script - (char*)script->mem;
1022
0
  info->timestamp = script->timestamp;
1023
1024
0
  memcpy(buf, script->mem, script->size);
1025
1026
0
  new_script = (zend_persistent_script*)((char*)buf + info->script_offset);
1027
0
  SERIALIZE_STR(new_script->script.filename);
1028
1029
0
  zend_file_cache_serialize_hash(&new_script->script.class_table, script, info, buf, zend_file_cache_serialize_class);
1030
0
  zend_file_cache_serialize_hash(&new_script->script.function_table, script, info, buf, zend_file_cache_serialize_func);
1031
0
  zend_file_cache_serialize_op_array(&new_script->script.main_op_array, script, info, buf);
1032
0
  zend_file_cache_serialize_warnings(new_script, info, buf);
1033
0
  zend_file_cache_serialize_early_bindings(new_script, info, buf);
1034
1035
0
  new_script->mem = NULL;
1036
0
}
1037
1038
static char *zend_file_cache_get_bin_file_path(zend_string *script_path)
1039
0
{
1040
0
  size_t len;
1041
0
  char *filename;
1042
1043
0
#ifndef ZEND_WIN32
1044
0
  len = strlen(ZCG(accel_directives).file_cache);
1045
0
  filename = emalloc(len + 33 + ZSTR_LEN(script_path) + sizeof(SUFFIX));
1046
0
  memcpy(filename, ZCG(accel_directives).file_cache, len);
1047
0
  filename[len] = '/';
1048
0
  memcpy(filename + len + 1, zend_system_id, 32);
1049
0
  memcpy(filename + len + 33, ZSTR_VAL(script_path), ZSTR_LEN(script_path));
1050
0
  memcpy(filename + len + 33 + ZSTR_LEN(script_path), SUFFIX, sizeof(SUFFIX));
1051
#else
1052
  len = strlen(ZCG(accel_directives).file_cache);
1053
1054
  filename = emalloc(len + 33 + 33 + ZSTR_LEN(script_path) + sizeof(SUFFIX));
1055
1056
  memcpy(filename, ZCG(accel_directives).file_cache, len);
1057
  filename[len] = '\\';
1058
  memcpy(filename + 1 + len, accel_uname_id, 32);
1059
  len += 1 + 32;
1060
  filename[len] = '\\';
1061
1062
  memcpy(filename + len + 1, zend_system_id, 32);
1063
1064
  if (ZSTR_LEN(script_path) >= 7 && ':' == ZSTR_VAL(script_path)[4] && '/' == ZSTR_VAL(script_path)[5]  && '/' == ZSTR_VAL(script_path)[6]) {
1065
    /* phar:// or file:// */
1066
    *(filename + len + 33) = '\\';
1067
    memcpy(filename + len + 34, ZSTR_VAL(script_path), 4);
1068
    if (ZSTR_LEN(script_path) - 7 >= 2 && ':' == ZSTR_VAL(script_path)[8]) {
1069
      *(filename + len + 38) = '\\';
1070
      *(filename + len + 39) = ZSTR_VAL(script_path)[7];
1071
      memcpy(filename + len + 40, ZSTR_VAL(script_path) + 9, ZSTR_LEN(script_path) - 9);
1072
      memcpy(filename + len + 40 + ZSTR_LEN(script_path) - 9, SUFFIX, sizeof(SUFFIX));
1073
    } else {
1074
      memcpy(filename + len + 38, ZSTR_VAL(script_path) + 7, ZSTR_LEN(script_path) - 7);
1075
      memcpy(filename + len + 38 + ZSTR_LEN(script_path) - 7, SUFFIX, sizeof(SUFFIX));
1076
    }
1077
  } else if (ZSTR_LEN(script_path) >= 2 && ':' == ZSTR_VAL(script_path)[1]) {
1078
    /* local fs */
1079
    *(filename + len + 33) = '\\';
1080
    *(filename + len + 34) = ZSTR_VAL(script_path)[0];
1081
    memcpy(filename + len + 35, ZSTR_VAL(script_path) + 2, ZSTR_LEN(script_path) - 2);
1082
    memcpy(filename + len + 35 + ZSTR_LEN(script_path) - 2, SUFFIX, sizeof(SUFFIX));
1083
  } else {
1084
    /* network path */
1085
    memcpy(filename + len + 33, ZSTR_VAL(script_path), ZSTR_LEN(script_path));
1086
    memcpy(filename + len + 33 + ZSTR_LEN(script_path), SUFFIX, sizeof(SUFFIX));
1087
  }
1088
#endif
1089
1090
0
  return filename;
1091
0
}
1092
1093
/**
1094
 * Helper function for zend_file_cache_script_store().
1095
 *
1096
 * @return true on success, false on error and errno is set to indicate the cause of the error
1097
 */
1098
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)
1099
0
{
1100
0
  ssize_t written;
1101
0
  const ssize_t total_size = (ssize_t)(sizeof(*info) + script->size + info->str_size);
1102
1103
0
#ifdef HAVE_SYS_UIO_H
1104
0
  const struct iovec vec[] = {
1105
0
    { .iov_base = (void *)info, .iov_len = sizeof(*info) },
1106
0
    { .iov_base = (void *)buf, .iov_len = script->size },
1107
0
    { .iov_base = (void *)ZSTR_VAL(s), .iov_len = info->str_size },
1108
0
  };
1109
1110
0
  written = writev(fd, vec, sizeof(vec) / sizeof(vec[0]));
1111
0
  if (EXPECTED(written == total_size)) {
1112
0
    return true;
1113
0
  }
1114
1115
0
  errno = written == -1 ? errno : EAGAIN;
1116
0
  return false;
1117
#else
1118
  if (UNEXPECTED(ZEND_LONG_MAX < (zend_long)total_size)) {
1119
# ifdef EFBIG
1120
    errno = EFBIG;
1121
# else
1122
    errno = ERANGE;
1123
# endif
1124
    return false;
1125
  }
1126
1127
  written = write(fd, info, sizeof(*info));
1128
  if (UNEXPECTED(written != sizeof(*info))) {
1129
    errno = written == -1 ? errno : EAGAIN;
1130
    return false;
1131
  }
1132
1133
  written = write(fd, buf, script->size);
1134
  if (UNEXPECTED(written != script->size)) {
1135
    errno = written == -1 ? errno : EAGAIN;
1136
    return false;
1137
  }
1138
1139
  written = write(fd, ZSTR_VAL(s), info->str_size);
1140
  if (UNEXPECTED(written != info->str_size)) {
1141
    errno = written == -1 ? errno : EAGAIN;
1142
    return false;
1143
  }
1144
1145
  return true;
1146
#endif
1147
0
}
1148
1149
int zend_file_cache_script_store(zend_persistent_script *script, bool in_shm)
1150
0
{
1151
0
  int fd;
1152
0
  char *filename;
1153
0
  zend_file_cache_metainfo info;
1154
0
  void *mem, *buf;
1155
1156
0
#ifdef HAVE_JIT
1157
  /* FIXME: dump jited codes out to file cache? */
1158
0
  if (JIT_G(on)) {
1159
0
    return FAILURE;
1160
0
  }
1161
0
#endif
1162
1163
0
  if (ZCG(accel_directives).file_cache_read_only) {
1164
0
    return FAILURE;
1165
0
  }
1166
1167
0
  filename = zend_file_cache_get_bin_file_path(script->script.filename);
1168
1169
0
  if (zend_file_cache_mkdir(filename, strlen(ZCG(accel_directives).file_cache)) != SUCCESS) {
1170
0
    zend_accel_error(ACCEL_LOG_WARNING, "opcache cannot create directory for file '%s', %s\n", filename, strerror(errno));
1171
0
    efree(filename);
1172
0
    return FAILURE;
1173
0
  }
1174
1175
0
  fd = zend_file_cache_open(filename, O_CREAT | O_EXCL | O_RDWR | O_BINARY, S_IRUSR | S_IWUSR);
1176
0
  if (fd < 0) {
1177
0
    if (errno != EEXIST) {
1178
0
      zend_accel_error(ACCEL_LOG_WARNING, "opcache cannot create file '%s', %s\n", filename, strerror(errno));
1179
0
    }
1180
0
    efree(filename);
1181
0
    return FAILURE;
1182
0
  }
1183
1184
0
  if (zend_file_cache_flock(fd, LOCK_EX) != 0) {
1185
0
    close(fd);
1186
0
    efree(filename);
1187
0
    return FAILURE;
1188
0
  }
1189
1190
0
#if defined(__AVX__) || defined(__SSE2__)
1191
  /* Align to 64-byte boundary */
1192
0
  mem = emalloc(script->size + 64);
1193
0
  buf = (void*)(((uintptr_t)mem + 63L) & ~63L);
1194
#else
1195
  mem = buf = emalloc(script->size);
1196
#endif
1197
1198
0
  ZCG(mem) = zend_string_alloc(4096 - (_ZSTR_HEADER_SIZE + 1), 0);
1199
1200
0
  zend_shared_alloc_init_xlat_table();
1201
0
  if (!in_shm) {
1202
0
    script->corrupted = true; /* used to check if script restored to SHM or process memory */
1203
0
  }
1204
0
  zend_file_cache_serialize(script, &info, buf);
1205
0
  if (!in_shm) {
1206
0
    script->corrupted = false;
1207
0
  }
1208
0
  zend_shared_alloc_destroy_xlat_table();
1209
1210
0
  zend_string *const s = (zend_string*)ZCG(mem);
1211
1212
#if __has_feature(memory_sanitizer)
1213
  /* The buffer may contain uninitialized regions. However, the uninitialized parts will not be
1214
   * used when reading the cache. We should probably still try to get things fully initialized
1215
   * for reproducibility, but for now ignore this issue. */
1216
  __msan_unpoison(&info, sizeof(info));
1217
  __msan_unpoison(buf, script->size);
1218
#endif
1219
1220
0
  info.checksum = zend_adler32(ADLER32_INIT, buf, script->size);
1221
0
  info.checksum = zend_adler32(info.checksum, (unsigned char*)ZSTR_VAL(s), info.str_size);
1222
1223
0
  if (!zend_file_cache_script_write(fd, script, &info, buf, s)) {
1224
0
    zend_accel_error(ACCEL_LOG_WARNING, "opcache cannot write to file '%s': %s\n", filename, strerror(errno));
1225
0
    zend_string_release_ex(s, 0);
1226
0
    close(fd);
1227
0
    efree(mem);
1228
0
    zend_file_cache_unlink(filename);
1229
0
    efree(filename);
1230
0
    return FAILURE;
1231
0
  }
1232
1233
0
  zend_string_release_ex(s, 0);
1234
0
  efree(mem);
1235
0
  if (zend_file_cache_flock(fd, LOCK_UN) != 0) {
1236
0
    zend_accel_error(ACCEL_LOG_WARNING, "opcache cannot unlock file '%s': %s\n", filename, strerror(errno));
1237
0
  }
1238
0
  close(fd);
1239
0
  efree(filename);
1240
1241
0
  return SUCCESS;
1242
0
}
1243
1244
static void zend_file_cache_unserialize_hash(HashTable               *ht,
1245
                                             zend_persistent_script  *script,
1246
                                             void                    *buf,
1247
                                             unserialize_callback_t   func,
1248
                                             dtor_func_t              dtor)
1249
0
{
1250
0
  ht->pDestructor = dtor;
1251
0
  if (HT_FLAGS(ht) & HASH_FLAG_UNINITIALIZED) {
1252
0
    if (EXPECTED(!file_cache_only)) {
1253
0
      HT_SET_DATA_ADDR(ht, &ZCSG(uninitialized_bucket));
1254
0
    } else {
1255
0
      HT_SET_DATA_ADDR(ht, &uninitialized_bucket);
1256
0
    }
1257
0
    return;
1258
0
  }
1259
0
  if (IS_UNSERIALIZED(ht->arData)) {
1260
0
    return;
1261
0
  }
1262
0
  UNSERIALIZE_PTR(ht->arData);
1263
0
  if (HT_IS_PACKED(ht)) {
1264
0
    zval *p, *end;
1265
1266
0
    p = ht->arPacked;
1267
0
    end = p + ht->nNumUsed;
1268
0
    while (p < end) {
1269
0
      if (Z_TYPE_P(p) != IS_UNDEF) {
1270
0
        func(p, script, buf);
1271
0
      }
1272
0
      p++;
1273
0
    }
1274
0
  } else {
1275
0
    Bucket *p, *end;
1276
1277
0
    p = ht->arData;
1278
0
    end = p + ht->nNumUsed;
1279
0
    while (p < end) {
1280
0
      if (Z_TYPE(p->val) != IS_UNDEF) {
1281
0
        UNSERIALIZE_STR(p->key);
1282
0
        func(&p->val, script, buf);
1283
0
      }
1284
0
      p++;
1285
0
    }
1286
0
  }
1287
0
}
1288
1289
static void zend_file_cache_unserialize_ast(zend_ast                *ast,
1290
                                            zend_persistent_script  *script,
1291
                                            void                    *buf)
1292
0
{
1293
0
  uint32_t i;
1294
1295
0
  if (ast->kind == ZEND_AST_ZVAL || ast->kind == ZEND_AST_CONSTANT) {
1296
0
    zend_file_cache_unserialize_zval(&((zend_ast_zval*)ast)->val, script, buf);
1297
0
  } else if (zend_ast_is_list(ast)) {
1298
0
    zend_ast_list *list = zend_ast_get_list(ast);
1299
0
    for (i = 0; i < list->children; i++) {
1300
0
      if (list->child[i] && !IS_UNSERIALIZED(list->child[i])) {
1301
0
        UNSERIALIZE_PTR(list->child[i]);
1302
0
        zend_file_cache_unserialize_ast(list->child[i], script, buf);
1303
0
      }
1304
0
    }
1305
0
  } else if (ast->kind == ZEND_AST_OP_ARRAY) {
1306
0
    zval z;
1307
0
    ZVAL_PTR(&z, zend_ast_get_op_array(ast)->op_array);
1308
0
    zend_file_cache_unserialize_func(&z, script, buf);
1309
0
    zend_ast_get_op_array(ast)->op_array = Z_PTR(z);
1310
0
  } else if (ast->kind == ZEND_AST_CALLABLE_CONVERT) {
1311
0
    zend_ast_fcc *fcc = (zend_ast_fcc*)ast;
1312
0
    ZEND_MAP_PTR_NEW(fcc->fptr);
1313
0
    if (!IS_UNSERIALIZED(fcc->args)) {
1314
0
      UNSERIALIZE_PTR(fcc->args);
1315
0
      zend_file_cache_unserialize_ast(fcc->args, script, buf);
1316
0
    }
1317
0
  } else if (zend_ast_is_decl(ast)) {
1318
    /* Not implemented. */
1319
0
    ZEND_UNREACHABLE();
1320
0
  } else {
1321
0
    uint32_t children = zend_ast_get_num_children(ast);
1322
0
    for (i = 0; i < children; i++) {
1323
0
      if (ast->child[i] && !IS_UNSERIALIZED(ast->child[i])) {
1324
0
        UNSERIALIZE_PTR(ast->child[i]);
1325
0
        zend_file_cache_unserialize_ast(ast->child[i], script, buf);
1326
0
      }
1327
0
    }
1328
0
  }
1329
0
}
1330
1331
static void zend_file_cache_unserialize_zval(zval                    *zv,
1332
                                             zend_persistent_script  *script,
1333
                                             void                    *buf)
1334
0
{
1335
0
  switch (Z_TYPE_P(zv)) {
1336
0
    case IS_STRING:
1337
      /* We can't use !IS_UNSERIALIZED here, because that does not recognize unserialized
1338
       * interned strings in non-shm mode. */
1339
0
      if (IS_SERIALIZED(Z_STR_P(zv)) || IS_SERIALIZED_INTERNED(Z_STR_P(zv))) {
1340
0
        UNSERIALIZE_STR(Z_STR_P(zv));
1341
0
      }
1342
0
      break;
1343
0
    case IS_ARRAY:
1344
0
      if (!IS_UNSERIALIZED(Z_ARR_P(zv))) {
1345
0
        HashTable *ht;
1346
1347
0
        UNSERIALIZE_PTR(Z_ARR_P(zv));
1348
0
        ht = Z_ARR_P(zv);
1349
0
        zend_file_cache_unserialize_hash(ht,
1350
0
            script, buf, zend_file_cache_unserialize_zval, ZVAL_PTR_DTOR);
1351
0
      }
1352
0
      break;
1353
0
    case IS_CONSTANT_AST:
1354
0
      if (!IS_UNSERIALIZED(Z_AST_P(zv))) {
1355
0
        UNSERIALIZE_PTR(Z_AST_P(zv));
1356
0
        zend_file_cache_unserialize_ast(Z_ASTVAL_P(zv), script, buf);
1357
0
      }
1358
0
      break;
1359
0
    case IS_INDIRECT:
1360
      /* Used by static properties. */
1361
0
      UNSERIALIZE_PTR(Z_INDIRECT_P(zv));
1362
0
      break;
1363
0
    case IS_PTR:
1364
      /* Used by attributes on constants, will be handled separately */
1365
0
      break;
1366
0
    default:
1367
0
      ZEND_ASSERT(Z_TYPE_P(zv) < IS_STRING);
1368
0
      break;
1369
0
  }
1370
0
}
1371
1372
static void zend_file_cache_unserialize_attribute(zval *zv, zend_persistent_script *script, void *buf)
1373
0
{
1374
0
  zend_attribute *attr;
1375
0
  uint32_t i;
1376
1377
0
  UNSERIALIZE_PTR(Z_PTR_P(zv));
1378
0
  attr = Z_PTR_P(zv);
1379
1380
0
  UNSERIALIZE_STR(attr->name);
1381
0
  UNSERIALIZE_STR(attr->lcname);
1382
0
  UNSERIALIZE_STR(attr->validation_error);
1383
1384
0
  for (i = 0; i < attr->argc; i++) {
1385
0
    UNSERIALIZE_STR(attr->args[i].name);
1386
0
    zend_file_cache_unserialize_zval(&attr->args[i].value, script, buf);
1387
0
  }
1388
0
}
1389
1390
static void zend_file_cache_unserialize_type(
1391
    zend_type *type, zend_class_entry *scope, zend_persistent_script *script, void *buf)
1392
0
{
1393
0
  if (ZEND_TYPE_HAS_LIST(*type)) {
1394
0
    zend_type_list *list = ZEND_TYPE_LIST(*type);
1395
0
    UNSERIALIZE_PTR(list);
1396
0
    ZEND_TYPE_SET_PTR(*type, list);
1397
1398
0
    zend_type *list_type;
1399
0
    ZEND_TYPE_LIST_FOREACH_MUTABLE(list, list_type) {
1400
0
      zend_file_cache_unserialize_type(list_type, scope, script, buf);
1401
0
    } ZEND_TYPE_LIST_FOREACH_END();
1402
0
  } else if (ZEND_TYPE_HAS_NAME(*type)) {
1403
0
    zend_string *type_name = ZEND_TYPE_NAME(*type);
1404
0
    UNSERIALIZE_STR(type_name);
1405
0
    ZEND_TYPE_SET_PTR(*type, type_name);
1406
0
    if (!script->corrupted) {
1407
0
      zend_accel_get_class_name_map_ptr(type_name);
1408
0
    } else {
1409
0
      zend_alloc_ce_cache(type_name);
1410
0
    }
1411
0
  }
1412
0
}
1413
1414
static void zend_file_cache_unserialize_op_array(zend_op_array           *op_array,
1415
                                                 zend_persistent_script  *script,
1416
                                                 void                    *buf)
1417
0
{
1418
0
  if (!script->corrupted) {
1419
0
    if (op_array != &script->script.main_op_array) {
1420
0
      op_array->fn_flags |= ZEND_ACC_IMMUTABLE;
1421
0
      ZEND_MAP_PTR_NEW(op_array->run_time_cache);
1422
0
    } else {
1423
0
      ZEND_ASSERT(!(op_array->fn_flags & ZEND_ACC_IMMUTABLE));
1424
0
      ZEND_MAP_PTR_INIT(op_array->run_time_cache, NULL);
1425
0
    }
1426
0
    if (op_array->static_variables) {
1427
0
      ZEND_MAP_PTR_NEW(op_array->static_variables_ptr);
1428
0
    }
1429
0
  } else {
1430
0
    op_array->fn_flags &= ~ZEND_ACC_IMMUTABLE;
1431
0
    ZEND_MAP_PTR_INIT(op_array->static_variables_ptr, NULL);
1432
0
    ZEND_MAP_PTR_INIT(op_array->run_time_cache, NULL);
1433
0
  }
1434
1435
  /* Check whether this op_array has already been unserialized. */
1436
0
  if (IS_UNSERIALIZED(op_array->opcodes)) {
1437
0
    ZEND_ASSERT(op_array->scope && "Only method op_arrays should be shared");
1438
0
    return;
1439
0
  }
1440
1441
0
  if (op_array->refcount) {
1442
0
    op_array->refcount = NULL;
1443
0
    UNSERIALIZE_PTR(op_array->static_variables);
1444
0
    UNSERIALIZE_PTR(op_array->literals);
1445
0
    UNSERIALIZE_PTR(op_array->opcodes);
1446
0
    UNSERIALIZE_PTR(op_array->arg_info);
1447
0
    UNSERIALIZE_PTR(op_array->vars);
1448
0
    UNSERIALIZE_STR(op_array->function_name);
1449
0
    UNSERIALIZE_STR(op_array->filename);
1450
0
    UNSERIALIZE_PTR(op_array->live_range);
1451
0
    UNSERIALIZE_PTR(op_array->scope);
1452
0
    UNSERIALIZE_STR(op_array->doc_comment);
1453
0
    UNSERIALIZE_ATTRIBUTES(op_array->attributes);
1454
0
    UNSERIALIZE_PTR(op_array->try_catch_array);
1455
0
    UNSERIALIZE_PTR(op_array->prototype);
1456
0
    UNSERIALIZE_PTR(op_array->prop_info);
1457
0
    return;
1458
0
  }
1459
1460
0
  if (op_array->static_variables) {
1461
0
    HashTable *ht;
1462
1463
0
    UNSERIALIZE_PTR(op_array->static_variables);
1464
0
    ht = op_array->static_variables;
1465
0
    zend_file_cache_unserialize_hash(ht,
1466
0
        script, buf, zend_file_cache_unserialize_zval, ZVAL_PTR_DTOR);
1467
0
  }
1468
1469
0
  if (op_array->literals) {
1470
0
    zval *p, *end;
1471
1472
0
    UNSERIALIZE_PTR(op_array->literals);
1473
0
    p = op_array->literals;
1474
0
    end = p + op_array->last_literal;
1475
0
    while (p < end) {
1476
0
      zend_file_cache_unserialize_zval(p, script, buf);
1477
0
      p++;
1478
0
    }
1479
0
  }
1480
1481
0
  {
1482
0
    zend_op *opline, *end;
1483
1484
0
    UNSERIALIZE_PTR(op_array->opcodes);
1485
0
    opline = op_array->opcodes;
1486
0
    end = opline + op_array->last;
1487
0
    while (opline < end) {
1488
#if ZEND_USE_ABS_CONST_ADDR
1489
      if (opline->op1_type == IS_CONST) {
1490
        UNSERIALIZE_PTR(opline->op1.zv);
1491
      }
1492
      if (opline->op2_type == IS_CONST) {
1493
        UNSERIALIZE_PTR(opline->op2.zv);
1494
      }
1495
#else
1496
0
      if (opline->op1_type == IS_CONST) {
1497
0
        ZEND_PASS_TWO_UPDATE_CONSTANT(op_array, opline, opline->op1);
1498
0
      }
1499
0
      if (opline->op2_type == IS_CONST) {
1500
0
        ZEND_PASS_TWO_UPDATE_CONSTANT(op_array, opline, opline->op2);
1501
0
      }
1502
0
#endif
1503
#if ZEND_USE_ABS_JMP_ADDR
1504
      switch (opline->opcode) {
1505
        case ZEND_JMP:
1506
        case ZEND_FAST_CALL:
1507
          UNSERIALIZE_PTR(opline->op1.jmp_addr);
1508
          break;
1509
        case ZEND_JMPZ:
1510
        case ZEND_JMPNZ:
1511
        case ZEND_JMPZ_EX:
1512
        case ZEND_JMPNZ_EX:
1513
        case ZEND_JMP_SET:
1514
        case ZEND_COALESCE:
1515
        case ZEND_FE_RESET_R:
1516
        case ZEND_FE_RESET_RW:
1517
        case ZEND_ASSERT_CHECK:
1518
        case ZEND_JMP_NULL:
1519
        case ZEND_BIND_INIT_STATIC_OR_JMP:
1520
        case ZEND_JMP_FRAMELESS:
1521
          UNSERIALIZE_PTR(opline->op2.jmp_addr);
1522
          break;
1523
        case ZEND_CATCH:
1524
          if (!(opline->extended_value & ZEND_LAST_CATCH)) {
1525
            UNSERIALIZE_PTR(opline->op2.jmp_addr);
1526
          }
1527
          break;
1528
        case ZEND_FE_FETCH_R:
1529
        case ZEND_FE_FETCH_RW:
1530
        case ZEND_SWITCH_LONG:
1531
        case ZEND_SWITCH_STRING:
1532
          /* relative extended_value don't have to be changed */
1533
          break;
1534
      }
1535
#endif
1536
1537
0
      if (opline->opcode == ZEND_OP_DATA
1538
0
        && (opline-1)->opcode == ZEND_DECLARE_ATTRIBUTED_CONST
1539
0
      ) {
1540
0
        zval *literal = RT_CONSTANT(opline, opline->op1);
1541
0
        UNSERIALIZE_ATTRIBUTES(Z_PTR_P(literal));
1542
0
      }
1543
0
      zend_deserialize_opcode_handler(opline);
1544
0
      opline++;
1545
0
    }
1546
1547
0
    UNSERIALIZE_PTR(op_array->scope);
1548
1549
0
    if (op_array->arg_info) {
1550
0
      zend_arg_info *p, *end;
1551
0
      UNSERIALIZE_PTR(op_array->arg_info);
1552
0
      p = op_array->arg_info;
1553
0
      end = p + op_array->num_args;
1554
0
      if (op_array->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
1555
0
        p--;
1556
0
      }
1557
0
      if (op_array->fn_flags & ZEND_ACC_VARIADIC) {
1558
0
        end++;
1559
0
      }
1560
0
      while (p < end) {
1561
0
        if (!IS_UNSERIALIZED(p->name)) {
1562
0
          UNSERIALIZE_STR(p->name);
1563
0
        }
1564
0
        zend_file_cache_unserialize_type(&p->type, (op_array->fn_flags & ZEND_ACC_CLOSURE) ? NULL : op_array->scope, script, buf);
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
}