zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

_structs.h (32029B) - Raw


      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 
    202 #define __DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK 0xff000000
    203 
    204 /* Return pc field of arm_thread_state64_t as a data pointer value */
    205 #define __darwin_arm_thread_state64_get_pc(ts) \
    206 	__extension__ ({ const _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
    207 	(uintptr_t)(__tsp->__opaque_pc && !(__tsp->__opaque_flags &       \
    208 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ?                   \
    209 	ptrauth_auth_data(__tsp->__opaque_pc,                             \
    210 	ptrauth_key_process_independent_code,                             \
    211 	((__tsp->__opaque_flags &                                         \
    212 	__DARWIN_ARM_THREAD_STATE64_FLAGS_KERNEL_SIGNED_PC) == 0 &&       \
    213 	(__tsp->__opaque_flags &                                          \
    214 	__DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK)) ?             \
    215 	ptrauth_blend_discriminator((void *)(unsigned long)               \
    216 	(__tsp->__opaque_flags &                                          \
    217 	__DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK),               \
    218 	ptrauth_string_discriminator("pc")) :                             \
    219 	ptrauth_string_discriminator("pc")) : __tsp->__opaque_pc); })
    220 /* Return pc field of arm_thread_state64_t as a function pointer. May return
    221  * NULL if a valid function pointer cannot be constructed, the caller should
    222  * fall back to the __darwin_arm_thread_state64_get_pc() macro in that case. */
    223 #define __darwin_arm_thread_state64_get_pc_fptr(ts) \
    224 	__extension__ ({ const _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
    225 	(__tsp->__opaque_pc && !(__tsp->__opaque_flags &                  \
    226 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ?                   \
    227 	ptrauth_auth_function(__tsp->__opaque_pc,                         \
    228 	ptrauth_key_process_independent_code,                             \
    229 	((__tsp->__opaque_flags &                                         \
    230 	__DARWIN_ARM_THREAD_STATE64_FLAGS_KERNEL_SIGNED_PC) == 0 &&       \
    231 	(__tsp->__opaque_flags &                                          \
    232 	__DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK)) ?             \
    233 	ptrauth_blend_discriminator((void *)(unsigned long)               \
    234 	(__tsp->__opaque_flags &                                          \
    235 	__DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK),               \
    236 	ptrauth_string_discriminator("pc")) :                             \
    237 	ptrauth_string_discriminator("pc")) : NULL); })
    238 /* Set pc field of arm_thread_state64_t to a function pointer */
    239 #define __darwin_arm_thread_state64_set_pc_fptr(ts, fptr) \
    240 	__extension__ ({ _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts);   \
    241 	__typeof__(fptr) __f = (fptr); __tsp->__opaque_pc =           \
    242 	(__f ? (!(__tsp->__opaque_flags &                             \
    243 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ?               \
    244 	ptrauth_auth_and_resign(__f, ptrauth_key_function_pointer, 0, \
    245 	ptrauth_key_process_independent_code,                         \
    246 	(__tsp->__opaque_flags &                                      \
    247 	__DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK) ?          \
    248 	ptrauth_blend_discriminator((void *)(unsigned long)           \
    249 	(__tsp->__opaque_flags &                                      \
    250 	__DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK),           \
    251 	ptrauth_string_discriminator("pc")) :                         \
    252 	ptrauth_string_discriminator("pc")) : ptrauth_auth_data(__f,  \
    253 	ptrauth_key_function_pointer, 0)) : __f);                     \
    254 	__tsp->__opaque_flags &=                                      \
    255 	~__DARWIN_ARM_THREAD_STATE64_FLAGS_KERNEL_SIGNED_PC; })
    256 /* Set pc field of arm_thread_state64_t to an already signed function pointer */
    257 #define __darwin_arm_thread_state64_set_pc_presigned_fptr(ts, presigned_fptr)           \
    258 	__extension__ ({ _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts);                                     \
    259 	__typeof__(presigned_fptr) __f = (presigned_fptr); __tsp->__opaque_pc = __f;    \
    260 	__tsp->__opaque_flags &=                                                                        \
    261 	~__DARWIN_ARM_THREAD_STATE64_FLAGS_KERNEL_SIGNED_PC; })
    262 /* Return lr field of arm_thread_state64_t as a data pointer value */
    263 #define __darwin_arm_thread_state64_get_lr(ts) \
    264 	__extension__ ({ const _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
    265 	(uintptr_t)(__tsp->__opaque_lr && !(__tsp->__opaque_flags & (     \
    266 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH |                    \
    267 	__DARWIN_ARM_THREAD_STATE64_FLAGS_IB_SIGNED_LR)) ?                \
    268 	ptrauth_auth_data(__tsp->__opaque_lr,                             \
    269 	ptrauth_key_process_independent_code,                             \
    270 	((__tsp->__opaque_flags &                                         \
    271 	__DARWIN_ARM_THREAD_STATE64_FLAGS_KERNEL_SIGNED_LR) == 0 &&       \
    272 	(__tsp->__opaque_flags &                                          \
    273 	__DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK)) ?             \
    274 	ptrauth_blend_discriminator((void *)(unsigned long)               \
    275 	(__tsp->__opaque_flags &                                          \
    276 	__DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK),               \
    277 	ptrauth_string_discriminator("lr")) :                             \
    278 	ptrauth_string_discriminator("lr")) : __tsp->__opaque_lr); })
    279 /* Return lr field of arm_thread_state64_t as a function pointer. May return
    280  * NULL if a valid function pointer cannot be constructed, the caller should
    281  * fall back to the __darwin_arm_thread_state64_get_lr() macro in that case. */
    282 #define __darwin_arm_thread_state64_get_lr_fptr(ts) \
    283 	__extension__ ({ const _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
    284 	(__tsp->__opaque_lr && !(__tsp->__opaque_flags & (                \
    285 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH |                    \
    286 	__DARWIN_ARM_THREAD_STATE64_FLAGS_IB_SIGNED_LR)) ?                \
    287 	ptrauth_auth_function(__tsp->__opaque_lr,                         \
    288 	ptrauth_key_process_independent_code,                             \
    289 	((__tsp->__opaque_flags &                                         \
    290 	__DARWIN_ARM_THREAD_STATE64_FLAGS_KERNEL_SIGNED_LR) == 0 &&       \
    291 	(__tsp->__opaque_flags &                                          \
    292 	__DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK)) ?             \
    293 	ptrauth_blend_discriminator((void *)(unsigned long)               \
    294 	(__tsp->__opaque_flags &                                          \
    295 	__DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK),               \
    296 	ptrauth_string_discriminator("lr")) :                             \
    297 	ptrauth_string_discriminator("lr")) : NULL); })
    298 /* Set lr field of arm_thread_state64_t to a function pointer */
    299 #define __darwin_arm_thread_state64_set_lr_fptr(ts, fptr) \
    300 	__extension__ ({ _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts);            \
    301 	__typeof__(fptr) __f = (fptr); __tsp->__opaque_lr =                    \
    302 	(__f ? (!(__tsp->__opaque_flags &                                      \
    303 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ? (__tsp->__opaque_flags \
    304 	&= ~__DARWIN_ARM_THREAD_STATE64_FLAGS_IB_SIGNED_LR ,                   \
    305 	ptrauth_auth_and_resign(__f, ptrauth_key_function_pointer, 0,          \
    306 	ptrauth_key_process_independent_code,                                  \
    307 	(__tsp->__opaque_flags &                                               \
    308 	__DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK) ?                   \
    309 	ptrauth_blend_discriminator((void *)(unsigned long)                    \
    310 	(__tsp->__opaque_flags &                                               \
    311 	__DARWIN_ARM_THREAD_STATE64_USER_DIVERSIFIER_MASK),                    \
    312 	ptrauth_string_discriminator("lr")) :                                  \
    313 	ptrauth_string_discriminator("lr"))) : ptrauth_auth_data(__f,          \
    314 	ptrauth_key_function_pointer, 0)) : __f); __tsp->__opaque_flags &=     \
    315 	~__DARWIN_ARM_THREAD_STATE64_FLAGS_KERNEL_SIGNED_LR; })
    316 /* Set lr field of arm_thread_state64_t to an already signed function pointer */
    317 #define __darwin_arm_thread_state64_set_lr_presigned_fptr(ts, presigned_fptr)           \
    318 	__extension__ ({ _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts);                                     \
    319 	__typeof__(presigned_fptr) __f = (presigned_fptr); __tsp->__opaque_lr = __f;    \
    320 	__tsp->__opaque_flags &=                                                                        \
    321 	~__DARWIN_ARM_THREAD_STATE64_FLAGS_KERNEL_SIGNED_LR & ~__DARWIN_ARM_THREAD_STATE64_FLAGS_IB_SIGNED_LR; })
    322 /* Return sp field of arm_thread_state64_t as a data pointer value */
    323 #define __darwin_arm_thread_state64_get_sp(ts) \
    324 	__extension__ ({ const _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
    325 	(uintptr_t)(__tsp->__opaque_sp && !(__tsp->__opaque_flags &       \
    326 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ?                   \
    327 	ptrauth_auth_data(__tsp->__opaque_sp,                             \
    328 	ptrauth_key_process_independent_data,                             \
    329 	ptrauth_string_discriminator("sp")) : __tsp->__opaque_sp); })
    330 /* Set sp field of arm_thread_state64_t to a data pointer value */
    331 #define __darwin_arm_thread_state64_set_sp(ts, ptr) \
    332 	__extension__ ({ _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
    333 	void *__p = (void*)(uintptr_t)(ptr); __tsp->__opaque_sp =   \
    334 	(__p && !(__tsp->__opaque_flags &                           \
    335 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ?             \
    336 	ptrauth_sign_unauthenticated(__p,                           \
    337 	ptrauth_key_process_independent_data,                       \
    338 	ptrauth_string_discriminator("sp")) : __p); })
    339 /* Return fp field of arm_thread_state64_t as a data pointer value */
    340 #define __darwin_arm_thread_state64_get_fp(ts) \
    341 	__extension__ ({ const _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
    342 	(uintptr_t)(__tsp->__opaque_fp && !(__tsp->__opaque_flags &       \
    343 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ?                   \
    344 	ptrauth_auth_data(__tsp->__opaque_fp,                             \
    345 	ptrauth_key_process_independent_data,                             \
    346 	ptrauth_string_discriminator("fp")) : __tsp->__opaque_fp); })
    347 /* Set fp field of arm_thread_state64_t to a data pointer value */
    348 #define __darwin_arm_thread_state64_set_fp(ts, ptr) \
    349 	__extension__ ({ _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts); \
    350 	void *__p = (void*)(uintptr_t)(ptr); __tsp->__opaque_fp =   \
    351 	(__p && !(__tsp->__opaque_flags &                           \
    352 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ?             \
    353 	ptrauth_sign_unauthenticated(__p,                           \
    354 	ptrauth_key_process_independent_data,                       \
    355 	ptrauth_string_discriminator("fp")) : __p); })
    356 
    357 /* Strip ptr auth bits from pc, lr, sp and fp field of arm_thread_state64_t */
    358 #define __darwin_arm_thread_state64_ptrauth_strip(ts) \
    359 	__extension__ ({ _STRUCT_ARM_THREAD_STATE64 *__tsp = &(ts);               \
    360 	__tsp->__opaque_pc = ((__tsp->__opaque_flags &                            \
    361 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ? __tsp->__opaque_pc :      \
    362 	ptrauth_strip(__tsp->__opaque_pc, ptrauth_key_process_independent_code)); \
    363 	__tsp->__opaque_lr = ((__tsp->__opaque_flags &                            \
    364 	(__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH |                           \
    365 	__DARWIN_ARM_THREAD_STATE64_FLAGS_IB_SIGNED_LR)) ? __tsp->__opaque_lr :   \
    366 	ptrauth_strip(__tsp->__opaque_lr, ptrauth_key_process_independent_code)); \
    367 	__tsp->__opaque_sp = ((__tsp->__opaque_flags &                            \
    368 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ? __tsp->__opaque_sp :      \
    369 	ptrauth_strip(__tsp->__opaque_sp, ptrauth_key_process_independent_data)); \
    370 	__tsp->__opaque_fp = ((__tsp->__opaque_flags &                            \
    371 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH) ? __tsp->__opaque_fp :      \
    372 	ptrauth_strip(__tsp->__opaque_fp, ptrauth_key_process_independent_data)); \
    373 	__tsp->__opaque_flags |=                                                  \
    374 	__DARWIN_ARM_THREAD_STATE64_FLAGS_NO_PTRAUTH; __tsp->__opaque_flags &=    \
    375 	~(__DARWIN_ARM_THREAD_STATE64_FLAGS_KERNEL_SIGNED_PC |                    \
    376 	__DARWIN_ARM_THREAD_STATE64_FLAGS_KERNEL_SIGNED_LR); })
    377 
    378 #else /* __has_feature(ptrauth_calls) && defined(__LP64__) */
    379 
    380 #if __DARWIN_OPAQUE_ARM_THREAD_STATE64
    381 
    382 #ifndef __LP64__
    383 #error "Invalid configuration"
    384 #endif
    385 
    386 /* Return pc field of arm_thread_state64_t as a data pointer value */
    387 #define __darwin_arm_thread_state64_get_pc(ts) \
    388 	((uintptr_t)((ts).__opaque_pc))
    389 /* Return pc field of arm_thread_state64_t as a function pointer */
    390 #define __darwin_arm_thread_state64_get_pc_fptr(ts) \
    391 	((ts).__opaque_pc)
    392 /* Set pc field of arm_thread_state64_t to a function pointer */
    393 #define __darwin_arm_thread_state64_set_pc_fptr(ts, fptr) \
    394 	((ts).__opaque_pc = (fptr))
    395 /* Set pc field of arm_thread_state64_t to an already signed function pointer */
    396 #define __darwin_arm_thread_state64_set_pc_presigned_fptr(ts, presigned_fptr)           \
    397 	((ts).__opaque_pc = (presigned_fptr))
    398 /* Return lr field of arm_thread_state64_t as a data pointer value */
    399 #define __darwin_arm_thread_state64_get_lr(ts) \
    400 	((uintptr_t)((ts).__opaque_lr))
    401 /* Return lr field of arm_thread_state64_t as a function pointer */
    402 #define __darwin_arm_thread_state64_get_lr_fptr(ts) \
    403 	((ts).__opaque_lr)
    404 /* Set lr field of arm_thread_state64_t to a function pointer */
    405 #define __darwin_arm_thread_state64_set_lr_fptr(ts, fptr) \
    406 	((ts).__opaque_lr = (fptr))
    407 /* Set lr field of arm_thread_state64_t to a presigned function pointer */
    408 #define __darwin_arm_thread_state64_set_lr_presigned_fptr(ts, presigned_fptr) \
    409 	((ts).__opaque_lr = (presigned_fptr))
    410 /* Return sp field of arm_thread_state64_t as a data pointer value */
    411 #define __darwin_arm_thread_state64_get_sp(ts) \
    412 	((uintptr_t)((ts).__opaque_sp))
    413 /* Set sp field of arm_thread_state64_t to a data pointer value */
    414 #define __darwin_arm_thread_state64_set_sp(ts, ptr) \
    415 	((ts).__opaque_sp = (void*)(uintptr_t)(ptr))
    416 /* Return fp field of arm_thread_state64_t as a data pointer value */
    417 #define __darwin_arm_thread_state64_get_fp(ts) \
    418 	((uintptr_t)((ts).__opaque_fp))
    419 /* Set fp field of arm_thread_state64_t to a data pointer value */
    420 #define __darwin_arm_thread_state64_set_fp(ts, ptr) \
    421 	((ts).__opaque_fp = (void*)(uintptr_t)(ptr))
    422 /* Strip ptr auth bits from pc, lr, sp and fp field of arm_thread_state64_t */
    423 #define __darwin_arm_thread_state64_ptrauth_strip(ts) \
    424 	(void)(ts)
    425 
    426 #else /* __DARWIN_OPAQUE_ARM_THREAD_STATE64 */
    427 #if __DARWIN_UNIX03
    428 
    429 /* Return pc field of arm_thread_state64_t as a data pointer value */
    430 #define __darwin_arm_thread_state64_get_pc(ts) \
    431 	((ts).__pc)
    432 /* Return pc field of arm_thread_state64_t as a function pointer */
    433 #define __darwin_arm_thread_state64_get_pc_fptr(ts) \
    434 	((void*)(uintptr_t)((ts).__pc))
    435 /* Set pc field of arm_thread_state64_t to a function pointer */
    436 #define __darwin_arm_thread_state64_set_pc_fptr(ts, fptr) \
    437 	((ts).__pc = (uintptr_t)(fptr))
    438 /* Set pc field of arm_thread_state64_t to an already signed function pointer */
    439 #define __darwin_arm_thread_state64_set_pc_presigned_fptr(ts, presigned_fptr)           \
    440 	((ts).__pc = (uintptr_t)(presigned_fptr))
    441 /* Return lr field of arm_thread_state64_t as a data pointer value */
    442 #define __darwin_arm_thread_state64_get_lr(ts) \
    443 	((ts).__lr)
    444 /* Return lr field of arm_thread_state64_t as a function pointer */
    445 #define __darwin_arm_thread_state64_get_lr_fptr(ts) \
    446 	((void*)(uintptr_t)((ts).__lr))
    447 /* Set lr field of arm_thread_state64_t to a function pointer */
    448 #define __darwin_arm_thread_state64_set_lr_fptr(ts, fptr) \
    449 	((ts).__lr = (uintptr_t)(fptr))
    450 /* Set lr field of arm_thread_state64_t to a presigned function pointer */
    451 #define __darwin_arm_thread_state64_set_lr_presigned_fptr(ts, presigned_fptr) \
    452 	((ts).__lr = ((uintptr_t)presigned_fptr))
    453 /* Return sp field of arm_thread_state64_t as a data pointer value */
    454 #define __darwin_arm_thread_state64_get_sp(ts) \
    455 	((ts).__sp)
    456 /* Set sp field of arm_thread_state64_t to a data pointer value */
    457 #define __darwin_arm_thread_state64_set_sp(ts, ptr) \
    458 	((ts).__sp = (uintptr_t)(ptr))
    459 /* Return fp field of arm_thread_state64_t as a data pointer value */
    460 #define __darwin_arm_thread_state64_get_fp(ts) \
    461 	((ts).__fp)
    462 /* Set fp field of arm_thread_state64_t to a data pointer value */
    463 #define __darwin_arm_thread_state64_set_fp(ts, ptr) \
    464 	((ts).__fp = (uintptr_t)(ptr))
    465 /* Strip ptr auth bits from pc, lr, sp and fp field of arm_thread_state64_t */
    466 #define __darwin_arm_thread_state64_ptrauth_strip(ts) \
    467 	(void)(ts)
    468 
    469 #else /* __DARWIN_UNIX03 */
    470 
    471 /* Return pc field of arm_thread_state64_t as a data pointer value */
    472 #define __darwin_arm_thread_state64_get_pc(ts) \
    473 	((ts).pc)
    474 /* Return pc field of arm_thread_state64_t as a function pointer */
    475 #define __darwin_arm_thread_state64_get_pc_fptr(ts) \
    476 	((void*)(uintptr_t)((ts).pc))
    477 /* Set pc field of arm_thread_state64_t to a function pointer */
    478 #define __darwin_arm_thread_state64_set_pc_fptr(ts, fptr) \
    479 	((ts).pc = (uintptr_t)(fptr))
    480 /* Set pc field of arm_thread_state64_t to an already signed function pointer */
    481 #define __darwin_arm_thread_state64_set_pc_presigned_fptr(ts, presigned_fptr)           \
    482 	((ts).pc = (uintptr_t)(presigned_fptr))
    483 /* Return lr field of arm_thread_state64_t as a data pointer value */
    484 #define __darwin_arm_thread_state64_get_lr(ts) \
    485 	((ts).lr)
    486 /* Return lr field of arm_thread_state64_t as a function pointer */
    487 #define __darwin_arm_thread_state64_get_lr_fptr(ts) \
    488 	((void*)(uintptr_t)((ts).lr))
    489 /* Set lr field of arm_thread_state64_t to a function pointer */
    490 #define __darwin_arm_thread_state64_set_lr_fptr(ts, fptr) \
    491 	((ts).lr = (uintptr_t)(fptr))
    492 /* Set lr field of arm_thread_state64_t to a presigned function pointer */
    493 #define __darwin_arm_thread_state64_set_lr_presigned_fptr(ts, presigned_fptr) \
    494 	((ts).lr = ((uintptr_t)presigned_fptr))
    495 /* Return sp field of arm_thread_state64_t as a data pointer value */
    496 #define __darwin_arm_thread_state64_get_sp(ts) \
    497 	((ts).sp)
    498 /* Set sp field of arm_thread_state64_t to a data pointer value */
    499 #define __darwin_arm_thread_state64_set_sp(ts, ptr) \
    500 	((ts).sp = (uintptr_t)(ptr))
    501 /* Return fp field of arm_thread_state64_t as a data pointer value */
    502 #define __darwin_arm_thread_state64_get_fp(ts) \
    503 	((ts).fp)
    504 /* Set fp field of arm_thread_state64_t to a data pointer value */
    505 #define __darwin_arm_thread_state64_set_fp(ts, ptr) \
    506 	((ts).fp = (uintptr_t)(ptr))
    507 /* Strip ptr auth bits from pc, lr, sp and fp field of arm_thread_state64_t */
    508 #define __darwin_arm_thread_state64_ptrauth_strip(ts) \
    509 	(void)(ts)
    510 
    511 #endif /* __DARWIN_UNIX03 */
    512 #endif /* __DARWIN_OPAQUE_ARM_THREAD_STATE64 */
    513 
    514 #endif /* __has_feature(ptrauth_calls) && defined(__LP64__) */
    515 #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL && defined(__arm64__) */
    516 
    517 #if __DARWIN_UNIX03
    518 #define _STRUCT_ARM_VFP_STATE struct __darwin_arm_vfp_state
    519 _STRUCT_ARM_VFP_STATE
    520 {
    521 	__uint32_t __r[64];
    522 	__uint32_t __fpscr;
    523 };
    524 #else /* !__DARWIN_UNIX03 */
    525 #define _STRUCT_ARM_VFP_STATE struct arm_vfp_state
    526 _STRUCT_ARM_VFP_STATE
    527 {
    528 	__uint32_t r[64];
    529 	__uint32_t fpscr;
    530 };
    531 #endif /* __DARWIN_UNIX03 */
    532 
    533 #if __DARWIN_UNIX03
    534 #define _STRUCT_ARM_NEON_STATE64 struct __darwin_arm_neon_state64
    535 #define _STRUCT_ARM_NEON_STATE   struct __darwin_arm_neon_state
    536 
    537 #if defined(__arm64__)
    538 _STRUCT_ARM_NEON_STATE64
    539 {
    540 	__uint128_t __v[32];
    541 	__uint32_t  __fpsr;
    542 	__uint32_t  __fpcr;
    543 };
    544 
    545 _STRUCT_ARM_NEON_STATE
    546 {
    547 	__uint128_t __v[16];
    548 	__uint32_t  __fpsr;
    549 	__uint32_t  __fpcr;
    550 };
    551 #elif defined(__arm__)
    552 /*
    553  * No 128-bit intrinsic for ARM; leave it opaque for now.
    554  */
    555 _STRUCT_ARM_NEON_STATE64
    556 {
    557 	char opaque[(32 * 16) + (2 * sizeof(__uint32_t))];
    558 } __attribute__((aligned(16)));
    559 
    560 _STRUCT_ARM_NEON_STATE
    561 {
    562 	char opaque[(16 * 16) + (2 * sizeof(__uint32_t))];
    563 } __attribute__((aligned(16)));
    564 
    565 #else
    566 #error Unknown architecture.
    567 #endif
    568 
    569 #else /* !__DARWIN_UNIX03 */
    570 #define _STRUCT_ARM_NEON_STATE64 struct arm_neon_state64
    571 #define _STRUCT_ARM_NEON_STATE struct arm_neon_state
    572 
    573 #if defined(__arm64__)
    574 _STRUCT_ARM_NEON_STATE64
    575 {
    576 	__uint128_t q[32];
    577 	uint32_t    fpsr;
    578 	uint32_t    fpcr;
    579 };
    580 
    581 _STRUCT_ARM_NEON_STATE
    582 {
    583 	__uint128_t q[16];
    584 	uint32_t    fpsr;
    585 	uint32_t    fpcr;
    586 };
    587 #elif defined(__arm__)
    588 /*
    589  * No 128-bit intrinsic for ARM; leave it opaque for now.
    590  */
    591 _STRUCT_ARM_NEON_STATE64
    592 {
    593 	char opaque[(32 * 16) + (2 * sizeof(__uint32_t))];
    594 } __attribute__((aligned(16)));
    595 
    596 _STRUCT_ARM_NEON_STATE
    597 {
    598 	char opaque[(16 * 16) + (2 * sizeof(__uint32_t))];
    599 } __attribute__((aligned(16)));
    600 
    601 #else
    602 #error Unknown architecture.
    603 #endif
    604 
    605 #endif /* __DARWIN_UNIX03 */
    606 
    607 
    608 #define _STRUCT_ARM_PAGEIN_STATE struct __arm_pagein_state
    609 _STRUCT_ARM_PAGEIN_STATE
    610 {
    611 	int __pagein_error;
    612 };
    613 
    614 #if __DARWIN_UNIX03
    615 #define _STRUCT_ARM_SME_STATE struct __darwin_arm_sme_state
    616 _STRUCT_ARM_SME_STATE
    617 {
    618 	__uint64_t      __svcr;
    619 	__uint64_t      __tpidr2_el0;
    620 	__uint16_t      __svl_b;
    621 };
    622 
    623 #define _STRUCT_ARM_SVE_Z_STATE struct __darwin_arm_sve_z_state
    624 _STRUCT_ARM_SVE_Z_STATE
    625 {
    626 	char            __z[16][256];
    627 } __attribute__((aligned(4)));
    628 
    629 #define _STRUCT_ARM_SVE_P_STATE struct __darwin_arm_sve_p_state
    630 _STRUCT_ARM_SVE_P_STATE
    631 {
    632 	char            __p[16][256 / 8];
    633 } __attribute__((aligned(4)));
    634 
    635 #define _STRUCT_ARM_SME_ZA_STATE struct __darwin_arm_sme_za_state
    636 _STRUCT_ARM_SME_ZA_STATE
    637 {
    638 	char            __za[4096];
    639 } __attribute__((aligned(4)));
    640 
    641 #define _STRUCT_ARM_SME2_STATE struct __darwin_arm_sme2_state
    642 _STRUCT_ARM_SME2_STATE
    643 {
    644 	char            __zt0[64];
    645 } __attribute__((aligned(4)));
    646 #else /* !__DARWIN_UNIX03 */
    647 #define _STRUCT_ARM_SME_STATE struct arm_sme_state
    648 _STRUCT_ARM_SME_STATE
    649 {
    650 	__uint64_t      svcr;
    651 	__uint64_t      tpidr2_el0;
    652 	__uint16_t      svl_b;
    653 };
    654 
    655 #define _STRUCT_ARM_SVE_Z_STATE struct arm_sve_z_state
    656 _STRUCT_ARM_SVE_Z_STATE
    657 {
    658 	char            z[16][256];
    659 } __attribute__((aligned(4)));
    660 
    661 #define _STRUCT_ARM_SVE_P_STATE struct arm_sve_p_state
    662 _STRUCT_ARM_SVE_P_STATE
    663 {
    664 	char            p[16][256 / 8];
    665 } __attribute__((aligned(4)));
    666 
    667 #define _STRUCT_ARM_SME_ZA_STATE struct arm_sme_za_state
    668 _STRUCT_ARM_SME_ZA_STATE
    669 {
    670 	char            za[4096];
    671 } __attribute__((aligned(4)));
    672 
    673 #define _STRUCT_ARM_SME2_STATE struct arm_sme2_state
    674 _STRUCT_ARM_SME2_STATE
    675 {
    676 	char            zt0[64];
    677 } __attribute__((aligned(4)));
    678 #endif /* __DARWIN_UNIX03 */
    679 
    680 /*
    681  * Debug State
    682  */
    683 #if defined(__arm__)
    684 /* Old-fashioned debug state is only for ARM */
    685 
    686 #if __DARWIN_UNIX03
    687 #define _STRUCT_ARM_DEBUG_STATE struct __darwin_arm_debug_state
    688 _STRUCT_ARM_DEBUG_STATE
    689 {
    690 	__uint32_t __bvr[16];
    691 	__uint32_t __bcr[16];
    692 	__uint32_t __wvr[16];
    693 	__uint32_t __wcr[16];
    694 };
    695 #else /* !__DARWIN_UNIX03 */
    696 #define _STRUCT_ARM_DEBUG_STATE struct arm_debug_state
    697 _STRUCT_ARM_DEBUG_STATE
    698 {
    699 	__uint32_t bvr[16];
    700 	__uint32_t bcr[16];
    701 	__uint32_t wvr[16];
    702 	__uint32_t wcr[16];
    703 };
    704 #endif /* __DARWIN_UNIX03 */
    705 
    706 #elif defined(__arm64__)
    707 
    708 /* ARM's arm_debug_state is ARM64's arm_legacy_debug_state */
    709 
    710 #if __DARWIN_UNIX03
    711 #define _STRUCT_ARM_LEGACY_DEBUG_STATE struct __arm_legacy_debug_state
    712 _STRUCT_ARM_LEGACY_DEBUG_STATE
    713 {
    714 	__uint32_t __bvr[16];
    715 	__uint32_t __bcr[16];
    716 	__uint32_t __wvr[16];
    717 	__uint32_t __wcr[16];
    718 };
    719 #else /* __DARWIN_UNIX03 */
    720 #define _STRUCT_ARM_LEGACY_DEBUG_STATE struct arm_legacy_debug_state
    721 _STRUCT_ARM_LEGACY_DEBUG_STATE
    722 {
    723 	__uint32_t bvr[16];
    724 	__uint32_t bcr[16];
    725 	__uint32_t wvr[16];
    726 	__uint32_t wcr[16];
    727 };
    728 #endif /* __DARWIN_UNIX03 */
    729 #else
    730 #error unknown architecture
    731 #endif
    732 
    733 #if __DARWIN_UNIX03
    734 #define _STRUCT_ARM_DEBUG_STATE32 struct __darwin_arm_debug_state32
    735 _STRUCT_ARM_DEBUG_STATE32
    736 {
    737 	__uint32_t __bvr[16];
    738 	__uint32_t __bcr[16];
    739 	__uint32_t __wvr[16];
    740 	__uint32_t __wcr[16];
    741 	__uint64_t __mdscr_el1; /* Bit 0 is SS (Hardware Single Step) */
    742 };
    743 
    744 #define _STRUCT_ARM_DEBUG_STATE64 struct __darwin_arm_debug_state64
    745 _STRUCT_ARM_DEBUG_STATE64
    746 {
    747 	__uint64_t __bvr[16];
    748 	__uint64_t __bcr[16];
    749 	__uint64_t __wvr[16];
    750 	__uint64_t __wcr[16];
    751 	__uint64_t __mdscr_el1; /* Bit 0 is SS (Hardware Single Step) */
    752 };
    753 #else /* !__DARWIN_UNIX03 */
    754 #define _STRUCT_ARM_DEBUG_STATE32 struct arm_debug_state32
    755 _STRUCT_ARM_DEBUG_STATE32
    756 {
    757 	__uint32_t bvr[16];
    758 	__uint32_t bcr[16];
    759 	__uint32_t wvr[16];
    760 	__uint32_t wcr[16];
    761 	__uint64_t mdscr_el1; /* Bit 0 is SS (Hardware Single Step) */
    762 };
    763 
    764 #define _STRUCT_ARM_DEBUG_STATE64 struct arm_debug_state64
    765 _STRUCT_ARM_DEBUG_STATE64
    766 {
    767 	__uint64_t bvr[16];
    768 	__uint64_t bcr[16];
    769 	__uint64_t wvr[16];
    770 	__uint64_t wcr[16];
    771 	__uint64_t mdscr_el1; /* Bit 0 is SS (Hardware Single Step) */
    772 };
    773 #endif /* __DARWIN_UNIX03 */
    774 
    775 #if __DARWIN_UNIX03
    776 #define _STRUCT_ARM_CPMU_STATE64 struct __darwin_arm_cpmu_state64
    777 _STRUCT_ARM_CPMU_STATE64
    778 {
    779 	__uint64_t __ctrs[16];
    780 };
    781 #else /* __DARWIN_UNIX03 */
    782 #define _STRUCT_ARM_CPMU_STATE64 struct arm_cpmu_state64
    783 _STRUCT_ARM_CPMU_STATE64
    784 {
    785 	__uint64_t ctrs[16];
    786 };
    787 #endif /* !__DARWIN_UNIX03 */
    788 
    789 #endif /* defined (__arm__) || defined (__arm64__) */
    790 
    791 #endif /* _MACH_ARM__STRUCTS_H_ */