From 9871dc5976ded0788d8fb69acd78f14e64751d2e Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Wed, 17 Aug 2022 17:22:52 -0700 Subject: Use PIOD_READ_CHERI_CAP to read memory capabilities from running processes. --- gdb/fbsd-nat.c | 23 +++++++++++++++++++++++ gdb/fbsd-nat.h | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c index 9b2a7eda647..992c138aaac 100644 --- a/gdb/fbsd-nat.c +++ b/gdb/fbsd-nat.c @@ -54,6 +54,10 @@ #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, diff --git a/gdb/fbsd-nat.h b/gdb/fbsd-nat.h index b74be75d66c..1fc42528a23 100644 --- a/gdb/fbsd-nat.h +++ b/gdb/fbsd-nat.h @@ -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. */ -- cgit v1.2.1