Skip to content

Commit a924e1c

Browse files
LoongT4oarnaud-lb
authored andcommitted
Fix the JIT buffer relocation failure at the corner case (#11266)
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 <[email protected]> Signed-off-by: Dmitry Stogov <[email protected]>
1 parent b8e9c5b commit a924e1c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Diff for: ext/opcache/shared_alloc_mmap.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,13 @@ static void *find_prefered_mmap_base(size_t requested_size)
7676
}
7777
if ((uintptr_t)execute_ex >= start) {
7878
/* the current segment lays before PHP .text segment or PHP .text segment itself */
79+
/*Search for candidates at the end of the free segment near the .text segment
80+
to prevent candidates from being missed due to large hole*/
7981
if (last_free_addr + requested_size <= start) {
80-
last_candidate = last_free_addr;
82+
last_candidate = ZEND_MM_ALIGNED_SIZE_EX(start - requested_size, huge_page_size);
83+
if (last_candidate + requested_size > start) {
84+
last_candidate -= huge_page_size;
85+
}
8186
}
8287
if ((uintptr_t)execute_ex < end) {
8388
/* the current segment is PHP .text segment itself */
@@ -128,7 +133,10 @@ static void *find_prefered_mmap_base(size_t requested_size)
128133
if ((uintptr_t)execute_ex >= e_start) {
129134
/* the current segment lays before PHP .text segment or PHP .text segment itself */
130135
if (last_free_addr + requested_size <= e_start) {
131-
last_candidate = last_free_addr;
136+
last_candidate = ZEND_MM_ALIGNED_SIZE_EX(e_start - requested_size, huge_page_size);
137+
if (last_candidate + requested_size > e_start) {
138+
last_candidate -= huge_page_size;
139+
}
132140
}
133141
if ((uintptr_t)execute_ex < e_end) {
134142
/* the current segment is PHP .text segment itself */

0 commit comments

Comments
 (0)