target/arm: Update CNTP for PREDDESC
[qemu/ar7.git] / tests / tcg / aarch64 / pauth-4.c
blob24a639e36ca03f4947e5ae7b599bbe4335f03b05
1 #include <stdint.h>
2 #include <assert.h>
3 #include <stdio.h>
4 #include <stdlib.h>
6 #define TESTS 1000
8 int main()
10 int i, count = 0;
11 float perc;
12 void *base = malloc(TESTS);
14 for (i = 0; i < TESTS; i++) {
15 uintptr_t in, x, y;
17 in = i + (uintptr_t) base;
19 asm("mov %0, %[in]\n\t"
20 "pacia %0, sp\n\t" /* sigill if pauth not supported */
21 "eor %0, %0, #4\n\t" /* corrupt single bit */
22 "mov %1, %0\n\t"
23 "autia %1, sp\n\t" /* validate corrupted pointer */
24 "xpaci %0\n\t" /* strip pac from corrupted pointer */
25 : /* out */ "=r"(x), "=r"(y)
26 : /* in */ [in] "r" (in)
27 : /* clobbers */);
30 * Once stripped, the corrupted pointer is of the form 0x0000...wxyz.
31 * We expect the autia to indicate failure, producing a pointer of the
32 * form 0x000e....wxyz. Use xpaci and != for the test, rather than
33 * extracting explicit bits from the top, because the location of the
34 * error code "e" depends on the configuration of virtual memory.
36 if (x != y) {
37 count++;
41 perc = (float) count / (float) TESTS;
42 printf("Checks Passed: %0.2f%%", perc * 100.0);
43 assert(perc > 0.95);
44 return 0;