@@ -2621,6 +2621,7 @@ static void zend_reset_cache_vars(void)
2621
2621
ZCSG (restart_pending ) = false;
2622
2622
ZCSG (force_restart_time ) = 0 ;
2623
2623
ZCSG (map_ptr_last ) = CG (map_ptr_last );
2624
+ ZCSG (map_ptr_static_last ) = zend_map_ptr_static_last ;
2624
2625
}
2625
2626
2626
2627
static void accel_reset_pcre_cache (void )
@@ -2636,7 +2637,7 @@ static void accel_reset_pcre_cache(void)
2636
2637
} ZEND_HASH_FOREACH_END ();
2637
2638
}
2638
2639
2639
- zend_result accel_activate ( INIT_FUNC_ARGS )
2640
+ ZEND_RINIT_FUNCTION ( zend_accelerator )
2640
2641
{
2641
2642
if (!ZCG (enabled ) || !accel_startup_ok ) {
2642
2643
ZCG (accelerator_enabled ) = false;
@@ -2972,12 +2973,15 @@ static void accel_globals_ctor(zend_accel_globals *accel_globals)
2972
2973
GC_MAKE_PERSISTENT_LOCAL (accel_globals -> key );
2973
2974
}
2974
2975
2975
- #ifdef ZTS
2976
2976
static void accel_globals_dtor (zend_accel_globals * accel_globals )
2977
2977
{
2978
+ #ifdef ZTS
2978
2979
zend_string_free (accel_globals -> key );
2979
- }
2980
2980
#endif
2981
+ if (accel_globals -> preloaded_internal_run_time_cache ) {
2982
+ pefree (accel_globals -> preloaded_internal_run_time_cache , 1 );
2983
+ }
2984
+ }
2981
2985
2982
2986
#ifdef HAVE_HUGE_CODE_PAGES
2983
2987
# ifndef _WIN32
@@ -3466,6 +3470,8 @@ void accel_shutdown(void)
3466
3470
if (!ZCG (enabled ) || !accel_startup_ok ) {
3467
3471
#ifdef ZTS
3468
3472
ts_free_id (accel_globals_id );
3473
+ #else
3474
+ accel_globals_dtor (& accel_globals );
3469
3475
#endif
3470
3476
return ;
3471
3477
}
@@ -3482,6 +3488,8 @@ void accel_shutdown(void)
3482
3488
3483
3489
#ifdef ZTS
3484
3490
ts_free_id (accel_globals_id );
3491
+ #else
3492
+ accel_globals_dtor (& accel_globals );
3485
3493
#endif
3486
3494
3487
3495
if (!_file_cache_only ) {
@@ -4382,7 +4390,7 @@ static zend_persistent_script* preload_script_in_shared_memory(zend_persistent_s
4382
4390
return new_persistent_script ;
4383
4391
}
4384
4392
4385
- static void preload_load (void )
4393
+ static void preload_load (size_t orig_map_ptr_static_last )
4386
4394
{
4387
4395
/* Load into process tables */
4388
4396
zend_script * script = & ZCSG (preload_script )-> script ;
@@ -4417,14 +4425,42 @@ static void preload_load(void)
4417
4425
if (EG (class_table )) {
4418
4426
EG (persistent_classes_count ) = EG (class_table )-> nNumUsed ;
4419
4427
}
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 )) {
4422
4431
CG (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 * ));
4425
4450
CG (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
+ }
4428
4464
}
4429
4465
}
4430
4466
@@ -4433,7 +4469,7 @@ static zend_result accel_preload(const char *config, bool in_child)
4433
4469
zend_file_handle file_handle ;
4434
4470
zend_result ret ;
4435
4471
char * orig_open_basedir ;
4436
- size_t orig_map_ptr_last ;
4472
+ size_t orig_map_ptr_last , orig_map_ptr_static_last ;
4437
4473
uint32_t orig_compiler_options ;
4438
4474
4439
4475
ZCG (enabled ) = false;
@@ -4444,6 +4480,7 @@ static zend_result accel_preload(const char *config, bool in_child)
4444
4480
accelerator_orig_compile_file = preload_compile_file ;
4445
4481
4446
4482
orig_map_ptr_last = CG (map_ptr_last );
4483
+ orig_map_ptr_static_last = zend_map_ptr_static_last ;
4447
4484
4448
4485
/* Compile and execute preloading script */
4449
4486
zend_stream_init_filename (& file_handle , (char * ) config );
@@ -4623,7 +4660,7 @@ static zend_result accel_preload(const char *config, bool in_child)
4623
4660
SHM_PROTECT ();
4624
4661
HANDLE_UNBLOCK_INTERRUPTIONS ();
4625
4662
4626
- preload_load ();
4663
+ preload_load (orig_map_ptr_static_last );
4627
4664
4628
4665
/* Store individual scripts with unlinked classes */
4629
4666
HANDLE_BLOCK_INTERRUPTIONS ();
@@ -4874,7 +4911,7 @@ static zend_result accel_finish_startup(void)
4874
4911
4875
4912
if (ZCSG (preload_script )) {
4876
4913
/* Preloading was done in another process */
4877
- preload_load ();
4914
+ preload_load (zend_map_ptr_static_last );
4878
4915
zend_shared_alloc_unlock ();
4879
4916
return SUCCESS ;
4880
4917
}
@@ -4902,7 +4939,7 @@ static zend_result accel_finish_startup(void)
4902
4939
}
4903
4940
4904
4941
if (ZCSG (preload_script )) {
4905
- preload_load ();
4942
+ preload_load (zend_map_ptr_static_last );
4906
4943
}
4907
4944
4908
4945
zend_shared_alloc_unlock ();
@@ -4916,6 +4953,12 @@ static zend_result accel_finish_startup(void)
4916
4953
#endif /* ZEND_WIN32 */
4917
4954
}
4918
4955
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
+
4919
4962
ZEND_EXT_API zend_extension zend_extension_entry = {
4920
4963
ACCELERATOR_PRODUCT_NAME , /* name */
4921
4964
PHP_VERSION , /* version */
@@ -4924,7 +4967,7 @@ ZEND_EXT_API zend_extension zend_extension_entry = {
4924
4967
"Copyright (c)" , /* copyright */
4925
4968
accel_startup , /* startup */
4926
4969
NULL , /* shutdown */
4927
- NULL , /* per-script activation */
4970
+ accel_activate , /* per-script activation */
4928
4971
#ifdef HAVE_JIT
4929
4972
accel_deactivate , /* per-script deactivation */
4930
4973
#else
0 commit comments