master
c 48 lines 992 Bytes
Raw
1 /*
2 * Memory tagging, full-address reporting.
3 *
4 * Copyright (c) 2021 Linaro Ltd
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8 #include "mte.h"
9
10 static void *faulting_ptr;
11
12 void pass(int sig, siginfo_t *info, void *uc)
13 {
14 assert(faulting_ptr == info->si_addr);
15 exit(0);
16 }
17
18 int main(int ac, char **av)
19 {
20 struct sigaction sa;
21 int *p0, *p1, *p2;
22 long excl = 1;
23
24 enable_mte(PR_MTE_TCF_SYNC);
25 p0 = alloc_mte_mem(sizeof(*p0));
26
27 /* Create two differently tagged pointers. */
28 asm("irg %0,%1,%2" : "=r"(p1) : "r"(p0), "r"(excl));
29 asm("gmi %0,%1,%0" : "+r"(excl) : "r" (p1));
30 assert(excl != 1);
31 asm("irg %0,%1,%2" : "=r"(p2) : "r"(p0), "r"(excl));
32 assert(p1 != p2);
33
34 /* Store the tag from the first pointer. */
35 asm("stg %0, [%0]" : : "r"(p1));
36
37 *p1 = 0;
38
39 memset(&sa, 0, sizeof(sa));
40 sa.sa_sigaction = pass;
41 sa.sa_flags = SA_SIGINFO;
42 sigaction(SIGSEGV, &sa, NULL);
43
44 faulting_ptr = p2;
45 *p2 = 0;
46
47 abort();
48 }