Merge pull request #1942 from danog/move_jit_check

Move JIT check to BigInteger
This commit is contained in:
terrafrost 2023-09-25 06:44:51 -05:00 committed by GitHub
commit 4777b59ce9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 14 deletions

View File

@ -29,6 +29,7 @@ namespace phpseclib3\Math;
use phpseclib3\Exception\BadConfigurationException;
use phpseclib3\Math\BigInteger\Engines\Engine;
use UnexpectedValueException;
/**
* Pure-PHP arbitrary precision integer arithmetic library. Supports base-2, base-10, base-16, and base-256
@ -143,13 +144,16 @@ class BigInteger implements \JsonSerializable
['PHP64', ['DefaultEngine']],
['PHP32', ['DefaultEngine']]
];
foreach ($engines as $engine) {
try {
self::setEngine($engine[0], $engine[1]);
break;
return;
} catch (\Exception $e) {
}
}
throw new UnexpectedValueException('No valid BigInteger found. This is only possible when JIT is enabled on Windows and neither the GMP or BCMath extensions are available so either disable JIT or install GMP / BCMath');
}
}

View File

@ -1326,4 +1326,18 @@ abstract class PHP extends Engine
return array_reverse($vals);
}
/**
* @return bool
*/
protected static function testJITOnWindows()
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && function_exists('opcache_get_status') && !defined('PHPSECLIB_ALLOW_JIT')) {
$status = opcache_get_status();
if ($status && isset($status['jit']) && $status['jit']['enabled'] && $status['jit']['on']) {
return true;
}
}
return false;
}
}

View File

@ -102,7 +102,7 @@ class PHP32 extends PHP
*/
public static function isValidEngine()
{
return PHP_INT_SIZE >= 4;
return PHP_INT_SIZE >= 4 && !self::testJITOnWindows();
}
/**

View File

@ -103,7 +103,7 @@ class PHP64 extends PHP
*/
public static function isValidEngine()
{
return PHP_INT_SIZE >= 8;
return PHP_INT_SIZE >= 8 && !self::testJITOnWindows();
}
/**

View File

@ -19,14 +19,4 @@ if (extension_loaded('mbstring')) {
'is not supported by phpseclib.'
);
}
}
// see https://github.com/php/php-src/issues/11917
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && function_exists('opcache_get_status') && !defined('PHPSECLIB_ALLOW_JIT')) {
$status = opcache_get_status();
if ($status && isset($status['jit']) && $status['jit']['enabled'] && $status['jit']['on']) {
throw new UnexpectedValueException(
'JIT on Windows is not currently supported'
);
}
}
}