AArch64: Use HWCAP to detect pauth feature
authorAlan Hayward <alan.hayward@arm.com>
Fri, 22 Mar 2019 10:00:28 +0000 (10:00 +0000)
committerAlan Hayward <alan.hayward@arm.com>
Fri, 22 Mar 2019 10:10:22 +0000 (10:10 +0000)
Add aarch64_get_hwcap functions for reading the HWCAP.
From this extract the PACA value and use this to enable pauth.

gdb/ChangeLog:

* aarch64-linux-nat.c
(aarch64_linux_nat_target::read_description): Read PACA hwcap.
* aarch64-linux-tdep.c
(aarch64_linux_core_read_description): Likewise.
(aarch64_linux_get_hwcap): New function.
* aarch64-linux-tdep.h (AARCH64_HWCAP_PACA): New define.
(aarch64_linux_get_hwcap): New declaration.

gdb/gdbserver/ChangeLog:

* linux-aarch64-low.c (AARCH64_HWCAP_PACA): New define.
(aarch64_get_hwcap): New function.
(aarch64_arch_setup): Read APIA hwcap.

gdb/ChangeLog
gdb/aarch64-linux-nat.c
gdb/aarch64-linux-tdep.c
gdb/aarch64-linux-tdep.h
gdb/gdbserver/ChangeLog
gdb/gdbserver/linux-aarch64-low.c

index 743f510b29523f34a40a5960df806a63caeaf96c..bd09e4fd73c9e8e90a8b8c32505acc71b50be25a 100644 (file)
@@ -1,3 +1,14 @@
+2019-03-22  Alan Hayward  <alan.hayward@arm.com>
+           Jiong Wang  <jiong.wang@arm.com>
+
+       * aarch64-linux-nat.c
+       (aarch64_linux_nat_target::read_description): Read PACA hwcap.
+       * aarch64-linux-tdep.c
+       (aarch64_linux_core_read_description): Likewise.
+       (aarch64_linux_get_hwcap): New function.
+       * aarch64-linux-tdep.h (AARCH64_HWCAP_PACA): New define.
+       (aarch64_linux_get_hwcap): New declaration.
+
 2019-03-22  Alan Hayward  <alan.hayward@arm.com>
            Jiong Wang  <jiong.wang@arm.com>
 
index f58a41e19555b87b07d037ce87b6379d0c3fb1e7..9572055d9f4cc36fd05cbaa3e88c416c6ebe50b3 100644 (file)
@@ -606,8 +606,11 @@ aarch64_linux_nat_target::read_description ()
   if (ret == 0)
     return tdesc_arm_with_neon;
 
-  /* pauth not yet supported.  */
-  return aarch64_read_description (aarch64_sve_get_vq (tid), false);
+  CORE_ADDR hwcap = 0;
+  bool pauth_p = aarch64_linux_get_hwcap (this, &hwcap)
+                && (hwcap & AARCH64_HWCAP_PACA);
+
+  return aarch64_read_description (aarch64_sve_get_vq (tid), pauth_p);
 }
 
 /* Convert a native/host siginfo object, into/from the siginfo in the
index 445019accc74ead28e3da30416adc856d847aebb..d7db23ef38e9e4e2c59f4a7c1d9ba58ccdc0f7b1 100644 (file)
@@ -637,12 +637,11 @@ aarch64_linux_core_read_description (struct gdbarch *gdbarch,
 {
   CORE_ADDR aarch64_hwcap = 0;
 
-  if (target_auxv_search (target, AT_HWCAP, &aarch64_hwcap) != 1)
-    return NULL;
+  if (!aarch64_linux_get_hwcap (target, &aarch64_hwcap))
+    return nullptr;
 
-  /* pauth not yet supported.  */
   return aarch64_read_description (aarch64_linux_core_read_vq (gdbarch, abfd),
-                                  false);
+                                  aarch64_hwcap & AARCH64_HWCAP_PACA);
 }
 
 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
@@ -1420,6 +1419,15 @@ aarch64_linux_gcc_target_options (struct gdbarch *gdbarch)
   return NULL;
 }
 
+/* See aarch64-linux-tdep.h.  */
+
+bool
+aarch64_linux_get_hwcap (struct target_ops *target, CORE_ADDR *hwcap)
+{
+  *hwcap = 0;
+  return target_auxv_search (target, AT_HWCAP, hwcap) == 1;
+}
+
 static void
 aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
index 814222ead0c11395f969dfbde9e36709819500f1..e9f7c9bccf4885447a61a24a22a02885581c21b9 100644 (file)
 extern const struct regset aarch64_linux_gregset;
 extern const struct regset aarch64_linux_fpregset;
 
+/* Matches HWCAP_PACA in kernel header arch/arm64/include/uapi/asm/hwcap.h.  */
+#define AARCH64_HWCAP_PACA (1 << 30)
+
+/* Fetch the AT_HWCAP entry from the auxv vector for the given TARGET.  */
+bool aarch64_linux_get_hwcap (struct target_ops *target, CORE_ADDR *hwcap);
+
 #endif /* AARCH64_LINUX_TDEP_H */
index 9fdbe1d866ee9ce9a4ecfb79ea5f99f6b3ac8c25..3b585ca99239ecbeaa2479e7e303f344b46fc9d6 100644 (file)
@@ -1,3 +1,10 @@
+2019-03-22  Alan Hayward  <alan.hayward@arm.com>
+           Jiong Wang  <jiong.wang@arm.com>
+
+       * linux-aarch64-low.c (AARCH64_HWCAP_PACA): New define.
+       (aarch64_get_hwcap): New function.
+       (aarch64_arch_setup): Read APIA hwcap.
+
 2019-03-22  Alan Hayward  <alan.hayward@arm.com>
            Jiong Wang  <jiong.wang@arm.com>
 
index db329da4dc9555054670ce15f7aff6886f2535bb..e2e25f0e27a4143edd81f0378caa322494dbe6c6 100644 (file)
@@ -485,6 +485,33 @@ aarch64_linux_new_fork (struct process_info *parent,
   *child->priv->arch_private = *parent->priv->arch_private;
 }
 
+/* Matches HWCAP_PACA in kernel header arch/arm64/include/uapi/asm/hwcap.h.  */
+#define AARCH64_HWCAP_PACA (1 << 30)
+
+/* Fetch the AT_HWCAP entry from the auxv vector.  */
+
+static bool
+aarch64_get_hwcap (unsigned long *valp)
+{
+  unsigned char *data = (unsigned char *) alloca (16);
+  int offset = 0;
+
+  while ((*the_target->read_auxv) (offset, data, 16) == 16)
+    {
+      unsigned long *data_p = (unsigned long *)data;
+      if (data_p[0] == AT_HWCAP)
+       {
+         *valp = data_p[1];
+         return true;
+       }
+
+      offset += 16;
+    }
+
+  *valp = 0;
+  return false;
+}
+
 /* Implementation of linux_target_ops method "arch_setup".  */
 
 static void
@@ -501,8 +528,10 @@ aarch64_arch_setup (void)
   if (is_elf64)
     {
       uint64_t vq = aarch64_sve_get_vq (tid);
-      /* pauth not yet supported.  */
-      current_process ()->tdesc = aarch64_linux_read_description (vq, false);
+      unsigned long hwcap = 0;
+      bool pauth_p = aarch64_get_hwcap (&hwcap) && (hwcap & AARCH64_HWCAP_PACA);
+
+      current_process ()->tdesc = aarch64_linux_read_description (vq, pauth_p);
     }
   else
     current_process ()->tdesc = tdesc_arm_with_neon;