Skip to content

Commit e90c96b

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Fix GH-11715: opcache.interned_strings_buffer either has no effect or opcache_get_status() / phpinfo() is wrong
2 parents a17e84f + 404f1d3 commit e90c96b

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

ext/opcache/ZendAccelerator.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2864,7 +2864,7 @@ static zend_result zend_accel_init_shm(void)
28642864
zend_shared_alloc_lock();
28652865

28662866
if (ZCG(accel_directives).interned_strings_buffer) {
2867-
accel_shared_globals_size = ZCG(accel_directives).interned_strings_buffer * 1024 * 1024;
2867+
accel_shared_globals_size = sizeof(zend_accel_shared_globals) + ZCG(accel_directives).interned_strings_buffer * 1024 * 1024;
28682868
} else {
28692869
/* Make sure there is always at least one interned string hash slot,
28702870
* so the table can be queried unconditionally. */
@@ -2905,7 +2905,7 @@ static zend_result zend_accel_init_shm(void)
29052905
ZCSG(interned_strings).top =
29062906
ZCSG(interned_strings).start;
29072907
ZCSG(interned_strings).end =
2908-
(zend_string*)((char*)accel_shared_globals +
2908+
(zend_string*)((char*)(accel_shared_globals + 1) + /* table data is stored after accel_shared_globals */
29092909
ZCG(accel_directives).interned_strings_buffer * 1024 * 1024);
29102910
ZCSG(interned_strings).saved_top = NULL;
29112911

ext/opcache/tests/gh11715.phpt

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
GH-11715 (opcache.interned_strings_buffer either has no effect or opcache_get_status() / phpinfo() is wrong)
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.enable=1
7+
opcache.enable_cli=1
8+
opcache.interned_strings_buffer=16
9+
--FILE--
10+
<?php
11+
12+
$info = opcache_get_status()['interned_strings_usage'];
13+
var_dump($info['used_memory'] + $info['free_memory']);
14+
var_dump($info['buffer_size']);
15+
16+
?>
17+
--EXPECT--
18+
int(16777216)
19+
int(16777216)

ext/opcache/zend_accelerator_module.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#define STRING_NOT_NULL(s) (NULL == (s)?"":s)
4242
#define MIN_ACCEL_FILES 200
4343
#define MAX_ACCEL_FILES 1000000
44-
#define MAX_INTERNED_STRINGS_BUFFER_SIZE ((zend_long)((UINT32_MAX-PLATFORM_ALIGNMENT)/(1024*1024)))
44+
#define MAX_INTERNED_STRINGS_BUFFER_SIZE ((zend_long)((UINT32_MAX-PLATFORM_ALIGNMENT-sizeof(zend_accel_shared_globals))/(1024*1024)))
4545
#define TOKENTOSTR(X) #X
4646

4747
static zif_handler orig_file_exists = NULL;
@@ -525,7 +525,7 @@ void zend_accel_info(ZEND_MODULE_INFO_FUNC_ARGS)
525525
snprintf(buf, sizeof(buf), "%zu", ZSMMG(wasted_shared_memory));
526526
php_info_print_table_row(2, "Wasted memory", buf);
527527
if (ZCSG(interned_strings).start && ZCSG(interned_strings).end) {
528-
snprintf(buf, sizeof(buf), "%zu", (size_t)((char*)ZCSG(interned_strings).top - (char*)ZCSG(interned_strings).start));
528+
snprintf(buf, sizeof(buf), "%zu", (size_t)((char*)ZCSG(interned_strings).top - (char*)(accel_shared_globals + 1)));
529529
php_info_print_table_row(2, "Interned Strings Used memory", buf);
530530
snprintf(buf, sizeof(buf), "%zu", (size_t)((char*)ZCSG(interned_strings).end - (char*)ZCSG(interned_strings).top));
531531
php_info_print_table_row(2, "Interned Strings Free memory", buf);
@@ -686,8 +686,8 @@ ZEND_FUNCTION(opcache_get_status)
686686
zval interned_strings_usage;
687687

688688
array_init(&interned_strings_usage);
689-
add_assoc_long(&interned_strings_usage, "buffer_size", (char*)ZCSG(interned_strings).end - (char*)ZCSG(interned_strings).start);
690-
add_assoc_long(&interned_strings_usage, "used_memory", (char*)ZCSG(interned_strings).top - (char*)ZCSG(interned_strings).start);
689+
add_assoc_long(&interned_strings_usage, "buffer_size", (char*)ZCSG(interned_strings).end - (char*)(accel_shared_globals + 1));
690+
add_assoc_long(&interned_strings_usage, "used_memory", (char*)ZCSG(interned_strings).top - (char*)(accel_shared_globals + 1));
691691
add_assoc_long(&interned_strings_usage, "free_memory", (char*)ZCSG(interned_strings).end - (char*)ZCSG(interned_strings).top);
692692
add_assoc_long(&interned_strings_usage, "number_of_strings", ZCSG(interned_strings).nNumOfElements);
693693
add_assoc_zval(return_value, "interned_strings_usage", &interned_strings_usage);

0 commit comments

Comments
 (0)