Files
binutils-gdb/gdb/arch/aarch64-gcs-linux.h
Thiago Jung Bauermann 9e4e5ac9dd GDB, gdbserver: aarch64-linux: Initial Guarded Control Stack support
Add the org.gnu.gdb.aarch64.gcs feature with the GCSPR register, and the
org.gnu.gdb.aarch64.gcs.linux feature with "registers" to represent the
Linux kernel ptrace and prctl knobs that enable and lock specific GCS
functionality.

This code supports GCS only in Linux userspace applications, so the
GCSPR that is exposed is the one at EL0.

Also, support for calling inferior functions is enabled by adding an
implementation for the shadow_stack_push gdbarch method.

If for some reason a target description contains the
org.gnu.gdb.aarch64.gcs feature but not the
org.gnu.gdb.aarch64.gcs.linux feature then GCS support is disabled and
GDB continues the debugging session.  Features that need GCS
support (for example, calling inferior functions) will not work and the
inferior will get a segmentation fault signal instead.  There's a
testcase for this scenario but it only checks the native debugging case,
even though in practice this problem would only occur in remote
debugging with a broken stub or gdbserver.  I tested manually with a
gdbserver hacked to send a broken target description and it worked as
described.

Testcases gdb.arch/aarch64-gcs.exp, gdb.arch/aarch64-gcs-core.exp and
gdb.arch/aarch64-gcs-wrong-tdesc.exp are included to cover the added
functionality.

The change in the core_find procedure allows aarch64-gcs-core.exp to
recover the output from the crashed program.  It's needed because the
test program in this testcase prints to stdout the value of the GCSPR
right before crashing, and the testcase needs it to check whether GDB
got it right.
2025-06-21 21:25:02 -03:00

45 lines
1.2 KiB
C

/* Common Linux target-dependent definitions for AArch64 GCS
Copyright (C) 2025 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 <http://www.gnu.org/licenses/>. */
#ifndef ARCH_AARCH64_GCS_LINUX_H
#define ARCH_AARCH64_GCS_LINUX_H
#include <stdint.h>
/* Feature check for Guarded Control Stack. */
#ifndef HWCAP_GCS
#define HWCAP_GCS (1UL << 32)
#endif
/* Make sure we only define these if the kernel header doesn't. */
#ifndef GCS_MAGIC
/* GCS state (NT_ARM_GCS). */
struct user_gcs
{
uint64_t features_enabled;
uint64_t features_locked;
uint64_t gcspr_el0;
};
#endif /* GCS_MAGIC */
#endif /* ARCH_AARCH64_GCS_LINUX_H */