@@ -79,6 +79,13 @@ static void zend_hash_persist(HashTable *ht, zend_persist_func_t pPersistElement
79
79
HT_SET_DATA_ADDR (ht , & uninitialized_bucket );
80
80
return ;
81
81
}
82
+ if (ht -> nNumUsed == 0 ) {
83
+ efree (HT_GET_DATA_ADDR (ht ));
84
+ ht -> nTableMask = HT_MIN_MASK ;
85
+ HT_SET_DATA_ADDR (ht , & uninitialized_bucket );
86
+ ht -> u .flags &= ~HASH_FLAG_INITIALIZED ;
87
+ return ;
88
+ }
82
89
if (ht -> u .flags & HASH_FLAG_PACKED ) {
83
90
void * data = HT_GET_DATA_ADDR (ht );
84
91
zend_accel_store (data , HT_USED_SIZE (ht ));
@@ -92,7 +99,11 @@ static void zend_hash_persist(HashTable *ht, zend_persist_func_t pPersistElement
92
99
while (hash_size >> 1 > ht -> nNumUsed ) {
93
100
hash_size >>= 1 ;
94
101
}
102
+ if (hash_size < - HT_MIN_MASK ) {
103
+ hash_size = - HT_MIN_MASK ;
104
+ }
95
105
ht -> nTableMask = - hash_size ;
106
+ ZEND_ASSERT (((zend_uintptr_t )ZCG (mem ) & 0x7 ) == 0 ); /* should be 8 byte aligned */
96
107
HT_SET_DATA_ADDR (ht , ZCG (mem ));
97
108
ZCG (mem ) = (void * )((char * )ZCG (mem ) + ZEND_ALIGNED_SIZE ((hash_size * sizeof (uint32_t )) + (ht -> nNumUsed * sizeof (Bucket ))));
98
109
HT_HASH_RESET (ht );
@@ -120,6 +131,7 @@ static void zend_hash_persist(HashTable *ht, zend_persist_func_t pPersistElement
120
131
void * data = ZCG (mem );
121
132
void * old_data = HT_GET_DATA_ADDR (ht );
122
133
134
+ ZEND_ASSERT (((zend_uintptr_t )ZCG (mem ) & 0x7 ) == 0 ); /* should be 8 byte aligned */
123
135
ZCG (mem ) = (void * )((char * )data + HT_USED_SIZE (ht ));
124
136
memcpy (data , old_data , HT_USED_SIZE (ht ));
125
137
efree (old_data );
@@ -149,6 +161,13 @@ static void zend_hash_persist_immutable(HashTable *ht)
149
161
HT_SET_DATA_ADDR (ht , & uninitialized_bucket );
150
162
return ;
151
163
}
164
+ if (ht -> nNumUsed == 0 ) {
165
+ efree (HT_GET_DATA_ADDR (ht ));
166
+ ht -> nTableMask = HT_MIN_MASK ;
167
+ HT_SET_DATA_ADDR (ht , & uninitialized_bucket );
168
+ ht -> u .flags &= ~HASH_FLAG_INITIALIZED ;
169
+ return ;
170
+ }
152
171
if (ht -> u .flags & HASH_FLAG_PACKED ) {
153
172
HT_SET_DATA_ADDR (ht , zend_accel_memdup (HT_GET_DATA_ADDR (ht ), HT_USED_SIZE (ht )));
154
173
} else if (ht -> nNumUsed < - (int32_t )ht -> nTableMask / 2 ) {
@@ -160,7 +179,11 @@ static void zend_hash_persist_immutable(HashTable *ht)
160
179
while (hash_size >> 1 > ht -> nNumUsed ) {
161
180
hash_size >>= 1 ;
162
181
}
182
+ if (hash_size < - HT_MIN_MASK ) {
183
+ hash_size = - HT_MIN_MASK ;
184
+ }
163
185
ht -> nTableMask = - hash_size ;
186
+ ZEND_ASSERT (((zend_uintptr_t )ZCG (mem ) & 0x7 ) == 0 ); /* should be 8 byte aligned */
164
187
HT_SET_DATA_ADDR (ht , ZCG (mem ));
165
188
ZCG (mem ) = (void * )((char * )ZCG (mem ) + (hash_size * sizeof (uint32_t )) + (ht -> nNumUsed * sizeof (Bucket )));
166
189
HT_HASH_RESET (ht );
@@ -187,6 +210,7 @@ static void zend_hash_persist_immutable(HashTable *ht)
187
210
} else {
188
211
void * data = ZCG (mem );
189
212
213
+ ZEND_ASSERT (((zend_uintptr_t )ZCG (mem ) & 0x7 ) == 0 ); /* should be 8 byte aligned */
190
214
ZCG (mem ) = (void * )((char * )data + HT_USED_SIZE (ht ));
191
215
memcpy (data , HT_GET_DATA_ADDR (ht ), HT_USED_SIZE (ht ));
192
216
HT_SET_DATA_ADDR (ht , data );
@@ -869,6 +893,7 @@ zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script
869
893
{
870
894
script -> mem = ZCG (mem );
871
895
896
+ ZEND_ASSERT (((zend_uintptr_t )ZCG (mem ) & 0x7 ) == 0 ); /* should be 8 byte aligned */
872
897
zend_shared_alloc_clear_xlat_table ();
873
898
874
899
zend_accel_store (script , sizeof (zend_persistent_script ));
@@ -880,6 +905,8 @@ zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script
880
905
#ifdef __SSE2__
881
906
/* Align to 64-byte boundary */
882
907
ZCG (mem ) = (void * )(((zend_uintptr_t )ZCG (mem ) + 63L ) & ~63L );
908
+ #else
909
+ ZEND_ASSERT (((zend_uintptr_t )ZCG (mem ) & 0x7 ) == 0 ); /* should be 8 byte aligned */
883
910
#endif
884
911
885
912
script -> arena_mem = ZCG (arena_mem ) = ZCG (mem );
0 commit comments