@@ -2614,6 +2614,7 @@ static void zend_reset_cache_vars(void)
26142614 ZCSG (restart_pending ) = false;
26152615 ZCSG (force_restart_time ) = 0 ;
26162616 ZCSG (map_ptr_last ) = CG (map_ptr_last );
2617+ ZCSG (map_ptr_static_last ) = zend_map_ptr_static_last ;
26172618}
26182619
26192620static void accel_reset_pcre_cache (void )
@@ -2629,7 +2630,7 @@ static void accel_reset_pcre_cache(void)
26292630 } ZEND_HASH_FOREACH_END ();
26302631}
26312632
2632- zend_result accel_activate ( INIT_FUNC_ARGS )
2633+ ZEND_RINIT_FUNCTION ( zend_accelerator )
26332634{
26342635 if (!ZCG (enabled ) || !accel_startup_ok ) {
26352636 ZCG (accelerator_enabled ) = false;
@@ -2961,12 +2962,15 @@ static void accel_globals_ctor(zend_accel_globals *accel_globals)
29612962 GC_MAKE_PERSISTENT_LOCAL (accel_globals -> key );
29622963}
29632964
2964- #ifdef ZTS
29652965static void accel_globals_dtor (zend_accel_globals * accel_globals )
29662966{
2967+ #ifdef ZTS
29672968 zend_string_free (accel_globals -> key );
2968- }
29692969#endif
2970+ if (accel_globals -> preloaded_internal_run_time_cache ) {
2971+ pefree (accel_globals -> preloaded_internal_run_time_cache , 1 );
2972+ }
2973+ }
29702974
29712975#ifdef HAVE_HUGE_CODE_PAGES
29722976# ifndef _WIN32
@@ -3407,6 +3411,8 @@ void accel_shutdown(void)
34073411 if (!ZCG (enabled ) || !accel_startup_ok ) {
34083412#ifdef ZTS
34093413 ts_free_id (accel_globals_id );
3414+ #else
3415+ accel_globals_dtor (& accel_globals );
34103416#endif
34113417 return ;
34123418 }
@@ -3421,6 +3427,8 @@ void accel_shutdown(void)
34213427
34223428#ifdef ZTS
34233429 ts_free_id (accel_globals_id );
3430+ #else
3431+ accel_globals_dtor (& accel_globals );
34243432#endif
34253433
34263434 if (!_file_cache_only ) {
@@ -4318,7 +4326,7 @@ static zend_persistent_script* preload_script_in_shared_memory(zend_persistent_s
43184326 return new_persistent_script ;
43194327}
43204328
4321- static void preload_load (void )
4329+ static void preload_load (size_t orig_map_ptr_static_last )
43224330{
43234331 /* Load into process tables */
43244332 zend_script * script = & ZCSG (preload_script )-> script ;
@@ -4353,14 +4361,42 @@ static void preload_load(void)
43534361 if (EG (class_table )) {
43544362 EG (persistent_classes_count ) = EG (class_table )-> nNumUsed ;
43554363 }
4356- if (CG (map_ptr_last ) != ZCSG (map_ptr_last )) {
4357- size_t old_map_ptr_last = CG (map_ptr_last );
4364+
4365+ size_t old_map_ptr_last = CG (map_ptr_last );
4366+ if (zend_map_ptr_static_last != ZCSG (map_ptr_static_last ) || old_map_ptr_last != ZCSG (map_ptr_last )) {
43584367 CG (map_ptr_last ) = ZCSG (map_ptr_last );
4359- CG (map_ptr_size ) = ZEND_MM_ALIGNED_SIZE_EX (CG (map_ptr_last ) + 1 , 4096 );
4360- CG (map_ptr_real_base ) = perealloc (CG (map_ptr_real_base ), CG (map_ptr_size ) * sizeof (void * ), 1 );
4368+ CG (map_ptr_size ) = ZEND_MM_ALIGNED_SIZE_EX (ZCSG (map_ptr_last ) + 1 , 4096 );
4369+ zend_map_ptr_static_last = ZCSG (map_ptr_static_last );
4370+
4371+ /* Grow map_ptr table as needed, but allocate once for static + regular map_ptrs */
4372+ size_t new_static_size = ZEND_MM_ALIGNED_SIZE_EX (zend_map_ptr_static_last , 4096 );
4373+ if (zend_map_ptr_static_size != new_static_size ) {
4374+ void * new_base = pemalloc ((new_static_size + CG (map_ptr_size )) * sizeof (void * ), 1 );
4375+ if (CG (map_ptr_real_base )) {
4376+ memcpy ((void * * ) new_base + new_static_size - zend_map_ptr_static_size , CG (map_ptr_real_base ), (old_map_ptr_last + zend_map_ptr_static_size ) * sizeof (void * ));
4377+ pefree (CG (map_ptr_real_base ), 1 );
4378+ }
4379+ CG (map_ptr_real_base ) = new_base ;
4380+ zend_map_ptr_static_size = new_static_size ;
4381+ } else {
4382+ CG (map_ptr_real_base ) = perealloc (CG (map_ptr_real_base ), (zend_map_ptr_static_size + CG (map_ptr_size )) * sizeof (void * ), 1 );
4383+ }
4384+
4385+ memset ((void * * ) CG (map_ptr_real_base ) + zend_map_ptr_static_size + old_map_ptr_last , 0 , (CG (map_ptr_last ) - old_map_ptr_last ) * sizeof (void * ));
43614386 CG (map_ptr_base ) = ZEND_MAP_PTR_BIASED_BASE (CG (map_ptr_real_base ));
4362- memset ((void * * ) CG (map_ptr_real_base ) + old_map_ptr_last , 0 ,
4363- (CG (map_ptr_last ) - old_map_ptr_last ) * sizeof (void * ));
4387+ }
4388+
4389+ if (orig_map_ptr_static_last != zend_map_ptr_static_last ) {
4390+ /* preloaded static entries currently are all runtime cache pointers, just assign them as such */
4391+ size_t runtime_cache_size = zend_internal_run_time_cache_reserved_size ();
4392+ ZCG (preloaded_internal_run_time_cache_size ) = (zend_map_ptr_static_last - orig_map_ptr_static_last ) * runtime_cache_size ;
4393+ char * cache = pemalloc (ZCG (preloaded_internal_run_time_cache_size ), 1 );
4394+ ZCG (preloaded_internal_run_time_cache ) = cache ;
4395+
4396+ for (size_t cur_static_map_ptr = orig_map_ptr_static_last ; cur_static_map_ptr < zend_map_ptr_static_last ; ++ cur_static_map_ptr ) {
4397+ * ZEND_MAP_PTR_STATIC_NUM_TO_PTR (cur_static_map_ptr ) = cache ;
4398+ cache += runtime_cache_size ;
4399+ }
43644400 }
43654401}
43664402
@@ -4369,7 +4405,7 @@ static zend_result accel_preload(const char *config, bool in_child)
43694405 zend_file_handle file_handle ;
43704406 zend_result ret ;
43714407 char * orig_open_basedir ;
4372- size_t orig_map_ptr_last ;
4408+ size_t orig_map_ptr_last , orig_map_ptr_static_last ;
43734409 uint32_t orig_compiler_options ;
43744410
43754411 ZCG (enabled ) = false;
@@ -4380,6 +4416,7 @@ static zend_result accel_preload(const char *config, bool in_child)
43804416 accelerator_orig_compile_file = preload_compile_file ;
43814417
43824418 orig_map_ptr_last = CG (map_ptr_last );
4419+ orig_map_ptr_static_last = zend_map_ptr_static_last ;
43834420
43844421 /* Compile and execute preloading script */
43854422 zend_stream_init_filename (& file_handle , (char * ) config );
@@ -4559,7 +4596,7 @@ static zend_result accel_preload(const char *config, bool in_child)
45594596 SHM_PROTECT ();
45604597 HANDLE_UNBLOCK_INTERRUPTIONS ();
45614598
4562- preload_load ();
4599+ preload_load (orig_map_ptr_static_last );
45634600
45644601 /* Store individual scripts with unlinked classes */
45654602 HANDLE_BLOCK_INTERRUPTIONS ();
@@ -4811,7 +4848,7 @@ static zend_result accel_finish_startup(void)
48114848
48124849 if (ZCSG (preload_script )) {
48134850 /* Preloading was done in another process */
4814- preload_load ();
4851+ preload_load (zend_map_ptr_static_last );
48154852 zend_shared_alloc_unlock ();
48164853 return SUCCESS ;
48174854 }
@@ -4839,7 +4876,7 @@ static zend_result accel_finish_startup(void)
48394876 }
48404877
48414878 if (ZCSG (preload_script )) {
4842- preload_load ();
4879+ preload_load (zend_map_ptr_static_last );
48434880 }
48444881
48454882 zend_shared_alloc_unlock ();
@@ -4853,6 +4890,12 @@ static zend_result accel_finish_startup(void)
48534890#endif /* ZEND_WIN32 */
48544891}
48554892
4893+ static void accel_activate (void ) {
4894+ if (ZCG (preloaded_internal_run_time_cache )) {
4895+ memset (ZCG (preloaded_internal_run_time_cache ), 0 , ZCG (preloaded_internal_run_time_cache_size ));
4896+ }
4897+ }
4898+
48564899ZEND_EXT_API zend_extension zend_extension_entry = {
48574900 ACCELERATOR_PRODUCT_NAME , /* name */
48584901 PHP_VERSION , /* version */
@@ -4861,7 +4904,7 @@ ZEND_EXT_API zend_extension zend_extension_entry = {
48614904 "Copyright (c)" , /* copyright */
48624905 accel_startup , /* startup */
48634906 NULL , /* shutdown */
4864- NULL , /* per-script activation */
4907+ accel_activate , /* per-script activation */
48654908#ifdef HAVE_JIT
48664909 accel_deactivate , /* per-script deactivation */
48674910#else
0 commit comments