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