xref: /xnu-8019.80.24/osfmk/mach/arm/_structs.h (revision a325d9c4a84054e40bbe985afedcb50ab80993ea) !
1 /*
2  * Copyright (c) 2004-2007 Apple Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
6  * This file contains Original Code and/or Modifications of Original Code
7  * as defined in and that are subject to the Apple Public Source License
8  * Version 2.0 (the 'License'). You may not use this file except in
9  * compliance with the License. The rights granted to you under the License
10  * may not be used to create, or enable the creation or redistribution of,
11  * unlawful or unlicensed copies of an Apple operating system, or to
12  * circumvent, violate, or enable the circumvention or violation of, any
13  * terms of an Apple operating system software license agreement.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
18  * The Original Code and all software distributed under the License are
19  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23  * Please see the License for the specific language governing rights and
24  * limitations under the License.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27  */
28 /*
29  * @OSF_COPYRIGHT@
30  */
31 #ifndef _MACH_ARM__STRUCTS_H_
32 #define _MACH_ARM__STRUCTS_H_
33 
34 #if defined (__arm__) || defined (__arm64__)
35 
36 #include <sys/cdefs.h> /* __DARWIN_UNIX03 */
37 #include <machine/types.h> /* __uint32_t */
38 
39 #if __DARWIN_UNIX03
40 #define _STRUCT_ARM_EXCEPTION_STATE struct __darwin_arm_exception_state
41 _STRUCT_ARM_EXCEPTION_STATE
42 {
43 	__uint32_t __exception; /* number of arm exception taken */
44 	__uint32_t __fsr;       /* Fault status */
45 	__uint32_t __far;       /* Virtual Fault Address */
46 };
47 #else /* !__DARWIN_UNIX03 */
48 #define _STRUCT_ARM_EXCEPTION_STATE struct arm_exception_state
49 _STRUCT_ARM_EXCEPTION_STATE
50 {
51 	__uint32_t exception;   /* number of arm exception taken */
52 	__uint32_t fsr;         /* Fault status */
53 	__uint32_t far;         /* Virtual Fault Address */
54 };
55 #endif /* __DARWIN_UNIX03 */
56 
57 #if __DARWIN_UNIX03
58 #define _STRUCT_ARM_EXCEPTION_STATE64 struct __darwin_arm_exception_state64
59 _STRUCT_ARM_EXCEPTION_STATE64
60 {
61 	__uint64_t __far;       /* Virtual Fault Address */
62 	__uint32_t __esr;       /* Exception syndrome */
63 	__uint32_t __exception; /* number of arm exception taken */
64 };
65 #else /* !__DARWIN_UNIX03 */
66 #define _STRUCT_ARM_EXCEPTION_STATE64 struct arm_exception_state64
67 _STRUCT_ARM_EXCEPTION_STATE64
68 {
69 	__uint64_t far;         /* Virtual Fault Address */
70 	__uint32_t esr;         /* Exception syndrome */
71 	__uint32_t exception;   /* number of arm exception taken */
72 };
73 #endif /* __DARWIN_UNIX03 */
74 
75 #if __DARWIN_UNIX03
76 #define _STRUCT_ARM_THREAD_STATE struct __darwin_arm_thread_state
77 _STRUCT_ARM_THREAD_STATE
78 {
79 	__uint32_t __r[13]; /* General purpose register r0-r12 */
80 	__uint32_t __sp;    /* Stack pointer r13 */
81 	__uint32_t __lr;    /* Link register r14 */
82 	__uint32_t __pc;    /* Program counter r15 */
83 	__uint32_t __cpsr;  /* Current program status register */
84 };
85 #else /* !__DARWIN_UNIX03 */
86 #define _STRUCT_ARM_THREAD_STATE struct arm_thread_state
87 _STRUCT_ARM_THREAD_STATE
88 {
89 	__uint32_t r[13];   /* General purpose register r0-r12 */
90 	__uint32_t sp;      /* Stack pointer r13 */
91 	__uint32_t lr;      /* Link register r14 */
92 	__uint32_t pc;      /* Program counter r15 */
93 	__uint32_t cpsr;    /* Current program status register */
94 };
95 #endif /* __DARWIN_UNIX03 */
96 
97 #if defined(KERNEL)
98 
99 #define __DARWIN_OPAQUE_ARM_THREAD_STATE64 0
100 #define __DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH 0x1
101 #define __DARWIN_ARM_THREAD_STATE64_FLAGS_IB_SIGNED_LR 0x2
102 
103 #define _STRUCT_ARM_THREAD_STATE64      struct arm_thread_state64
104 _STRUCT_ARM_THREAD_STATE64
105 {
106 	__uint64_t    x[29];    /* General purpose registers x0-x28 */
107 	__uint64_t    fp;               /* Frame pointer x29 */
108 	__uint64_t    lr;               /* Link register x30 */
109 	__uint64_t    sp;               /* Stack pointer x31 */
110 	__uint64_t    pc;               /* Program counter */
111 	__uint32_t    cpsr;             /* Current program status register */
112 	__uint32_t    flags;    /* Flags describing structure format */
113 };
114 
115 #else /* defined(KERNEL) */
116 
117 /*
118  * By default, the pointer fields in the arm_thread_state64_t structure are
119  * opaque on the arm64e architecture and require the use of accessor macros.
120  * This mode can also be enabled on the arm64 architecture by building with
121  * -D__DARWIN_OPAQUE_ARM_THREAD_STATE64=1.
122  */
123 #if defined(__arm64__) && defined(__LP64__)
124 
125 #if __has_feature(ptrauth_calls)
126 #define __DARWIN_OPAQUE_ARM_THREAD_STATE64 1
127 #define __DARWIN_PTRAUTH_ARM_THREAD_STATE64 1
128 #endif /* __has_feature(ptrauth_calls) */
129 
130 #ifndef __DARWIN_OPAQUE_ARM_THREAD_STATE64
131 #define __DARWIN_OPAQUE_ARM_THREAD_STATE64 0
132 #endif
133 
134 #else /* defined(__arm64__) && defined(__LP64__) */
135 
136 #undef __DARWIN_OPAQUE_ARM_THREAD_STATE64
137 #define __DARWIN_OPAQUE_ARM_THREAD_STATE64 0
138 
139 #endif /* defined(__arm64__) && defined(__LP64__) */
140 
141 #if __DARWIN_UNIX03
142 #define _STRUCT_ARM_THREAD_STATE64 struct __darwin_arm_thread_state64
143 #if __DARWIN_OPAQUE_ARM_THREAD_STATE64
144 _STRUCT_ARM_THREAD_STATE64
145 {
146 	__uint64_t __x[29];     /* General purpose registers x0-x28 */
147 	void*      __opaque_fp; /* Frame pointer x29 */
148 	void*      __opaque_lr; /* Link register x30 */
149 	void*      __opaque_sp; /* Stack pointer x31 */
150 	void*      __opaque_pc; /* Program counter */
151 	__uint32_t __cpsr;      /* Current program status register */
152 	__uint32_t __opaque_flags; /* Flags describing structure format */
153 };
154 #else /* __DARWIN_OPAQUE_ARM_THREAD_STATE64 */
155 _STRUCT_ARM_THREAD_STATE64
156 {
157 	__uint64_t __x[29]; /* General purpose registers x0-x28 */
158 	__uint64_t __fp;    /* Frame pointer x29 */
159 	__uint64_t __lr;    /* Link register x30 */
160 	__uint64_t __sp;    /* Stack pointer x31 */
161 	__uint64_t __pc;    /* Program counter */
162 	__uint32_t __cpsr;  /* Current program status register */
163 	__uint32_t __pad;   /* Same size for 32-bit or 64-bit clients */
164 };
165 #endif /* __DARWIN_OPAQUE_ARM_THREAD_STATE64 */
166 #else /* !__DARWIN_UNIX03 */
167 #define _STRUCT_ARM_THREAD_STATE64 struct arm_thread_state64
168 #if __DARWIN_OPAQUE_ARM_THREAD_STATE64
169 _STRUCT_ARM_THREAD_STATE64
170 {
171 	__uint64_t x[29];       /* General purpose registers x0-x28 */
172 	void*      __opaque_fp; /* Frame pointer x29 */
173 	void*      __opaque_lr; /* Link register x30 */
174 	void*      __opaque_sp; /* Stack pointer x31 */
175 	void*      __opaque_pc; /* Program counter */
176 	__uint32_t cpsr;        /* Current program status register */
177 	__uint32_t __opaque_flags; /* Flags describing structure format */
178 };
179 #else /* __DARWIN_OPAQUE_ARM_THREAD_STATE64 */
180 _STRUCT_ARM_THREAD_STATE64
181 {
182 	__uint64_t x[29]; /* General purpose registers x0-x28 */
183 	__uint64_t fp;    /* Frame pointer x29 */
184 	__uint64_t lr;    /* Link register x30 */
185 	__uint64_t sp;    /* Stack pointer x31 */
186 	__uint64_t pc;    /* Program counter */
187 	__uint32_t cpsr;  /* Current program status register */
188 	__uint32_t __pad; /* Same size for 32-bit or 64-bit clients */
189 };
190 #endif /* __DARWIN_OPAQUE_ARM_THREAD_STATE64 */
191 #endif /* __DARWIN_UNIX03 */
192 
193 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL && defined(__arm64__)
194 
195 /* Accessor macros for arm_thread_state64_t pointer fields */
196 
197 #if __has_feature(ptrauth_calls) && defined(__LP64__)
198 #include <ptrauth.h>
199 
200 #if !__DARWIN_OPAQUE_ARM_THREAD_STATE64 || !__DARWIN_PTRAUTH_ARM_THREAD_STATE64
201 #error "Invalid configuration"
202 #endif
203 
204 #define __DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH 0x1
205 #define __DARWIN_ARM_THREAD_STATE64_FLAGS_IB_SIGNED_LR 0x2
206 
207 /* Return pc field of arm_thread_state64_t as a data pointer value */
208 #define __darwin_arm_thread_state64_get_pc(ts) \
209 	__extension__ ({ const _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
210 	(uintptr_t)(__tsp->__opaque_pc && !(__tsp->__opaque_flags &       \
211 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ?                   \
212 	ptrauth_auth_data(__tsp->__opaque_pc,                             \
213 	ptrauth_key_process_independent_code,                             \
214 	ptrauth_string_discriminator("pc")) : __tsp->__opaque_pc); })
215 /* Return pc field of arm_thread_state64_t as a function pointer. May return
216  * NULL if a valid function pointer cannot be constructed, the caller should
217  * fall back to the __darwin_arm_thread_state64_get_pc() macro in that case. */
218 #define __darwin_arm_thread_state64_get_pc_fptr(ts) \
219 	__extension__ ({ const _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
220 	(__tsp->__opaque_pc && !(__tsp->__opaque_flags &                  \
221 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ?                   \
222 	ptrauth_auth_function(__tsp->__opaque_pc,                         \
223 	ptrauth_key_process_independent_code,                             \
224 	ptrauth_string_discriminator("pc")) : NULL); })
225 /* Set pc field of arm_thread_state64_t to a function pointer */
226 #define __darwin_arm_thread_state64_set_pc_fptr(ts, fptr) \
227 	__extension__ ({ _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts);   \
228 	__typeof__(fptr) __f = (fptr); __tsp->__opaque_pc =           \
229 	(__f ? (!(__tsp->__opaque_flags &                             \
230 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ?               \
231 	ptrauth_auth_and_resign(__f, ptrauth_key_function_pointer, 0, \
232 	ptrauth_key_process_independent_code,                         \
233 	ptrauth_string_discriminator("pc")) : ptrauth_auth_data(__f,  \
234 	ptrauth_key_function_pointer, 0)) : __f); })
235 /* Return lr field of arm_thread_state64_t as a data pointer value */
236 #define __darwin_arm_thread_state64_get_lr(ts) \
237 	__extension__ ({ const _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
238 	(uintptr_t)(__tsp->__opaque_lr && !(__tsp->__opaque_flags & (     \
239 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH |                    \
240 	__DARWIN_ARM_THREAD_STATE64_FLAGS_IB_SIGNED_LR)) ?                \
241 	ptrauth_auth_data(__tsp->__opaque_lr,                             \
242 	ptrauth_key_process_independent_code,                             \
243 	ptrauth_string_discriminator("lr")) : __tsp->__opaque_lr); })
244 /* Return lr field of arm_thread_state64_t as a function pointer. May return
245  * NULL if a valid function pointer cannot be constructed, the caller should
246  * fall back to the __darwin_arm_thread_state64_get_lr() macro in that case. */
247 #define __darwin_arm_thread_state64_get_lr_fptr(ts) \
248 	__extension__ ({ const _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
249 	(__tsp->__opaque_lr && !(__tsp->__opaque_flags & (                \
250 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH |                    \
251 	__DARWIN_ARM_THREAD_STATE64_FLAGS_IB_SIGNED_LR)) ?                \
252 	ptrauth_auth_function(__tsp->__opaque_lr,                         \
253 	ptrauth_key_process_independent_code,                             \
254 	ptrauth_string_discriminator("lr")) : NULL); })
255 /* Set lr field of arm_thread_state64_t to a function pointer */
256 #define __darwin_arm_thread_state64_set_lr_fptr(ts, fptr) \
257 	__extension__ ({ _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts);            \
258 	__typeof__(fptr) __f = (fptr); __tsp->__opaque_lr =                    \
259 	(__f ? (!(__tsp->__opaque_flags &                                      \
260 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ? (__tsp->__opaque_flags \
261 	&= ~__DARWIN_ARM_THREAD_STATE64_FLAGS_IB_SIGNED_LR ,                   \
262 	ptrauth_auth_and_resign(__f, ptrauth_key_function_pointer, 0,          \
263 	ptrauth_key_process_independent_code,                                  \
264 	ptrauth_string_discriminator("lr"))) : ptrauth_auth_data(__f,          \
265 	ptrauth_key_function_pointer, 0)) : __f); })
266 /* Return sp field of arm_thread_state64_t as a data pointer value */
267 #define __darwin_arm_thread_state64_get_sp(ts) \
268 	__extension__ ({ const _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
269 	(uintptr_t)(__tsp->__opaque_sp && !(__tsp->__opaque_flags &       \
270 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ?                   \
271 	ptrauth_auth_data(__tsp->__opaque_sp,                             \
272 	ptrauth_key_process_independent_data,                             \
273 	ptrauth_string_discriminator("sp")) : __tsp->__opaque_sp); })
274 /* Set sp field of arm_thread_state64_t to a data pointer value */
275 #define __darwin_arm_thread_state64_set_sp(ts, ptr) \
276 	__extension__ ({ _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
277 	void *__p = (void*)(uintptr_t)(ptr); __tsp->__opaque_sp =   \
278 	(__p && !(__tsp->__opaque_flags &                           \
279 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ?             \
280 	ptrauth_sign_unauthenticated(__p,                           \
281 	ptrauth_key_process_independent_data,                       \
282 	ptrauth_string_discriminator("sp")) : __p); })
283 /* Return fp field of arm_thread_state64_t as a data pointer value */
284 #define __darwin_arm_thread_state64_get_fp(ts) \
285 	__extension__ ({ const _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
286 	(uintptr_t)(__tsp->__opaque_fp && !(__tsp->__opaque_flags &       \
287 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ?                   \
288 	ptrauth_auth_data(__tsp->__opaque_fp,                             \
289 	ptrauth_key_process_independent_data,                             \
290 	ptrauth_string_discriminator("fp")) : __tsp->__opaque_fp); })
291 /* Set fp field of arm_thread_state64_t to a data pointer value */
292 #define __darwin_arm_thread_state64_set_fp(ts, ptr) \
293 	__extension__ ({ _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
294 	void *__p = (void*)(uintptr_t)(ptr); __tsp->__opaque_fp =   \
295 	(__p && !(__tsp->__opaque_flags &                           \
296 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ?             \
297 	ptrauth_sign_unauthenticated(__p,                           \
298 	ptrauth_key_process_independent_data,                       \
299 	ptrauth_string_discriminator("fp")) : __p); })
300 
301 /* Strip ptr auth bits from pc, lr, sp and fp field of arm_thread_state64_t */
302 #define __darwin_arm_thread_state64_ptrauth_strip(ts) \
303 	__extension__ ({ _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts);               \
304 	__tsp->__opaque_pc = ((__tsp->__opaque_flags &                            \
305 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ? __tsp->__opaque_pc :      \
306 	ptrauth_strip(__tsp->__opaque_pc, ptrauth_key_process_independent_code)); \
307 	__tsp->__opaque_lr = ((__tsp->__opaque_flags &                            \
308 	(__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH |                           \
309 	__DARWIN_ARM_THREAD_STATE64_FLAGS_IB_SIGNED_LR)) ? __tsp->__opaque_lr :   \
310 	ptrauth_strip(__tsp->__opaque_lr, ptrauth_key_process_independent_code)); \
311 	__tsp->__opaque_sp = ((__tsp->__opaque_flags &                            \
312 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ? __tsp->__opaque_sp :      \
313 	ptrauth_strip(__tsp->__opaque_sp, ptrauth_key_process_independent_data)); \
314 	__tsp->__opaque_fp = ((__tsp->__opaque_flags &                            \
315 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ? __tsp->__opaque_fp :      \
316 	ptrauth_strip(__tsp->__opaque_fp, ptrauth_key_process_independent_data)); \
317 	__tsp->__opaque_flags |=                                                  \
318 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH; })
319 
320 #else /* __has_feature(ptrauth_calls) && defined(__LP64__) */
321 
322 #if __DARWIN_OPAQUE_ARM_THREAD_STATE64
323 
324 #ifndef __LP64__
325 #error "Invalid configuration"
326 #endif
327 
328 /* Return pc field of arm_thread_state64_t as a data pointer value */
329 #define __darwin_arm_thread_state64_get_pc(ts) \
330 	((uintptr_t)((ts).__opaque_pc))
331 /* Return pc field of arm_thread_state64_t as a function pointer */
332 #define __darwin_arm_thread_state64_get_pc_fptr(ts) \
333 	((ts).__opaque_pc)
334 /* Set pc field of arm_thread_state64_t to a function pointer */
335 #define __darwin_arm_thread_state64_set_pc_fptr(ts, fptr) \
336 	((ts).__opaque_pc = (fptr))
337 /* Return lr field of arm_thread_state64_t as a data pointer value */
338 #define __darwin_arm_thread_state64_get_lr(ts) \
339 	((uintptr_t)((ts).__opaque_lr))
340 /* Return lr field of arm_thread_state64_t as a function pointer */
341 #define __darwin_arm_thread_state64_get_lr_fptr(ts) \
342 	((ts).__opaque_lr)
343 /* Set lr field of arm_thread_state64_t to a function pointer */
344 #define __darwin_arm_thread_state64_set_lr_fptr(ts, fptr) \
345 	((ts).__opaque_lr = (fptr))
346 /* Return sp field of arm_thread_state64_t as a data pointer value */
347 #define __darwin_arm_thread_state64_get_sp(ts) \
348 	((uintptr_t)((ts).__opaque_sp))
349 /* Set sp field of arm_thread_state64_t to a data pointer value */
350 #define __darwin_arm_thread_state64_set_sp(ts, ptr) \
351 	((ts).__opaque_sp = (void*)(uintptr_t)(ptr))
352 /* Return fp field of arm_thread_state64_t as a data pointer value */
353 #define __darwin_arm_thread_state64_get_fp(ts) \
354 	((uintptr_t)((ts).__opaque_fp))
355 /* Set fp field of arm_thread_state64_t to a data pointer value */
356 #define __darwin_arm_thread_state64_set_fp(ts, ptr) \
357 	((ts).__opaque_fp = (void*)(uintptr_t)(ptr))
358 /* Strip ptr auth bits from pc, lr, sp and fp field of arm_thread_state64_t */
359 #define __darwin_arm_thread_state64_ptrauth_strip(ts) \
360 	(void)(ts)
361 
362 #else /* __DARWIN_OPAQUE_ARM_THREAD_STATE64 */
363 #if __DARWIN_UNIX03
364 
365 /* Return pc field of arm_thread_state64_t as a data pointer value */
366 #define __darwin_arm_thread_state64_get_pc(ts) \
367 	((ts).__pc)
368 /* Return pc field of arm_thread_state64_t as a function pointer */
369 #define __darwin_arm_thread_state64_get_pc_fptr(ts) \
370 	((void*)(uintptr_t)((ts).__pc))
371 /* Set pc field of arm_thread_state64_t to a function pointer */
372 #define __darwin_arm_thread_state64_set_pc_fptr(ts, fptr) \
373 	((ts).__pc = (uintptr_t)(fptr))
374 /* Return lr field of arm_thread_state64_t as a data pointer value */
375 #define __darwin_arm_thread_state64_get_lr(ts) \
376 	((ts).__lr)
377 /* Return lr field of arm_thread_state64_t as a function pointer */
378 #define __darwin_arm_thread_state64_get_lr_fptr(ts) \
379 	((void*)(uintptr_t)((ts).__lr))
380 /* Set lr field of arm_thread_state64_t to a function pointer */
381 #define __darwin_arm_thread_state64_set_lr_fptr(ts, fptr) \
382 	((ts).__lr = (uintptr_t)(fptr))
383 /* Return sp field of arm_thread_state64_t as a data pointer value */
384 #define __darwin_arm_thread_state64_get_sp(ts) \
385 	((ts).__sp)
386 /* Set sp field of arm_thread_state64_t to a data pointer value */
387 #define __darwin_arm_thread_state64_set_sp(ts, ptr) \
388 	((ts).__sp = (uintptr_t)(ptr))
389 /* Return fp field of arm_thread_state64_t as a data pointer value */
390 #define __darwin_arm_thread_state64_get_fp(ts) \
391 	((ts).__fp)
392 /* Set fp field of arm_thread_state64_t to a data pointer value */
393 #define __darwin_arm_thread_state64_set_fp(ts, ptr) \
394 	((ts).__fp = (uintptr_t)(ptr))
395 /* Strip ptr auth bits from pc, lr, sp and fp field of arm_thread_state64_t */
396 #define __darwin_arm_thread_state64_ptrauth_strip(ts) \
397 	(void)(ts)
398 
399 #else /* __DARWIN_UNIX03 */
400 
401 /* Return pc field of arm_thread_state64_t as a data pointer value */
402 #define __darwin_arm_thread_state64_get_pc(ts) \
403 	((ts).pc)
404 /* Return pc field of arm_thread_state64_t as a function pointer */
405 #define __darwin_arm_thread_state64_get_pc_fptr(ts) \
406 	((void*)(uintptr_t)((ts).pc))
407 /* Set pc field of arm_thread_state64_t to a function pointer */
408 #define __darwin_arm_thread_state64_set_pc_fptr(ts, fptr) \
409 	((ts).pc = (uintptr_t)(fptr))
410 /* Return lr field of arm_thread_state64_t as a data pointer value */
411 #define __darwin_arm_thread_state64_get_lr(ts) \
412 	((ts).lr)
413 /* Return lr field of arm_thread_state64_t as a function pointer */
414 #define __darwin_arm_thread_state64_get_lr_fptr(ts) \
415 	((void*)(uintptr_t)((ts).lr))
416 /* Set lr field of arm_thread_state64_t to a function pointer */
417 #define __darwin_arm_thread_state64_set_lr_fptr(ts, fptr) \
418 	((ts).lr = (uintptr_t)(fptr))
419 /* Return sp field of arm_thread_state64_t as a data pointer value */
420 #define __darwin_arm_thread_state64_get_sp(ts) \
421 	((ts).sp)
422 /* Set sp field of arm_thread_state64_t to a data pointer value */
423 #define __darwin_arm_thread_state64_set_sp(ts, ptr) \
424 	((ts).sp = (uintptr_t)(ptr))
425 /* Return fp field of arm_thread_state64_t as a data pointer value */
426 #define __darwin_arm_thread_state64_get_fp(ts) \
427 	((ts).fp)
428 /* Set fp field of arm_thread_state64_t to a data pointer value */
429 #define __darwin_arm_thread_state64_set_fp(ts, ptr) \
430 	((ts).fp = (uintptr_t)(ptr))
431 /* Strip ptr auth bits from pc, lr, sp and fp field of arm_thread_state64_t */
432 #define __darwin_arm_thread_state64_ptrauth_strip(ts) \
433 	(void)(ts)
434 
435 #endif /* __DARWIN_UNIX03 */
436 #endif /* __DARWIN_OPAQUE_ARM_THREAD_STATE64 */
437 
438 #endif /* __has_feature(ptrauth_calls) && defined(__LP64__) */
439 #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL && defined(__arm64__) */
440 #endif /* !defined(KERNEL) */
441 
442 #if __DARWIN_UNIX03
443 #define _STRUCT_ARM_VFP_STATE struct __darwin_arm_vfp_state
444 _STRUCT_ARM_VFP_STATE
445 {
446 	__uint32_t __r[64];
447 	__uint32_t __fpscr;
448 };
449 #else /* !__DARWIN_UNIX03 */
450 #define _STRUCT_ARM_VFP_STATE struct arm_vfp_state
451 _STRUCT_ARM_VFP_STATE
452 {
453 	__uint32_t r[64];
454 	__uint32_t fpscr;
455 };
456 #endif /* __DARWIN_UNIX03 */
457 
458 #if __DARWIN_UNIX03
459 #define _STRUCT_ARM_NEON_STATE64 struct __darwin_arm_neon_state64
460 #define _STRUCT_ARM_NEON_STATE   struct __darwin_arm_neon_state
461 
462 #if defined(__arm64__)
463 _STRUCT_ARM_NEON_STATE64
464 {
465 	__uint128_t __v[32];
466 	__uint32_t  __fpsr;
467 	__uint32_t  __fpcr;
468 };
469 
470 _STRUCT_ARM_NEON_STATE
471 {
472 	__uint128_t __v[16];
473 	__uint32_t  __fpsr;
474 	__uint32_t  __fpcr;
475 };
476 #elif defined(__arm__)
477 /*
478  * No 128-bit intrinsic for ARM; leave it opaque for now.
479  */
480 _STRUCT_ARM_NEON_STATE64
481 {
482 	char opaque[(32 * 16) + (2 * sizeof(__uint32_t))];
483 } __attribute__((aligned(16)));
484 
485 _STRUCT_ARM_NEON_STATE
486 {
487 	char opaque[(16 * 16) + (2 * sizeof(__uint32_t))];
488 } __attribute__((aligned(16)));
489 
490 #else
491 #error Unknown architecture.
492 #endif
493 
494 #else /* !__DARWIN_UNIX03 */
495 #define _STRUCT_ARM_NEON_STATE64 struct arm_neon_state64
496 #define _STRUCT_ARM_NEON_STATE struct arm_neon_state
497 
498 #if defined(__arm64__)
499 _STRUCT_ARM_NEON_STATE64
500 {
501 	__uint128_t q[32];
502 	uint32_t    fpsr;
503 	uint32_t    fpcr;
504 };
505 
506 _STRUCT_ARM_NEON_STATE
507 {
508 	__uint128_t q[16];
509 	uint32_t    fpsr;
510 	uint32_t    fpcr;
511 };
512 #elif defined(__arm__)
513 /*
514  * No 128-bit intrinsic for ARM; leave it opaque for now.
515  */
516 _STRUCT_ARM_NEON_STATE64
517 {
518 	char opaque[(32 * 16) + (2 * sizeof(__uint32_t))];
519 } __attribute__((aligned(16)));
520 
521 _STRUCT_ARM_NEON_STATE
522 {
523 	char opaque[(16 * 16) + (2 * sizeof(__uint32_t))];
524 } __attribute__((aligned(16)));
525 
526 #else
527 #error Unknown architecture.
528 #endif
529 
530 #endif /* __DARWIN_UNIX03 */
531 
532 
533 #define _STRUCT_ARM_PAGEIN_STATE struct __arm_pagein_state
534 _STRUCT_ARM_PAGEIN_STATE
535 {
536 	int __pagein_error;
537 };
538 
539 /*
540  * Debug State
541  */
542 #if defined(__arm__)
543 /* Old-fashioned debug state is only for ARM */
544 
545 #if __DARWIN_UNIX03
546 #define _STRUCT_ARM_DEBUG_STATE struct __darwin_arm_debug_state
547 _STRUCT_ARM_DEBUG_STATE
548 {
549 	__uint32_t __bvr[16];
550 	__uint32_t __bcr[16];
551 	__uint32_t __wvr[16];
552 	__uint32_t __wcr[16];
553 };
554 #else /* !__DARWIN_UNIX03 */
555 #define _STRUCT_ARM_DEBUG_STATE struct arm_debug_state
556 _STRUCT_ARM_DEBUG_STATE
557 {
558 	__uint32_t bvr[16];
559 	__uint32_t bcr[16];
560 	__uint32_t wvr[16];
561 	__uint32_t wcr[16];
562 };
563 #endif /* __DARWIN_UNIX03 */
564 
565 #elif defined(__arm64__)
566 
567 /* ARM's arm_debug_state is ARM64's arm_legacy_debug_state */
568 
569 #if __DARWIN_UNIX03
570 #define _STRUCT_ARM_LEGACY_DEBUG_STATE struct __arm_legacy_debug_state
571 _STRUCT_ARM_LEGACY_DEBUG_STATE
572 {
573 	__uint32_t __bvr[16];
574 	__uint32_t __bcr[16];
575 	__uint32_t __wvr[16];
576 	__uint32_t __wcr[16];
577 };
578 #else /* __DARWIN_UNIX03 */
579 #define _STRUCT_ARM_LEGACY_DEBUG_STATE struct arm_legacy_debug_state
580 _STRUCT_ARM_LEGACY_DEBUG_STATE
581 {
582 	__uint32_t bvr[16];
583 	__uint32_t bcr[16];
584 	__uint32_t wvr[16];
585 	__uint32_t wcr[16];
586 };
587 #endif /* __DARWIN_UNIX03 */
588 #else
589 #error unknown architecture
590 #endif
591 
592 #if __DARWIN_UNIX03
593 #define _STRUCT_ARM_DEBUG_STATE32 struct __darwin_arm_debug_state32
594 _STRUCT_ARM_DEBUG_STATE32
595 {
596 	__uint32_t __bvr[16];
597 	__uint32_t __bcr[16];
598 	__uint32_t __wvr[16];
599 	__uint32_t __wcr[16];
600 	__uint64_t __mdscr_el1; /* Bit 0 is SS (Hardware Single Step) */
601 };
602 
603 #define _STRUCT_ARM_DEBUG_STATE64 struct __darwin_arm_debug_state64
604 _STRUCT_ARM_DEBUG_STATE64
605 {
606 	__uint64_t __bvr[16];
607 	__uint64_t __bcr[16];
608 	__uint64_t __wvr[16];
609 	__uint64_t __wcr[16];
610 	__uint64_t __mdscr_el1; /* Bit 0 is SS (Hardware Single Step) */
611 };
612 #else /* !__DARWIN_UNIX03 */
613 #define _STRUCT_ARM_DEBUG_STATE32 struct arm_debug_state32
614 _STRUCT_ARM_DEBUG_STATE32
615 {
616 	__uint32_t bvr[16];
617 	__uint32_t bcr[16];
618 	__uint32_t wvr[16];
619 	__uint32_t wcr[16];
620 	__uint64_t mdscr_el1; /* Bit 0 is SS (Hardware Single Step) */
621 };
622 
623 #define _STRUCT_ARM_DEBUG_STATE64 struct arm_debug_state64
624 _STRUCT_ARM_DEBUG_STATE64
625 {
626 	__uint64_t bvr[16];
627 	__uint64_t bcr[16];
628 	__uint64_t wvr[16];
629 	__uint64_t wcr[16];
630 	__uint64_t mdscr_el1; /* Bit 0 is SS (Hardware Single Step) */
631 };
632 #endif /* __DARWIN_UNIX03 */
633 
634 #if __DARWIN_UNIX03
635 #define _STRUCT_ARM_CPMU_STATE64 struct __darwin_arm_cpmu_state64
636 _STRUCT_ARM_CPMU_STATE64
637 {
638 	__uint64_t __ctrs[16];
639 };
640 #else /* __DARWIN_UNIX03 */
641 #define _STRUCT_ARM_CPMU_STATE64 struct arm_cpmu_state64
642 _STRUCT_ARM_CPMU_STATE64
643 {
644 	__uint64_t ctrs[16];
645 };
646 #endif /* !__DARWIN_UNIX03 */
647 
648 #endif /* defined (__arm__) || defined (__arm64__) */
649 
650 #endif /* _MACH_ARM__STRUCTS_H_ */
651