|
| 1 | +#ifndef ASM_TRAMPOLINE_AARCH_64_H_ |
| 2 | +#define ASM_TRAMPOLINE_AARCH_64_H_ |
| 3 | + |
| 4 | +/* |
| 5 | + * References: |
| 6 | + * - https://developer.arm.com/documentation/101028/0012/5--Feature-test-macros |
| 7 | + * - https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst |
| 8 | + */ |
| 9 | + |
| 10 | +#if defined(__ARM_FEATURE_BTI_DEFAULT) && __ARM_FEATURE_BTI_DEFAULT == 1 |
| 11 | + #define BTI_J hint 36 /* bti j: for jumps, IE br instructions */ |
| 12 | + #define BTI_C hint 34 /* bti c: for calls, IE bl instructions */ |
| 13 | + #define GNU_PROPERTY_AARCH64_BTI 1 /* bit 0 GNU Notes is for BTI support */ |
| 14 | +#else |
| 15 | + #define BTI_J |
| 16 | + #define BTI_C |
| 17 | + #define GNU_PROPERTY_AARCH64_BTI 0 |
| 18 | +#endif |
| 19 | + |
| 20 | +#if defined(__ARM_FEATURE_PAC_DEFAULT) |
| 21 | + #if __ARM_FEATURE_PAC_DEFAULT & 1 |
| 22 | + #define SIGN_LR hint 25 /* paciasp: sign with the A key */ |
| 23 | + #define VERIFY_LR hint 29 /* autiasp: verify with the A key */ |
| 24 | + #elif __ARM_FEATURE_PAC_DEFAULT & 2 |
| 25 | + #define SIGN_LR hint 27 /* pacibsp: sign with the b key */ |
| 26 | + #define VERIFY_LR hint 31 /* autibsp: verify with the b key */ |
| 27 | + #endif |
| 28 | + #define GNU_PROPERTY_AARCH64_POINTER_AUTH 2 /* bit 1 GNU Notes is for PAC support */ |
| 29 | +#else |
| 30 | + #define SIGN_LR BTI_C |
| 31 | + #define VERIFY_LR |
| 32 | + #define GNU_PROPERTY_AARCH64_POINTER_AUTH 0 |
| 33 | +#endif |
| 34 | + |
| 35 | +/* Add the BTI and PAC support to GNU Notes section */ |
| 36 | +#if GNU_PROPERTY_AARCH64_BTI != 0 || GNU_PROPERTY_AARCH64_POINTER_AUTH != 0 |
| 37 | + .pushsection .note.gnu.property, "a"; /* Start a new allocatable section */ |
| 38 | + .balign 8; /* align it on a byte boundry */ |
| 39 | + .long 4; /* size of "GNU\0" */ |
| 40 | + .long 0x10; /* size of descriptor */ |
| 41 | + .long 0x5; /* NT_GNU_PROPERTY_TYPE_0 */ |
| 42 | + .asciz "GNU"; |
| 43 | + .long 0xc0000000; /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */ |
| 44 | + .long 4; /* Four bytes of data */ |
| 45 | + .long (GNU_PROPERTY_AARCH64_BTI|GNU_PROPERTY_AARCH64_POINTER_AUTH); /* BTI or PAC is enabled */ |
| 46 | + .long 0; /* padding for 8 byte alignment */ |
| 47 | + .popsection; /* end the section */ |
| 48 | +#endif |
| 49 | + |
| 50 | +#endif |
0 commit comments