@@ -735,14 +735,16 @@ static void compiler_globals_ctor(zend_compiler_globals *compiler_globals) /* {{
735735 compiler_globals -> map_ptr_base = ZEND_MAP_PTR_BIASED_BASE (NULL );
736736 compiler_globals -> map_ptr_size = 0 ;
737737 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 ) {
739740 /* Allocate map_ptr table */
740741 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 );
742743 compiler_globals -> map_ptr_real_base = base ;
743744 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 * ));
745746 }
747+ zend_init_internal_run_time_cache ();
746748}
747749/* }}} */
748750
@@ -785,6 +787,10 @@ static void compiler_globals_dtor(zend_compiler_globals *compiler_globals) /* {{
785787 compiler_globals -> map_ptr_base = ZEND_MAP_PTR_BIASED_BASE (NULL );
786788 compiler_globals -> map_ptr_size = 0 ;
787789 }
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+ }
788794}
789795/* }}} */
790796
@@ -1115,6 +1121,10 @@ zend_result zend_post_startup(void) /* {{{ */
11151121 }
11161122 compiler_globals -> map_ptr_real_base = NULL ;
11171123 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 ;
11181128 if ((script_encoding_list = (zend_encoding * * )compiler_globals -> script_encoding_list )) {
11191129 compiler_globals_ctor (compiler_globals );
11201130 compiler_globals -> script_encoding_list = (const zend_encoding * * )script_encoding_list ;
@@ -1198,6 +1208,9 @@ void zend_shutdown(void) /* {{{ */
11981208 CG (script_encoding_list_size ) = 0 ;
11991209 }
12001210#endif
1211+ zend_map_ptr_static_last = 0 ;
1212+ zend_map_ptr_static_size = 0 ;
1213+
12011214 zend_destroy_rsrc_list_dtors ();
12021215
12031216 zend_unload_modules ();
@@ -1297,9 +1310,9 @@ ZEND_API void zend_activate(void) /* {{{ */
12971310 init_executor ();
12981311 startup_scanner ();
12991312 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 * ));
13011314 }
1302- zend_init_internal_run_time_cache ();
1315+ zend_reset_internal_run_time_cache ();
13031316 zend_observer_activate ();
13041317}
13051318/* }}} */
@@ -1984,6 +1997,9 @@ void free_estring(char **str_p) /* {{{ */
19841997}
19851998/* }}} */
19861999
2000+ ZEND_API size_t zend_map_ptr_static_size ;
2001+ ZEND_API size_t zend_map_ptr_static_last ;
2002+
19872003ZEND_API void zend_map_ptr_reset (void )
19882004{
19892005 CG (map_ptr_last ) = global_map_ptr_last ;
@@ -1996,15 +2012,36 @@ ZEND_API void *zend_map_ptr_new(void)
19962012 if (CG (map_ptr_last ) >= CG (map_ptr_size )) {
19972013 /* Grow map_ptr table */
19982014 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 );
20002016 CG (map_ptr_base ) = ZEND_MAP_PTR_BIASED_BASE (CG (map_ptr_real_base ));
20012017 }
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 );
20032019 * ptr = NULL ;
20042020 CG (map_ptr_last )++ ;
20052021 return ZEND_MAP_PTR_PTR2OFFSET (ptr );
20062022}
20072023
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+
20082045ZEND_API void zend_map_ptr_extend (size_t last )
20092046{
20102047 if (last > CG (map_ptr_last )) {
@@ -2013,10 +2050,10 @@ ZEND_API void zend_map_ptr_extend(size_t last)
20132050 if (last >= CG (map_ptr_size )) {
20142051 /* Grow map_ptr table */
20152052 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 );
20172054 CG (map_ptr_base ) = ZEND_MAP_PTR_BIASED_BASE (CG (map_ptr_real_base ));
20182055 }
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 );
20202057 memset (ptr , 0 , (last - CG (map_ptr_last )) * sizeof (void * ));
20212058 CG (map_ptr_last ) = last ;
20222059 }
0 commit comments