Skip to content

Commit 929536b

Browse files
committed
Hint the opcache shm mapping location only when JIT is enabled
Closes GH-14793 Fixes GH-13775
1 parent a924e1c commit 929536b

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Diff for: NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ PHP NEWS
2020
- Opcache:
2121
. Fixed bug GH-13817 (Segmentation fault for enabled observers after pass 4).
2222
(Bob)
23+
. Fixed bug GH-13775 (Memory leak possibly related to opcache SHM placement).
24+
(Arnaud)
2325

2426
- PDO_Firebird:
2527
. Fix bogus fallthrough path in firebird_handle_get_attribute(). (nielsdos)

Diff for: ext/opcache/shared_alloc_mmap.c

+13-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121

2222
#include "zend_shared_alloc.h"
23+
#include "jit/zend_jit.h"
2324

2425
#ifdef USE_MMAP
2526

@@ -45,7 +46,7 @@
4546
# define MAP_HUGETLB MAP_ALIGNED_SUPER
4647
#endif
4748

48-
#if (defined(__linux__) || defined(__FreeBSD__)) && (defined(__x86_64__) || defined (__aarch64__)) && !defined(__SANITIZE_ADDRESS__)
49+
#if defined(HAVE_JIT) && (defined(__linux__) || defined(__FreeBSD__)) && (defined(__x86_64__) || defined (__aarch64__)) && !defined(__SANITIZE_ADDRESS__)
4950
static void *find_prefered_mmap_base(size_t requested_size)
5051
{
5152
size_t huge_page_size = 2 * 1024 * 1024;
@@ -188,8 +189,17 @@ static int create_segments(size_t requested_size, zend_shared_segment ***shared_
188189
#ifdef PROT_MAX
189190
flags |= PROT_MAX(PROT_READ | PROT_WRITE | PROT_EXEC);
190191
#endif
191-
#if (defined(__linux__) || defined(__FreeBSD__)) && (defined(__x86_64__) || defined (__aarch64__)) && !defined(__SANITIZE_ADDRESS__)
192-
void *hint = find_prefered_mmap_base(requested_size);
192+
#if defined(HAVE_JIT) && (defined(__linux__) || defined(__FreeBSD__)) && (defined(__x86_64__) || defined (__aarch64__)) && !defined(__SANITIZE_ADDRESS__)
193+
void *hint;
194+
if (JIT_G(enabled) && JIT_G(buffer_size)
195+
&& zend_jit_check_support() == SUCCESS) {
196+
hint = find_prefered_mmap_base(requested_size);
197+
} else {
198+
/* Do not use a hint if JIT is not enabled, as this profits only JIT and
199+
* this is potentially unsafe when the only suitable candidate is just
200+
* after the heap (e.g. in non-PIE builds) (GH-13775). */
201+
hint = MAP_FAILED;
202+
}
193203
if (hint != MAP_FAILED) {
194204
# ifdef MAP_HUGETLB
195205
size_t huge_page_size = 2 * 1024 * 1024;

0 commit comments

Comments
 (0)