@@ -449,7 +449,13 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
449
449
zend_file_cache_metainfo * info ,
450
450
void * buf )
451
451
{
452
- if (op_array -> static_variables && !IS_SERIALIZED (op_array -> static_variables )) {
452
+ /* Check whether this op_array has already been serialized. */
453
+ if (IS_SERIALIZED (op_array -> opcodes )) {
454
+ ZEND_ASSERT (op_array -> scope && "Only method op_arrays should be shared" );
455
+ return ;
456
+ }
457
+
458
+ if (op_array -> static_variables ) {
453
459
HashTable * ht ;
454
460
455
461
SERIALIZE_PTR (op_array -> static_variables );
@@ -458,7 +464,14 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
458
464
zend_file_cache_serialize_hash (ht , script , info , buf , zend_file_cache_serialize_zval );
459
465
}
460
466
461
- if (op_array -> scope && !IS_SERIALIZED (op_array -> opcodes )) {
467
+ ZEND_MAP_PTR_INIT (op_array -> static_variables_ptr , & op_array -> static_variables );
468
+ if (op_array -> fn_flags & ZEND_ACC_IMMUTABLE ) {
469
+ ZEND_MAP_PTR_INIT (op_array -> run_time_cache , NULL );
470
+ } else {
471
+ SERIALIZE_PTR (ZEND_MAP_PTR (op_array -> run_time_cache ));
472
+ }
473
+
474
+ if (op_array -> scope ) {
462
475
if (UNEXPECTED (zend_shared_alloc_get_xlat_entry (op_array -> opcodes ))) {
463
476
op_array -> refcount = (uint32_t * )(intptr_t )-1 ;
464
477
SERIALIZE_PTR (op_array -> literals );
@@ -478,7 +491,7 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
478
491
zend_shared_alloc_register_xlat_entry (op_array -> opcodes , op_array -> opcodes );
479
492
}
480
493
481
- if (op_array -> literals && ! IS_SERIALIZED ( op_array -> literals ) ) {
494
+ if (op_array -> literals ) {
482
495
zval * p , * end ;
483
496
484
497
SERIALIZE_PTR (op_array -> literals );
@@ -491,7 +504,7 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
491
504
}
492
505
}
493
506
494
- if (! IS_SERIALIZED ( op_array -> opcodes )) {
507
+ {
495
508
zend_op * opline , * end ;
496
509
497
510
#if !ZEND_USE_ABS_CONST_ADDR
@@ -602,13 +615,6 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
602
615
SERIALIZE_ATTRIBUTES (op_array -> attributes );
603
616
SERIALIZE_PTR (op_array -> try_catch_array );
604
617
SERIALIZE_PTR (op_array -> prototype );
605
-
606
- ZEND_MAP_PTR_INIT (op_array -> static_variables_ptr , & op_array -> static_variables );
607
- if (op_array -> fn_flags & ZEND_ACC_IMMUTABLE ) {
608
- ZEND_MAP_PTR_INIT (op_array -> run_time_cache , NULL );
609
- } else {
610
- SERIALIZE_PTR (ZEND_MAP_PTR (op_array -> run_time_cache ));
611
- }
612
618
}
613
619
}
614
620
@@ -1213,7 +1219,13 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
1213
1219
zend_persistent_script * script ,
1214
1220
void * buf )
1215
1221
{
1216
- if (op_array -> static_variables && !IS_UNSERIALIZED (op_array -> static_variables )) {
1222
+ /* Check whether this op_array has already been unserialized. */
1223
+ if (IS_UNSERIALIZED (op_array -> opcodes )) {
1224
+ ZEND_ASSERT (op_array -> scope && "Only method op_arrays should be shared" );
1225
+ return ;
1226
+ }
1227
+
1228
+ if (op_array -> static_variables ) {
1217
1229
HashTable * ht ;
1218
1230
1219
1231
UNSERIALIZE_PTR (op_array -> static_variables );
@@ -1222,6 +1234,26 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
1222
1234
script , buf , zend_file_cache_unserialize_zval , ZVAL_PTR_DTOR );
1223
1235
}
1224
1236
1237
+ if (op_array -> fn_flags & ZEND_ACC_IMMUTABLE ) {
1238
+ if (op_array -> static_variables ) {
1239
+ ZEND_MAP_PTR_NEW (op_array -> static_variables_ptr );
1240
+ } else {
1241
+ ZEND_MAP_PTR_INIT (op_array -> static_variables_ptr , & op_array -> static_variables );
1242
+ }
1243
+ ZEND_MAP_PTR_NEW (op_array -> run_time_cache );
1244
+ } else {
1245
+ ZEND_MAP_PTR_INIT (op_array -> static_variables_ptr , & op_array -> static_variables );
1246
+ if (ZEND_MAP_PTR (op_array -> run_time_cache )) {
1247
+ if (script -> corrupted ) {
1248
+ /* Not in SHM: Use serialized arena pointer. */
1249
+ UNSERIALIZE_PTR (ZEND_MAP_PTR (op_array -> run_time_cache ));
1250
+ } else {
1251
+ /* In SHM: Allocate new pointer. */
1252
+ ZEND_MAP_PTR_NEW (op_array -> run_time_cache );
1253
+ }
1254
+ }
1255
+ }
1256
+
1225
1257
if (op_array -> refcount ) {
1226
1258
op_array -> refcount = NULL ;
1227
1259
UNSERIALIZE_PTR (op_array -> literals );
@@ -1239,7 +1271,7 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
1239
1271
return ;
1240
1272
}
1241
1273
1242
- if (op_array -> literals && ! IS_UNSERIALIZED ( op_array -> literals ) ) {
1274
+ if (op_array -> literals ) {
1243
1275
zval * p , * end ;
1244
1276
1245
1277
UNSERIALIZE_PTR (op_array -> literals );
@@ -1251,7 +1283,7 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
1251
1283
}
1252
1284
}
1253
1285
1254
- if (! IS_UNSERIALIZED ( op_array -> opcodes )) {
1286
+ {
1255
1287
zend_op * opline , * end ;
1256
1288
1257
1289
UNSERIALIZE_PTR (op_array -> opcodes );
@@ -1353,26 +1385,6 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
1353
1385
UNSERIALIZE_ATTRIBUTES (op_array -> attributes );
1354
1386
UNSERIALIZE_PTR (op_array -> try_catch_array );
1355
1387
UNSERIALIZE_PTR (op_array -> prototype );
1356
-
1357
- if (op_array -> fn_flags & ZEND_ACC_IMMUTABLE ) {
1358
- if (op_array -> static_variables ) {
1359
- ZEND_MAP_PTR_NEW (op_array -> static_variables_ptr );
1360
- } else {
1361
- ZEND_MAP_PTR_INIT (op_array -> static_variables_ptr , & op_array -> static_variables );
1362
- }
1363
- ZEND_MAP_PTR_NEW (op_array -> run_time_cache );
1364
- } else {
1365
- ZEND_MAP_PTR_INIT (op_array -> static_variables_ptr , & op_array -> static_variables );
1366
- if (ZEND_MAP_PTR (op_array -> run_time_cache )) {
1367
- if (script -> corrupted ) {
1368
- /* Not in SHM: Use serialized arena pointer. */
1369
- UNSERIALIZE_PTR (ZEND_MAP_PTR (op_array -> run_time_cache ));
1370
- } else {
1371
- /* In SHM: Allocate new pointer. */
1372
- ZEND_MAP_PTR_NEW (op_array -> run_time_cache );
1373
- }
1374
- }
1375
- }
1376
1388
}
1377
1389
}
1378
1390
0 commit comments