2019-02-05 19:52:39 +03:00
|
|
|
#include <assert.h>
|
|
|
|
#include <sys/prctl.h>
|
2019-03-12 18:42:21 +03:00
|
|
|
#include <stdio.h>
|
2019-02-05 19:52:39 +03:00
|
|
|
|
|
|
|
#ifndef PR_PAC_RESET_KEYS
|
|
|
|
#define PR_PAC_RESET_KEYS 54
|
|
|
|
#define PR_PAC_APDAKEY (1 << 2)
|
|
|
|
#endif
|
|
|
|
|
2019-03-12 18:42:21 +03:00
|
|
|
#define TESTS 1000
|
|
|
|
|
2019-02-05 19:52:39 +03:00
|
|
|
int main()
|
|
|
|
{
|
2019-03-12 18:42:21 +03:00
|
|
|
int x, i, count = 0;
|
2019-02-05 19:52:39 +03:00
|
|
|
void *p0 = &x, *p1, *p2;
|
2019-03-12 18:42:21 +03:00
|
|
|
float perc;
|
|
|
|
|
|
|
|
for (i = 0; i < TESTS; i++) {
|
|
|
|
asm volatile("pacdza %0" : "=r"(p1) : "0"(p0));
|
|
|
|
prctl(PR_PAC_RESET_KEYS, PR_PAC_APDAKEY, 0, 0, 0);
|
|
|
|
asm volatile("pacdza %0" : "=r"(p2) : "0"(p0));
|
2019-02-05 19:52:39 +03:00
|
|
|
|
2019-03-12 18:42:21 +03:00
|
|
|
if (p1 != p0) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if (p1 != p2) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
2019-02-05 19:52:39 +03:00
|
|
|
|
2019-03-12 18:42:21 +03:00
|
|
|
perc = (float) count / (float) (TESTS * 2);
|
2020-03-05 19:09:19 +03:00
|
|
|
printf("Ptr Check: %0.2f%%\n", perc * 100.0);
|
2019-03-12 18:42:21 +03:00
|
|
|
assert(perc > 0.95);
|
2019-02-05 19:52:39 +03:00
|
|
|
return 0;
|
|
|
|
}
|