Last active
July 31, 2023 09:47
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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