@@ -94,6 +94,18 @@ static int zend_file_cache_flock(int fd, int type)
94
94
(((char*)(ptr) >= (char*)script->mem && (char*)(ptr) < (char*)script->mem + script->size) || \
95
95
IS_ACCEL_INTERNED(ptr))
96
96
#define SERIALIZE_PTR (ptr ) do { \
97
+ if (ptr) { \
98
+ ZEND_ASSERT(IS_UNSERIALIZED(ptr)); \
99
+ (ptr) = (void*)((char*)(ptr) - (char*)script->mem); \
100
+ } \
101
+ } while (0)
102
+ #define UNSERIALIZE_PTR (ptr ) do { \
103
+ if (ptr) { \
104
+ ZEND_ASSERT(IS_SERIALIZED(ptr)); \
105
+ (ptr) = (void*)((char*)buf + (size_t)(ptr)); \
106
+ } \
107
+ } while (0)
108
+ #define SERIALIZE_STR (ptr ) do { \
97
109
if (ptr) { \
98
110
if (IS_ACCEL_INTERNED(ptr)) { \
99
111
(ptr) = zend_file_cache_serialize_interned((zend_string*)(ptr), info); \
@@ -103,10 +115,10 @@ static int zend_file_cache_flock(int fd, int type)
103
115
} \
104
116
} \
105
117
} while (0)
106
- #define UNSERIALIZE_PTR (ptr ) do { \
118
+ #define UNSERIALIZE_STR (ptr ) do { \
107
119
if (ptr) { \
108
120
if (IS_SERIALIZED_INTERNED(ptr)) { \
109
- (ptr) = (void*)zend_file_cache_unserialize_interned((zend_string*)(ptr)); \
121
+ (ptr) = (void*)zend_file_cache_unserialize_interned((zend_string*)(ptr), script->corrupted ); \
110
122
} else { \
111
123
ZEND_ASSERT(IS_SERIALIZED(ptr)); \
112
124
(ptr) = (void*)((char*)buf + (size_t)(ptr)); \
@@ -190,15 +202,20 @@ static void *zend_file_cache_serialize_interned(zend_string *str,
190
202
return ret ;
191
203
}
192
204
193
- static void * zend_file_cache_unserialize_interned (zend_string * str )
205
+ static void * zend_file_cache_unserialize_interned (zend_string * str , int in_shm )
194
206
{
195
207
zend_string * ret ;
196
208
197
209
str = (zend_string * )((char * )ZCG (mem ) + ((size_t )(str ) & ~Z_UL (1 )));
198
210
ret = accel_new_interned_string (str );
199
211
if (ret == str ) {
200
212
/* String wasn't interned but we will use it as interned anyway */
201
- GC_FLAGS (ret ) |= IS_STR_INTERNED | IS_STR_PERMANENT ;
213
+ if (in_shm ) {
214
+ GC_FLAGS (ret ) |= IS_STR_INTERNED | IS_STR_PERMANENT ;
215
+ } else {
216
+ GC_FLAGS (ret ) |= IS_STR_INTERNED ;
217
+ GC_FLAGS (ret ) &= ~IS_STR_PERMANENT ;
218
+ }
202
219
}
203
220
return ret ;
204
221
}
@@ -224,7 +241,7 @@ static void zend_file_cache_serialize_hash(HashTable *ht,
224
241
end = p + ht -> nNumUsed ;
225
242
while (p < end ) {
226
243
if (Z_TYPE (p -> val ) != IS_UNDEF ) {
227
- SERIALIZE_PTR (p -> key );
244
+ SERIALIZE_STR (p -> key );
228
245
func (& p -> val , script , info , buf );
229
246
}
230
247
p ++ ;
@@ -272,7 +289,7 @@ static void zend_file_cache_serialize_zval(zval *zv,
272
289
case IS_STRING :
273
290
case IS_CONSTANT :
274
291
if (!IS_SERIALIZED (Z_STR_P (zv ))) {
275
- SERIALIZE_PTR (Z_STR_P (zv ));
292
+ SERIALIZE_STR (Z_STR_P (zv ));
276
293
}
277
294
break ;
278
295
case IS_ARRAY :
@@ -400,10 +417,10 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
400
417
}
401
418
while (p < end ) {
402
419
if (!IS_SERIALIZED (p -> name )) {
403
- SERIALIZE_PTR (p -> name );
420
+ SERIALIZE_STR (p -> name );
404
421
}
405
422
if (!IS_SERIALIZED (p -> class_name )) {
406
- SERIALIZE_PTR (p -> class_name );
423
+ SERIALIZE_STR (p -> class_name );
407
424
}
408
425
p ++ ;
409
426
}
@@ -418,17 +435,17 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
418
435
end = p + op_array -> last_var ;
419
436
while (p < end ) {
420
437
if (!IS_SERIALIZED (* p )) {
421
- SERIALIZE_PTR (* p );
438
+ SERIALIZE_STR (* p );
422
439
}
423
440
p ++ ;
424
441
}
425
442
}
426
443
427
- SERIALIZE_PTR (op_array -> function_name );
428
- SERIALIZE_PTR (op_array -> filename );
444
+ SERIALIZE_STR (op_array -> function_name );
445
+ SERIALIZE_STR (op_array -> filename );
429
446
SERIALIZE_PTR (op_array -> brk_cont_array );
430
447
SERIALIZE_PTR (op_array -> scope );
431
- SERIALIZE_PTR (op_array -> doc_comment );
448
+ SERIALIZE_STR (op_array -> doc_comment );
432
449
SERIALIZE_PTR (op_array -> try_catch_array );
433
450
SERIALIZE_PTR (op_array -> prototype );
434
451
}
@@ -463,10 +480,10 @@ static void zend_file_cache_serialize_prop_info(zval *zv,
463
480
SERIALIZE_PTR (prop -> ce );
464
481
}
465
482
if (prop -> name && !IS_SERIALIZED (prop -> name )) {
466
- SERIALIZE_PTR (prop -> name );
483
+ SERIALIZE_STR (prop -> name );
467
484
}
468
485
if (prop -> doc_comment && !IS_SERIALIZED (prop -> doc_comment )) {
469
- SERIALIZE_PTR (prop -> doc_comment );
486
+ SERIALIZE_STR (prop -> doc_comment );
470
487
}
471
488
}
472
489
}
@@ -482,7 +499,7 @@ static void zend_file_cache_serialize_class(zval *zv,
482
499
ce = Z_PTR_P (zv );
483
500
UNSERIALIZE_PTR (ce );
484
501
485
- SERIALIZE_PTR (ce -> name );
502
+ SERIALIZE_STR (ce -> name );
486
503
zend_file_cache_serialize_hash (& ce -> function_table , script , info , buf , zend_file_cache_serialize_func );
487
504
if (ce -> default_properties_table ) {
488
505
zval * p , * end ;
@@ -509,8 +526,8 @@ static void zend_file_cache_serialize_class(zval *zv,
509
526
}
510
527
}
511
528
zend_file_cache_serialize_hash (& ce -> constants_table , script , info , buf , zend_file_cache_serialize_zval );
512
- SERIALIZE_PTR (ZEND_CE_FILENAME (ce ));
513
- SERIALIZE_PTR (ZEND_CE_DOC_COMMENT (ce ));
529
+ SERIALIZE_STR (ZEND_CE_FILENAME (ce ));
530
+ SERIALIZE_STR (ZEND_CE_DOC_COMMENT (ce ));
514
531
zend_file_cache_serialize_hash (& ce -> properties_info , script , info , buf , zend_file_cache_serialize_prop_info );
515
532
516
533
if (ce -> trait_aliases ) {
@@ -533,15 +550,15 @@ static void zend_file_cache_serialize_class(zval *zv,
533
550
UNSERIALIZE_PTR (m );
534
551
535
552
if (m -> method_name ) {
536
- SERIALIZE_PTR (m -> method_name );
553
+ SERIALIZE_STR (m -> method_name );
537
554
}
538
555
if (m -> class_name ) {
539
- SERIALIZE_PTR (m -> class_name );
556
+ SERIALIZE_STR (m -> class_name );
540
557
}
541
558
}
542
559
543
560
if (q -> alias ) {
544
- SERIALIZE_PTR (q -> alias );
561
+ SERIALIZE_STR (q -> alias );
545
562
}
546
563
p ++ ;
547
564
}
@@ -567,10 +584,10 @@ static void zend_file_cache_serialize_class(zval *zv,
567
584
UNSERIALIZE_PTR (m );
568
585
569
586
if (m -> method_name ) {
570
- SERIALIZE_PTR (m -> method_name );
587
+ SERIALIZE_STR (m -> method_name );
571
588
}
572
589
if (m -> class_name ) {
573
- SERIALIZE_PTR (m -> class_name );
590
+ SERIALIZE_STR (m -> class_name );
574
591
}
575
592
}
576
593
@@ -582,7 +599,7 @@ static void zend_file_cache_serialize_class(zval *zv,
582
599
UNSERIALIZE_PTR (s );
583
600
584
601
while (* s ) {
585
- SERIALIZE_PTR (* s );
602
+ SERIALIZE_STR (* s );
586
603
s ++ ;
587
604
}
588
605
}
@@ -622,7 +639,7 @@ static void zend_file_cache_serialize(zend_persistent_script *script,
622
639
memcpy (buf , script -> mem , script -> size );
623
640
624
641
new_script = (zend_persistent_script * )((char * )buf + info -> script_offset );
625
- SERIALIZE_PTR (new_script -> full_path );
642
+ SERIALIZE_STR (new_script -> full_path );
626
643
627
644
zend_file_cache_serialize_hash (& new_script -> class_table , script , info , buf , zend_file_cache_serialize_class );
628
645
zend_file_cache_serialize_hash (& new_script -> function_table , script , info , buf , zend_file_cache_serialize_func );
@@ -754,7 +771,7 @@ static void zend_file_cache_unserialize_hash(HashTable *ht,
754
771
end = p + ht -> nNumUsed ;
755
772
while (p < end ) {
756
773
if (Z_TYPE (p -> val ) != IS_UNDEF ) {
757
- UNSERIALIZE_PTR (p -> key );
774
+ UNSERIALIZE_STR (p -> key );
758
775
func (& p -> val , script , buf );
759
776
}
760
777
p ++ ;
@@ -797,7 +814,7 @@ static void zend_file_cache_unserialize_zval(zval *zv,
797
814
case IS_STRING :
798
815
case IS_CONSTANT :
799
816
if (!IS_UNSERIALIZED (Z_STR_P (zv ))) {
800
- UNSERIALIZE_PTR (Z_STR_P (zv ));
817
+ UNSERIALIZE_STR (Z_STR_P (zv ));
801
818
}
802
819
break ;
803
820
case IS_ARRAY :
@@ -914,10 +931,10 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
914
931
}
915
932
while (p < end ) {
916
933
if (!IS_UNSERIALIZED (p -> name )) {
917
- UNSERIALIZE_PTR (p -> name );
934
+ UNSERIALIZE_STR (p -> name );
918
935
}
919
936
if (!IS_UNSERIALIZED (p -> class_name )) {
920
- UNSERIALIZE_PTR (p -> class_name );
937
+ UNSERIALIZE_STR (p -> class_name );
921
938
}
922
939
p ++ ;
923
940
}
@@ -931,17 +948,17 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
931
948
end = p + op_array -> last_var ;
932
949
while (p < end ) {
933
950
if (!IS_UNSERIALIZED (* p )) {
934
- UNSERIALIZE_PTR (* p );
951
+ UNSERIALIZE_STR (* p );
935
952
}
936
953
p ++ ;
937
954
}
938
955
}
939
956
940
- UNSERIALIZE_PTR (op_array -> function_name );
941
- UNSERIALIZE_PTR (op_array -> filename );
957
+ UNSERIALIZE_STR (op_array -> function_name );
958
+ UNSERIALIZE_STR (op_array -> filename );
942
959
UNSERIALIZE_PTR (op_array -> brk_cont_array );
943
960
UNSERIALIZE_PTR (op_array -> scope );
944
- UNSERIALIZE_PTR (op_array -> doc_comment );
961
+ UNSERIALIZE_STR (op_array -> doc_comment );
945
962
UNSERIALIZE_PTR (op_array -> try_catch_array );
946
963
UNSERIALIZE_PTR (op_array -> prototype );
947
964
}
@@ -972,10 +989,10 @@ static void zend_file_cache_unserialize_prop_info(zval *zv,
972
989
UNSERIALIZE_PTR (prop -> ce );
973
990
}
974
991
if (prop -> name && !IS_UNSERIALIZED (prop -> name )) {
975
- UNSERIALIZE_PTR (prop -> name );
992
+ UNSERIALIZE_STR (prop -> name );
976
993
}
977
994
if (prop -> doc_comment && !IS_UNSERIALIZED (prop -> doc_comment )) {
978
- UNSERIALIZE_PTR (prop -> doc_comment );
995
+ UNSERIALIZE_STR (prop -> doc_comment );
979
996
}
980
997
}
981
998
}
@@ -989,7 +1006,7 @@ static void zend_file_cache_unserialize_class(zval *zv,
989
1006
UNSERIALIZE_PTR (Z_PTR_P (zv ));
990
1007
ce = Z_PTR_P (zv );
991
1008
992
- UNSERIALIZE_PTR (ce -> name );
1009
+ UNSERIALIZE_STR (ce -> name );
993
1010
zend_file_cache_unserialize_hash (& ce -> function_table , script , buf , zend_file_cache_unserialize_func );
994
1011
if (ce -> default_properties_table ) {
995
1012
zval * p , * end ;
@@ -1014,8 +1031,8 @@ static void zend_file_cache_unserialize_class(zval *zv,
1014
1031
}
1015
1032
}
1016
1033
zend_file_cache_unserialize_hash (& ce -> constants_table , script , buf , zend_file_cache_unserialize_zval );
1017
- UNSERIALIZE_PTR (ZEND_CE_FILENAME (ce ));
1018
- UNSERIALIZE_PTR (ZEND_CE_DOC_COMMENT (ce ));
1034
+ UNSERIALIZE_STR (ZEND_CE_FILENAME (ce ));
1035
+ UNSERIALIZE_STR (ZEND_CE_DOC_COMMENT (ce ));
1019
1036
zend_file_cache_unserialize_hash (& ce -> properties_info , script , buf , zend_file_cache_unserialize_prop_info );
1020
1037
1021
1038
if (ce -> trait_aliases ) {
@@ -1035,15 +1052,15 @@ static void zend_file_cache_unserialize_class(zval *zv,
1035
1052
m = q -> trait_method ;
1036
1053
1037
1054
if (m -> method_name ) {
1038
- UNSERIALIZE_PTR (m -> method_name );
1055
+ UNSERIALIZE_STR (m -> method_name );
1039
1056
}
1040
1057
if (m -> class_name ) {
1041
- UNSERIALIZE_PTR (m -> class_name );
1058
+ UNSERIALIZE_STR (m -> class_name );
1042
1059
}
1043
1060
}
1044
1061
1045
1062
if (q -> alias ) {
1046
- UNSERIALIZE_PTR (q -> alias );
1063
+ UNSERIALIZE_STR (q -> alias );
1047
1064
}
1048
1065
p ++ ;
1049
1066
}
@@ -1066,10 +1083,10 @@ static void zend_file_cache_unserialize_class(zval *zv,
1066
1083
m = q -> trait_method ;
1067
1084
1068
1085
if (m -> method_name ) {
1069
- UNSERIALIZE_PTR (m -> method_name );
1086
+ UNSERIALIZE_STR (m -> method_name );
1070
1087
}
1071
1088
if (m -> class_name ) {
1072
- UNSERIALIZE_PTR (m -> class_name );
1089
+ UNSERIALIZE_STR (m -> class_name );
1073
1090
}
1074
1091
}
1075
1092
@@ -1080,7 +1097,7 @@ static void zend_file_cache_unserialize_class(zval *zv,
1080
1097
s = (zend_string * * )q -> exclude_from_classes ;
1081
1098
1082
1099
while (* s ) {
1083
- UNSERIALIZE_PTR (* s );
1100
+ UNSERIALIZE_STR (* s );
1084
1101
s ++ ;
1085
1102
}
1086
1103
}
@@ -1109,7 +1126,7 @@ static void zend_file_cache_unserialize(zend_persistent_script *script,
1109
1126
{
1110
1127
script -> mem = buf ;
1111
1128
1112
- UNSERIALIZE_PTR (script -> full_path );
1129
+ UNSERIALIZE_STR (script -> full_path );
1113
1130
1114
1131
zend_file_cache_unserialize_hash (& script -> class_table , script , buf , zend_file_cache_unserialize_class );
1115
1132
zend_file_cache_unserialize_hash (& script -> function_table , script , buf , zend_file_cache_unserialize_func );
@@ -1266,7 +1283,9 @@ zend_persistent_script *zend_file_cache_script_load(zend_file_handle *file_handl
1266
1283
1267
1284
ZCG (mem ) = ((char * )mem + info .mem_size );
1268
1285
script = (zend_persistent_script * )((char * )buf + info .script_offset );
1286
+ script -> corrupted = cache_it ; /* used to check if script restored to SHM or process memory */
1269
1287
zend_file_cache_unserialize (script , buf );
1288
+ script -> corrupted = 0 ;
1270
1289
1271
1290
if (cache_it ) {
1272
1291
script -> dynamic_members .checksum = zend_accel_script_checksum (script );
0 commit comments