Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the JIT buffer relocation failure at the corner case #11266

Merged
merged 1 commit into from
May 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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