crypto/ppccap.c: SIGILL-free processor capabilities detection on MacOS X.
authorAndy Polyakov <appro@openssl.org>
Sat, 1 Apr 2017 13:28:28 +0000 (15:28 +0200)
committerAndy Polyakov <appro@openssl.org>
Sun, 2 Apr 2017 20:10:06 +0000 (22:10 +0200)
It seems to be problematic to probe processor capabilities with SIGILL
on MacOS X. The problem should be limited to cases when application code
is debugged, but crashes were reported even during normal execution...

Reviewed-by: Kurt Roeckx <kurt@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(cherry picked from commit 0bd93bbe4ae60e5f318b298bfe617e468a7b71d0)

crypto/ppccap.c

index ef38b172d9af9c871af9d9ccdec011994d6ef545..3baf9f7b76c1d0f832f0661d5e949602cca6c467 100644 (file)
 #  define __power_set(a) (_system_configuration.implementation & (a))
 # endif
 #endif
+#if defined(__APPLE__) && defined(__MACH__)
+# include <sys/types.h>
+# include <sys/sysctl.h>
+#endif
 #include <openssl/crypto.h>
 #include <openssl/bn.h>
 
@@ -230,6 +234,28 @@ void OPENSSL_cpuid_setup(void)
 # endif
 #endif
 
+#if defined(__APPLE__) && defined(__MACH__)
+    OPENSSL_ppccap_P |= PPC_FPU;
+
+    {
+        int val;
+        size_t len = sizeof(val);
+
+        if (sysctlbyname("hw.optional.64bitops", &val, &len, NULL, 0) == 0) {
+            if (val)
+                OPENSSL_ppccap_P |= PPC_FPU64;
+        }
+
+        len = sizeof(val);
+        if (sysctlbyname("hw.optional.altivec", &val, &len, NULL, 0) == 0) {
+            if (val)
+                OPENSSL_ppccap_P |= PPC_ALTIVEC;
+        }
+
+        return;
+    }
+#endif
+
     if (getauxval != NULL) {
         unsigned long hwcap = getauxval(HWCAP);