8000 Don't use immutable classes and op_arrays in file_cache_only mode. · php/php-src@59c96eb · GitHub
[go: up one dir, main page]

Skip to content

Commit 59c96eb

Browse files
committed
Don't use immutable classes and op_arrays in file_cache_only mode.
1 parent 8fc3169 commit 59c96eb

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

ext/opcache/zend_persist.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,16 @@ static void zend_persist_op_array(zval *zv)
640640
ZEND_ASSERT(op_array->type == ZEND_USER_FUNCTION);
641641
op_array = Z_PTR_P(zv) = zend_shared_memdup(Z_PTR_P(zv), sizeof(zend_op_array));
642642
zend_persist_op_array_ex(op_array, NULL);
643-
op_array->fn_flags |= ZEND_ACC_IMMUTABLE;
644-
ZEND_MAP_PTR_NEW(op_array->run_time_cache);
645-
if (op_array->static_variables) {
646-
ZEND_MAP_PTR_NEW(op_array->static_variables_ptr);
643+
if (!ZCG(current_persistent_script)->corrupted) {
644+
op_array->fn_flags |= ZEND_ACC_IMMUTABLE;
645+
ZEND_MAP_PTR_NEW(op_array->run_time_cache);
646+
if (op_array->static_variables) {
647+
ZEND_MAP_PTR_NEW(op_array->static_variables_ptr);
648+
}
649+
} else {
650+
ZEND_MAP_PTR_INIT(op_array->run_time_cache, ZCG(arena_mem));
651+
ZCG(arena_mem) = (void*)(((char*)ZCG(arena_mem)) + ZEND_ALIGNED_SIZE(sizeof(void*)));
652+
ZEND_MAP_PTR_SET(op_array->run_time_cache, NULL);
647653
}
648654
}
649655

@@ -776,7 +782,8 @@ static void zend_persist_class_entry(zval *zv)
776782

777783
if (ce->type == ZEND_USER_CLASS) {
778784
if ((ce->ce_flags & ZEND_ACC_LINKED)
779-
&& (ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
785+
&& (ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)
786+
&& !ZCG(current_persistent_script)->corrupted) {
780787
ZCG(is_immutable_class) = 1;
781788
ce = Z_PTR_P(zv) = zend_shared_memdup_put(ce, sizeof(zend_class_entry));
782789
ce->ce_flags |= ZEND_ACC_IMMUTABLE;

ext/opcache/zend_persist_calc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ static void zend_persist_op_array_calc(zval *zv)
265265
ZEND_ASSERT(op_array->type == ZEND_USER_FUNCTION);
266266
ADD_SIZE(sizeof(zend_op_array));
267267
zend_persist_op_array_calc_ex(Z_PTR_P(zv));
268+
if (ZCG(current_persistent_script)->corrupted) {
269+
ADD_ARENA_SIZE(sizeof(void*));
270+
}
268271
}
269272

270273
static void zend_persist_class_method_calc(zval *zv)
@@ -330,7 +333,8 @@ static void zend_persist_class_entry_calc(zval *zv)
330333
if (ce->type == ZEND_USER_CLASS) {
331334
ZCG(is_immutable_class) =
332335
(ce->ce_flags & ZEND_ACC_LINKED) &&
333-
(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED);
336+
(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED) &&
337+
!ZCG(current_persistent_script)->corrupted;
334338

335339
ADD_SIZE_EX(sizeof(zend_class_entry));
336340
ADD_INTERNED_STRING(ce->name, 0);

0 commit comments

Comments
 (0)
0