1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Merge branch 'PHP-8.3' into PHP-8.4

* PHP-8.3:
  Fix GH-18417: Windows SHM reattachment fails when increasing memory_consumption or jit_buffer_size
This commit is contained in:
Niels Dossche
2025-04-28 19:52:22 +02:00
3 changed files with 54 additions and 6 deletions

4
NEWS
View File

@@ -12,6 +12,10 @@ PHP NEWS
. Fix IntlDateFormatter::parseToCalendar() reference type system breaks.
(nielsdos)
- Opcache:
. Fixed bug GH-18417 (Windows SHM reattachment fails when increasing
memory_consumption or jit_buffer_size). (nielsdos)
- SPL:
. Fixed bug GH-18421 (Integer overflow with large numbers in LimitIterator).
(nielsdos)

View File

@@ -69,9 +69,9 @@ static void zend_win_error_message(int type, char *msg, int err)
php_win32_error_msg_free(buf);
}
static char *create_name_with_username(char *name)
static char *create_name_with_username(const char *name, size_t unique_id)
{
static char newname[MAXPATHLEN + 1 + 32 + 1 + 20 + 1 + 32 + 1];
static char newname[MAXPATHLEN + 1 + 32 + 1 + 20 + 1 + 32 + sizeof("ffffffffffffffff")-1 + 1];
char *p = newname;
p += strlcpy(newname, name, MAXPATHLEN + 1);
*(p++) = '@';
@@ -80,7 +80,11 @@ static char *create_name_with_username(char *name)
p += strlcpy(p, sapi_module.name, 21);
*(p++) = '@';
p = zend_mempcpy(p, zend_system_id, 32);
*(p++) = '\0';
if (unique_id) {
p += snprintf(p, sizeof("ffffffffffffffff"), "%zx", unique_id) + 1;
} else {
*(p++) = '\0';
}
ZEND_ASSERT(p - newname <= sizeof(newname));
return newname;
@@ -88,7 +92,7 @@ static char *create_name_with_username(char *name)
void zend_shared_alloc_create_lock(void)
{
memory_mutex = CreateMutex(NULL, FALSE, create_name_with_username(ACCEL_MUTEX_NAME));
memory_mutex = CreateMutex(NULL, FALSE, create_name_with_username(ACCEL_MUTEX_NAME, 0));
if (!memory_mutex) {
zend_accel_error(ACCEL_LOG_FATAL, "Cannot create mutex (error %u)", GetLastError());
return;
@@ -222,7 +226,7 @@ static int create_segments(size_t requested_size, zend_shared_segment ***shared_
can be called before the child process is killed. In this case, the mapping will fail
and we have to sleep some time (until the child releases the mapping object) and retry.*/
do {
memfile = OpenFileMapping(FILE_MAP_READ|FILE_MAP_WRITE|FILE_MAP_EXECUTE, 0, create_name_with_username(ACCEL_FILEMAP_NAME));
memfile = OpenFileMapping(FILE_MAP_READ|FILE_MAP_WRITE|FILE_MAP_EXECUTE, 0, create_name_with_username(ACCEL_FILEMAP_NAME, requested_size));
if (memfile == NULL) {
err = GetLastError();
break;
@@ -267,7 +271,7 @@ static int create_segments(size_t requested_size, zend_shared_segment ***shared_
(*shared_segments_p)[0] = shared_segment;
memfile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_EXECUTE_READWRITE | SEC_COMMIT, size_high, size_low,
create_name_with_username(ACCEL_FILEMAP_NAME));
create_name_with_username(ACCEL_FILEMAP_NAME, requested_size));
if (memfile == NULL) {
err = GetLastError();
zend_shared_alloc_unlock_win32();

View File

@@ -0,0 +1,40 @@
--TEST--
GH-18417 (Windows SHM reattachment fails when increasing memory_consumption or jit_buffer_size)
--SKIPIF--
<?php
$extDir = ini_get('extension_dir');
if (!file_exists($extDir . '/php_opcache.dll')) {
die('skip Opcache DLL not found in extension_dir (Windows-only)');
}
?>
--FILE--
<?php
$memory_consumption = (int) ini_get("opcache.memory_consumption");
$new_memory_consumption = $memory_consumption * 2;
$extension_dir = ini_get("extension_dir");
$descriptorspec = [
0 => ["pipe", "r"],
1 => ["pipe", "w"],
2 => ["pipe", "w"],
];
$proc = proc_open([
PHP_BINARY,
"-n",
"-d", "extension_dir=$extension_dir",
"-d", "zend_extension=opcache",
"-d", "opcache.memory_consumption=$new_memory_consumption",
"-d", "opcache.enable=1",
"-d", "opcache.enable_cli=1",
"-r",
"echo 1;"
], $descriptorspec, $pipes);
echo stream_get_contents($pipes[1]);
echo stream_get_contents($pipes[2]);
proc_close($proc);
?>
--EXPECT--
1