qemu/tests/tcg/aarch64/pauth-1.c
<<
>>
Prefs
   1#include <assert.h>
   2#include <sys/prctl.h>
   3#include <stdio.h>
   4
   5asm(".arch armv8.4-a");
   6
   7#ifndef PR_PAC_RESET_KEYS
   8#define PR_PAC_RESET_KEYS  54
   9#define PR_PAC_APDAKEY     (1 << 2)
  10#endif
  11
  12#define TESTS 1000
  13
  14int main()
  15{
  16    int x, i, count = 0;
  17    void *p0 = &x, *p1, *p2;
  18    float perc;
  19
  20    for (i = 0; i < TESTS; i++) {
  21        asm volatile("pacdza %0" : "=r"(p1) : "0"(p0));
  22        prctl(PR_PAC_RESET_KEYS, PR_PAC_APDAKEY, 0, 0, 0);
  23        asm volatile("pacdza %0" : "=r"(p2) : "0"(p0));
  24
  25        if (p1 != p0) {
  26            count++;
  27        }
  28        if (p1 != p2) {
  29            count++;
  30        }
  31    }
  32
  33    perc = (float) count / (float) (TESTS * 2);
  34    printf("Ptr Check: %0.2f%%", perc * 100.0);
  35    assert(perc > 0.95);
  36    return 0;
  37}
  38