Skip to content

Commit 36c0364

Browse files
committed
Hint the opcache shm mapping location only when JIT is enabled
1 parent 5a726fd commit 36c0364

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

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 may be unsafe when the hole after the heap is the only candidate
200+
* (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)