@@ -2614,6 +2614,7 @@ static void zend_reset_cache_vars(void)
2614
2614
ZCSG (restart_pending ) = false;
2615
2615
ZCSG (force_restart_time ) = 0 ;
2616
2616
ZCSG (map_ptr_last ) = CG (map_ptr_last );
2617
+ ZCSG (map_ptr_static_last ) = zend_map_ptr_static_last ;
2617
2618
}
2618
2619
2619
2620
static void accel_reset_pcre_cache (void )
@@ -2629,7 +2630,7 @@ static void accel_reset_pcre_cache(void)
2629
2630
} ZEND_HASH_FOREACH_END ();
2630
2631
}
2631
2632
2632
- zend_result accel_activate ( INIT_FUNC_ARGS )
2633
+ ZEND_RINIT_FUNCTION ( zend_accelerator )
2633
2634
{
2634
2635
if (!ZCG (enabled ) || !accel_startup_ok ) {
2635
2636
ZCG (accelerator_enabled ) = false;
@@ -2961,12 +2962,15 @@ static void accel_globals_ctor(zend_accel_globals *accel_globals)
2961
2962
GC_MAKE_PERSISTENT_LOCAL (accel_globals -> key );
2962
2963
}
2963
2964
2964
- #ifdef ZTS
2965
2965
static void accel_globals_dtor (zend_accel_globals * accel_globals )
2966
2966
{
2967
+ #ifdef ZTS
2967
2968
zend_string_free (accel_globals -> key );
2968
- }
2969
2969
#endif
2970
+ if (accel_globals -> preloaded_internal_run_time_cache ) {
2971
+ pefree (accel_globals -> preloaded_internal_run_time_cache , 1 );
2972
+ }
2973
+ }
2970
2974
2971
2975
#ifdef HAVE_HUGE_CODE_PAGES
2972
2976
# ifndef _WIN32
@@ -3407,6 +3411,8 @@ void accel_shutdown(void)
3407
3411
if (!ZCG (enabled ) || !accel_startup_ok ) {
3408
3412
#ifdef ZTS
3409
3413
ts_free_id (accel_globals_id );
3414
+ #else
3415
+ accel_globals_dtor (& accel_globals );
3410
3416
#endif
3411
3417
return ;
3412
3418
}
@@ -3421,6 +3427,8 @@ void accel_shutdown(void)
3421
3427
3422
3428
#ifdef ZTS
3423
3429
ts_free_id (accel_globals_id );
3430
+ #else
3431
+ accel_globals_dtor (& accel_globals );
3424
3432
#endif
3425
3433
3426
3434
if (!_file_cache_only ) {
@@ -4318,7 +4326,7 @@ static zend_persistent_script* preload_script_in_shared_memory(zend_persistent_s
4318
4326
return new_persistent_script ;
4319
4327
}
4320
4328
4321
- static void preload_load (void )
4329
+ static void preload_load (size_t orig_map_ptr_static_last )
4322
4330
{
4323
4331
/* Load into process tables */
4324
4332
zend_script * script = & ZCSG (preload_script )-> script ;
@@ -4353,14 +4361,42 @@ static void preload_load(void)
4353
4361
if (EG (class_table )) {
4354
4362
EG (persistent_classes_count ) = EG (class_table )-> nNumUsed ;
4355
4363
}
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 )) {
4358
4367
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 * ));
4361
4386
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
+ }
4364
4400
}
4365
4401
}
4366
4402
@@ -4369,7 +4405,7 @@ static zend_result accel_preload(const char *config, bool in_child)
4369
4405
zend_file_handle file_handle ;
4370
4406
zend_result ret ;
4371
4407
char * orig_open_basedir ;
4372
- size_t orig_map_ptr_last ;
4408
+ size_t orig_map_ptr_last , orig_map_ptr_static_last ;
4373
4409
uint32_t orig_compiler_options ;
4374
4410
4375
4411
ZCG (enabled ) = false;
@@ -4380,6 +4416,7 @@ static zend_result accel_preload(const char *config, bool in_child)
4380
4416
accelerator_orig_compile_file = preload_compile_file ;
4381
4417
4382
4418
orig_map_ptr_last = CG (map_ptr_last );
4419
+ orig_map_ptr_static_last = zend_map_ptr_static_last ;
4383
4420
4384
4421
/* Compile and execute preloading script */
4385
4422
zend_stream_init_filename (& file_handle , (char * ) config );
@@ -4559,7 +4596,7 @@ static zend_result accel_preload(const char *config, bool in_child)
4559
4596
SHM_PROTECT ();
4560
4597
HANDLE_UNBLOCK_INTERRUPTIONS ();
4561
4598
4562
- preload_load ();
4599
+ preload_load (orig_map_ptr_static_last );
4563
4600
4564
4601
/* Store individual scripts with unlinked classes */
4565
4602
HANDLE_BLOCK_INTERRUPTIONS ();
@@ -4811,7 +4848,7 @@ static zend_result accel_finish_startup(void)
4811
4848
4812
4849
if (ZCSG (preload_script )) {
4813
4850
/* Preloading was done in another process */
4814
- preload_load ();
4851
+ preload_load (zend_map_ptr_static_last );
4815
4852
zend_shared_alloc_unlock ();
4816
4853
return SUCCESS ;
4817
4854
}
@@ -4839,7 +4876,7 @@ static zend_result accel_finish_startup(void)
4839
4876
}
4840
4877
4841
4878
if (ZCSG (preload_script )) {
4842
- preload_load ();
4879
+ preload_load (zend_map_ptr_static_last );
4843
4880
}
4844
4881
4845
4882
zend_shared_alloc_unlock ();
@@ -4853,6 +4890,12 @@ static zend_result accel_finish_startup(void)
4853
4890
#endif /* ZEND_WIN32 */
4854
4891
}
4855
4892
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
+
4856
4899
ZEND_EXT_API zend_extension zend_extension_entry = {
4857
4900
ACCELERATOR_PRODUCT_NAME , /* name */
4858
4901
PHP_VERSION , /* version */
@@ -4861,7 +4904,7 @@ ZEND_EXT_API zend_extension zend_extension_entry = {
4861
4904
"Copyright (c)" , /* copyright */
4862
4905
accel_startup , /* startup */
4863
4906
NULL , /* shutdown */
4864
- NULL , /* per-script activation */
4907
+ accel_activate , /* per-script activation */
4865
4908
#ifdef HAVE_JIT
4866
4909
accel_deactivate , /* per-script deactivation */
4867
4910
#else
0 commit comments