@@ -2621,6 +2621,7 @@ static void zend_reset_cache_vars(void)
26212621ZCSG (restart_pending ) = false;
26222622ZCSG (force_restart_time ) = 0 ;
26232623ZCSG (map_ptr_last ) = CG (map_ptr_last );
2624+ ZCSG (map_ptr_static_last ) = zend_map_ptr_static_last ;
26242625}
26252626
26262627static void accel_reset_pcre_cache (void )
@@ -2636,7 +2637,7 @@ static void accel_reset_pcre_cache(void)
26362637} ZEND_HASH_FOREACH_END ();
26372638}
26382639
2639- zend_result accel_activate ( INIT_FUNC_ARGS )
2640+ ZEND_RINIT_FUNCTION ( zend_accelerator )
26402641{
26412642if (!ZCG (enabled ) || !accel_startup_ok ) {
26422643ZCG (accelerator_enabled ) = false;
@@ -2972,12 +2973,15 @@ static void accel_globals_ctor(zend_accel_globals *accel_globals)
29722973GC_MAKE_PERSISTENT_LOCAL (accel_globals -> key );
29732974}
29742975
2975- #ifdef ZTS
29762976static void accel_globals_dtor (zend_accel_globals * accel_globals )
29772977{
2978+ #ifdef ZTS
29782979zend_string_free (accel_globals -> key );
2979- }
29802980#endif
2981+ if (accel_globals -> preloaded_internal_run_time_cache ) {
2982+ pefree (accel_globals -> preloaded_internal_run_time_cache , 1 );
2983+ }
2984+ }
29812985
29822986#ifdef HAVE_HUGE_CODE_PAGES
29832987# ifndef _WIN32
@@ -3466,6 +3470,8 @@ void accel_shutdown(void)
34663470if (!ZCG (enabled ) || !accel_startup_ok ) {
34673471#ifdef ZTS
34683472ts_free_id (accel_globals_id );
3473+ #else
3474+ accel_globals_dtor (& accel_globals );
34693475#endif
34703476return ;
34713477}
@@ -3482,6 +3488,8 @@ void accel_shutdown(void)
34823488
34833489#ifdef ZTS
34843490ts_free_id (accel_globals_id );
3491+ #else
3492+ accel_globals_dtor (& accel_globals );
34853493#endif
34863494
34873495if (!_file_cache_only ) {
@@ -4382,7 +4390,7 @@ static zend_persistent_script* preload_script_in_shared_memory(zend_persistent_s
43824390return new_persistent_script ;
43834391}
43844392
4385- static void preload_load (void )
4393+ static void preload_load (size_t orig_map_ptr_static_last )
43864394{
43874395/* Load into process tables */
43884396zend_script * script = & ZCSG (preload_script )-> script ;
@@ -4417,14 +4425,42 @@ static void preload_load(void)
44174425if (EG (class_table )) {
44184426EG (persistent_classes_count ) = EG (class_table )-> nNumUsed ;
44194427}
4420- if (CG (map_ptr_last ) != ZCSG (map_ptr_last )) {
4421- size_t old_map_ptr_last = CG (map_ptr_last );
4428+
4429+ size_t old_map_ptr_last = CG (map_ptr_last );
4430+ if (zend_map_ptr_static_last != ZCSG (map_ptr_static_last ) || old_map_ptr_last != ZCSG (map_ptr_last )) {
44224431CG (map_ptr_last ) = ZCSG (map_ptr_last );
4423- CG (map_ptr_size ) = ZEND_MM_ALIGNED_SIZE_EX (CG (map_ptr_last ) + 1 , 4096 );
4424- CG (map_ptr_real_base ) = perealloc (CG (map_ptr_real_base ), CG (map_ptr_size ) * sizeof (void * ), 1 );
4432+ CG (map_ptr_size ) = ZEND_MM_ALIGNED_SIZE_EX (ZCSG (map_ptr_last ) + 1 , 4096 );
4433+ zend_map_ptr_static_last = ZCSG (map_ptr_static_last );
4434+
4435+ /* Grow map_ptr table as needed, but allocate once for static + regular map_ptrs */
4436+ size_t new_static_size = ZEND_MM_ALIGNED_SIZE_EX (zend_map_ptr_static_last , 4096 );
4437+ if (zend_map_ptr_static_size != new_static_size ) {
4438+ void * new_base = pemalloc ((new_static_size + CG (map_ptr_size )) * sizeof (void * ), 1 );
4439+ if (CG (map_ptr_real_base )) {
4440+ 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 * ));
4441+ pefree (CG (map_ptr_real_base ), 1 );
4442+ }
4443+ CG (map_ptr_real_base ) = new_base ;
4444+ zend_map_ptr_static_size = new_static_size ;
4445+ } else {
4446+ CG (map_ptr_real_base ) = perealloc (CG (map_ptr_real_base ), (zend_map_ptr_static_size + CG (map_ptr_size )) * sizeof (void * ), 1 );
4447+ }
4448+
4449+ 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 * ));
44254450CG (map_ptr_base ) = ZEND_MAP_PTR_BIASED_BASE (CG (map_ptr_real_base ));
4426- memset ((void * * ) CG (map_ptr_real_base ) + old_map_ptr_last , 0 ,
4427- (CG (map_ptr_last ) - old_map_ptr_last ) * sizeof (void * ));
4451+ }
4452+
4453+ if (orig_map_ptr_static_last != zend_map_ptr_static_last ) {
4454+ /* preloaded static entries currently are all runtime cache pointers, just assign them as such */
4455+ size_t runtime_cache_size = zend_internal_run_time_cache_reserved_size ();
4456+ ZCG (preloaded_internal_run_time_cache_size ) = (zend_map_ptr_static_last - orig_map_ptr_static_last ) * runtime_cache_size ;
4457+ char * cache = pemalloc (ZCG (preloaded_internal_run_time_cache_size ), 1 );
4458+ ZCG (preloaded_internal_run_time_cache ) = cache ;
4459+
4460+ 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 ) {
4461+ * ZEND_MAP_PTR_STATIC_NUM_TO_PTR (cur_static_map_ptr ) = cache ;
4462+ cache += runtime_cache_size ;
4463+ }
44284464}
44294465}
44304466
@@ -4433,7 +4469,7 @@ static zend_result accel_preload(const char *config, bool in_child)
44334469zend_file_handle file_handle ;
44344470zend_result ret ;
44354471char * orig_open_basedir ;
4436- size_t orig_map_ptr_last ;
4472+ size_t orig_map_ptr_last , orig_map_ptr_static_last ;
44374473uint32_t orig_compiler_options ;
44384474
44394475ZCG (enabled ) = false;
@@ -4444,6 +4480,7 @@ static zend_result accel_preload(const char *config, bool in_child)
44444480accelerator_orig_compile_file = preload_compile_file ;
44454481
44464482orig_map_ptr_last = CG (map_ptr_last );
4483+ orig_map_ptr_static_last = zend_map_ptr_static_last ;
44474484
44484485/* Compile and execute preloading script */
44494486zend_stream_init_filename (& file_handle , (char * ) config );
@@ -4623,7 +4660,7 @@ static zend_result accel_preload(const char *config, bool in_child)
46234660SHM_PROTECT ();
46244661HANDLE_UNBLOCK_INTERRUPTIONS ();
46254662
4626- preload_load ();
4663+ preload_load (orig_map_ptr_static_last );
46274664
46284665/* Store individual scripts with unlinked classes */
46294666HANDLE_BLOCK_INTERRUPTIONS ();
@@ -4874,7 +4911,7 @@ static zend_result accel_finish_startup(void)
48744911
48754912if (ZCSG (preload_script )) {
48764913/* Preloading was done in another process */
4877- preload_load ();
4914+ preload_load (zend_map_ptr_static_last );
48784915zend_shared_alloc_unlock ();
48794916return SUCCESS ;
48804917}
@@ -4902,7 +4939,7 @@ static zend_result accel_finish_startup(void)
49024939}
49034940
49044941if (ZCSG (preload_script )) {
4905- preload_load ();
4942+ preload_load (zend_map_ptr_static_last );
49064943}
49074944
49084945zend_shared_alloc_unlock ();
@@ -4916,6 +4953,12 @@ static zend_result accel_finish_startup(void)
49164953#endif /* ZEND_WIN32 */
49174954}
49184955
4956+ static void accel_activate (void ) {
4957+ if (ZCG (preloaded_internal_run_time_cache )) {
4958+ memset (ZCG (preloaded_internal_run_time_cache ), 0 , ZCG (preloaded_internal_run_time_cache_size ));
4959+ }
4960+ }
4961+
49194962ZEND_EXT_API zend_extension zend_extension_entry = {
49204963ACCELERATOR_PRODUCT_NAME , /* name */
49214964PHP_VERSION ,/* version */
@@ -4924,7 +4967,7 @@ ZEND_EXT_API zend_extension zend_extension_entry = {
49244967"Copyright (c)" ,/* copyright */
49254968accel_startup , /* startup */
49264969NULL ,/* shutdown */
4927- NULL , /* per-script activation */
4970+ accel_activate , /* per-script activation */
49284971#ifdef HAVE_JIT
49294972accel_deactivate , /* per-script deactivation */
49304973#else
0 commit comments