1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
| | #include <stdint.h>
#define MTE_TAG_GRANULE 16
#define MTE_TAG_MASK (0xFULL << 56)
/**
* Read the allocated tag for `addr`.
*/
static inline uintptr_t mte_load_tag(uintptr_t addr)
{
uintptr_t tag;
__asm__ __volatile__ ("ldg %0, [%1]\n"
: "=&r" (tag) : "r"(addr));
return tag;
}
/**
* Store the allocated tag for `addr`.
* The tag is derived from `addr`.
*/
static inline void mte_store_tag(uintptr_t addr)
{
__asm__ __volatile__ ("stg %0, [%0]\n"
: : "r"(addr) : "memory");
}
/**
* Tag `addr` with random tag.
* If the address is already tagged, make sure the new tag differs.
*/
static inline uintptr_t mte_insert_random_tag(uintptr_t addr)
{
uintptr_t reg;
__asm__ __volatile__("gmi %0, %1, xzr\n"
"irg %1, %1, %0\n"
: "=&r"(reg), "+r" (addr));
return addr;
}
|