Skip to content

Commit 1380b65

Browse files
committed
Remove reundant address comparison in accel_remap_huge_pages
Closes GH-8830 MAP_FIXED guarantees mmap will return that exact address or fail so the address comparison is redundant. The return value of this function is unused but I kept it because it improves readability.
1 parent 2ca4116 commit 1380b65

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

ext/opcache/ZendAccelerator.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -2984,19 +2984,19 @@ static int accel_remap_huge_pages(void *start, size_t size, size_t real_size, co
29842984
zend_error(E_WARNING,
29852985
ACCELERATOR_PRODUCT_NAME " huge_code_pages: mmap(HUGETLB) failed: %s (%d)",
29862986
strerror(errno), errno);
2987-
return -1;
2987+
return FAILURE;
29882988
# endif
29892989
}
29902990

2991+
// Given the MAP_FIXED flag the address can never diverge
2992+
ZEND_ASSERT(ret == start);
29912993
zend_mmap_set_name(start, size, "zend_huge_code_pages");
2994+
memcpy(start, mem, real_size);
2995+
mprotect(start, size, PROT_READ | PROT_EXEC);
29922996

2993-
if (ret == start) {
2994-
memcpy(start, mem, real_size);
2995-
mprotect(start, size, PROT_READ | PROT_EXEC);
2996-
}
29972997
munmap(mem, size);
29982998

2999-
return (ret == start) ? 0 : -1;
2999+
return SUCCESS;
30003000
}
30013001

30023002
static void accel_move_code_to_huge_pages(void)

0 commit comments

Comments
 (0)