From f8b217a3452e76113b833eec8a49bc2b6e8d1fdd Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Mon, 8 Aug 2022 23:54:24 +0200 Subject: [PATCH] Fix pcre.jit on Apple Silicon This backports https://github.com/zherczeg/sljit/pull/105. Relates to bug #80435, however, it doesn't solve the bus error on PHP 8.0, but PHP 8.1 builds fine now. Closes GH-9279. --- NEWS | 3 +++ ext/pcre/pcre2lib/sljit/sljitExecAllocator.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/NEWS b/NEWS index ac630004c5de0..a5dcc78b668dd 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,9 @@ PHP NEWS . Fixed bug #77780 ("Headers already sent..." when previous connection was aborted). (Jakub Zelenka) +- PCRE: + . Fixed pcre.jit on Apple Silicon. (Niklas Keller) + - Streams: . Fixed bug GH-9316 ($http_response_header is wrong for long status line). (cmb, timwolla) diff --git a/ext/pcre/pcre2lib/sljit/sljitExecAllocator.c b/ext/pcre/pcre2lib/sljit/sljitExecAllocator.c index 6e5bf78e45fe9..b268624822219 100644 --- a/ext/pcre/pcre2lib/sljit/sljitExecAllocator.c +++ b/ext/pcre/pcre2lib/sljit/sljitExecAllocator.c @@ -187,10 +187,13 @@ static SLJIT_INLINE void* alloc_chunk(sljit_uw size) if (retval == MAP_FAILED) return NULL; +#ifdef __FreeBSD__ + /* HardenedBSD's mmap lies, so check permissions again */ if (mprotect(retval, size, PROT_READ | PROT_WRITE | PROT_EXEC) < 0) { munmap(retval, size); return NULL; } +#endif /* FreeBSD */ SLJIT_UPDATE_WX_FLAGS(retval, (uint8_t *)retval + size, 0);