Skip to content

Commit 49fc38a

Browse files
committed
Revert "Fix phpGH-17715: Handle preloaded internal function runtime cache (php#17835)"
This reverts commit 53fa98e.
1 parent 4a1789c commit 49fc38a

File tree

7 files changed

+22
-129
lines changed

7 files changed

+22
-129
lines changed

Zend/zend_enum.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,7 @@ static void zend_enum_register_func(zend_class_entry *ce, zend_known_string_id n
418418
zif->module = EG(current_module);
419419
zif->scope = ce;
420420
zif->T = ZEND_OBSERVER_ENABLED;
421-
if (EG(active)) { // at run-time
422-
if (CG(compiler_options) & ZEND_COMPILE_PRELOAD) {
423-
zif->fn_flags |= ZEND_ACC_PRELOADED;
424-
}
421+
if (EG(active)) { // at run-time
425422
ZEND_MAP_PTR_INIT(zif->run_time_cache, zend_arena_calloc(&CG(arena), 1, zend_internal_run_time_cache_reserved_size()));
426423
} else {
427424
#ifdef ZTS

Zend/zend_map_ptr.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ typedef struct _zend_string zend_string;
7070
} while (0)
7171
# define ZEND_MAP_PTR_BIASED_BASE(real_base) \
7272
((void*)(((uintptr_t)(real_base)) + zend_map_ptr_static_size * sizeof(void *) - 1))
73-
/* Note: chunked like: [8192..12287][4096..8191][0..4095] */
74-
#define ZEND_MAP_PTR_STATIC_NUM_TO_PTR(num) \
75-
((void **)CG(map_ptr_real_base) + zend_map_ptr_static_size - ZEND_MM_ALIGNED_SIZE_EX((num) + 1, 4096) + ((num) & 4095))
7673
#else
7774
# error "Unknown ZEND_MAP_PTR_KIND"
7875
#endif

ext/opcache/ZendAccelerator.c

Lines changed: 15 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,7 +2627,6 @@ static void zend_reset_cache_vars(void)
26272627
ZCSG(restart_pending) = false;
26282628
ZCSG(force_restart_time) = 0;
26292629
ZCSG(map_ptr_last) = CG(map_ptr_last);
2630-
ZCSG(map_ptr_static_last) = zend_map_ptr_static_last;
26312630
}
26322631

26332632
static void accel_reset_pcre_cache(void)
@@ -2643,7 +2642,7 @@ static void accel_reset_pcre_cache(void)
26432642
} ZEND_HASH_FOREACH_END();
26442643
}
26452644

