| 1 |
/* |
| 2 |
Permission is hereby granted, free of charge, to any person obtaining |
| 3 |
a copy of this software and associated documentation files (the |
| 4 |
``Software''), to deal in the Software without restriction, including |
| 5 |
without limitation the rights to use, copy, modify, merge, publish, |
| 6 |
distribute, sublicense, and/or sell copies of the Software, and to |
| 7 |
permit persons to whom the Software is furnished to do so, subject to |
| 8 |
the following conditions: |
| 9 |
|
| 10 |
The above copyright notice and this permission notice shall be |
| 11 |
included in all copies or substantial portions of the Software. |
| 12 |
|
| 13 |
THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, |
| 14 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 15 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 16 |
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 17 |
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 18 |
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 19 |
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 20 |
|
| 21 |
#define AARCH64_RET_VOID 0 |
| 22 |
#define AARCH64_RET_INT64 1 |
| 23 |
#define AARCH64_RET_INT128 2 |
| 24 |
|
| 25 |
#define AARCH64_RET_UNUSED3 3 |
| 26 |
#define AARCH64_RET_UNUSED4 4 |
| 27 |
#define AARCH64_RET_UNUSED5 5 |
| 28 |
#define AARCH64_RET_UNUSED6 6 |
| 29 |
#define AARCH64_RET_UNUSED7 7 |
| 30 |
|
| 31 |
/* Note that FFI_TYPE_FLOAT == 2, _DOUBLE == 3, _LONGDOUBLE == 4, |
| 32 |
so _S4 through _Q1 are layed out as (TYPE * 4) + (4 - COUNT). */ |
| 33 |
#define AARCH64_RET_S4 8 |
| 34 |
#define AARCH64_RET_S3 9 |
| 35 |
#define AARCH64_RET_S2 10 |
| 36 |
#define AARCH64_RET_S1 11 |
| 37 |
|
| 38 |
#define AARCH64_RET_D4 12 |
| 39 |
#define AARCH64_RET_D3 13 |
| 40 |
#define AARCH64_RET_D2 14 |
| 41 |
#define AARCH64_RET_D1 15 |
| 42 |
|
| 43 |
#define AARCH64_RET_Q4 16 |
| 44 |
#define AARCH64_RET_Q3 17 |
| 45 |
#define AARCH64_RET_Q2 18 |
| 46 |
#define AARCH64_RET_Q1 19 |
| 47 |
|
| 48 |
/* Note that each of the sub-64-bit integers gets two entries. */ |
| 49 |
#define AARCH64_RET_UINT8 20 |
| 50 |
#define AARCH64_RET_UINT16 22 |
| 51 |
#define AARCH64_RET_UINT32 24 |
| 52 |
|
| 53 |
#define AARCH64_RET_SINT8 26 |
| 54 |
#define AARCH64_RET_SINT16 28 |
| 55 |
#define AARCH64_RET_SINT32 30 |
| 56 |
|
| 57 |
#define AARCH64_RET_MASK 31 |
| 58 |
|
| 59 |
#define AARCH64_RET_IN_MEM (1 << 5) |
| 60 |
#define AARCH64_RET_NEED_COPY (1 << 6) |
| 61 |
|
| 62 |
#define AARCH64_FLAG_ARG_V_BIT 7 |
| 63 |
#define AARCH64_FLAG_ARG_V (1 << AARCH64_FLAG_ARG_V_BIT) |
| 64 |
#define AARCH64_FLAG_VARARG (1 << 8) |
| 65 |
|
| 66 |
#define N_X_ARG_REG 8 |
| 67 |
#define N_V_ARG_REG 8 |
| 68 |
#define CALL_CONTEXT_SIZE (N_V_ARG_REG * 16 + N_X_ARG_REG * 8) |
| 69 |
|
| 70 |
#if defined(FFI_EXEC_STATIC_TRAMP) |
| 71 |
/* |
| 72 |
* For the trampoline code table mapping, a mapping size of 16K is chosen to |
| 73 |
* cover the base page sizes of 4K and 16K. |
| 74 |
*/ |
| 75 |
#define AARCH64_TRAMP_MAP_SHIFT 14 |
| 76 |
#define AARCH64_TRAMP_MAP_SIZE (1 << AARCH64_TRAMP_MAP_SHIFT) |
| 77 |
#define AARCH64_TRAMP_SIZE 32 |
| 78 |
|
| 79 |
#endif |
| 80 |
|
| 81 |
/* Helpers for writing assembly compatible with arm ptr auth */ |
| 82 |
#ifdef LIBFFI_ASM |
| 83 |
|
| 84 |
#if defined(HAVE_ARM64E_PTRAUTH) |
| 85 |
/* ARM64E ABI For Darwin */ |
| 86 |
#define SIGN_LR pacibsp |
| 87 |
#define SIGN_LR_WITH_REG(x) pacib lr, x |
| 88 |
#define AUTH_LR_AND_RET retab |
| 89 |
#define AUTH_LR_WITH_REG(x) autib lr, x |
| 90 |
#define BRANCH_AND_LINK_TO_REG blraaz |
| 91 |
#define SIGN_LR_LINUX_ONLY |
| 92 |
#define BRANCH_TO_REG braaz |
| 93 |
#define PAC_CFI_WINDOW_SAVE |
| 94 |
#define GNU_PROPERTY_AARCH64_POINTER_AUTH 0 |
| 95 |
/* Linux PAC Support */ |
| 96 |
#elif defined(__ARM_FEATURE_PAC_DEFAULT) |
| 97 |
#define GNU_PROPERTY_AARCH64_POINTER_AUTH (1 << 1) |
| 98 |
#define PAC_CFI_WINDOW_SAVE cfi_window_save |
| 99 |
#define TMP_REG x9 |
| 100 |
#define BRANCH_TO_REG br |
| 101 |
#define BRANCH_AND_LINK_TO_REG blr |
| 102 |
#define SIGN_LR_LINUX_ONLY SIGN_LR |
| 103 |
/* Which key to sign with? */ |
| 104 |
#if (__ARM_FEATURE_PAC_DEFAULT & 1) == 1 |
| 105 |
/* Signed with A-key */ |
| 106 |
#define SIGN_LR hint #25 /* paciasp */ |
| 107 |
#define AUTH_LR hint #29 /* autiasp */ |
| 108 |
#else |
| 109 |
/* Signed with B-key */ |
| 110 |
#define SIGN_LR hint #27 /* pacibsp */ |
| 111 |
#define AUTH_LR hint #31 /* autibsp */ |
| 112 |
#endif /* __ARM_FEATURE_PAC_DEFAULT */ |
| 113 |
#define AUTH_LR_WITH_REG(x) _auth_lr_with_reg x |
| 114 |
.macro _auth_lr_with_reg modifier |
| 115 |
mov TMP_REG, sp |
| 116 |
mov sp, \modifier |
| 117 |
AUTH_LR |
| 118 |
mov sp, TMP_REG |
| 119 |
.endm |
| 120 |
#define SIGN_LR_WITH_REG(x) _sign_lr_with_reg x |
| 121 |
.macro _sign_lr_with_reg modifier |
| 122 |
mov TMP_REG, sp |
| 123 |
mov sp, \modifier |
| 124 |
SIGN_LR |
| 125 |
mov sp, TMP_REG |
| 126 |
.endm |
| 127 |
#define AUTH_LR_AND_RET _auth_lr_and_ret modifier |
| 128 |
.macro _auth_lr_and_ret modifier |
| 129 |
AUTH_LR |
| 130 |
ret |
| 131 |
.endm |
| 132 |
#undef TMP_REG |
| 133 |
|
| 134 |
/* No Pointer Auth */ |
| 135 |
#else |
| 136 |
#define SIGN_LR |
| 137 |
#define SIGN_LR_WITH_REG(x) |
| 138 |
#define AUTH_LR_AND_RET ret |
| 139 |
#define AUTH_LR_WITH_REG(x) |
| 140 |
#define BRANCH_AND_LINK_TO_REG blr |
| 141 |
#define SIGN_LR_LINUX_ONLY |
| 142 |
#define BRANCH_TO_REG br |
| 143 |
#define PAC_CFI_WINDOW_SAVE |
| 144 |
#define GNU_PROPERTY_AARCH64_POINTER_AUTH 0 |
| 145 |
#endif /* HAVE_ARM64E_PTRAUTH */ |
| 146 |
#endif /* LIBFFI_ASM */ |