Browse Source

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.
rdb 6 years ago
parent
commit
bf6dbefdd2
1 changed files with 11 additions and 17 deletions
  1. 11 17
      panda/src/display/graphicsPipe.cxx

+ 11 - 17
panda/src/display/graphicsPipe.cxx

@@ -56,36 +56,30 @@ union cpuid_info {
 };
 
 /**
- * Returns the highest cpuid leaf that is supported by the CPU.
+ * Gets cpuid info for the given leaf.
  */
-static inline uint32_t get_cpuid_max(uint32_t leaf) {
+static inline void get_cpuid(uint32_t leaf, cpuid_info &info) {
 #if defined(__GNUC__) && !defined(__APPLE__)
-  return __get_cpuid_max(leaf, nullptr);
+  __cpuid(leaf, info.eax, info.ebx, info.ecx, info.edx);
 #elif defined(_MSC_VER)
-  uint32_t p[4] = {0};
-  __cpuid((int *)p, leaf);
-  return p[0];
+  __cpuid((int *)info.str, leaf);
 #else
-  unsigned int eax = 0;
   __asm__ ("cpuid\n\t"
-           : "=a" (eax)
+           : "=a" (info.eax), "=b" (info.ebx), "=c" (info.ecx), "=d" (info.edx)
            : "0" (leaf));
-  return eax;
 #endif
 }
 
 /**
- * Gets cpuid info for the given leaf.
+ * Returns the highest cpuid leaf that is supported by the CPU.
  */
-static inline void get_cpuid(uint32_t leaf, cpuid_info &info) {
+static inline uint32_t get_cpuid_max(uint32_t leaf) {
 #if defined(__GNUC__) && !defined(__APPLE__)
-  __cpuid(leaf, info.eax, info.ebx, info.ecx, info.edx);
-#elif defined(_MSC_VER)
-  __cpuid((int *)info.str, leaf);
+  return __get_cpuid_max(leaf, nullptr);
 #else
-  __asm__ ("cpuid\n\t"
-           : "=a" (info.eax), "=b" (info.ebx), "=c" (info.ecx), "=d" (info.edx)
-           : "0" (leaf));
+  cpuid_info info;
+  get_cpuid(leaf, info);
+  return info.eax;
 #endif
 }
 #endif