@@ -403,7 +403,13 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
403
403
zend_file_cache_metainfo * info ,
404
404
void * buf )
405
405
{
406
- if (op_array -> static_variables && !IS_SERIALIZED (op_array -> static_variables )) {
406
+ /* Check whether this op_array has already been serialized. */
407
+ if (IS_SERIALIZED (op_array -> opcodes )) {
408
+ ZEND_ASSERT (op_array -> scope && "Only method op_arrays should be shared" );
409
+ return ;
410
+ }
411
+
412
+ if (op_array -> static_variables ) {
407
413
HashTable * ht ;
408
414
409
415
SERIALIZE_PTR (op_array -> static_variables );
@@ -412,7 +418,14 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
412
418
zend_file_cache_serialize_hash (ht , script , info , buf , zend_file_cache_serialize_zval );
413
419
}
414
420
415
- if (op_array -> scope && !IS_SERIALIZED (op_array -> opcodes )) {
421
+ ZEND_MAP_PTR_INIT (op_array -> static_variables_ptr , & op_array -> static_variables );
422
+ if (op_array -> fn_flags & ZEND_ACC_IMMUTABLE ) {
423
+ ZEND_MAP_PTR_INIT (op_array -> run_time_cache , NULL );
424
+ } else {
425
+ SERIALIZE_PTR (ZEND_MAP_PTR (op_array -> run_time_cache ));
426
+ }
427
+
428
+ if (op_array -> scope ) {
416
429
if (UNEXPECTED (zend_shared_alloc_get_xlat_entry (op_array -> opcodes ))) {
417
430
op_array -> refcount = (uint32_t * )(intptr_t )-1 ;
418
431
SERIALIZE_PTR (op_array -> literals );
@@ -431,7 +444,7 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
431
444
zend_shared_alloc_register_xlat_entry (op_array -> opcodes , op_array -> opcodes );
432
445
}
433
446
434
- if (op_array -> literals && ! IS_SERIALIZED ( op_array -> literals ) ) {
447
+ if (op_array -> literals ) {
435
448
zval * p , * end ;
436
449
437
450
SERIALIZE_PTR (op_array -> literals );
@@ -444,7 +457,7 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
444
457
}
445
458
}
446
459
447
- if (! IS_SERIALIZED ( op_array -> opcodes )) {
460
+ {
448
461
zend_op * opline , * end ;
449
462
450
463
#if !ZEND_USE_ABS_CONST_ADDR
@@ -552,13 +565,6 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
552
565
SERIALIZE_STR (op_array -> doc_comment );
553
566
SERIALIZE_PTR (op_array -> try_catch_array );
554
567
SERIALIZE_PTR (op_array -> prototype );
555
-
556
- ZEND_MAP_PTR_INIT (op_array -> static_variables_ptr , & op_array -> static_variables );
557
- if (op_array -> fn_flags & ZEND_ACC_IMMUTABLE ) {
558
- ZEND_MAP_PTR_INIT (op_array -> run_time_cache , NULL );
559
- } else {
560
- SERIALIZE_PTR (ZEND_MAP_PTR (op_array -> run_time_cache ));
561
- }
562
568
}
563
569
}
564
570
@@ -1107,7 +1113,13 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
1107
1113
zend_persistent_script * script ,
1108
1114
void * buf )
1109
1115
{
1110
- if (op_array -> static_variables && !IS_UNSERIALIZED (op_array -> static_variables )) {
1116
+ /* Check whether this op_array has already been unserialized. */
1117
+ if (IS_UNSERIALIZED (op_array -> opcodes )) {
1118
+ ZEND_ASSERT (op_array -> scope && "Only method op_arrays should be shared" );
1119
+ return ;
1120
+ }
1121
+
1122
+ if (op_array -> static_variables ) {
1111
1123
HashTable * ht ;
1112
1124
1113
1125
UNSERIALIZE_PTR (op_array -> static_variables );
@@ -1116,6 +1128,26 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
1116
1128
script , buf , zend_file_cache_unserialize_zval , ZVAL_PTR_DTOR );
1117
1129
}
1118
1130
1131
+ if (op_array -> fn_flags & ZEND_ACC_IMMUTABLE ) {
1132
+ if (op_array -> static_variables ) {
1133
+ ZEND_MAP_PTR_NEW (op_array -> static_variables_ptr );
1134
+ } else {
1135
+ ZEND_MAP_PTR_INIT (op_array -> static_variables_ptr , & op_array -> static_variables );
1136
+ }
1137
+ ZEND_MAP_PTR_NEW (op_array -> run_time_cache );
1138
+ } else {
1139
+ ZEND_MAP_PTR_INIT (op_array -> static_variables_ptr , & op_array -> static_variables );
1140
+ if (ZEND_MAP_PTR (op_array -> run_time_cache )) {
1141
+ if (script -> corrupted ) {
1142
+ /* Not in SHM: Use serialized arena pointer. */
1143
+ UNSERIALIZE_PTR (ZEND_MAP_PTR (op_array -> run_time_cache ));
1144
+ } else {
1145
+ /* In SHM: Allocate new pointer. */
1146
+ ZEND_MAP_PTR_NEW (op_array -> run_time_cache );
1147
+ }
1148
+ }
1149
+ }
1150
+
1119
1151
if (op_array -> refcount ) {
1120
1152
op_array -> refcount = NULL ;
1121
1153
UNSERIALIZE_PTR (op_array -> literals );
@@ -1132,7 +1164,7 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
1132
1164
return ;
1133
1165
}
1134
1166
1135
- if (op_array -> literals && ! IS_UNSERIALIZED ( op_array -> literals ) ) {
1167
+ if (op_array -> literals ) {
1136
1168
zval * p , * end ;
1137
1169
1138
1170
UNSERIALIZE_PTR (op_array -> literals );
@@ -1144,7 +1176,7 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
1144
1176
}
1145
1177
}
1146
1178
1147
- if (! IS_UNSERIALIZED ( op_array -> opcodes )) {
1179
+ {
1148
1180
zend_op * opline , * end ;
1149
1181
1150
1182
UNSERIALIZE_PTR (op_array -> opcodes );
@@ -1244,26 +1276,6 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
1244
1276
UNSERIALIZE_STR (op_array -> doc_comment );
1245
1277
UNSERIALIZE_PTR (op_array -> try_catch_array );
1246
1278
UNSERIALIZE_PTR (op_array -> prototype );
1247
-
1248
- if (op_array -> fn_flags & ZEND_ACC_IMMUTABLE ) {
1249
- if (op_array -> static_variables ) {
1250
- ZEND_MAP_PTR_NEW (op_array -> static_variables_ptr );
1251
- } else {
1252
- ZEND_MAP_PTR_INIT (op_array -> static_variables_ptr , & op_array -> static_variables );
1253
- }
1254
- ZEND_MAP_PTR_NEW (op_array -> run_time_cache );
1255
- } else {
1256
- ZEND_MAP_PTR_INIT (op_array -> static_variables_ptr , & op_array -> static_variables );
1257
- if (ZEND_MAP_PTR (op_array -> run_time_cache )) {
1258
- if (script -> corrupted ) {
1259
- /* Not in SHM: Use serialized arena pointer. */
1260
- UNSERIALIZE_PTR (ZEND_MAP_PTR (op_array -> run_time_cache ));
1261
- } else {
1262
- /* In SHM: Allocate new pointer. */
1263
- ZEND_MAP_PTR_NEW (op_array -> run_time_cache );
1264
- }
1265
- }
1266
- }
1267
1279
}
1268
1280
}
1269
1281
0 commit comments