2646-
ZEND_RINIT_FUNCTION(zend_accelerator)
2645+
zend_result accel_activate(INIT_FUNC_ARGS)
26472646
{
26482647
if (!ZCG(enabled) || !accel_startup_ok) {
26492648
ZCG(accelerator_enabled) = false;
@@ -2949,13 +2948,12 @@ static void accel_globals_ctor(zend_accel_globals *accel_globals)
29492948
GC_MAKE_PERSISTENT_LOCAL(accel_globals->key);
29502949
}
29512950

2951+
#ifdef ZTS
29522952
static void accel_globals_dtor(zend_accel_globals *accel_globals)
29532953
{
29542954
zend_string_free(accel_globals->key);
2955-
if (accel_globals->preloaded_internal_run_time_cache) {
2956-
pefree(accel_globals->preloaded_internal_run_time_cache, 1);
2957-
}
29582955
}
2956+
#endif
29592957

29602958
#ifdef HAVE_HUGE_CODE_PAGES
29612959
# ifndef _WIN32
@@ -3445,8 +3443,6 @@ void accel_shutdown(void)
34453443
if (!ZCG(enabled) || !accel_startup_ok) {
34463444
#ifdef ZTS
34473445
ts_free_id(accel_globals_id);
3448-
#else
3449-
accel_globals_dtor(&accel_globals);
34503446
#endif
34513447
return;
34523448
}
@@ -3463,8 +3459,6 @@ void accel_shutdown(void)
34633459

34643460
#ifdef ZTS
34653461
ts_free_id(accel_globals_id);
3466-
#else
3467-
accel_globals_dtor(&accel_globals);
34683462
#endif
34693463

34703464
if (!_file_cache_only) {
@@ -4458,7 +4452,7 @@ static zend_persistent_script* preload_script_in_shared_memory(zend_persistent_s
44584452
return new_persistent_script;
44594453
}
44604454

4461-
static void preload_load(size_t orig_map_ptr_static_last)
4455+
static void preload_load(void)
44624456
{
44634457
/* Load into process tables */
44644458
zend_script *script = &ZCSG(preload_script)->script;
@@ -4493,42 +4487,14 @@ static void preload_load(size_t orig_map_ptr_static_last)
44934487
if (EG(class_table)) {
44944488
EG(persistent_classes_count) = EG(class_table)->nNumUsed;
44954489
}
4496-
4497-
size_t old_map_ptr_last = CG(map_ptr_last);
4498-
if (zend_map_ptr_static_last != ZCSG(map_ptr_static_last) || old_map_ptr_last != ZCSG(map_ptr_last)) {
4490+
if (CG(map_ptr_last) != ZCSG(map_ptr_last)) {
4491+
size_t old_map_ptr_last = CG(map_ptr_last);
44994492
CG(map_ptr_last) = ZCSG(map_ptr_last);
4500-
CG(map_ptr_size) = ZEND_MM_ALIGNED_SIZE_EX(ZCSG(map_ptr_last) + 1, 4096);
4501-
zend_map_ptr_static_last = ZCSG(map_ptr_static_last);
4502-
4503-
/* Grow map_ptr table as needed, but allocate once for static + regular map_ptrs */
4504-
size_t new_static_size = ZEND_MM_ALIGNED_SIZE_EX(zend_map_ptr_static_last, 4096);
4505-
if (zend_map_ptr_static_size != new_static_size) {
4506-
void *new_base = pemalloc((new_static_size + CG(map_ptr_size)) * sizeof(void *), 1);
4507-
if (CG(map_ptr_real_base)) {
4508-
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 *));
4509-
pefree(CG(map_ptr_real_base), 1);
4510-
}
4511-
CG(map_ptr_real_base) = new_base;
4512-
zend_map_ptr_static_size = new_static_size;
4513-
} else {
4514-
CG(map_ptr_real_base) = perealloc(CG(map_ptr_real_base), (zend_map_ptr_static_size + CG(map_ptr_size)) * sizeof(void *), 1);
4515-
}
4516-
4517-
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 *));
4493+
CG(map_ptr_size) = ZEND_MM_ALIGNED_SIZE_EX(CG(map_ptr_last) + 1, 4096);
4494+
CG(map_ptr_real_base) = perealloc(CG(map_ptr_real_base), CG(map_ptr_size) * sizeof(void*), 1);
45184495
CG(map_ptr_base) = ZEND_MAP_PTR_BIASED_BASE(CG(map_ptr_real_base));
4519-
}
4520-
4521-
if (orig_map_ptr_static_last != zend_map_ptr_static_last) {
4522-
/* preloaded static entries currently are all runtime cache pointers, just assign them as such */
4523-
size_t runtime_cache_size = zend_internal_run_time_cache_reserved_size();
4524-
ZCG(preloaded_internal_run_time_cache_size) = (zend_map_ptr_static_last - orig_map_ptr_static_last) * runtime_cache_size;
4525-
char *cache = pemalloc(ZCG(preloaded_internal_run_time_cache_size), 1);
4526-
ZCG(preloaded_internal_run_time_cache) = cache;
4527-
4528-
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) {
4529-
*ZEND_MAP_PTR_STATIC_NUM_TO_PTR(cur_static_map_ptr) = cache;
4530-
cache += runtime_cache_size;
4531-
}
4496+
memset((void **) CG(map_ptr_real_base) + old_map_ptr_last, 0,
4497+
(CG(map_ptr_last) - old_map_ptr_last) * sizeof(void *));
45324498
}
45334499
}
45344500

@@ -4570,7 +4536,7 @@ static zend_result accel_preload(const char *config, bool in_child)
45704536
zend_file_handle file_handle;
45714537
zend_result ret;
45724538
char *orig_open_basedir;
4573-
size_t orig_map_ptr_last, orig_map_ptr_static_last;
4539+
size_t orig_map_ptr_last;
45744540
uint32_t orig_compiler_options;
45754541

45764542
ZCG(enabled) = false;
@@ -4581,7 +4547,6 @@ static zend_result accel_preload(const char *config, bool in_child)
45814547
accelerator_orig_compile_file = preload_compile_file;
45824548

45834549
orig_map_ptr_last = CG(map_ptr_last);
4584-
orig_map_ptr_static_last = zend_map_ptr_static_last;
45854550

45864551
/* Compile and execute preloading script */
45874552
zend_stream_init_filename(&file_handle, (char *) config);
@@ -4761,7 +4726,7 @@ static zend_result accel_preload(const char *config, bool in_child)
47614726
SHM_PROTECT();
47624727
HANDLE_UNBLOCK_INTERRUPTIONS();
47634728

4764-
preload_load(orig_map_ptr_static_last);
4729+
preload_load();
47654730

47664731
/* Store individual scripts with unlinked classes */
47674732
HANDLE_BLOCK_INTERRUPTIONS();
@@ -5034,7 +4999,7 @@ static zend_result accel_finish_startup(void)
50344999

