Skip to content

Commit ead61c7

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Hint the opcache shm mapping location only when JIT is enabled Fix the JIT buffer relocation failure at the corner case (#11266)
2 parents 46924ac + 929536b commit ead61c7

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

@@ -48,7 +49,7 @@
4849
# define MAP_HUGETLB MAP_ALIGNED_SUPER
4950
#endif
5051

51-
#if (defined(__linux__) || defined(__FreeBSD__)) && (defined(__x86_64__) || defined (__aarch64__)) && !defined(__SANITIZE_ADDRESS__)
52+
#if defined(HAVE_JIT) && (defined(__linux__) || defined(__FreeBSD__)) && (defined(__x86_64__) || defined (__aarch64__)) && !defined(__SANITIZE_ADDRESS__)
5253
static void *find_prefered_mmap_base(size_t requested_size)
5354
{
5455
size_t huge_page_size = 2 * 1024 * 1024;
@@ -197,8 +198,17 @@ static int create_segments(size_t requested_size, zend_shared_segment ***shared_
197198
#ifdef PROT_MAX
198199
flags |= PROT_MAX(PROT_READ | PROT_WRITE | PROT_EXEC);
199200
#endif
200-
#if (defined(__linux__) || defined(__FreeBSD__)) && (defined(__x86_64__) || defined (__aarch64__)) && !defined(__SANITIZE_ADDRESS__)
201-
void *hint = find_prefered_mmap_base(requested_size);
201+
#if defined(HAVE_JIT) && (defined(__linux__) || defined(__FreeBSD__)) && (defined(__x86_64__) || defined (__aarch64__)) && !defined(__SANITIZE_ADDRESS__)
202+
void *hint;
203+
if (JIT_G(enabled) && JIT_G(buffer_size)
204+
&& zend_jit_check_support() == SUCCESS) {
205+
hint = find_prefered_mmap_base(requested_size);
206+
} else {
207+
/* Do not use a hint if JIT is not enabled, as this profits only JIT and
208+
* this is potentially unsafe when the only suitable candidate is just
209+
* after the heap (e.g. in non-PIE builds) (GH-13775). */
210+
hint = MAP_FAILED;
211+
}
202212
if (hint != MAP_FAILED) {
203213
# ifdef MAP_HUGETLB
204214
size_t huge_page_size = 2 * 1024 * 1024;

0 commit comments

Comments
 (0)