Skip to content

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

Closed
@realFlowControl

Description

@realFlowControl

Description

The following code:

<?php
echo "Done";

Resulted in this output:

mprotect() failed [13] Permission denied
Bus error: 10

But I expected this output instead:

done

Executed on CLI using /opt/php/8.3/bin/php -n -d "zend_extension=opcache" -d "opcache.enable_cli=1" -d "opcache.jit=tracing" -d "opcache.jit_buffer_size=40M" -f test.php (where test.php holds the above content).

Using lldb I get the following:

Process 39185 launched: '/opt/php/8.3/bin/php' (arm64)
mprotect() failed [13] Permission denied
Process 39185 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x110fa3ff0)
    frame #0: 0x0000000102deb668 opcache.so`zend_jit_startup(buf=0x000000010e7a4000, size=41943040, reattached=false) at zend_jit.c:4994:13
   4991		dasm_ptr = dasm_end = (void*)(((char*)dasm_buf) + size - sizeof(*dasm_ptr) * 2);
   4992		if (!reattached) {
   4993			zend_jit_unprotect();
-> 4994			*dasm_ptr = dasm_buf;
   4995	#if _WIN32
   4996			/* reserve space for global labels */
   4997			*dasm_ptr = (void**)*dasm_ptr + zend_lb_MAX;
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x110fa3ff0)
  * frame #0: 0x0000000102deb668 opcache.so`zend_jit_startup(buf=0x000000010e7a4000, size=41943040, reattached=false) at zend_jit.c:4994:13
    frame #1: 0x0000000102d93590 opcache.so`accel_post_startup at ZendAccelerator.c:3253:8
    frame #2: 0x00000001007f6550 php`zend_post_startup at zend.c:1072:7
    frame #3: 0x00000001006f95ec php`php_module_startup(sf=0x0000000101506e28, additional_module=0x0000000000000000) at main.c:2259:6
    frame #4: 0x0000000100a9c84c php`php_cli_startup(sapi_module=0x0000000101506e28) at php_cli.c:410:9
    frame #5: 0x0000000100a9a860 php`main(argc=12, argv=0x0000600002344000) at php_cli.c:1307:6
    frame #6: 0x0000000189acd0e0 dyld`start + 2360

The mprotect() failed [13] Permission denied originates from the mprotect() call in zend_jit_unprotect() in

if (mprotect(dasm_buf, dasm_size, opts) != 0) {
fprintf(stderr, "mprotect() failed [%d] %s\n", errno, strerror(errno));
}

This might be related: https://developer.apple.com/forums/thread/672804

PHP Version

8.3 ZTS (it is not failing on NTS version of PHP, only on ZTS)

Operating System

MacOS 14.13.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions