1c194f
commit 6bb6c8a65a341a67bd059ec6e1c805813eb17264
1c194f
Author: Mark Wielaard <mark@klomp.org>
1c194f
Date:   Tue Jun 19 18:00:45 2018 +0200
1c194f
1c194f
    Mask AT_HWCAPS on arm64 to those instructions VEX implements.
1c194f
    
1c194f
    This patch makes sure that the process running under valgrind only sees
1c194f
    the AES, PMULL, SHA1, SHA2, CRC32, FP, and ASIMD features in auxv AT_HWCAPS.
1c194f
    
1c194f
    https://bugs.kde.org/show_bug.cgi?id=381556
1c194f
1af9e5
diff --git a/coregrind/m_initimg/initimg-linux.c b/coregrind/m_initimg/initimg-linux.c
1c194f
index 30e1f85..61cc458 100644
1af9e5
--- a/coregrind/m_initimg/initimg-linux.c
1af9e5
+++ b/coregrind/m_initimg/initimg-linux.c
1c194f
@@ -703,6 +703,19 @@ Addr setup_client_stack( void*  init_sp,
1af9e5
                   (and anything above) are not supported by Valgrind. */
1af9e5
                auxv->u.a_val &= VKI_HWCAP_S390_TE - 1;
1af9e5
             }
1af9e5
+#           elif defined(VGP_arm64_linux)
1af9e5
+            {
1c194f
+               /* Limit the AT_HWCAP to just those features we explicitly
1c194f
+		  support in VEX.  */
1c194f
+#define ARM64_SUPPORTED_HWCAP (VKI_HWCAP_AES	        \
1c194f
+                               | VKI_HWCAP_PMULL        \
1c194f
+                               | VKI_HWCAP_SHA1         \
1c194f
+                               | VKI_HWCAP_SHA2         \
1c194f
+                               | VKI_HWCAP_CRC32        \
1c194f
+                               | VKI_HWCAP_FP           \
1c194f
+                               | VKI_HWCAP_ASIMD)
1c194f
+               auxv->u.a_val &= ARM64_SUPPORTED_HWCAP;
1af9e5
+            }
1af9e5
 #           endif
1af9e5
             break;
1af9e5
 #        if defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)
1c194f
diff --git a/include/vki/vki-arm64-linux.h b/include/vki/vki-arm64-linux.h
1c194f
index af6b435..54b0428 100644
1c194f
--- a/include/vki/vki-arm64-linux.h
1c194f
+++ b/include/vki/vki-arm64-linux.h
1c194f
@@ -692,6 +692,39 @@ struct vki_shminfo64 {
1c194f
 #define VKI_TIOCSSERIAL     0x541F
1c194f
 
1c194f
 //----------------------------------------------------------------------
1c194f
+// From linux-4.17/include/uapi/asm-generic/ioctls.h
1c194f
+//----------------------------------------------------------------------
1c194f
+
1c194f
+#define VKI_HWCAP_FP                (1 << 0)
1c194f
+#define VKI_HWCAP_ASIMD             (1 << 1)
1c194f
+#define VKI_HWCAP_EVTSTRM           (1 << 2)
1c194f
+#define VKI_HWCAP_AES               (1 << 3)
1c194f
+#define VKI_HWCAP_PMULL             (1 << 4)
1c194f
+#define VKI_HWCAP_SHA1              (1 << 5)
1c194f
+#define VKI_HWCAP_SHA2              (1 << 6)
1c194f
+#define VKI_HWCAP_CRC32             (1 << 7)
1c194f
+#define VKI_HWCAP_ATOMICS           (1 << 8)
1c194f
+#define VKI_HWCAP_FPHP              (1 << 9)
1c194f
+#define VKI_HWCAP_ASIMDHP           (1 << 10)
1c194f
+#define VKI_HWCAP_CPUID             (1 << 11)
1c194f
+#define VKI_HWCAP_ASIMDRDM          (1 << 12)
1c194f
+#define VKI_HWCAP_JSCVT             (1 << 13)
1c194f
+#define VKI_HWCAP_FCMA              (1 << 14)
1c194f
+#define VKI_HWCAP_LRCPC             (1 << 15)
1c194f
+#define VKI_HWCAP_DCPOP             (1 << 16)
1c194f
+#define VKI_HWCAP_SHA3              (1 << 17)
1c194f
+#define VKI_HWCAP_SM3               (1 << 18)
1c194f
+#define VKI_HWCAP_SM4               (1 << 19)
1c194f
+#define VKI_HWCAP_ASIMDDP           (1 << 20)
1c194f
+#define VKI_HWCAP_SHA512            (1 << 21)
1c194f
+#define VKI_HWCAP_SVE               (1 << 22)
1c194f
+#define VKI_HWCAP_ASIMDFHM          (1 << 23)
1c194f
+#define VKI_HWCAP_DIT               (1 << 24)
1c194f
+#define VKI_HWCAP_USCAT             (1 << 25)
1c194f
+#define VKI_HWCAP_ILRCPC            (1 << 26)
1c194f
+#define VKI_HWCAP_FLAGM             (1 << 27)
1c194f
+
1c194f
+//----------------------------------------------------------------------
1c194f
 // And that's it!
1c194f
 //----------------------------------------------------------------------
1c194f