summaryrefslogtreecommitdiff
path: root/gdb/gdbarch.h
diff options
context:
space:
mode:
authorLuis Machado <luis.machado@linaro.org>2020-06-19 17:36:14 -0300
committerLuis Machado <luis.machado@linaro.org>2021-03-24 14:47:52 -0300
commitc193949e75809a656b99c8408e5b29504aec436a (patch)
treee8adec412217398f1684fe69a4a26d63f3be7046 /gdb/gdbarch.h
parentdbe692af2d1814100748b18a5dd70214e8611107 (diff)
downloadbinutils-gdb-c193949e75809a656b99c8408e5b29504aec436a.tar.gz
New gdbarch memory tagging hooks
We need some new gdbarch hooks to help us manipulate memory tags without having to have GDB call the target methods directly. This patch adds the following hooks: gdbarch_memtag_to_string -- Returns a printable string corresponding to the tag. gdbarch_tagged_address_p -- Checks if a particular address is protected with memory tagging. gdbarch_memtag_matches_p -- Checks if the logical tag of a pointer and the allocation tag from the address the pointer points to matches. gdbarch_set_memtags: -- Sets either the allocation tag or the logical tag for a particular value. gdbarch_get_memtag: -- Gets either the allocation tag or the logical tag for a particular value. gdbarch_memtag_granule_size -- Sets the memory tag granule size, which represents the number of bytes a particular allocation tag covers. For example, this is 16 bytes for AArch64's MTE. I've used struct value as opposed to straight CORE_ADDR so other architectures can use the infrastructure without having to rely on a particular type for addresses/pointers. Some architecture may use pointers of 16 bytes that don't fit in a CORE_ADDR, for example. gdb/ChangeLog: 2021-03-24 Luis Machado <luis.machado@linaro.org> * arch-utils.c (default_memtag_to_string, default_tagged_address_p) (default_memtag_matches_p, default_set_memtags) (default_get_memtag): New functions. * arch-utils.h (default_memtag_to_string, default_tagged_address_p) (default_memtag_matches_p, default_set_memtags) (default_get_memtag): New prototypes. * gdbarch.c: Regenerate. * gdbarch.h: Regenerate. * gdbarch.sh (memtag_to_string, tagged_address_p, memtag_matches_p) (set_memtags, get_memtag, memtag_granule_size): New gdbarch hooks. (enum memtag_type): New enum.
Diffstat (limited to 'gdb/gdbarch.h')
-rw-r--r--gdb/gdbarch.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 342c29c5980..7157e5596fd 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -117,6 +117,18 @@ enum function_call_return_method
return_method_struct,
};
+enum class memtag_type
+{
+ /* Logical tag, the tag that is stored in unused bits of a pointer to a
+ virtual address. */
+ logical = 0,
+
+ /* Allocation tag, the tag that is associated with every granule of memory in
+ the physical address space. Allocation tags are used to validate memory
+ accesses via pointers containing logical tags. */
+ allocation,
+};
+
/* The following are pre-initialized by GDBARCH. */
@@ -712,6 +724,48 @@ extern void set_gdbarch_addr_bits_remove (struct gdbarch *gdbarch, gdbarch_addr_
extern int gdbarch_significant_addr_bit (struct gdbarch *gdbarch);
extern void set_gdbarch_significant_addr_bit (struct gdbarch *gdbarch, int significant_addr_bit);
+/* Return a string representation of the memory tag TAG. */
+
+typedef std::string (gdbarch_memtag_to_string_ftype) (struct gdbarch *gdbarch, struct value *tag);
+extern std::string gdbarch_memtag_to_string (struct gdbarch *gdbarch, struct value *tag);
+extern void set_gdbarch_memtag_to_string (struct gdbarch *gdbarch, gdbarch_memtag_to_string_ftype *memtag_to_string);
+
+/* Return true if ADDRESS contains a tag and false otherwise. */
+
+typedef bool (gdbarch_tagged_address_p_ftype) (struct gdbarch *gdbarch, struct value *address);
+extern bool gdbarch_tagged_address_p (struct gdbarch *gdbarch, struct value *address);
+extern void set_gdbarch_tagged_address_p (struct gdbarch *gdbarch, gdbarch_tagged_address_p_ftype *tagged_address_p);
+
+/* Return true if the tag from ADDRESS matches the memory tag for that
+ particular address. Return false otherwise. */
+
+typedef bool (gdbarch_memtag_matches_p_ftype) (struct gdbarch *gdbarch, struct value *address);
+extern bool gdbarch_memtag_matches_p (struct gdbarch *gdbarch, struct value *address);
+extern void set_gdbarch_memtag_matches_p (struct gdbarch *gdbarch, gdbarch_memtag_matches_p_ftype *memtag_matches_p);
+
+/* Set the tags of type TAG_TYPE, for the memory address range
+ [ADDRESS, ADDRESS + LENGTH) to TAGS.
+ Return true if successful and false otherwise. */
+
+typedef bool (gdbarch_set_memtags_ftype) (struct gdbarch *gdbarch, struct value *address, size_t length, const gdb::byte_vector &tags, memtag_type tag_type);
+extern bool gdbarch_set_memtags (struct gdbarch *gdbarch, struct value *address, size_t length, const gdb::byte_vector &tags, memtag_type tag_type);
+extern void set_gdbarch_set_memtags (struct gdbarch *gdbarch, gdbarch_set_memtags_ftype *set_memtags);
+
+/* Return the tag of type TAG_TYPE associated with the memory address ADDRESS,
+ assuming ADDRESS is tagged. */
+
+typedef struct value * (gdbarch_get_memtag_ftype) (struct gdbarch *gdbarch, struct value *address, memtag_type tag_type);
+extern struct value * gdbarch_get_memtag (struct gdbarch *gdbarch, struct value *address, memtag_type tag_type);
+extern void set_gdbarch_get_memtag (struct gdbarch *gdbarch, gdbarch_get_memtag_ftype *get_memtag);
+
+/* memtag_granule_size is the size of the allocation tag granule, for
+ architectures that support memory tagging.
+ This is 0 for architectures that do not support memory tagging.
+ For a non-zero value, this represents the number of bytes of memory per tag. */
+
+extern CORE_ADDR gdbarch_memtag_granule_size (struct gdbarch *gdbarch);
+extern void set_gdbarch_memtag_granule_size (struct gdbarch *gdbarch, CORE_ADDR memtag_granule_size);
+
/* FIXME/cagney/2001-01-18: This should be split in two. A target method that
indicates if the target needs software single step. An ISA method to
implement it.