]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use PIOD_READ_CHERI_CAP to read memory capabilities from running processes.
authorJohn Baldwin <jhb@FreeBSD.org>
Thu, 18 Aug 2022 00:22:52 +0000 (17:22 -0700)
committerJohn Baldwin <jhb@FreeBSD.org>
Thu, 1 Sep 2022 23:47:42 +0000 (16:47 -0700)
gdb/fbsd-nat.c
gdb/fbsd-nat.h

index 9b2a7eda6478a45a865ff7bbbe5dbdea92394db6..992c138aaac53747f213fea3049254293d50cea1 100644 (file)
 #define        PT_SETREGSET    43      /* Set a target register set */
 #endif
 
+#ifndef PIOD_READ_CHERI_CAP
+#define        PIOD_READ_CHERI_CAP     7       /* Read CHERI capabilities */
+#endif
+
 /* Return the name of a file that can be opened to get the symbols for
    the child process identified by PID.  */
 
@@ -1953,6 +1957,25 @@ fbsd_nat_target::supports_disable_randomization ()
 #endif
 }
 
+#if __has_feature(capabilities)
+gdb::byte_vector
+fbsd_nat_target::read_capability (CORE_ADDR addr)
+{
+  struct ptrace_io_desc piod;
+  gdb::byte_vector cap_vec (sizeof (uintcap_t) + 1);
+
+  piod.piod_op = PIOD_READ_CHERI_CAP;
+  piod.piod_offs = (void *) (uintptr_t) addr;
+  piod.piod_addr = cap_vec.data ();
+  piod.piod_len = cap_vec.size ();
+  if (ptrace (PT_IO, get_ptrace_pid (inferior_ptid), (PTRACE_TYPE_ARG3) &piod,
+             0) == -1)
+    return {};
+
+  return cap_vec;
+}
+#endif
+
 /* See fbsd-nat.h.  */
 bool
 fbsd_nat_target::have_register_set (ptid_t ptid, int fetch_op, void *regs,
index b74be75d66c50278a89f1827ff42e427338602a8..1fc42528a23e7dac41e9bd402f681f1393fb43d8 100644 (file)
@@ -109,6 +109,10 @@ public:
 
   bool supports_disable_randomization () override;
 
+#if __has_feature(capabilities)
+  gdb::byte_vector read_capability (CORE_ADDR addr) override;
+#endif
+
   /* Methods meant to be overridden by arch-specific target
      classes.  */