Skip to content

re-enable JIT for ZTS builds on Apple Silicon#22712

Open
realFlowControl wants to merge 3 commits into
php:masterfrom
realFlowControl:florian/apple-silicon-zts-jit
Open

re-enable JIT for ZTS builds on Apple Silicon#22712
realFlowControl wants to merge 3 commits into
php:masterfrom
realFlowControl:florian/apple-silicon-zts-jit

Conversation

@realFlowControl

@realFlowControl realFlowControl commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #13400

For __APPLE__ && __aarch64__ && ZTS, this PR moves the JIT buffer out of the OPcache shared memory and creates a dedicated mapping.

Background

OPcache JIT is currently disabled for ZTS builds on Apple Silicon. The JIT buffer normally lives at the end of OPcache's MAP_SHARED | MAP_ANON allocation. In ZTS, one thread may generate code while another executes existing code, so the buffer must remain executable while it is writable.

Apple Silicon rejects RWX anonymous mappings with EPERM. Apple's supported solution is MAP_JIT with pthread_jit_write_protect_np(), which provides per-thread write protection, but macOS rejects MAP_JIT | MAP_SHARED with EINVAL. The existing combined OPcache/JIT mapping won't work on Apple Silicon.

@henderkes

Copy link
Copy Markdown
Contributor

I don't know if this was in response to my mail, but thank you 😄

@realFlowControl

Copy link
Copy Markdown
Contributor Author

I don't know if this was in response to my mail, but thank you 😄

Actually yes, haha. I knew that this should work, I just was not working on it and then reading your mail reminded me of it 👍

Comment thread ext/opcache/jit/zend_jit.c
Comment on lines +3800 to +3801
buf = mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANON | MAP_JIT, -1, 0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clarify if MAP_JIT can be used freely without an com.apple.security.cs.allow-jit entitlement?

@bwoebi bwoebi Jul 13, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The com.apple.security.cs.allow-jit entitlement is required only when an app adopts the Hardened Runtime capability.

As per https://developer.apple.com/documentation/apple-silicon/porting-just-in-time-compilers-to-apple-silicon.

i.e. it's not relevant to non-app store executables.

Comment thread ext/opcache/ZendAccelerator.c Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mprotect() failed [13] Permission denied followed by a SIBGUS on MacOS with Apple Silicon and PHP ZTS

4 participants