Skip to content

Commit 3660bc3

Browse files
committed
opcache fixing w/x pages creation on freebsd 13.1 and above.
By default, the system allows these but admin can disable them system wide. However the procctl api permits to control it per process. Closes GH-9896.
1 parent e57d056 commit 3660bc3

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ PHP NEWS
4545
(Arnaud, Kapitan Oczywisty)
4646
. Made opcache.preload_user always optional in the cli and phpdbg SAPIs.
4747
(Arnaud)
48+
. Allows W/X bits on page creation on FreeBSD despite system settings.
49+
(David Carlier)
4850

4951
- PCNTL:
5052
. SA_ONSTACK is now set for pcntl_signal. (Kévin Dunglas)

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ sys/file.h \
410410
sys/mman.h \
411411
sys/mount.h \
412412
sys/poll.h \
413+
sys/procctl.h \
413414
sys/resource.h \
414415
sys/select.h \
415416
sys/socket.h \

ext/opcache/shared_alloc_mmap.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
#endif
3535

3636
#include "zend_execute.h"
37+
#ifdef HAVE_SYS_PROCCTL_H
38+
#include <sys/procctl.h>
39+
#endif
3740

3841
#if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
3942
# define MAP_ANONYMOUS MAP_ANON
@@ -156,6 +159,12 @@ static int create_segments(size_t requested_size, zend_shared_segment ***shared_
156159
zend_shared_segment *shared_segment;
157160
int flags = PROT_READ | PROT_WRITE, fd = -1;
158161
void *p;
162+
#if defined(HAVE_PROCCTL) && defined(PROC_WXMAP_CTL)
163+
int enable_wxmap = PROC_WX_MAPPINGS_PERMIT;
164+
if (procctl(P_PID, getpid(), PROC_WXMAP_CTL, &enable_wxmap) == -1) {
165+
return ALLOC_FAILURE;
166+
}
167+
#endif
159168
#ifdef PROT_MPROTECT
160169
flags |= PROT_MPROTECT(PROT_EXEC);
161170
#endif

0 commit comments

Comments
 (0)