From bf6dbefdd2d5744e712eff7cafbd784733b05846 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 6 Jan 2020 18:11:40 +0100 Subject: [PATCH] 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. --- panda/src/display/graphicsPipe.cxx | 32 ++++++++++++------------------ 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/panda/src/display/graphicsPipe.cxx b/panda/src/display/graphicsPipe.cxx index 937987f567..52ccfa426d 100644 --- a/panda/src/display/graphicsPipe.cxx +++ b/panda/src/display/graphicsPipe.cxx @@ -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