2 * Linux kernel fallback API definitions for MTE and test helpers.
4 * Copyright (c) 2021 Linaro Ltd
5 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include <sys/prctl.h>
17 #ifndef PR_SET_TAGGED_ADDR_CTRL
18 # define PR_SET_TAGGED_ADDR_CTRL 55
20 #ifndef PR_TAGGED_ADDR_ENABLE
21 # define PR_TAGGED_ADDR_ENABLE (1UL << 0)
23 #ifndef PR_MTE_TCF_SHIFT
24 # define PR_MTE_TCF_SHIFT 1
25 # define PR_MTE_TCF_NONE (0UL << PR_MTE_TCF_SHIFT)
26 # define PR_MTE_TCF_SYNC (1UL << PR_MTE_TCF_SHIFT)
27 # define PR_MTE_TCF_ASYNC (2UL << PR_MTE_TCF_SHIFT)
28 # define PR_MTE_TAG_SHIFT 3
32 # define PROT_MTE 0x20
36 # define SEGV_MTEAERR 8
37 # define SEGV_MTESERR 9
40 static void enable_mte(int tcf
)
42 int r
= prctl(PR_SET_TAGGED_ADDR_CTRL
,
43 PR_TAGGED_ADDR_ENABLE
| tcf
| (0xfffe << PR_MTE_TAG_SHIFT
),
46 perror("PR_SET_TAGGED_ADDR_CTRL");
51 static void * alloc_mte_mem(size_t size
) __attribute__((unused
));
52 static void * alloc_mte_mem(size_t size
)
54 void *p
= mmap(NULL
, size
, PROT_READ
| PROT_WRITE
| PROT_MTE
,
55 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
56 if (p
== MAP_FAILED
) {
57 perror("mmap PROT_MTE");