@@ -145,6 +145,8 @@ static void preload_restart(void);
145145# define LOCKVAL (v ) (ZCSG(v))
146146#endif
147147
148+ #define ZCG_KEY_LEN (MAXPATHLEN * 8)
149+
148150/**
149151 * Clear AVX/SSE2-aligned memory.
150152 */
@@ -1194,7 +1196,8 @@ zend_string *accel_make_persistent_key(zend_string *str)
11941196 char * key ;
11951197 int key_length ;
11961198
1197- ZSTR_LEN (& ZCG (key )) = 0 ;
1199+ ZEND_ASSERT (GC_REFCOUNT (ZCG (key )) == 1 );
1200+ ZSTR_LEN (ZCG (key )) = 0 ;
11981201
11991202 /* CWD and include_path don't matter for absolute file names and streams */
12001203 if (IS_ABSOLUTE_PATH (path , path_length )) {
@@ -1304,7 +1307,7 @@ zend_string *accel_make_persistent_key(zend_string *str)
13041307 }
13051308
13061309 /* Calculate key length */
1307- if (UNEXPECTED ((size_t )(cwd_len + path_length + include_path_len + 2 ) >= sizeof ( ZCG ( _key )) )) {
1310+ if (UNEXPECTED ((size_t )(cwd_len + path_length + include_path_len + 2 ) >= ZCG_KEY_LEN )) {
13081311 return NULL ;
13091312 }
13101313
@@ -1313,7 +1316,7 @@ zend_string *accel_make_persistent_key(zend_string *str)
13131316 * since in itself, it may include colons (which we use to separate
13141317 * different components of the key)
13151318 */
1316- key = ZSTR_VAL (& ZCG (key ));
1319+ key = ZSTR_VAL (ZCG (key ));
13171320 memcpy (key , path , path_length );
13181321 key [path_length ] = ':' ;
13191322 key_length = path_length + 1 ;
@@ -1337,7 +1340,7 @@ zend_string *accel_make_persistent_key(zend_string *str)
13371340 parent_script_len = ZSTR_LEN (parent_script );
13381341 while ((-- parent_script_len > 0 ) && !IS_SLASH (ZSTR_VAL (parent_script )[parent_script_len ]));
13391342
1340- if (UNEXPECTED ((size_t )(key_length + parent_script_len + 1 ) >= sizeof ( ZCG ( _key )) )) {
1343+ if (UNEXPECTED ((size_t )(key_length + parent_script_len + 1 ) >= ZCG_KEY_LEN )) {
13411344 return NULL ;
13421345 }
13431346 key [key_length ] = ':' ;
@@ -1346,11 +1349,9 @@ zend_string *accel_make_persistent_key(zend_string *str)
13461349 key_length += parent_script_len ;
13471350 }
13481351 key [key_length ] = '\0' ;
1349- GC_SET_REFCOUNT (& ZCG (key ), 1 );
1350- GC_TYPE_INFO (& ZCG (key )) = GC_STRING ;
1351- ZSTR_H (& ZCG (key )) = 0 ;
1352- ZSTR_LEN (& ZCG (key )) = key_length ;
1353- return & ZCG (key );
1352+ ZSTR_H (ZCG (key )) = 0 ;
1353+ ZSTR_LEN (ZCG (key )) = key_length ;
1354+ return ZCG (key );
13541355 }
13551356
13561357 /* not use_cwd */
@@ -2025,8 +2026,8 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
20252026 ZCG (cache_opline ) == EG (current_execute_data )-> opline ))) {
20262027
20272028 persistent_script = ZCG (cache_persistent_script );
2028- if (ZSTR_LEN (& ZCG (key ))) {
2029- key = & ZCG (key );
2029+ if (ZSTR_LEN (ZCG (key ))) {
2030+ key = ZCG (key );
20302031 }
20312032
20322033 } else {
@@ -2579,7 +2580,7 @@ static zend_string* persistent_zend_resolve_path(zend_string *filename)
25792580 SHM_PROTECT ();
25802581 HANDLE_UNBLOCK_INTERRUPTIONS ();
25812582 } else {
2582- ZSTR_LEN (& ZCG (key )) = 0 ;
2583+ ZSTR_LEN (ZCG (key )) = 0 ;
25832584 }
25842585 ZCG (cache_opline ) = EG (current_execute_data ) ? EG (current_execute_data )-> opline : NULL ;
25852586 ZCG (cache_persistent_script ) = persistent_script ;
@@ -2951,7 +2952,15 @@ static void accel_globals_ctor(zend_accel_globals *accel_globals)
29512952 ZEND_TSRMLS_CACHE_UPDATE ();
29522953#endif
29532954 memset (accel_globals , 0 , sizeof (zend_accel_globals ));
2955+ accel_globals -> key = zend_string_alloc (ZCG_KEY_LEN , true);
2956+ }
2957+
2958+ #ifdef ZTS
2959+ static void accel_globals_dtor (zend_accel_globals * accel_globals )
2960+ {
2961+ zend_string_free (accel_globals -> key );
29542962}
2963+ #endif
29552964
29562965#ifdef HAVE_HUGE_CODE_PAGES
29572966# ifndef _WIN32
@@ -3127,7 +3136,7 @@ static void accel_move_code_to_huge_pages(void)
31273136static int accel_startup (zend_extension * extension )
31283137{
31293138#ifdef ZTS
3130- accel_globals_id = ts_allocate_id (& accel_globals_id , sizeof (zend_accel_globals ), (ts_allocate_ctor ) accel_globals_ctor , NULL );
3139+ accel_globals_id = ts_allocate_id (& accel_globals_id , sizeof (zend_accel_globals ), (ts_allocate_ctor ) accel_globals_ctor , ( ts_allocate_dtor ) accel_globals_dtor );
31313140#else
31323141 accel_globals_ctor (& accel_globals );
31333142#endif
0 commit comments