Skip to content

Commit 16da1f5

Browse files
Rather than erroring, disable JIT when pthread protection is unavailable (GH-22853)
1 parent 00f4cd6 commit 16da1f5

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

ext/opcache/jit/zend_jit.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3724,6 +3724,16 @@ int zend_jit_check_support(void)
37243724
{
37253725
int i;
37263726

3727+
#ifdef ZEND_JIT_USE_APPLE_MAP_JIT
3728+
if (!pthread_jit_write_protect_supported_np()) {
3729+
zend_accel_error(ACCEL_LOG_WARNING,
3730+
"Apple Silicon ZTS JIT requires pthread_jit_write_protect_np() support. JIT disabled.");
3731+
JIT_G(enabled) = 0;
3732+
JIT_G(on) = 0;
3733+
return FAILURE;
3734+
}
3735+
#endif
3736+
37273737
if (zend_execute_ex != execute_ex) {
37283738
if (zend_dtrace_enabled) {
37293739
zend_error(E_WARNING, "JIT is incompatible with DTrace. JIT disabled.");
@@ -3792,11 +3802,6 @@ void zend_jit_startup(void *buf, size_t size, bool reattached)
37923802
"Unable to share JIT buffer across fork using minherit(): %s (%d)",
37933803
strerror(error), error);
37943804
}
3795-
if (!pthread_jit_write_protect_supported_np()) {
3796-
munmap(buf, size);
3797-
zend_accel_error_noreturn(ACCEL_LOG_FATAL,
3798-
"Apple Silicon ZTS JIT requires pthread_jit_write_protect_np() support");
3799-
}
38003805
#endif
38013806

38023807
dasm_buf = buf;

ext/opcache/tests/jit/gh14267_001.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ opcache.jit_buffer_size=32M
99
opcache
1010
--FILE--
1111
<?php
12-
ini_set('opcache.jit', 'tracing');
12+
// Skip when JIT was completely disabled at runtime.
13+
if (($status = opcache_get_status()) === false || $status['jit']['enabled']) {
14+
ini_set('opcache.jit', 'tracing');
15+
}
1316
?>
1417
===DONE===
1518
--EXPECT--

ext/opcache/tests/jit/gh16393.phpt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ opcache.jit=1215
77
opcache.jit_buffer_size=64M
88
--FILE--
99
<?php
10-
ini_set('opcache.jit', 'tracing');
10+
// Skip when JIT was completely disabled at runtime.
11+
if (($status = opcache_get_status()) === false || $status['jit']['enabled']) {
12+
ini_set('opcache.jit', 'tracing');
13+
}
1114
class Test {
1215
}
1316
$appendProp2 = (function() {
1417
})->bindTo($test, Test::class);
1518
$appendProp2();
1619
?>
1720
--EXPECTF--
18-
Warning: Undefined variable $test in %sgh16393.php on line 6
21+
Warning: Undefined variable $test in %sgh16393.php on line 9

0 commit comments

Comments
 (0)