|
53 | 53 | #ifndef OPENSSL_HEADER_ARM_ARCH_H
|
54 | 54 | #define OPENSSL_HEADER_ARM_ARCH_H
|
55 | 55 |
|
| 56 | +#include <ring-core/target.h> |
| 57 | + |
56 | 58 | // arm_arch.h contains symbols used by ARM assembly, and the C code that calls
|
57 | 59 | // it. It is included as a public header to simplify the build, but is not
|
58 | 60 | // intended for external use.
|
59 | 61 |
|
60 |
| -#if defined(__ARMEL__) || defined(_M_ARM) || defined(__AARCH64EL__) || \ |
61 |
| - defined(_M_ARM64) |
| 62 | +#if defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64) |
62 | 63 |
|
63 | 64 | // ARMV7_NEON is true when a NEON unit is present in the current CPU.
|
64 | 65 | #define ARMV7_NEON (1 << 0)
|
|
91 | 92 | // will be included.
|
92 | 93 | #define __ARM_MAX_ARCH__ 8
|
93 | 94 |
|
94 |
| -// Support macros for |
95 |
| -// - Armv8.3-A Pointer Authentication and |
96 |
| -// - Armv8.5-A Branch Target Identification |
97 |
| -// features which require emitting a .note.gnu.property section with the |
98 |
| -// appropriate architecture-dependent feature bits set. |
99 |
| -// |
100 |
| -// |AARCH64_SIGN_LINK_REGISTER| and |AARCH64_VALIDATE_LINK_REGISTER| expand to |
101 |
| -// PACIxSP and AUTIxSP, respectively. |AARCH64_SIGN_LINK_REGISTER| should be |
102 |
| -// used immediately before saving the LR register (x30) to the stack. |
103 |
| -// |AARCH64_VALIDATE_LINK_REGISTER| should be used immediately after restoring |
104 |
| -// it. Note |AARCH64_SIGN_LINK_REGISTER|'s modifications to LR must be undone |
105 |
| -// with |AARCH64_VALIDATE_LINK_REGISTER| before RET. The SP register must also |
106 |
| -// have the same value at the two points. For example: |
107 |
| -// |
108 |
| -// .global f |
109 |
| -// f: |
110 |
| -// AARCH64_SIGN_LINK_REGISTER |
111 |
| -// stp x29, x30, [sp, #-96]! |
112 |
| -// mov x29, sp |
113 |
| -// ... |
114 |
| -// ldp x29, x30, [sp], #96 |
115 |
| -// AARCH64_VALIDATE_LINK_REGISTER |
116 |
| -// ret |
117 |
| -// |
118 |
| -// |AARCH64_VALID_CALL_TARGET| expands to BTI 'c'. Either it, or |
119 |
| -// |AARCH64_SIGN_LINK_REGISTER|, must be used at every point that may be an |
120 |
| -// indirect call target. In particular, all symbols exported from a file must |
121 |
| -// begin with one of these macros. For example, a leaf function that does not |
122 |
| -// save LR can instead use |AARCH64_VALID_CALL_TARGET|: |
123 |
| -// |
124 |
| -// .globl return_zero |
125 |
| -// return_zero: |
126 |
| -// AARCH64_VALID_CALL_TARGET |
127 |
| -// mov x0, #0 |
128 |
| -// ret |
129 |
| -// |
130 |
| -// A non-leaf function which does not immediately save LR may need both macros |
131 |
| -// because |AARCH64_SIGN_LINK_REGISTER| appears late. For example, the function |
132 |
| -// may jump to an alternate implementation before setting up the stack: |
133 |
| -// |
134 |
| -// .globl with_early_jump |
135 |
| -// with_early_jump: |
136 |
| -// AARCH64_VALID_CALL_TARGET |
137 |
| -// cmp x0, #128 |
138 |
| -// b.lt .Lwith_early_jump_128 |
139 |
| -// AARCH64_SIGN_LINK_REGISTER |
140 |
| -// stp x29, x30, [sp, #-96]! |
141 |
| -// mov x29, sp |
142 |
| -// ... |
143 |
| -// ldp x29, x30, [sp], #96 |
144 |
| -// AARCH64_VALIDATE_LINK_REGISTER |
145 |
| -// ret |
146 |
| -// |
147 |
| -// .Lwith_early_jump_128: |
148 |
| -// ... |
149 |
| -// ret |
150 |
| -// |
151 |
| -// These annotations are only required with indirect calls. Private symbols that |
152 |
| -// are only the target of direct calls do not require annotations. Also note |
153 |
| -// that |AARCH64_VALID_CALL_TARGET| is only valid for indirect calls (BLR), not |
154 |
| -// indirect jumps (BR). Indirect jumps in assembly are currently not supported |
155 |
| -// and would require a macro for BTI 'j'. |
156 |
| -// |
157 |
| -// Although not necessary, it is safe to use these macros in 32-bit ARM |
158 |
| -// assembly. This may be used to simplify dual 32-bit and 64-bit files. |
159 |
| -// |
160 |
| -// References: |
161 |
| -// - "ELF for the Arm® 64-bit Architecture" |
162 |
| -// https://github.com/ARM-software/abi-aa/blob/master/aaelf64/aaelf64.rst |
163 |
| -// - "Providing protection for complex software" |
164 |
| -// https://developer.arm.com/architectures/learn-the-architecture/providing-protection-for-complex-software |
165 |
| - |
166 |
| -#if defined(__ARM_FEATURE_BTI_DEFAULT) && __ARM_FEATURE_BTI_DEFAULT == 1 |
167 |
| -#define GNU_PROPERTY_AARCH64_BTI (1 << 0) // Has Branch Target Identification |
168 |
| -#define AARCH64_VALID_CALL_TARGET hint #34 // BTI 'c' |
169 |
| -#else |
170 |
| -#define GNU_PROPERTY_AARCH64_BTI 0 // No Branch Target Identification |
171 |
| -#define AARCH64_VALID_CALL_TARGET |
172 |
| -#endif |
173 |
| - |
174 |
| -#if defined(__ARM_FEATURE_PAC_DEFAULT) && \ |
175 |
| - (__ARM_FEATURE_PAC_DEFAULT & 1) == 1 // Signed with A-key |
176 |
| -#define GNU_PROPERTY_AARCH64_POINTER_AUTH \ |
177 |
| - (1 << 1) // Has Pointer Authentication |
178 |
| -#define AARCH64_SIGN_LINK_REGISTER hint #25 // PACIASP |
179 |
| -#define AARCH64_VALIDATE_LINK_REGISTER hint #29 // AUTIASP |
180 |
| -#elif defined(__ARM_FEATURE_PAC_DEFAULT) && \ |
181 |
| - (__ARM_FEATURE_PAC_DEFAULT & 2) == 2 // Signed with B-key |
182 |
| -#define GNU_PROPERTY_AARCH64_POINTER_AUTH \ |
183 |
| - (1 << 1) // Has Pointer Authentication |
184 |
| -#define AARCH64_SIGN_LINK_REGISTER hint #27 // PACIBSP |
185 |
| -#define AARCH64_VALIDATE_LINK_REGISTER hint #31 // AUTIBSP |
186 |
| -#else |
187 |
| -#define GNU_PROPERTY_AARCH64_POINTER_AUTH 0 // No Pointer Authentication |
188 |
| -#if GNU_PROPERTY_AARCH64_BTI != 0 |
189 |
| -#define AARCH64_SIGN_LINK_REGISTER AARCH64_VALID_CALL_TARGET |
190 |
| -#else |
191 |
| -#define AARCH64_SIGN_LINK_REGISTER |
192 |
| -#endif |
193 |
| -#define AARCH64_VALIDATE_LINK_REGISTER |
194 |
| -#endif |
195 |
| - |
196 |
| -#if GNU_PROPERTY_AARCH64_POINTER_AUTH != 0 || GNU_PROPERTY_AARCH64_BTI != 0 |
197 |
| -.pushsection .note.gnu.property, "a"; |
198 |
| -.balign 8; |
199 |
| -.long 4; |
200 |
| -.long 0x10; |
201 |
| -.long 0x5; |
202 |
| -.asciz "GNU"; |
203 |
| -.long 0xc0000000; /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */ |
204 |
| -.long 4; |
205 |
| -.long (GNU_PROPERTY_AARCH64_POINTER_AUTH | GNU_PROPERTY_AARCH64_BTI); |
206 |
| -.long 0; |
207 |
| -.popsection; |
208 |
| -#endif |
209 |
| - |
210 | 95 | #endif // __ASSEMBLER__
|
211 | 96 |
|
212 |
| -#endif // __ARMEL__ || _M_ARM || __AARCH64EL__ || _M_ARM64 |
| 97 | +#endif // ARM || AARCH64 |
213 | 98 |
|
214 | 99 | #endif // OPENSSL_HEADER_ARM_ARCH_H
|
0 commit comments