1 /* 2 * Memory tagging, re-reading tag checks. 3 * 4 * Copyright (c) 2021 Linaro Ltd 5 * SPDX-License-Identifier: GPL-2.0-or-later 6 */ 7 8 #include "mte.h" 9 10 void __attribute__((noinline)) tagset(void *p, size_t size) 11 { 12 size_t i; 13 for (i = 0; i < size; i += 16) { 14 asm("stg %0, [%0]" : : "r"(p + i)); 15 } 16 } 17 18 void __attribute__((noinline)) tagcheck(void *p, size_t size) 19 { 20 size_t i; 21 void *c; 22 23 for (i = 0; i < size; i += 16) { 24 asm("ldg %0, [%1]" : "=r"(c) : "r"(p + i), "0"(p)); 25 assert(c == p); 26 } 27 } 28 29 int main(int ac, char **av) 30 { 31 size_t size = getpagesize() * 4; 32 long excl = 1; 33 int *p0, *p1; 34 35 enable_mte(PR_MTE_TCF_ASYNC); 36 p0 = alloc_mte_mem(size); 37 38 /* Tag the pointer. */ 39 asm("irg %0,%1,%2" : "=r"(p1) : "r"(p0), "r"(excl)); 40 41 tagset(p1, size); 42 tagcheck(p1, size); 43 44 return 0; 45 } 46