Skip to content

Commit c620fee

Browse files
committed
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
2 parents 8fe5a44 + 7869af6 commit c620fee

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ PHP NEWS
1212
. Fix IntlDateFormatter::parseToCalendar() reference type system breaks.
1313
(nielsdos)
1414

15+
- Opcache:
16+
. Fixed bug GH-18417 (Windows SHM reattachment fails when increasing
17+
memory_consumption or jit_buffer_size). (nielsdos)
18+
1519
- SPL:
1620
. Fixed bug GH-18421 (Integer overflow with large numbers in LimitIterator).
1721
(nielsdos)

ext/opcache/shared_alloc_win32.c

+10-6
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ static void zend_win_error_message(int type, char *msg, int err)
6969
php_win32_error_msg_free(buf);
7070
}
7171

72-
static char *create_name_with_username(char *name)
72+
static char *create_name_with_username(const char *name, size_t unique_id)
7373
{
74-
static char newname[MAXPATHLEN + 1 + 32 + 1 + 20 + 1 + 32 + 1];
74+
static char newname[MAXPATHLEN + 1 + 32 + 1 + 20 + 1 + 32 + sizeof("ffffffffffffffff")-1 + 1];
7575
char *p = newname;
7676
p += strlcpy(newname, name, MAXPATHLEN + 1);
7777
*(p++) = '@';
@@ -80,15 +80,19 @@ static char *create_name_with_username(char *name)
8080
p += strlcpy(p, sapi_module.name, 21);
8181
*(p++) = '@';
8282
p = zend_mempcpy(p, zend_system_id, 32);
83-
*(p++) = '\0';
83+
if (unique_id) {
84+
p += snprintf(p, sizeof("ffffffffffffffff"), "%zx", unique_id) + 1;
85+
} else {
86+
*(p++) = '\0';
87+
}
8488
ZEND_ASSERT(p - newname <= sizeof(newname));
8589

8690
return newname;
8791
}
8892

8993
void zend_shared_alloc_create_lock(void)
9094
{
91-
memory_mutex = CreateMutex(NULL, FALSE, create_name_with_username(ACCEL_MUTEX_NAME));
95+
memory_mutex = CreateMutex(NULL, FALSE, create_name_with_username(ACCEL_MUTEX_NAME, 0));
9296
if (!memory_mutex) {
9397
zend_accel_error(ACCEL_LOG_FATAL, "Cannot create mutex (error %u)", GetLastError());
9498
return;
@@ -222,7 +226,7 @@ static int create_segments(size_t requested_size, zend_shared_segment ***shared_
222226
can be called before the child process is killed. In this case, the mapping will fail
223227
and we have to sleep some time (until the child releases the mapping object) and retry.*/
224228
do {
225-
memfile = OpenFileMapping(FILE_MAP_READ|FILE_MAP_WRITE|FILE_MAP_EXECUTE, 0, create_name_with_username(ACCEL_FILEMAP_NAME));
229+
memfile = OpenFileMapping(FILE_MAP_READ|FILE_MAP_WRITE|FILE_MAP_EXECUTE, 0, create_name_with_username(ACCEL_FILEMAP_NAME, requested_size));
226230
if (memfile == NULL) {
227231
err = GetLastError();
228232
break;
@@ -267,7 +271,7 @@ static int create_segments(size_t requested_size, zend_shared_segment ***shared_
267271
(*shared_segments_p)[0] = shared_segment;
268272

269273
memfile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_EXECUTE_READWRITE | SEC_COMMIT, size_high, size_low,
270-
create_name_with_username(ACCEL_FILEMAP_NAME));
274+
create_name_with_username(ACCEL_FILEMAP_NAME, requested_size));
271275
if (memfile == NULL) {
272276
err = GetLastError();
273277
zend_shared_alloc_unlock_win32();

ext/opcache/tests/gh18417.phpt

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
GH-18417 (Windows SHM reattachment fails when increasing memory_consumption or jit_buffer_size)
3+
--SKIPIF--
4+
<?php
5+
$extDir = ini_get('extension_dir');
6+
if (!file_exists($extDir . '/php_opcache.dll')) {
7+
die('skip Opcache DLL not found in extension_dir (Windows-only)');
8+
}
9+
?>
10+
--FILE--
11+
<?php
12+
$memory_consumption = (int) ini_get("opcache.memory_consumption");
13+
$new_memory_consumption = $memory_consumption * 2;
14+
$extension_dir = ini_get("extension_dir");
15+
16+
$descriptorspec = [
17+
0 => ["pipe", "r"],
18+
1 => ["pipe", "w"],
19+
2 => ["pipe", "w"],
20+
];
21+
22+
$proc = proc_open([
23+
PHP_BINARY,
24+
"-n",
25+
"-d", "extension_dir=$extension_dir",
26+
"-d", "zend_extension=opcache",
27+
"-d", "opcache.memory_consumption=$new_memory_consumption",
28+
"-d", "opcache.enable=1",
29+
"-d", "opcache.enable_cli=1",
30+
"-r",
31+
"echo 1;"
32+
], $descriptorspec, $pipes);
33+
34+
echo stream_get_contents($pipes[1]);
35+
echo stream_get_contents($pipes[2]);
36+
37+
proc_close($proc);
38+
?>
39+
--EXPECT--
40+
1

0 commit comments

Comments
 (0)