@@ -735,14 +735,16 @@ static void compiler_globals_ctor(zend_compiler_globals *compiler_globals) /* {{
735
735
compiler_globals -> map_ptr_base = ZEND_MAP_PTR_BIASED_BASE (NULL );
736
736
compiler_globals -> map_ptr_size = 0 ;
737
737
compiler_globals -> map_ptr_last = global_map_ptr_last ;
738
- if (compiler_globals -> map_ptr_last ) {
738
+ compiler_globals -> internal_run_time_cache = NULL ;
739
+ if (compiler_globals -> map_ptr_last || zend_map_ptr_static_size ) {
739
740
/* Allocate map_ptr table */
740
741
compiler_globals -> map_ptr_size = ZEND_MM_ALIGNED_SIZE_EX (compiler_globals -> map_ptr_last , 4096 );
741
- void * base = pemalloc (compiler_globals -> map_ptr_size * sizeof (void * ), 1 );
742
+ void * base = pemalloc (( zend_map_ptr_static_size + compiler_globals -> map_ptr_size ) * sizeof (void * ), 1 );
742
743
compiler_globals -> map_ptr_real_base = base ;
743
744
compiler_globals -> map_ptr_base = ZEND_MAP_PTR_BIASED_BASE (base );
744
- memset (base , 0 , compiler_globals -> map_ptr_last * sizeof (void * ));
745
+ memset (base , 0 , ( zend_map_ptr_static_size + compiler_globals -> map_ptr_last ) * sizeof (void * ));
745
746
}
747
+ zend_init_internal_run_time_cache ();
746
748
}
747
749
/* }}} */
748
750
@@ -785,6 +787,10 @@ static void compiler_globals_dtor(zend_compiler_globals *compiler_globals) /* {{
785
787
compiler_globals -> map_ptr_base = ZEND_MAP_PTR_BIASED_BASE (NULL );
786
788
compiler_globals -> map_ptr_size = 0 ;
787
789
}
790
+ if (compiler_globals -> internal_run_time_cache ) {
791
+ pefree (compiler_globals -> internal_run_time_cache , 1 );
792
+ compiler_globals -> internal_run_time_cache = NULL ;
793
+ }
788
794
}
789
795
/* }}} */
790
796
@@ -1115,6 +1121,10 @@ zend_result zend_post_startup(void) /* {{{ */
1115
1121
}
1116
1122
compiler_globals -> map_ptr_real_base = NULL ;
1117
1123
compiler_globals -> map_ptr_base = ZEND_MAP_PTR_BIASED_BASE (NULL );
1124
+ if (compiler_globals -> internal_run_time_cache ) {
1125
+ pefree (compiler_globals -> internal_run_time_cache , 1 );
1126
+ }
1127
+ compiler_globals -> internal_run_time_cache = NULL ;
1118
1128
if ((script_encoding_list = (zend_encoding * * )compiler_globals -> script_encoding_list )) {
1119
1129
compiler_globals_ctor (compiler_globals );
1120
1130
compiler_globals -> script_encoding_list = (const zend_encoding * * )script_encoding_list ;
@@ -1198,6 +1208,9 @@ void zend_shutdown(void) /* {{{ */
1198
1208
CG (script_encoding_list_size ) = 0 ;
1199
1209
}
1200
1210
#endif
1211
+ zend_map_ptr_static_last = 0 ;
1212
+ zend_map_ptr_static_size = 0 ;
1213
+
1201
1214
zend_destroy_rsrc_list_dtors ();
1202
1215
1203
1216
zend_unload_modules ();
@@ -1297,9 +1310,9 @@ ZEND_API void zend_activate(void) /* {{{ */
1297
1310
init_executor ();
1298
1311
startup_scanner ();
1299
1312
if (CG (map_ptr_last )) {
1300
- memset (CG (map_ptr_real_base ), 0 , CG (map_ptr_last ) * sizeof (void * ));
1313
+ memset (( void * * ) CG (map_ptr_real_base ) + zend_map_ptr_static_size , 0 , CG (map_ptr_last ) * sizeof (void * ));
1301
1314
}
1302
- zend_init_internal_run_time_cache ();
1315
+ zend_reset_internal_run_time_cache ();
1303
1316
zend_observer_activate ();
1304
1317
}
1305
1318
/* }}} */
@@ -1984,6 +1997,9 @@ void free_estring(char **str_p) /* {{{ */
1984
1997
}
1985
1998
/* }}} */
1986
1999
2000
+ ZEND_API size_t zend_map_ptr_static_size ;
2001
+ ZEND_API size_t zend_map_ptr_static_last ;
2002
+
1987
2003
ZEND_API void zend_map_ptr_reset (void )
1988
2004
{
1989
2005
CG (map_ptr_last ) = global_map_ptr_last ;
@@ -1996,15 +2012,36 @@ ZEND_API void *zend_map_ptr_new(void)
1996
2012
if (CG (map_ptr_last ) >= CG (map_ptr_size )) {
1997
2013
/* Grow map_ptr table */
1998
2014
CG (map_ptr_size ) = ZEND_MM_ALIGNED_SIZE_EX (CG (map_ptr_last ) + 1 , 4096 );
1999
- CG (map_ptr_real_base ) = perealloc (CG (map_ptr_real_base ), CG (map_ptr_size ) * sizeof (void * ), 1 );
2015
+ CG (map_ptr_real_base ) = perealloc (CG (map_ptr_real_base ), ( zend_map_ptr_static_size + CG (map_ptr_size ) ) * sizeof (void * ), 1 );
2000
2016
CG (map_ptr_base ) = ZEND_MAP_PTR_BIASED_BASE (CG (map_ptr_real_base ));
2001
2017
}
2002
- ptr = (void * * )CG (map_ptr_real_base ) + CG (map_ptr_last );
2018
+ ptr = (void * * )CG (map_ptr_real_base ) + zend_map_ptr_static_size + CG (map_ptr_last );
2003
2019
* ptr = NULL ;
2004
2020
CG (map_ptr_last )++ ;
2005
2021
return ZEND_MAP_PTR_PTR2OFFSET (ptr );
2006
2022
}
2007
2023
2024
+ ZEND_API void * zend_map_ptr_new_static (void )
2025
+ {
2026
+ void * * ptr ;
2027
+
2028
+ if (zend_map_ptr_static_last >= zend_map_ptr_static_size ) {
2029
+ zend_map_ptr_static_size += 4096 ;
2030
+ /* Grow map_ptr table */
2031
+ void * new_base = pemalloc ((zend_map_ptr_static_size + CG (map_ptr_size )) * sizeof (void * ), 1 );
2032
+ if (CG (map_ptr_real_base )) {
2033
+ memcpy ((void * * )new_base + 4096 , CG (map_ptr_real_base ), (CG (map_ptr_last ) + zend_map_ptr_static_size - 4096 ) * sizeof (void * ));
2034
+ pefree (CG (map_ptr_real_base ), 1 );
2035
+ }
2036
+ CG (map_ptr_real_base ) = new_base ;
2037
+ CG (map_ptr_base ) = ZEND_MAP_PTR_BIASED_BASE (new_base );
2038
+ }
2039
+ ptr = (void * * )CG (map_ptr_real_base ) + (zend_map_ptr_static_last & 4095 );
2040
+ * ptr = NULL ;
2041
+ zend_map_ptr_static_last ++ ;
2042
+ return ZEND_MAP_PTR_PTR2OFFSET (ptr );
2043
+ }
2044
+
2008
2045
ZEND_API void zend_map_ptr_extend (size_t last )
2009
2046
{
2010
2047
if (last > CG (map_ptr_last )) {
@@ -2013,10 +2050,10 @@ ZEND_API void zend_map_ptr_extend(size_t last)
2013
2050
if (last >= CG (map_ptr_size )) {
2014
2051
/* Grow map_ptr table */
2015
2052
CG (map_ptr_size ) = ZEND_MM_ALIGNED_SIZE_EX (last , 4096 );
2016
- CG (map_ptr_real_base ) = perealloc (CG (map_ptr_real_base ), CG (map_ptr_size ) * sizeof (void * ), 1 );
2053
+ CG (map_ptr_real_base ) = perealloc (CG (map_ptr_real_base ), ( zend_map_ptr_static_size + CG (map_ptr_size ) ) * sizeof (void * ), 1 );
2017
2054
CG (map_ptr_base ) = ZEND_MAP_PTR_BIASED_BASE (CG (map_ptr_real_base ));
2018
2055
}
2019
- ptr = (void * * )CG (map_ptr_real_base ) + CG (map_ptr_last );
2056
+ ptr = (void * * )CG (map_ptr_real_base ) + zend_map_ptr_static_size + CG (map_ptr_last );
2020
2057
memset (ptr , 0 , (last - CG (map_ptr_last )) * sizeof (void * ));
2021
2058
CG (map_ptr_last ) = last ;
2022
2059
}
0 commit comments