xref: /openbmc/qemu/tests/tcg/aarch64/pauth-4.c (revision 979a8902)
1 #include <stdint.h>
2 #include <assert.h>
3 
4 int main()
5 {
6   uintptr_t x, y;
7 
8   asm("mov %0, lr\n\t"
9       "pacia %0, sp\n\t"        /* sigill if pauth not supported */
10       "eor %0, %0, #4\n\t"      /* corrupt single bit */
11       "mov %1, %0\n\t"
12       "autia %1, sp\n\t"        /* validate corrupted pointer */
13       "xpaci %0\n\t"            /* strip pac from corrupted pointer */
14       : "=r"(x), "=r"(y));
15 
16   /*
17    * Once stripped, the corrupted pointer is of the form 0x0000...wxyz.
18    * We expect the autia to indicate failure, producing a pointer of the
19    * form 0x000e....wxyz.  Use xpaci and != for the test, rather than
20    * extracting explicit bits from the top, because the location of the
21    * error code "e" depends on the configuration of virtual memory.
22    */
23   assert(x != y);
24   return 0;
25 }
26