20#include "gdbsupport/common-defs.h"
21#include "gdbsupport/byte-vector.h"
25#include "arch/aarch64.h"
26#include "arch/aarch64-mte-linux.h"
35static void ATTRIBUTE_NORETURN
41 perror_with_name (_(
"PEEKMTETAGS not supported"));
44 perror_with_name (_(
"Couldn't fetch allocation tags"));
47 perror_with_name (_(
"PROT_MTE not enabled for requested address"));
49 perror_with_name (_(
"Unknown MTE error"));
57static void ATTRIBUTE_NORETURN
63 perror_with_name (_(
"POKEMTETAGS not supported"));
66 perror_with_name (_(
"Couldn't store allocation tags"));
69 perror_with_name (_(
"PROT_MTE not enabled for requested address"));
71 perror_with_name (_(
"Unknown MTE error"));
85static gdb::byte_vector
94 gdb_assert (tags.size () > 0 && max_size > 0);
101 size_t tag_count = tags.size ();
103 for (
size_t i = 0; i < t.size (); i++)
104 t[i] = tags[(pos + i) % tag_count];
113 gdb::byte_vector &tags)
115 size_t ntags = aarch64_mte_get_tag_granules (address, len,
116 AARCH64_MTE_GRANULE_SIZE);
122 gdb_byte tagbuf[ntags];
125 iovec.iov_base = tagbuf;
126 iovec.iov_len = ntags;
129 bool done_reading =
false;
133 while (!done_reading)
140 if (iovec.iov_len <= 0)
147 for (
size_t i = 0; i < iovec.iov_len; i++)
148 tags.push_back (tagbuf[i]);
151 if (tags.size () == ntags)
155 address += iovec.iov_len * AARCH64_MTE_GRANULE_SIZE;
156 iovec.iov_len = ntags - iovec.iov_len;
166 const gdb::byte_vector &tags)
168 if (tags.size () == 0)
172 size_t ntags = aarch64_mte_get_tag_granules (address, len,
173 AARCH64_MTE_GRANULE_SIZE);
179 bool done_writing =
false;
180 size_t tags_written = 0;
183 while (!done_writing)
190 iovec.iov_base = t.data ();
191 iovec.iov_len = t.size ();
198 if (iovec.iov_len <= 0)
201 tags_written += iovec.iov_len;
204 if (tags_written == ntags)
207 address += iovec.iov_len * AARCH64_MTE_GRANULE_SIZE;
bool aarch64_mte_store_memtags(int tid, CORE_ADDR address, size_t len, const gdb::byte_vector &tags)
static void ATTRIBUTE_NORETURN aarch64_mte_linux_peek_error(int error)
static void ATTRIBUTE_NORETURN aarch64_mte_linux_poke_error(int error)
bool aarch64_mte_fetch_memtags(int tid, CORE_ADDR address, size_t len, gdb::byte_vector &tags)
static gdb::byte_vector prepare_tag_vector(size_t granules, const gdb::byte_vector &tags, size_t pos, size_t max_size)
#define AARCH64_MTE_TAGS_MAX_SIZE
#define PTRACE_PEEKMTETAGS
#define PTRACE_POKEMTETAGS
#define ptrace(request, pid, addr, data)