display: fix get_cpuid_max clobbering %rbx (fixes Py 3.8 crash on macOS)

This could cause a crash when constructing a GraphicsPipe() under some conditions (observed in Python 3.8).  Credit goes to @CFSworks for tracking this down.
This commit is contained in:
rdb 2020-01-06 18:11:40 +01:00
parent b78f0b0881
commit bf6dbefdd2

View File

@ -55,25 +55,6 @@ union cpuid_info {
};
};
/**
* Returns the highest cpuid leaf that is supported by the CPU.
*/
static inline uint32_t get_cpuid_max(uint32_t leaf) {
#if defined(__GNUC__) && !defined(__APPLE__)
return __get_cpuid_max(leaf, nullptr);
#elif defined(_MSC_VER)
uint32_t p[4] = {0};
__cpuid((int *)p, leaf);
return p[0];
#else
unsigned int eax = 0;
__asm__ ("cpuid\n\t"
: "=a" (eax)
: "0" (leaf));
return eax;
#endif
}
/**
* Gets cpuid info for the given leaf.
*/
@ -88,6 +69,19 @@ static inline void get_cpuid(uint32_t leaf, cpuid_info &info) {
: "0" (leaf));
#endif
}
/**
* Returns the highest cpuid leaf that is supported by the CPU.
*/
static inline uint32_t get_cpuid_max(uint32_t leaf) {
#if defined(__GNUC__) && !defined(__APPLE__)
return __get_cpuid_max(leaf, nullptr);
#else
cpuid_info info;
get_cpuid(leaf, info);
return info.eax;
#endif
}
#endif
#ifdef IS_LINUX