Skip to content

Instantly share code, notes, and snippets.

@c272
Last active July 31, 2023 09:47
Show Gist options
  • Select an option

  • Save c272/1061a3b5caec76e0c5b368070494ae99 to your computer and use it in GitHub Desktop.

Select an option

Save c272/1061a3b5caec76e0c5b368070494ae99 to your computer and use it in GitHub Desktop.
Test for checking whether PAC is enabled, or is a NOP on the current system.
#include <cstdio>
#include <cstdint>
__attribute__((noinline))
int pac_test()
{
uint64_t original = 0;
uint64_t res = 0;
printf("I wonder if this has PAC enabled?\n");
__asm__ ("MOV %[original], X30\n"
"PACIASP\n"
"MOV %[result], X30\n"
: [result] "=r" (res), [original] "=r" (original)
);
printf("Original LR (X30): %ld\nNew LR (X30): %ld\n", original, res);
return original != res;
}
int main()
{
if (pac_test())
printf("PAC is enabled! (PACIASP)\n");
else
printf("PAC is not enabled (NOP).\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment