Hint the opcache shm mapping location only when JIT is enabled

Closes GH-14793
Fixes GH-13775
This commit is contained in:
Arnaud Le Blanc 2024-07-03 18:27:58 +02:00
parent a924e1c71b
commit 929536b697
No known key found for this signature in database
GPG key ID: 0098C05DD15ABC13
2 changed files with 15 additions and 3 deletions

2
NEWS
View file

@ -20,6 +20,8 @@ PHP NEWS
- Opcache:
. Fixed bug GH-13817 (Segmentation fault for enabled observers after pass 4).
(Bob)
. Fixed bug GH-13775 (Memory leak possibly related to opcache SHM placement).
(Arnaud)
- PDO_Firebird:
. Fix bogus fallthrough path in firebird_handle_get_attribute(). (nielsdos)

View file

@ -20,6 +20,7 @@
*/
#include "zend_shared_alloc.h"
#include "jit/zend_jit.h"
#ifdef USE_MMAP
@ -45,7 +46,7 @@
# define MAP_HUGETLB MAP_ALIGNED_SUPER
#endif
#if (defined(__linux__) || defined(__FreeBSD__)) && (defined(__x86_64__) || defined (__aarch64__)) && !defined(__SANITIZE_ADDRESS__)
#if defined(HAVE_JIT) && (defined(__linux__) || defined(__FreeBSD__)) && (defined(__x86_64__) || defined (__aarch64__)) && !defined(__SANITIZE_ADDRESS__)
static void *find_prefered_mmap_base(size_t requested_size)
{
size_t huge_page_size = 2 * 1024 * 1024;
@ -188,8 +189,17 @@ static int create_segments(size_t requested_size, zend_shared_segment ***shared_
#ifdef PROT_MAX
flags |= PROT_MAX(PROT_READ | PROT_WRITE | PROT_EXEC);
#endif
#if (defined(__linux__) || defined(__FreeBSD__)) && (defined(__x86_64__) || defined (__aarch64__)) && !defined(__SANITIZE_ADDRESS__)
void *hint = find_prefered_mmap_base(requested_size);
#if defined(HAVE_JIT) && (defined(__linux__) || defined(__FreeBSD__)) && (defined(__x86_64__) || defined (__aarch64__)) && !defined(__SANITIZE_ADDRESS__)
void *hint;
if (JIT_G(enabled) && JIT_G(buffer_size)
&& zend_jit_check_support() == SUCCESS) {
hint = find_prefered_mmap_base(requested_size);
} else {
/* Do not use a hint if JIT is not enabled, as this profits only JIT and
* this is potentially unsafe when the only suitable candidate is just
* after the heap (e.g. in non-PIE builds) (GH-13775). */
hint = MAP_FAILED;
}
if (hint != MAP_FAILED) {
# ifdef MAP_HUGETLB
size_t huge_page_size = 2 * 1024 * 1024;