1
2
3
4
5
6
7
8#include "mte.h"
9
10void pass(int sig, siginfo_t *info, void *uc)
11{
12 assert(info->si_code == SEGV_MTEAERR);
13 exit(0);
14}
15
16int main(int ac, char **av)
17{
18 struct sigaction sa;
19 long *p0, *p1, *p2;
20 long excl = 1;
21
22 enable_mte(PR_MTE_TCF_ASYNC);
23 p0 = alloc_mte_mem(sizeof(*p0));
24
25
26 asm("irg %0,%1,%2" : "=r"(p1) : "r"(p0), "r"(excl));
27 asm("gmi %0,%1,%0" : "+r"(excl) : "r" (p1));
28 assert(excl != 1);
29 asm("irg %0,%1,%2" : "=r"(p2) : "r"(p0), "r"(excl));
30 assert(p1 != p2);
31
32
33 asm("stg %0, [%0]" : : "r"(p1));
34
35 *p1 = 0;
36
37 memset(&sa, 0, sizeof(sa));
38 sa.sa_sigaction = pass;
39 sa.sa_flags = SA_SIGINFO;
40 sigaction(SIGSEGV, &sa, NULL);
41
42
43
44
45
46
47
48
49 asm("str %0, [%0]; yield" : : "r"(p2));
50 while (1);
51}
52