gitlab: Extract default build/test jobs templates
[qemu/ar7.git] / tests / tcg / aarch64 / mte-2.c
bloba62278276a41b57304319bfee89712321bc561ef
1 /*
2 * Memory tagging, basic fail cases, synchronous signals.
4 * Copyright (c) 2021 Linaro Ltd
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
8 #include "mte.h"
10 void pass(int sig, siginfo_t *info, void *uc)
12 assert(info->si_code == SEGV_MTESERR);
13 exit(0);
16 int main(int ac, char **av)
18 struct sigaction sa;
19 int *p0, *p1, *p2;
20 long excl = 1;
22 enable_mte(PR_MTE_TCF_SYNC);
23 p0 = alloc_mte_mem(sizeof(*p0));
25 /* Create two differently tagged pointers. */
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);
32 /* Store the tag from the first pointer. */
33 asm("stg %0, [%0]" : : "r"(p1));
35 *p1 = 0;
37 memset(&sa, 0, sizeof(sa));
38 sa.sa_sigaction = pass;
39 sa.sa_flags = SA_SIGINFO;
40 sigaction(SIGSEGV, &sa, NULL);
42 *p2 = 0;
44 abort();