diff options
author | Luis Machado <luis.machado@arm.com> | 2022-05-24 23:31:09 +0100 |
---|---|---|
committer | Luis Machado <luis.machado@arm.com> | 2022-12-16 11:18:32 +0000 |
commit | d88cb738e6a7a7179dfaff8af78d69250c852af1 (patch) | |
tree | c34f73f06cea5177a4763afb73baf2e8a41c68f6 /gdb/arch | |
parent | 22a8433e00fd33efcb1fa4961eb826cd97f2cd8b (diff) | |
download | gdb-d88cb738e6a7a7179dfaff8af78d69250c852af1.zip gdb-d88cb738e6a7a7179dfaff8af78d69250c852af1.tar.gz gdb-d88cb738e6a7a7179dfaff8af78d69250c852af1.tar.bz2 |
[aarch64] Fix removal of non-address bits for PAuth
PR gdb/28947
The address_significant gdbarch setting was introduced as a way to remove
non-address bits from pointers, and it is specified by a constant. This
constant represents the number of address bits in a pointer.
Right now AArch64 is the only architecture that uses it, and 56 was a
correct option so far.
But if we are using Pointer Authentication (PAuth), we might use up to 2 bytes
from the address space to store the required information. We could also have
cases where we're using both PAuth and MTE.
We could adjust the constant to 48 to cover those cases, but this doesn't
cover the case where GDB needs to sign-extend kernel addresses after removal
of the non-address bits.
This has worked so far because bit 55 is used to select between kernel-space
and user-space addresses. But trying to clear a range of bits crossing the
bit 55 boundary requires the hook to be smarter.
The following patch renames the gdbarch hook from significant_addr_bit to
remove_non_address_bits and passes a pointer as opposed to the number of
bits. The hook is now responsible for removing the required non-address bits
and sign-extending the address if needed.
While at it, make GDB and GDBServer share some more code for aarch64 and add a
new arch-specific testcase gdb.arch/aarch64-non-address-bits.exp.
Bug-url: https://sourceware.org/bugzilla/show_bug.cgi?id=28947
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diffstat (limited to 'gdb/arch')
-rw-r--r-- | gdb/arch/aarch64.c | 31 | ||||
-rw-r--r-- | gdb/arch/aarch64.h | 18 |
2 files changed, 49 insertions, 0 deletions
diff --git a/gdb/arch/aarch64.c b/gdb/arch/aarch64.c index 565c5e7..0df4140 100644 --- a/gdb/arch/aarch64.c +++ b/gdb/arch/aarch64.c @@ -59,3 +59,34 @@ aarch64_create_target_description (const aarch64_features &features) return tdesc.release (); } + +/* See arch/aarch64.h. */ + +CORE_ADDR +aarch64_remove_top_bits (CORE_ADDR pointer, CORE_ADDR mask) +{ + /* The VA range select bit is 55. This bit tells us if we have a + kernel-space address or a user-space address. */ + bool kernel_address = (pointer & VA_RANGE_SELECT_BIT_MASK) != 0; + + /* Remove the top non-address bits. */ + pointer &= ~mask; + + /* Sign-extend if we have a kernel-space address. */ + if (kernel_address) + pointer |= mask; + + return pointer; +} + +/* See arch/aarch64.h. */ + +CORE_ADDR +aarch64_mask_from_pac_registers (const CORE_ADDR cmask, const CORE_ADDR dmask) +{ + /* If the masks differ, default to using the one with the most coverage. */ + if (dmask != cmask) + return dmask > cmask ? dmask : cmask; + + return cmask; +} diff --git a/gdb/arch/aarch64.h b/gdb/arch/aarch64.h index b1a6ce3..6804819 100644 --- a/gdb/arch/aarch64.h +++ b/gdb/arch/aarch64.h @@ -71,6 +71,17 @@ namespace std target_desc * aarch64_create_target_description (const aarch64_features &features); +/* Given a pointer value POINTER and a MASK of non-address bits, remove the + non-address bits from the pointer and sign-extend the result if required. + The sign-extension is required so we can handle kernel addresses + correctly. */ +CORE_ADDR aarch64_remove_top_bits (CORE_ADDR pointer, CORE_ADDR mask); + +/* Given CMASK and DMASK the two PAC mask registers, return the correct PAC + mask to use for removing non-address bits from a pointer. */ +CORE_ADDR +aarch64_mask_from_pac_registers (const CORE_ADDR cmask, const CORE_ADDR dmask); + /* Register numbers of various important registers. Note that on SVE, the Z registers reuse the V register numbers and the V registers become pseudo registers. */ @@ -104,6 +115,13 @@ enum aarch64_regnum #define AARCH64_TLS_REGISTER_SIZE 8 #define V_REGISTER_SIZE 16 +/* PAC-related constants. */ +/* Bit 55 is used to select between a kernel-space and user-space address. */ +#define VA_RANGE_SELECT_BIT_MASK 0x80000000000000ULL +/* Mask with 1's in bits 55~63, used to remove the top byte of pointers + (Top Byte Ignore). */ +#define AARCH64_TOP_BITS_MASK 0xff80000000000000ULL + /* Pseudo register base numbers. */ #define AARCH64_Q0_REGNUM 0 #define AARCH64_D0_REGNUM (AARCH64_Q0_REGNUM + AARCH64_D_REGISTER_COUNT) |