Add CRYPTO_needs_hwcap2_workaround.

Bug: 203
Change-Id: I50384cce14509ab1ca36e6f0e9f192f9e458b313
Reviewed-on: https://boringssl-review.googlesource.com/20404
Commit-Queue: Steven Valdez <svaldez@google.com>
Reviewed-by: Steven Valdez <svaldez@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
diff --git a/crypto/cpu-arm-linux.c b/crypto/cpu-arm-linux.c
index a5f1f8a..839b632 100644
--- a/crypto/cpu-arm-linux.c
+++ b/crypto/cpu-arm-linux.c
@@ -288,7 +288,7 @@
 
 extern uint32_t OPENSSL_armcap_P;
 
-static int g_has_broken_neon;
+static int g_has_broken_neon, g_needs_hwcap2_workaround;
 
 void OPENSSL_cpuid_setup(void) {
   char *cpuinfo_data;
@@ -336,6 +336,7 @@
     }
     if (hwcap2 == 0) {
       hwcap2 = get_hwcap2_cpuinfo(&cpuinfo);
+      g_needs_hwcap2_workaround = hwcap2 != 0;
     }
 
     if (hwcap2 & HWCAP2_AES) {
@@ -357,4 +358,6 @@
 
 int CRYPTO_has_broken_NEON(void) { return g_has_broken_neon; }
 
+int CRYPTO_needs_hwcap2_workaround(void) { return g_needs_hwcap2_workaround; }
+
 #endif  // OPENSSL_ARM && !OPENSSL_STATIC_ARMCAP
diff --git a/include/openssl/cpu.h b/include/openssl/cpu.h
index 39e7264..dd95ddc 100644
--- a/include/openssl/cpu.h
+++ b/include/openssl/cpu.h
@@ -135,6 +135,10 @@
 // CRYPTO_has_broken_NEON returns one if the current CPU is known to have a
 // broken NEON unit. See https://crbug.com/341598.
 OPENSSL_EXPORT int CRYPTO_has_broken_NEON(void);
+
+// CRYPTO_needs_hwcap2_workaround returns one if the ARMv8 AArch32 AT_HWCAP2
+// workaround was needed. See https://crbug.com/boringssl/46.
+OPENSSL_EXPORT int CRYPTO_needs_hwcap2_workaround(void);
 #endif
 
 // CRYPTO_is_ARMv8_AES_capable returns true if the current CPU supports the