Skip to content

Commit 5a361c3

Browse files
committed
Possible fix for bug #77357
Don't invoke CPUID with feature levels above the supported maximum. In this case CPUID will return the highest supported basic information leaf, which will have unrelated bits in the relevant positions.
1 parent 349dbb7 commit 5a361c3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Diff for: Zend/zend_cpuinfo.c

+11-3
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,24 @@ void zend_cpu_startup(void)
7777
{
7878
if (!cpuinfo.initialized) {
7979
zend_cpu_info ebx;
80+
int max_feature;
8081

8182
cpuinfo.initialized = 1;
8283
__zend_cpuid(0, 0, &cpuinfo);
83-
if (cpuinfo.eax == 0) {
84+
max_feature = cpuinfo.eax;
85+
if (max_feature == 0) {
8486
return;
8587
}
88+
8689
__zend_cpuid(1, 0, &cpuinfo);
90+
8791
/* for avx2 */
88-
__zend_cpuid(7, 0, &ebx);
89-
cpuinfo.ebx = ebx.ebx;
92+
if (max_feature >= 7) {
93+
__zend_cpuid(7, 0, &ebx);
94+
cpuinfo.ebx = ebx.ebx;
95+
} else {
96+
cpuinfo.ebx = 0;
97+
}
9098
}
9199
}
92100

0 commit comments

Comments
 (0)