Skip to content

Commit

Permalink
Fix the JIT buffer relocation failure at the corner case (#11266)
Browse files Browse the repository at this point in the history
Avoid missing possible candidates due to the large address range of the free segment.
Eg, 

48000000-49400000 r-xs 08000000 00:0f 39322841               segment1
7ffff2ec8000-7ffff2f49000 rw-p 00000000 00:00 0              segment2
7ffff6fae000-7ffff735c000 r-xp 00200000 08:02 11538515       /usr/local/sbin/php-fpm

original code will miss the opportunity between [7ffff2ec** - 7ffff2ec8000].

Fix issue #11265.

Signed-off-by: Long, Tao <tao.long@intel.com>
Signed-off-by: Dmitry Stogov <dmitrystogov@gmail.com>
  • Loading branch information
LoongT4o committed May 23, 2023
1 parent 24ff7ee commit a2af8ac
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ext/opcache/shared_alloc_mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ static void *find_prefered_mmap_base(size_t requested_size)
while (fgets(buffer, MAXPATHLEN, f) && sscanf(buffer, "%lx-%lx", &start, &end) == 2) {
if ((uintptr_t)execute_ex >= start) {
/* the current segment lays before PHP .text segment or PHP .text segment itself */
/*Search for candidates at the end of the free segment near the .text segment
to prevent candidates from being missed due to large hole*/
if (last_free_addr + requested_size <= start) {
last_candidate = last_free_addr;
last_candidate = ZEND_MM_ALIGNED_SIZE_EX(start - requested_size, huge_page_size);
if (last_candidate + requested_size > start) {
last_candidate -= huge_page_size;
}
}
if ((uintptr_t)execute_ex < end) {
/* the current segment is PHP .text segment itself */
Expand Down Expand Up @@ -117,7 +122,10 @@ static void *find_prefered_mmap_base(size_t requested_size)
if ((uintptr_t)execute_ex >= e_start) {
/* the current segment lays before PHP .text segment or PHP .text segment itself */
if (last_free_addr + requested_size <= e_start) {
last_candidate = last_free_addr;
last_candidate = ZEND_MM_ALIGNED_SIZE_EX(e_start - requested_size, huge_page_size);
if (last_candidate + requested_size > e_start) {
last_candidate -= huge_page_size;
}
}
if ((uintptr_t)execute_ex < e_end) {
/* the current segment is PHP .text segment itself */
Expand Down

0 comments on commit a2af8ac

Please sign in to comment.