50355000
if (ZCSG(preload_script)) {
50365001
/* Preloading was done in another process */
5037-
preload_load(zend_map_ptr_static_last);
5002+
preload_load();
50385003
zend_shared_alloc_unlock();
50395004
return SUCCESS;
50405005
}
@@ -5062,7 +5027,7 @@ static zend_result accel_finish_startup(void)
50625027
}
50635028

50645029
if (ZCSG(preload_script)) {
5065-
preload_load(zend_map_ptr_static_last);
5030+
preload_load();
50665031
}
50675032

50685033
zend_shared_alloc_unlock();
@@ -5076,12 +5041,6 @@ static zend_result accel_finish_startup(void)
50765041
#endif /* ZEND_WIN32 */
50775042
}
50785043

5079-
static void accel_activate(void) {
5080-
if (ZCG(preloaded_internal_run_time_cache)) {
5081-
memset(ZCG(preloaded_internal_run_time_cache), 0, ZCG(preloaded_internal_run_time_cache_size));
5082-
}
5083-
}
5084-
50855044
static zend_extension opcache_extension_entry = {
50865045
ACCELERATOR_PRODUCT_NAME, /* name */
50875046
PHP_VERSION, /* version */
@@ -5090,7 +5049,7 @@ static zend_extension opcache_extension_entry = {
50905049
"Copyright (c)", /* copyright */
50915050
accel_startup, /* startup */
50925051
NULL, /* shutdown */
5093-
accel_activate, /* per-script activation */
5052+
NULL, /* per-script activation */
50945053
#ifdef HAVE_JIT
50955054
accel_deactivate, /* per-script deactivation */
50965055
#else

ext/opcache/ZendAccelerator.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,6 @@ typedef struct _zend_accel_globals {
218218
#ifndef ZEND_WIN32
219219
zend_ulong root_hash;
220220
#endif
221-
void *preloaded_internal_run_time_cache;
222-
size_t preloaded_internal_run_time_cache_size;
223221
bool preloading;
224222
/* preallocated shared-memory block to save current script */
225223
void *mem;
@@ -301,9 +299,11 @@ extern zend_accel_shared_globals *accel_shared_globals;
301299
#define ZCSG(element) (accel_shared_globals->element)
302300

303301
#ifdef ZTS
304-
# define ZCG(v) ZEND_TSRMG_FAST(accel_globals_offset, zend_accel_globals *, v)
302+
# define ZCG(v) ZEND_TSRMG(accel_globals_id, zend_accel_globals *, v)
305303
extern int accel_globals_id;
306-
extern size_t accel_globals_offset;
304+
# ifdef COMPILE_DL_OPCACHE
305+
ZEND_TSRMLS_CACHE_EXTERN()
306+
# endif
307307
#else
308308
# define ZCG(v) (accel_globals.v)
309309
extern zend_accel_globals accel_globals;

ext/opcache/tests/preload_enum_observed.phpt

Lines changed: 0 additions & 55 deletions
This file was deleted.

ext/opcache/zend_accelerator_module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ zend_module_entry opcache_module_entry = {
596596
ext_functions,
597597
ZEND_MINIT(zend_accelerator),
598598
ZEND_MSHUTDOWN(zend_accelerator),
599-
ZEND_RINIT(zend_accelerator),
599+
NULL,
600600
NULL,
601601
zend_accel_info,
602602
PHP_VERSION,

ext/opcache/zend_persist.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -759,11 +759,7 @@ static zend_op_array *zend_persist_class_method(zend_op_array *op_array, zend_cl
759759
// Real dynamically created internal functions like enum methods must have their own run_time_cache pointer. They're always on the same scope as their defining class.
760760
// However, copies - as caused by inheritance of internal methods - must retain the original run_time_cache pointer, shared with the source function.
761761
if (!op_array->scope || (op_array->scope == ce && !(op_array->fn_flags & ZEND_ACC_TRAIT_CLONE))) {
762-
if (op_array->fn_flags & ZEND_ACC_PRELOADED) {
763-
ZEND_MAP_PTR_NEW_STATIC(op_array->run_time_cache);
764-
} else {
765-
ZEND_MAP_PTR_NEW(op_array->run_time_cache);
766-
}
762+
ZEND_MAP_PTR_NEW(op_array->run_time_cache);
767763
}
768764
}
769765
}
@@ -1480,7 +1476,6 @@ zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script
14801476

14811477
if (for_shm) {
14821478
ZCSG(map_ptr_last) = CG(map_ptr_last);
1483-
ZCSG(map_ptr_static_last) = zend_map_ptr_static_last;
14841479
}
14851480

14861481
#ifdef HAVE_JIT

0 commit comments

Comments
 (0)