@@ -404,22 +404,22 @@ static inline void accel_unlock_all(void)
404404#define STRTAB_INVALID_POS 0
405405
406406#define STRTAB_HASH_TO_SLOT (tab , h ) \
407- ((uint32_t *)((char*)(tab) + sizeof(*(tab)) + ((h) & (tab)->nTableMask)))
407+ ((zend_string_table_pos_t *)((char*)(tab) + sizeof(*(tab)) + ((h) & (tab)->nTableMask)))
408408#define STRTAB_STR_TO_POS (tab , s ) \
409- ((uint32_t )((char*)s - (char*)(tab)))
409+ ((zend_string_table_pos_t )((( char*)s - (char*)(tab)) / ZEND_STRING_TABLE_POS_ALIGNMENT ))
410410#define STRTAB_POS_TO_STR (tab , pos ) \
411- ((zend_string*)((char*)(tab) + (pos)))
411+ ((zend_string*)((char*)(tab) + ((uintptr_t)( pos) * ZEND_STRING_TABLE_POS_ALIGNMENT )))
412412#define STRTAB_COLLISION (s ) \
413- (*((uint32_t *)((char*)s - sizeof(uint32_t ))))
413+ (*((zend_string_table_pos_t *)((char*)s - sizeof(zend_string_table_pos_t ))))
414414#define STRTAB_STR_SIZE (s ) \
415- ZEND_MM_ALIGNED_SIZE_EX(_ZSTR_HEADER_SIZE + ZSTR_LEN(s) + 5, 8 )
415+ ZEND_MM_ALIGNED_SIZE_EX(_ZSTR_STRUCT_SIZE( ZSTR_LEN(s)) + sizeof(zend_string_table_pos_t), ZEND_STRING_TABLE_POS_ALIGNMENT )
416416#define STRTAB_NEXT (s ) \
417417 ((zend_string*)((char*)(s) + STRTAB_STR_SIZE(s)))
418418
419419static void accel_interned_strings_restore_state (void )
420420{
421421 zend_string * s , * top ;
422- uint32_t * hash_slot , n ;
422+ zend_string_table_pos_t * hash_slot , n ;
423423
424424 /* clear removed content */
425425 memset (ZCSG (interned_strings ).saved_top ,
@@ -465,7 +465,7 @@ static void accel_interned_strings_save_state(void)
465465static zend_always_inline zend_string * accel_find_interned_string (zend_string * str )
466466{
467467 zend_ulong h ;
468- uint32_t pos ;
468+ zend_string_table_pos_t pos ;
469469 zend_string * s ;
470470
471471 if (IS_ACCEL_INTERNED (str )) {
@@ -500,7 +500,7 @@ static zend_always_inline zend_string *accel_find_interned_string(zend_string *s
500500zend_string * ZEND_FASTCALL accel_new_interned_string (zend_string * str )
501501{
502502 zend_ulong h ;
503- uint32_t pos , * hash_slot ;
503+ zend_string_table_pos_t pos , * hash_slot ;
504504 zend_string * s ;
505505
506506 if (UNEXPECTED (file_cache_only )) {
@@ -575,7 +575,7 @@ static zend_string* ZEND_FASTCALL accel_new_interned_string_for_php(zend_string
575575
576576static zend_always_inline zend_string * accel_find_interned_string_ex (zend_ulong h , const char * str , size_t size )
577577{
578- uint32_t pos ;
578+ zend_string_table_pos_t pos ;
579579 zend_string * s ;
580580
581581 /* check for existing interned string */
@@ -2842,7 +2842,7 @@ static zend_result zend_accel_init_shm(void)
28422842 } else {
28432843 /* Make sure there is always at least one interned string hash slot,
28442844 * so the table can be queried unconditionally. */
2845- accel_shared_globals_size = sizeof (zend_accel_shared_globals ) + sizeof (uint32_t );
2845+ accel_shared_globals_size = sizeof (zend_accel_shared_globals ) + sizeof (zend_string_table_pos_t );
28462846 }
28472847
28482848 accel_shared_globals = zend_shared_alloc (accel_shared_globals_size );
@@ -2869,18 +2869,22 @@ static zend_result zend_accel_init_shm(void)
28692869 hash_size |= (hash_size >> 8 );
28702870 hash_size |= (hash_size >> 16 );
28712871
2872- ZCSG (interned_strings ).nTableMask = hash_size << 2 ;
2872+ ZCSG (interned_strings ).nTableMask =
2873+ hash_size * sizeof (zend_string_table_pos_t );
28732874 ZCSG (interned_strings ).nNumOfElements = 0 ;
28742875 ZCSG (interned_strings ).start =
28752876 (zend_string * )((char * )& ZCSG (interned_strings ) +
28762877 sizeof (zend_string_table ) +
2877- ((hash_size + 1 ) * sizeof (uint32_t ))) +
2878+ ((hash_size + 1 ) * sizeof (zend_string_table_pos_t ))) +
28782879 8 ;
2880+ ZEND_ASSERT (((uintptr_t )ZCSG (interned_strings ).start & 0x7 ) == 0 ); /* should be 8 byte aligned */
2881+
28792882 ZCSG (interned_strings ).top =
28802883 ZCSG (interned_strings ).start ;
28812884 ZCSG (interned_strings ).end =
28822885 (zend_string * )((char * )(accel_shared_globals + 1 ) + /* table data is stored after accel_shared_globals */
28832886 ZCG (accel_directives ).interned_strings_buffer * 1024 * 1024 );
2887+ ZEND_ASSERT (((uintptr_t )ZCSG (interned_strings ).end - (uintptr_t )& ZCSG (interned_strings )) / ZEND_STRING_TABLE_POS_ALIGNMENT < ZEND_STRING_TABLE_POS_MAX );
28842888 ZCSG (interned_strings ).saved_top = NULL ;
28852889
28862890 memset ((char * )& ZCSG (interned_strings ) + sizeof (zend_string_table ),
0 commit comments