Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Buglink: https://bugs.launchpad.net/bugs/1921948 Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20210416183106.1516563-5-richard.henderson@linaro.org Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
- Loading branch information
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Memory tagging, faulting unaligned access. | ||
* | ||
* Copyright (c) 2021 Linaro Ltd | ||
* SPDX-License-Identifier: GPL-2.0-or-later | ||
*/ | ||
|
||
#include "mte.h" | ||
|
||
void pass(int sig, siginfo_t *info, void *uc) | ||
{ | ||
assert(info->si_code == SEGV_MTESERR); | ||
exit(0); | ||
} | ||
|
||
int main(int ac, char **av) | ||
{ | ||
struct sigaction sa; | ||
void *p0, *p1, *p2; | ||
long excl = 1; | ||
|
||
enable_mte(PR_MTE_TCF_SYNC); | ||
p0 = alloc_mte_mem(sizeof(*p0)); | ||
|
||
/* Create two differently tagged pointers. */ | ||
asm("irg %0,%1,%2" : "=r"(p1) : "r"(p0), "r"(excl)); | ||
asm("gmi %0,%1,%0" : "+r"(excl) : "r" (p1)); | ||
assert(excl != 1); | ||
asm("irg %0,%1,%2" : "=r"(p2) : "r"(p0), "r"(excl)); | ||
assert(p1 != p2); | ||
|
||
memset(&sa, 0, sizeof(sa)); | ||
sa.sa_sigaction = pass; | ||
sa.sa_flags = SA_SIGINFO; | ||
sigaction(SIGSEGV, &sa, NULL); | ||
|
||
/* Store store two different tags in sequential granules. */ | ||
asm("stg %0, [%0]" : : "r"(p1)); | ||
asm("stg %0, [%0]" : : "r"(p2 + 16)); | ||
|
||
/* Perform an unaligned load crossing the granules. */ | ||
asm volatile("ldr %0, [%1]" : "=r"(p0) : "r"(p1 + 12)); | ||
abort(); | ||
} |