From d15d83788392173cfdf87da973ca224b692104e4 Mon Sep 17 00:00:00 2001 From: Luis Machado Date: Tue, 5 Jan 2021 18:02:32 -0300 Subject: [PATCH] Add PTRACE_POKECAP request and move things to a Morello-specific file gdb/ChangeLog: 2021-01-15 Luis Machado * Makefile.in (HFILES_NO_SRCDIR): Add nat/aarch64-cap-linux.h. * aarch64-linux-nat.c: Include nat/aarch64-cap-linux.h. * nat/aarch64-cap-linux.h: New file. * nat/aarch64-linux.h (struct user_morello_state): Move to nat/aarch64-cap-linux.h. gdbserver/ChangeLog: 2021-01-15 Luis Machado * linux-aarch64-low.cc: Include nat/aarch64-cap-linux.h. --- gdb/Makefile.in | 1 + gdb/aarch64-linux-nat.c | 1 + gdb/nat/aarch64-cap-linux.h | 61 ++++++++++++++++++++++++++++++++++ gdb/nat/aarch64-linux.h | 24 ------------- gdbserver/linux-aarch64-low.cc | 1 + 5 files changed, 64 insertions(+), 24 deletions(-) create mode 100644 gdb/nat/aarch64-cap-linux.h diff --git a/gdb/Makefile.in b/gdb/Makefile.in index dd83e9bcad7..d33365b1032 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1528,6 +1528,7 @@ HFILES_NO_SRCDIR = \ mi/mi-main.h \ mi/mi-out.h \ mi/mi-parse.h \ + nat/aarch64-cap-linux.h \ nat/aarch64-linux.h \ nat/aarch64-linux-hw-point.h \ nat/aarch64-mte-linux-ptrace.h \ diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c index 5a79dd44493..5a5ebcc96e8 100644 --- a/gdb/aarch64-linux-nat.c +++ b/gdb/aarch64-linux-nat.c @@ -34,6 +34,7 @@ #include "aarch32-tdep.h" #include "arch/arm.h" #include "arch/aarch64-cap-linux.h" +#include "nat/aarch64-cap-linux.h" /* For Morello */ #include "nat/aarch64-linux.h" #include "nat/aarch64-linux-hw-point.h" #include "nat/aarch64-sve-linux-ptrace.h" diff --git a/gdb/nat/aarch64-cap-linux.h b/gdb/nat/aarch64-cap-linux.h new file mode 100644 index 00000000000..2b3c1dc5f3e --- /dev/null +++ b/gdb/nat/aarch64-cap-linux.h @@ -0,0 +1,61 @@ +/* Copyright (C) 2021 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef NAT_AARCH64_CAP_LINUX_H +#define NAT_AARCH64_CAP_LINUX_H + +/* Morello-specific requests. */ +#ifndef PTRACE_PEEKCAP +#define PTRACE_PEEKCAP 12 +#endif + +#ifndef PTRACE_POKECAP +#define PTRACE_POKECAP 13 +#endif + +/* Struct defining the layout of the capability register set. */ +struct user_morello_state { + /* General capability registers. */ + unsigned __int128 cregs[31]; + /* Capability program counter. */ + unsigned __int128 pcc; + /* Capability stack pointer. */ + unsigned __int128 csp; + /* Default data capability. */ + unsigned __int128 ddc; + unsigned __int128 ctpidr; + unsigned __int128 rcsp; + unsigned __int128 rddc; + unsigned __int128 rctpidr; + /* Compartment ID register. */ + unsigned __int128 cid; + /* Bitmap storing the tags of all the capability registers. + The tag for register is stored at bit index + MORELLO_PT_TAG_MAP_REG_BIT() in tag_map. */ + uint64_t tag_map; + /* Capability control register. */ + uint64_t cctlr; +}; + +/* Struct used to read/write capabilities using ptrace. */ +struct user_cap { + unsigned __int128 val; + uint8_t tag; + uint8_t __reserved[15]; +}; + +#endif /* NAT_AARCH64_CAP_LINUX_H */ diff --git a/gdb/nat/aarch64-linux.h b/gdb/nat/aarch64-linux.h index 6104dfa8ef2..1777ce32522 100644 --- a/gdb/nat/aarch64-linux.h +++ b/gdb/nat/aarch64-linux.h @@ -24,30 +24,6 @@ /* Defines ps_err_e, struct ps_prochandle. */ #include "gdb_proc_service.h" -/* Struct defining the layout of the capability register set. */ -struct user_morello_state { - /* General capability registers. */ - unsigned __int128 cregs[31]; - /* Capability program counter. */ - unsigned __int128 pcc; - /* Capability stack pointer. */ - unsigned __int128 csp; - /* Default data capability. */ - unsigned __int128 ddc; - unsigned __int128 ctpidr; - unsigned __int128 rcsp; - unsigned __int128 rddc; - unsigned __int128 rctpidr; - /* Compartment ID register. */ - unsigned __int128 cid; - /* Bitmap storing the tags of all the capability registers. - The tag for register is stored at bit index - MORELLO_PT_TAG_MAP_REG_BIT() in tag_map. */ - uint64_t tag_map; - /* Capability control register. */ - uint64_t cctlr; -}; - typedef int compat_int_t; typedef unsigned int compat_uptr_t; diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc index 48e0a3726f8..78c57b031e3 100644 --- a/gdbserver/linux-aarch64-low.cc +++ b/gdbserver/linux-aarch64-low.cc @@ -21,6 +21,7 @@ #include "server.h" #include "linux-low.h" +#include "nat/aarch64-cap-linux.h" /* For Morello */ #include "nat/aarch64-linux.h" #include "nat/aarch64-linux-hw-point.h" #include "arch/aarch64-cap-linux.h" -- 2.47.2