Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions ext/opcache/jit/zend_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -3554,22 +3554,25 @@ static int zend_jit_parse_config_num(zend_long jit)
if (jit < 0) return FAILURE;

if (jit % 10 == 0 || jit % 10 > 5) return FAILURE;
JIT_G(opt_level) = jit % 10;
uint8_t opt_level = jit % 10;

jit /= 10;
if (jit % 10 > 5 || jit % 10 == 4) return FAILURE;
JIT_G(trigger) = jit % 10;
uint8_t trigger = jit % 10;

jit /= 10;
if (jit % 10 > 2) return FAILURE;
JIT_G(opt_flags) = jit % 10;
uint32_t opt_flags = jit % 10;

jit /= 10;
if (jit % 10 > 1) return FAILURE;
JIT_G(opt_flags) |= ((jit % 10) ? ZEND_JIT_CPU_AVX : 0);
opt_flags |= ((jit % 10) ? ZEND_JIT_CPU_AVX : 0);

if (jit / 10 != 0) return FAILURE;

JIT_G(opt_level) = opt_level;
JIT_G(trigger) = trigger;
JIT_G(opt_flags) = opt_flags;
JIT_G(on) = 1;

return SUCCESS;
Expand All @@ -3585,7 +3588,9 @@ int zend_jit_config(zend_string *jit, int stage)
}

if (zend_string_equals_literal_ci(jit, "disable")) {
JIT_G(enabled) = 0;
if (stage == ZEND_INI_STAGE_STARTUP) {
JIT_G(enabled) = 0;
}
JIT_G(on) = 0;
return SUCCESS;
} else if (ZSTR_LEN(jit) == 0
Expand Down Expand Up @@ -3626,8 +3631,10 @@ int zend_jit_config(zend_string *jit, int stage)

failure:
zend_error(E_WARNING, "Invalid \"opcache.jit\" setting. Should be \"disable\", \"on\", \"off\", \"tracing\", \"function\" or 4-digit number");
JIT_G(enabled) = 0;
JIT_G(on) = 0;
if (stage == ZEND_INI_STAGE_STARTUP) {
JIT_G(enabled) = 0;
JIT_G(on) = 0;
}
return FAILURE;
}

Expand Down
45 changes: 45 additions & 0 deletions ext/opcache/tests/jit/gh25926.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--TEST--
GH-25926 (Runtime opcache.jit change leaves JIT disabled and options dangling for later requests)
--EXTENSIONS--
opcache
--SKIPIF--
<?php
if (ini_get('opcache.jit') === false) die('skip PHP is compiled without JIT');
?>
--CONFLICTS--
server
--FILE--
<?php
include __DIR__ . '/../php_cli_server.inc';
$ini = getenv('TEST_PHP_EXTRA_ARGS') . ' -d opcache.enable=1 -d opcache.enable_cli=1 -d opcache.jit=tracing -d opcache.jit_buffer_size=64M';
$ext = ini_get('extension_dir');
if (file_exists($ext . DIRECTORY_SEPARATOR . (PHP_OS_FAMILY === 'Windows' ? 'php_opcache.dll' : 'opcache.so'))) {
$ini .= ' -d extension_dir=' . $ext . ' -d zend_extension=opcache';
}
php_cli_server_start($ini);

$url = 'http://' . PHP_CLI_SERVER_ADDRESS . '/jit/gh25926_server.php';
foreach (['disable', 'garbage', '1265'] as $value) {
echo file_get_contents($url . '?jit=' . $value);
echo file_get_contents($url);
}
?>
--EXPECT--
string(7) "tracing"
string(7) "tracing"
bool(true)
bool(true)
int(5)
int(4)
bool(false)
string(7) "tracing"
bool(true)
bool(true)
int(5)
int(4)
bool(false)
string(7) "tracing"
bool(true)
bool(true)
int(5)
int(4)
13 changes: 13 additions & 0 deletions ext/opcache/tests/jit/gh25926_server.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
if (isset($_GET['jit'])) {
var_dump(@ini_set('opcache.jit', $_GET['jit']));
} else {
$jit = opcache_get_status(false)['jit'];
var_dump(
opcache_get_configuration()['directives']['opcache.jit'],
$jit['enabled'],
$jit['on'],
$jit['kind'],
$jit['opt_level'],
);
}
Loading