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#define _STRUCT_ARM_EXCEPTION_STATE64_V2 struct __darwin_arm_exception_state64_v2
66_STRUCT_ARM_EXCEPTION_STATE64_V2
67{
68 __uint64_t __far; /* Virtual Fault Address */
69 __uint64_t __esr; /* Exception syndrome */
70};
71#else /* !__DARWIN_UNIX03 */
72#define _STRUCT_ARM_EXCEPTION_STATE64 struct arm_exception_state64
73_STRUCT_ARM_EXCEPTION_STATE64
74{
75 __uint64_t far; /* Virtual Fault Address */
76 __uint32_t esr; /* Exception syndrome */
77 __uint32_t exception; /* number of arm exception taken */
78};
79#define _STRUCT_ARM_EXCEPTION_STATE64_V2 struct arm_exception_state64_v2
80_STRUCT_ARM_EXCEPTION_STATE64_V2
81{
82 __uint64_t far; /* Virtual Fault Address */
83 __uint64_t esr; /* Exception syndrome */
84};
85#endif /* __DARWIN_UNIX03 */
86
87#if __DARWIN_UNIX03
88#define _STRUCT_ARM_THREAD_STATE struct __darwin_arm_thread_state
89_STRUCT_ARM_THREAD_STATE
90{
91 __uint32_t __r[13]; /* General purpose register r0-r12 */
92 __uint32_t __sp; /* Stack pointer r13 */
93 __uint32_t __lr; /* Link register r14 */
94 __uint32_t __pc; /* Program counter r15 */
95 __uint32_t __cpsr; /* Current program status register */
96};
97#else /* !__DARWIN_UNIX03 */
98#define _STRUCT_ARM_THREAD_STATE struct arm_thread_state
99_STRUCT_ARM_THREAD_STATE
100{
101 __uint32_t r[13]; /* General purpose register r0-r12 */
102 __uint32_t sp; /* Stack pointer r13 */
103 __uint32_t lr; /* Link register r14 */
104 __uint32_t pc; /* Program counter r15 */
105 __uint32_t cpsr; /* Current program status register */
106};
107#endif /* __DARWIN_UNIX03 */
108
109
110/*
111 * By default, the pointer fields in the arm_thread_state64_t structure are
112 * opaque on the arm64e architecture and require the use of accessor macros.
113 * This mode can also be enabled on the arm64 architecture by building with
114 * -D__DARWIN_OPAQUE_ARM_THREAD_STATE64=1.
115 */
116#if defined(__arm64__) && defined(__LP64__)
117
118#if __has_feature(ptrauth_calls)
119#define __DARWIN_OPAQUE_ARM_THREAD_STATE64 1
120#define __DARWIN_PTRAUTH_ARM_THREAD_STATE64 1
121#endif /* __has_feature(ptrauth_calls) */
122
123#ifndef __DARWIN_OPAQUE_ARM_THREAD_STATE64
124#define __DARWIN_OPAQUE_ARM_THREAD_STATE64 0
125#endif
126
127#else /* defined(__arm64__) && defined(__LP64__) */
128
129#undef __DARWIN_OPAQUE_ARM_THREAD_STATE64
130#define __DARWIN_OPAQUE_ARM_THREAD_STATE64 0
131
132#endif /* defined(__arm64__) && defined(__LP64__) */
133
134#if __DARWIN_UNIX03
135#define _STRUCT_ARM_THREAD_STATE64 struct __darwin_arm_thread_state64
136#if __DARWIN_OPAQUE_ARM_THREAD_STATE64
137_STRUCT_ARM_THREAD_STATE64
138{
139 __uint64_t __x[29]; /* General purpose registers x0-x28 */
140 void* __opaque_fp; /* Frame pointer x29 */
141 void* __opaque_lr; /* Link register x30 */
142 void* __opaque_sp; /* Stack pointer x31 */
143 void* __opaque_pc; /* Program counter */
144 __uint32_t __cpsr; /* Current program status register */
145 __uint32_t __opaque_flags; /* Flags describing structure format */
146};
147#else /* __DARWIN_OPAQUE_ARM_THREAD_STATE64 */
148_STRUCT_ARM_THREAD_STATE64
149{
150 __uint64_t __x[29]; /* General purpose registers x0-x28 */
151 __uint64_t __fp; /* Frame pointer x29 */
152 __uint64_t __lr; /* Link register x30 */
153 __uint64_t __sp; /* Stack pointer x31 */
154 __uint64_t __pc; /* Program counter */
155 __uint32_t __cpsr; /* Current program status register */
156 __uint32_t __pad; /* Same size for 32-bit or 64-bit clients */
157};
158#endif /* __DARWIN_OPAQUE_ARM_THREAD_STATE64 */
159#else /* !__DARWIN_UNIX03 */
160#define _STRUCT_ARM_THREAD_STATE64 struct arm_thread_state64
161#if __DARWIN_OPAQUE_ARM_THREAD_STATE64
162_STRUCT_ARM_THREAD_STATE64
163{
164 __uint64_t x[29]; /* General purpose registers x0-x28 */
165 void* __opaque_fp; /* Frame pointer x29 */
166 void* __opaque_lr; /* Link register x30 */
167 void* __opaque_sp; /* Stack pointer x31 */
168 void* __opaque_pc; /* Program counter */
169 __uint32_t cpsr; /* Current program status register */
170 __uint32_t __opaque_flags; /* Flags describing structure format */
171};
172#else /* __DARWIN_OPAQUE_ARM_THREAD_STATE64 */
173_STRUCT_ARM_THREAD_STATE64
174{
175 __uint64_t x[29]; /* General purpose registers x0-x28 */
176 __uint64_t fp; /* Frame pointer x29 */
177 __uint64_t lr; /* Link register x30 */
178 __uint64_t sp; /* Stack pointer x31 */
179 __uint64_t pc; /* Program counter */
180 __uint32_t cpsr; /* Current program status register */
181 __uint32_t __pad; /* Same size for 32-bit or 64-bit clients */
182};
183#endif /* __DARWIN_OPAQUE_ARM_THREAD_STATE64 */
184#endif /* __DARWIN_UNIX03 */
185
186#if __DARWIN_C_LEVEL >= __DARWIN_C_FULL && defined(__arm64__)
187
188/* Accessor macros for arm_thread_state64_t pointer fields */
189
190#if __has_feature(ptrauth_calls) && defined(__LP64__)
191#include <ptrauth.h>
192
193#if !__DARWIN_OPAQUE_ARM_THREAD_STATE64 || !__DARWIN_PTRAUTH_ARM_THREAD_STATE64
194#error "Invalid configuration"
195#endif
196
197#define __DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH 0x1
198#define __DARWIN_ARM_THREAD_STATE64_FLAGS_IB_SIGNED_LR 0x2
199#define __DARWIN_ARM_THREAD_STATE64_FLAGS_KERNEL_SIGNED_PC 0x4
200#define __DARWIN_ARM_THREAD_STATE64_FLAGS_KERNEL_SIGNED_LR 0x8
201#define __DARWIN_ARM_THREAD_STATE64_FLAGS_CUSTOM_X18_ABI 0x10
202
203#define __DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK 0xff000000
204
205/* Return pc field of arm_thread_state64_t as a data pointer value */
206#define __darwin_arm_thread_state64_get_pc(ts) \
207 __extension__ ({ const _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
208 (uintptr_t)(__tsp->__opaque_pc && !(__tsp->__opaque_flags & \
209 __DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ? \
210 ptrauth_auth_data(__tsp->__opaque_pc, \
211 ptrauth_key_process_independent_code, \
212 ((__tsp->__opaque_flags & \
213 __DARWIN_ARM_THREAD_STATE64_FLAGS_KERNEL_SIGNED_PC) == 0 && \
214 (__tsp->__opaque_flags & \
215 __DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK)) ? \
216 ptrauth_blend_discriminator((void *)(unsigned long) \
217 (__tsp->__opaque_flags & \
218 __DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK), \
219 ptrauth_string_discriminator("pc")) : \
220 ptrauth_string_discriminator("pc")) : __tsp->__opaque_pc); })
221/* Return pc field of arm_thread_state64_t as a function pointer. May return
222 * NULL if a valid function pointer cannot be constructed, the caller should
223 * fall back to the __darwin_arm_thread_state64_get_pc() macro in that case. */
224#define __darwin_arm_thread_state64_get_pc_fptr(ts) \
225 __extension__ ({ const _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
226 (__tsp->__opaque_pc && !(__tsp->__opaque_flags & \
227 __DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ? \
228 ptrauth_auth_function(__tsp->__opaque_pc, \
229 ptrauth_key_process_independent_code, \
230 ((__tsp->__opaque_flags & \
231 __DARWIN_ARM_THREAD_STATE64_FLAGS_KERNEL_SIGNED_PC) == 0 && \
232 (__tsp->__opaque_flags & \
233 __DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK)) ? \
234 ptrauth_blend_discriminator((void *)(unsigned long) \
235 (__tsp->__opaque_flags & \
236 __DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK), \
237 ptrauth_string_discriminator("pc")) : \
238 ptrauth_string_discriminator("pc")) : NULL); })
239/* Set pc field of arm_thread_state64_t to a function pointer */
240#define __darwin_arm_thread_state64_set_pc_fptr(ts, fptr) \
241 __extension__ ({ _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
242 __typeof__(fptr) __f = (fptr); __tsp->__opaque_pc = \
243 (__f ? (!(__tsp->__opaque_flags & \
244 __DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ? \
245 ptrauth_auth_and_resign(__f, ptrauth_key_function_pointer, 0, \
246 ptrauth_key_process_independent_code, \
247 (__tsp->__opaque_flags & \
248 __DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK) ? \
249 ptrauth_blend_discriminator((void *)(unsigned long) \
250 (__tsp->__opaque_flags & \
251 __DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK), \
252 ptrauth_string_discriminator("pc")) : \
253 ptrauth_string_discriminator("pc")) : ptrauth_auth_data(__f, \
254 ptrauth_key_function_pointer, 0)) : __f); \
255 __tsp->__opaque_flags &= \
256 ~__DARWIN_ARM_THREAD_STATE64_FLAGS_KERNEL_SIGNED_PC; })
257/* Set pc field of arm_thread_state64_t to an already signed function pointer */
258#define __darwin_arm_thread_state64_set_pc_presigned_fptr(ts, presigned_fptr) \
259 __extension__ ({ _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
260 __typeof__(presigned_fptr) __f = (presigned_fptr); __tsp->__opaque_pc = __f; \
261 __tsp->__opaque_flags &= \
262 ~__DARWIN_ARM_THREAD_STATE64_FLAGS_KERNEL_SIGNED_PC; })
263/* Return lr field of arm_thread_state64_t as a data pointer value */
264#define __darwin_arm_thread_state64_get_lr(ts) \
265 __extension__ ({ const _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
266 (uintptr_t)(__tsp->__opaque_lr && !(__tsp->__opaque_flags & ( \
267 __DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH | \
268 __DARWIN_ARM_THREAD_STATE64_FLAGS_IB_SIGNED_LR)) ? \
269 ptrauth_auth_data(__tsp->__opaque_lr, \
270 ptrauth_key_process_independent_code, \
271 ((__tsp->__opaque_flags & \
272 __DARWIN_ARM_THREAD_STATE64_FLAGS_KERNEL_SIGNED_LR) == 0 && \
273 (__tsp->__opaque_flags & \
274 __DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK)) ? \
275 ptrauth_blend_discriminator((void *)(unsigned long) \
276 (__tsp->__opaque_flags & \
277 __DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK), \
278 ptrauth_string_discriminator("lr")) : \
279 ptrauth_string_discriminator("lr")) : __tsp->__opaque_lr); })
280/* Return lr field of arm_thread_state64_t as a function pointer. May return
281 * NULL if a valid function pointer cannot be constructed, the caller should
282 * fall back to the __darwin_arm_thread_state64_get_lr() macro in that case. */
283#define __darwin_arm_thread_state64_get_lr_fptr(ts) \
284 __extension__ ({ const _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
285 (__tsp->__opaque_lr && !(__tsp->__opaque_flags & ( \
286 __DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH | \
287 __DARWIN_ARM_THREAD_STATE64_FLAGS_IB_SIGNED_LR)) ? \
288 ptrauth_auth_function(__tsp->__opaque_lr, \
289 ptrauth_key_process_independent_code, \
290 ((__tsp->__opaque_flags & \
291 __DARWIN_ARM_THREAD_STATE64_FLAGS_KERNEL_SIGNED_LR) == 0 && \
292 (__tsp->__opaque_flags & \
293 __DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK)) ? \
294 ptrauth_blend_discriminator((void *)(unsigned long) \
295 (__tsp->__opaque_flags & \
296 __DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK), \
297 ptrauth_string_discriminator("lr")) : \
298 ptrauth_string_discriminator("lr")) : NULL); })
299/* Set lr field of arm_thread_state64_t to a function pointer */
300#define __darwin_arm_thread_state64_set_lr_fptr(ts, fptr) \
301 __extension__ ({ _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
302 __typeof__(fptr) __f = (fptr); __tsp->__opaque_lr = \
303 (__f ? (!(__tsp->__opaque_flags & \
304 __DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ? (__tsp->__opaque_flags \
305 &= ~__DARWIN_ARM_THREAD_STATE64_FLAGS_IB_SIGNED_LR , \
306 ptrauth_auth_and_resign(__f, ptrauth_key_function_pointer, 0, \
307 ptrauth_key_process_independent_code, \
308 (__tsp->__opaque_flags & \
309 __DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK) ? \
310 ptrauth_blend_discriminator((void *)(unsigned long) \
311 (__tsp->__opaque_flags & \
312 __DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK), \
313 ptrauth_string_discriminator("lr")) : \
314 ptrauth_string_discriminator("lr"))) : ptrauth_auth_data(__f, \
315 ptrauth_key_function_pointer, 0)) : __f); __tsp->__opaque_flags &= \
316 ~__DARWIN_ARM_THREAD_STATE64_FLAGS_KERNEL_SIGNED_LR; })
317/* Set lr field of arm_thread_state64_t to an already signed function pointer */
318#define __darwin_arm_thread_state64_set_lr_presigned_fptr(ts, presigned_fptr) \
319 __extension__ ({ _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
320 __typeof__(presigned_fptr) __f = (presigned_fptr); __tsp->__opaque_lr = __f; \
321 __tsp->__opaque_flags &= \
322 ~__DARWIN_ARM_THREAD_STATE64_FLAGS_KERNEL_SIGNED_LR & ~__DARWIN_ARM_THREAD_STATE64_FLAGS_IB_SIGNED_LR; })
323/* Return sp field of arm_thread_state64_t as a data pointer value */
324#define __darwin_arm_thread_state64_get_sp(ts) \
325 __extension__ ({ const _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
326 (uintptr_t)(__tsp->__opaque_sp && !(__tsp->__opaque_flags & \
327 __DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ? \
328 ptrauth_auth_data(__tsp->__opaque_sp, \
329 ptrauth_key_process_independent_data, \
330 ptrauth_string_discriminator("sp")) : __tsp->__opaque_sp); })
331/* Set sp field of arm_thread_state64_t to a data pointer value */
332#define __darwin_arm_thread_state64_set_sp(ts, ptr) \
333 __extension__ ({ _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
334 void *__p = (void*)(uintptr_t)(ptr); __tsp->__opaque_sp = \
335 (__p && !(__tsp->__opaque_flags & \
336 __DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ? \
337 ptrauth_sign_unauthenticated(__p, \
338 ptrauth_key_process_independent_data, \
339 ptrauth_string_discriminator("sp")) : __p); })
340/* Return fp field of arm_thread_state64_t as a data pointer value */
341#define __darwin_arm_thread_state64_get_fp(ts) \
342 __extension__ ({ const _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
343 (uintptr_t)(__tsp->__opaque_fp && !(__tsp->__opaque_flags & \
344 __DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ? \
345 ptrauth_auth_data(__tsp->__opaque_fp, \
346 ptrauth_key_process_independent_data, \
347 ptrauth_string_discriminator("fp")) : __tsp->__opaque_fp); })
348/* Set fp field of arm_thread_state64_t to a data pointer value */
349#define __darwin_arm_thread_state64_set_fp(ts, ptr) \
350 __extension__ ({ _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
351 void *__p = (void*)(uintptr_t)(ptr); __tsp->__opaque_fp = \
352 (__p && !(__tsp->__opaque_flags & \
353 __DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ? \
354 ptrauth_sign_unauthenticated(__p, \
355 ptrauth_key_process_independent_data, \
356 ptrauth_string_discriminator("fp")) : __p); })
357
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 __extension__ ({ _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
361 __tsp->__opaque_pc = ((__tsp->__opaque_flags & \
362 __DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ? __tsp->__opaque_pc : \
363 ptrauth_strip(__tsp->__opaque_pc, ptrauth_key_process_independent_code)); \
364 __tsp->__opaque_lr = ((__tsp->__opaque_flags & \
365 (__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH | \
366 __DARWIN_ARM_THREAD_STATE64_FLAGS_IB_SIGNED_LR)) ? __tsp->__opaque_lr : \
367 ptrauth_strip(__tsp->__opaque_lr, ptrauth_key_process_independent_code)); \
368 __tsp->__opaque_sp = ((__tsp->__opaque_flags & \
369 __DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ? __tsp->__opaque_sp : \
370 ptrauth_strip(__tsp->__opaque_sp, ptrauth_key_process_independent_data)); \
371 __tsp->__opaque_fp = ((__tsp->__opaque_flags & \
372 __DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ? __tsp->__opaque_fp : \
373 ptrauth_strip(__tsp->__opaque_fp, ptrauth_key_process_independent_data)); \
374 __tsp->__opaque_flags |= \
375 __DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH; __tsp->__opaque_flags &= \
376 ~(__DARWIN_ARM_THREAD_STATE64_FLAGS_KERNEL_SIGNED_PC | \
377 __DARWIN_ARM_THREAD_STATE64_FLAGS_KERNEL_SIGNED_LR); })
378
379#else /* __has_feature(ptrauth_calls) && defined(__LP64__) */
380
381#if __DARWIN_OPAQUE_ARM_THREAD_STATE64
382
383#ifndef __LP64__
384#error "Invalid configuration"
385#endif
386
387/* Return pc field of arm_thread_state64_t as a data pointer value */
388#define __darwin_arm_thread_state64_get_pc(ts) \
389 ((uintptr_t)((ts).__opaque_pc))
390/* Return pc field of arm_thread_state64_t as a function pointer */
391#define __darwin_arm_thread_state64_get_pc_fptr(ts) \
392 ((ts).__opaque_pc)
393/* Set pc field of arm_thread_state64_t to a function pointer */
394#define __darwin_arm_thread_state64_set_pc_fptr(ts, fptr) \
395 ((ts).__opaque_pc = (fptr))
396/* Set pc field of arm_thread_state64_t to an already signed function pointer */
397#define __darwin_arm_thread_state64_set_pc_presigned_fptr(ts, presigned_fptr) \
398 ((ts).__opaque_pc = (presigned_fptr))
399/* Return lr field of arm_thread_state64_t as a data pointer value */
400#define __darwin_arm_thread_state64_get_lr(ts) \
401 ((uintptr_t)((ts).__opaque_lr))
402/* Return lr field of arm_thread_state64_t as a function pointer */
403#define __darwin_arm_thread_state64_get_lr_fptr(ts) \
404 ((ts).__opaque_lr)
405/* Set lr field of arm_thread_state64_t to a function pointer */
406#define __darwin_arm_thread_state64_set_lr_fptr(ts, fptr) \
407 ((ts).__opaque_lr = (fptr))
408/* Set lr field of arm_thread_state64_t to a presigned function pointer */
409#define __darwin_arm_thread_state64_set_lr_presigned_fptr(ts, presigned_fptr) \
410 ((ts).__opaque_lr = (presigned_fptr))
411/* Return sp field of arm_thread_state64_t as a data pointer value */
412#define __darwin_arm_thread_state64_get_sp(ts) \
413 ((uintptr_t)((ts).__opaque_sp))
414/* Set sp field of arm_thread_state64_t to a data pointer value */
415#define __darwin_arm_thread_state64_set_sp(ts, ptr) \
416 ((ts).__opaque_sp = (void*)(uintptr_t)(ptr))
417/* Return fp field of arm_thread_state64_t as a data pointer value */
418#define __darwin_arm_thread_state64_get_fp(ts) \
419 ((uintptr_t)((ts).__opaque_fp))
420/* Set fp field of arm_thread_state64_t to a data pointer value */
421#define __darwin_arm_thread_state64_set_fp(ts, ptr) \
422 ((ts).__opaque_fp = (void*)(uintptr_t)(ptr))
423/* Strip ptr auth bits from pc, lr, sp and fp field of arm_thread_state64_t */
424#define __darwin_arm_thread_state64_ptrauth_strip(ts) \
425 (void)(ts)
426
427#else /* __DARWIN_OPAQUE_ARM_THREAD_STATE64 */
428#if __DARWIN_UNIX03
429
430/* Return pc field of arm_thread_state64_t as a data pointer value */
431#define __darwin_arm_thread_state64_get_pc(ts) \
432 ((ts).__pc)
433/* Return pc field of arm_thread_state64_t as a function pointer */
434#define __darwin_arm_thread_state64_get_pc_fptr(ts) \
435 ((void*)(uintptr_t)((ts).__pc))
436/* Set pc field of arm_thread_state64_t to a function pointer */
437#define __darwin_arm_thread_state64_set_pc_fptr(ts, fptr) \
438 ((ts).__pc = (uintptr_t)(fptr))
439/* Set pc field of arm_thread_state64_t to an already signed function pointer */
440#define __darwin_arm_thread_state64_set_pc_presigned_fptr(ts, presigned_fptr) \
441 ((ts).__pc = (uintptr_t)(presigned_fptr))
442/* Return lr field of arm_thread_state64_t as a data pointer value */
443#define __darwin_arm_thread_state64_get_lr(ts) \
444 ((ts).__lr)
445/* Return lr field of arm_thread_state64_t as a function pointer */
446#define __darwin_arm_thread_state64_get_lr_fptr(ts) \
447 ((void*)(uintptr_t)((ts).__lr))
448/* Set lr field of arm_thread_state64_t to a function pointer */
449#define __darwin_arm_thread_state64_set_lr_fptr(ts, fptr) \
450 ((ts).__lr = (uintptr_t)(fptr))
451/* Set lr field of arm_thread_state64_t to a presigned function pointer */
452#define __darwin_arm_thread_state64_set_lr_presigned_fptr(ts, presigned_fptr) \
453 ((ts).__lr = ((uintptr_t)presigned_fptr))
454/* Return sp field of arm_thread_state64_t as a data pointer value */
455#define __darwin_arm_thread_state64_get_sp(ts) \
456 ((ts).__sp)
457/* Set sp field of arm_thread_state64_t to a data pointer value */
458#define __darwin_arm_thread_state64_set_sp(ts, ptr) \
459 ((ts).__sp = (uintptr_t)(ptr))
460/* Return fp field of arm_thread_state64_t as a data pointer value */
461#define __darwin_arm_thread_state64_get_fp(ts) \
462 ((ts).__fp)
463/* Set fp field of arm_thread_state64_t to a data pointer value */
464#define __darwin_arm_thread_state64_set_fp(ts, ptr) \
465 ((ts).__fp = (uintptr_t)(ptr))
466/* Strip ptr auth bits from pc, lr, sp and fp field of arm_thread_state64_t */
467#define __darwin_arm_thread_state64_ptrauth_strip(ts) \
468 (void)(ts)
469
470#else /* __DARWIN_UNIX03 */
471
472/* Return pc field of arm_thread_state64_t as a data pointer value */
473#define __darwin_arm_thread_state64_get_pc(ts) \
474 ((ts).pc)
475/* Return pc field of arm_thread_state64_t as a function pointer */
476#define __darwin_arm_thread_state64_get_pc_fptr(ts) \
477 ((void*)(uintptr_t)((ts).pc))
478/* Set pc field of arm_thread_state64_t to a function pointer */
479#define __darwin_arm_thread_state64_set_pc_fptr(ts, fptr) \
480 ((ts).pc = (uintptr_t)(fptr))
481/* Set pc field of arm_thread_state64_t to an already signed function pointer */
482#define __darwin_arm_thread_state64_set_pc_presigned_fptr(ts, presigned_fptr) \
483 ((ts).pc = (uintptr_t)(presigned_fptr))
484/* Return lr field of arm_thread_state64_t as a data pointer value */
485#define __darwin_arm_thread_state64_get_lr(ts) \
486 ((ts).lr)
487/* Return lr field of arm_thread_state64_t as a function pointer */
488#define __darwin_arm_thread_state64_get_lr_fptr(ts) \
489 ((void*)(uintptr_t)((ts).lr))
490/* Set lr field of arm_thread_state64_t to a function pointer */
491#define __darwin_arm_thread_state64_set_lr_fptr(ts, fptr) \
492 ((ts).lr = (uintptr_t)(fptr))
493/* Set lr field of arm_thread_state64_t to a presigned function pointer */
494#define __darwin_arm_thread_state64_set_lr_presigned_fptr(ts, presigned_fptr) \
495 ((ts).lr = ((uintptr_t)presigned_fptr))
496/* Return sp field of arm_thread_state64_t as a data pointer value */
497#define __darwin_arm_thread_state64_get_sp(ts) \
498 ((ts).sp)
499/* Set sp field of arm_thread_state64_t to a data pointer value */
500#define __darwin_arm_thread_state64_set_sp(ts, ptr) \
501 ((ts).sp = (uintptr_t)(ptr))
502/* Return fp field of arm_thread_state64_t as a data pointer value */
503#define __darwin_arm_thread_state64_get_fp(ts) \
504 ((ts).fp)
505/* Set fp field of arm_thread_state64_t to a data pointer value */
506#define __darwin_arm_thread_state64_set_fp(ts, ptr) \
507 ((ts).fp = (uintptr_t)(ptr))
508/* Strip ptr auth bits from pc, lr, sp and fp field of arm_thread_state64_t */
509#define __darwin_arm_thread_state64_ptrauth_strip(ts) \
510 (void)(ts)
511
512#endif /* __DARWIN_UNIX03 */
513#endif /* __DARWIN_OPAQUE_ARM_THREAD_STATE64 */
514
515#endif /* __has_feature(ptrauth_calls) && defined(__LP64__) */
516#endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL && defined(__arm64__) */
517
518#if __DARWIN_UNIX03
519#define _STRUCT_ARM_VFP_STATE struct __darwin_arm_vfp_state
520_STRUCT_ARM_VFP_STATE
521{
522 __uint32_t __r[64];
523 __uint32_t __fpscr;
524};
525#else /* !__DARWIN_UNIX03 */
526#define _STRUCT_ARM_VFP_STATE struct arm_vfp_state
527_STRUCT_ARM_VFP_STATE
528{
529 __uint32_t r[64];
530 __uint32_t fpscr;
531};
532#endif /* __DARWIN_UNIX03 */
533
534#if __DARWIN_UNIX03
535#define _STRUCT_ARM_NEON_STATE64 struct __darwin_arm_neon_state64
536#define _STRUCT_ARM_NEON_STATE struct __darwin_arm_neon_state
537
538#if defined(__arm64__)
539_STRUCT_ARM_NEON_STATE64
540{
541 __uint128_t __v[32];
542 __uint32_t __fpsr;
543 __uint32_t __fpcr;
544};
545
546_STRUCT_ARM_NEON_STATE
547{
548 __uint128_t __v[16];
549 __uint32_t __fpsr;
550 __uint32_t __fpcr;
551};
552#elif defined(__arm__)
553/*
554 * No 128-bit intrinsic for ARM; leave it opaque for now.
555 */
556_STRUCT_ARM_NEON_STATE64
557{
558 char opaque[(32 * 16) + (2 * sizeof(__uint32_t))];
559} __attribute__((aligned(16)));
560
561_STRUCT_ARM_NEON_STATE
562{
563 char opaque[(16 * 16) + (2 * sizeof(__uint32_t))];
564} __attribute__((aligned(16)));
565
566#else
567#error Unknown architecture.
568#endif
569
570#else /* !__DARWIN_UNIX03 */
571#define _STRUCT_ARM_NEON_STATE64 struct arm_neon_state64
572#define _STRUCT_ARM_NEON_STATE struct arm_neon_state
573
574#if defined(__arm64__)
575_STRUCT_ARM_NEON_STATE64
576{
577 __uint128_t q[32];
578 uint32_t fpsr;
579 uint32_t fpcr;
580};
581
582_STRUCT_ARM_NEON_STATE
583{
584 __uint128_t q[16];
585 uint32_t fpsr;
586 uint32_t fpcr;
587};
588#elif defined(__arm__)
589/*
590 * No 128-bit intrinsic for ARM; leave it opaque for now.
591 */
592_STRUCT_ARM_NEON_STATE64
593{
594 char opaque[(32 * 16) + (2 * sizeof(__uint32_t))];
595} __attribute__((aligned(16)));
596
597_STRUCT_ARM_NEON_STATE
598{
599 char opaque[(16 * 16) + (2 * sizeof(__uint32_t))];
600} __attribute__((aligned(16)));
601
602#else
603#error Unknown architecture.
604#endif
605
606#endif /* __DARWIN_UNIX03 */
607
608
609#define _STRUCT_ARM_PAGEIN_STATE struct __arm_pagein_state
610_STRUCT_ARM_PAGEIN_STATE
611{
612 int __pagein_error;
613};
614
615#if __DARWIN_UNIX03
616#define _STRUCT_ARM_SME_STATE struct __darwin_arm_sme_state
617_STRUCT_ARM_SME_STATE
618{
619 __uint64_t __svcr;
620 __uint64_t __tpidr2_el0;
621 __uint16_t __svl_b;
622};
623
624#define _STRUCT_ARM_SVE_Z_STATE struct __darwin_arm_sve_z_state
625_STRUCT_ARM_SVE_Z_STATE
626{
627 char __z[16][256];
628} __attribute__((aligned(4)));
629
630#define _STRUCT_ARM_SVE_P_STATE struct __darwin_arm_sve_p_state
631_STRUCT_ARM_SVE_P_STATE
632{
633 char __p[16][256 / 8];
634} __attribute__((aligned(4)));
635
636#define _STRUCT_ARM_SME_ZA_STATE struct __darwin_arm_sme_za_state
637_STRUCT_ARM_SME_ZA_STATE
638{
639 char __za[4096];
640} __attribute__((aligned(4)));
641
642#define _STRUCT_ARM_SME2_STATE struct __darwin_arm_sme2_state
643_STRUCT_ARM_SME2_STATE
644{
645 char __zt0[64];
646} __attribute__((aligned(4)));
647#else /* !__DARWIN_UNIX03 */
648#define _STRUCT_ARM_SME_STATE struct arm_sme_state
649_STRUCT_ARM_SME_STATE
650{
651 __uint64_t svcr;
652 __uint64_t tpidr2_el0;
653 __uint16_t svl_b;
654};
655
656#define _STRUCT_ARM_SVE_Z_STATE struct arm_sve_z_state
657_STRUCT_ARM_SVE_Z_STATE
658{
659 char z[16][256];
660} __attribute__((aligned(4)));
661
662#define _STRUCT_ARM_SVE_P_STATE struct arm_sve_p_state
663_STRUCT_ARM_SVE_P_STATE
664{
665 char p[16][256 / 8];
666} __attribute__((aligned(4)));
667
668#define _STRUCT_ARM_SME_ZA_STATE struct arm_sme_za_state
669_STRUCT_ARM_SME_ZA_STATE
670{
671 char za[4096];
672} __attribute__((aligned(4)));
673
674#define _STRUCT_ARM_SME2_STATE struct arm_sme2_state
675_STRUCT_ARM_SME2_STATE
676{
677 char zt0[64];
678} __attribute__((aligned(4)));
679#endif /* __DARWIN_UNIX03 */
680
681/*
682 * Debug State
683 */
684#if defined(__arm__)
685/* Old-fashioned debug state is only for ARM */
686
687#if __DARWIN_UNIX03
688#define _STRUCT_ARM_DEBUG_STATE struct __darwin_arm_debug_state
689_STRUCT_ARM_DEBUG_STATE
690{
691 __uint32_t __bvr[16];
692 __uint32_t __bcr[16];
693 __uint32_t __wvr[16];
694 __uint32_t __wcr[16];
695};
696#else /* !__DARWIN_UNIX03 */
697#define _STRUCT_ARM_DEBUG_STATE struct arm_debug_state
698_STRUCT_ARM_DEBUG_STATE
699{
700 __uint32_t bvr[16];
701 __uint32_t bcr[16];
702 __uint32_t wvr[16];
703 __uint32_t wcr[16];
704};
705#endif /* __DARWIN_UNIX03 */
706
707#elif defined(__arm64__)
708
709/* ARM's arm_debug_state is ARM64's arm_legacy_debug_state */
710
711#if __DARWIN_UNIX03
712#define _STRUCT_ARM_LEGACY_DEBUG_STATE struct __arm_legacy_debug_state
713_STRUCT_ARM_LEGACY_DEBUG_STATE
714{
715 __uint32_t __bvr[16];
716 __uint32_t __bcr[16];
717 __uint32_t __wvr[16];
718 __uint32_t __wcr[16];
719};
720#else /* __DARWIN_UNIX03 */
721#define _STRUCT_ARM_LEGACY_DEBUG_STATE struct arm_legacy_debug_state
722_STRUCT_ARM_LEGACY_DEBUG_STATE
723{
724 __uint32_t bvr[16];
725 __uint32_t bcr[16];
726 __uint32_t wvr[16];
727 __uint32_t wcr[16];
728};
729#endif /* __DARWIN_UNIX03 */
730#else
731#error unknown architecture
732#endif
733
734#if __DARWIN_UNIX03
735#define _STRUCT_ARM_DEBUG_STATE32 struct __darwin_arm_debug_state32
736_STRUCT_ARM_DEBUG_STATE32
737{
738 __uint32_t __bvr[16];
739 __uint32_t __bcr[16];
740 __uint32_t __wvr[16];
741 __uint32_t __wcr[16];
742 __uint64_t __mdscr_el1; /* Bit 0 is SS (Hardware Single Step) */
743};
744
745#define _STRUCT_ARM_DEBUG_STATE64 struct __darwin_arm_debug_state64
746_STRUCT_ARM_DEBUG_STATE64
747{
748 __uint64_t __bvr[16];
749 __uint64_t __bcr[16];
750 __uint64_t __wvr[16];
751 __uint64_t __wcr[16];
752 __uint64_t __mdscr_el1; /* Bit 0 is SS (Hardware Single Step) */
753};
754#else /* !__DARWIN_UNIX03 */
755#define _STRUCT_ARM_DEBUG_STATE32 struct arm_debug_state32
756_STRUCT_ARM_DEBUG_STATE32
757{
758 __uint32_t bvr[16];
759 __uint32_t bcr[16];
760 __uint32_t wvr[16];
761 __uint32_t wcr[16];
762 __uint64_t mdscr_el1; /* Bit 0 is SS (Hardware Single Step) */
763};
764
765#define _STRUCT_ARM_DEBUG_STATE64 struct arm_debug_state64
766_STRUCT_ARM_DEBUG_STATE64
767{
768 __uint64_t bvr[16];
769 __uint64_t bcr[16];
770 __uint64_t wvr[16];
771 __uint64_t wcr[16];
772 __uint64_t mdscr_el1; /* Bit 0 is SS (Hardware Single Step) */
773};
774#endif /* __DARWIN_UNIX03 */
775
776#if __DARWIN_UNIX03
777#define _STRUCT_ARM_CPMU_STATE64 struct __darwin_arm_cpmu_state64
778_STRUCT_ARM_CPMU_STATE64
779{
780 __uint64_t __ctrs[16];
781};
782#else /* __DARWIN_UNIX03 */
783#define _STRUCT_ARM_CPMU_STATE64 struct arm_cpmu_state64
784_STRUCT_ARM_CPMU_STATE64
785{
786 __uint64_t ctrs[16];
787};
788#endif /* !__DARWIN_UNIX03 */
789
790#endif /* defined (__arm__) || defined (__arm64__) */
791
792#endif /* _MACH_ARM__STRUCTS_H_ */