| 1 | /* |
| 2 | * Copyright (c) 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 | * FILE_ID: thread_status.h |
| 30 | */ |
| 31 | |
| 32 | |
| 33 | #ifndef _ARM_THREAD_STATUS_H_ |
| 34 | #define _ARM_THREAD_STATUS_H_ |
| 35 | |
| 36 | #if defined (__arm__) || defined (__arm64__) |
| 37 | |
| 38 | #include <mach/machine/_structs.h> |
| 39 | #include <mach/machine/thread_state.h> |
| 40 | #include <mach/message.h> |
| 41 | #include <mach/vm_types.h> |
| 42 | |
| 43 | |
| 44 | /* |
| 45 | * Support for determining the state of a thread |
| 46 | */ |
| 47 | |
| 48 | |
| 49 | /* |
| 50 | * Flavors |
| 51 | */ |
| 52 | |
| 53 | #define ARM_THREAD_STATE 1 |
| 54 | #define ARM_UNIFIED_THREAD_STATE ARM_THREAD_STATE |
| 55 | #define ARM_VFP_STATE 2 |
| 56 | #define ARM_EXCEPTION_STATE 3 |
| 57 | #define ARM_DEBUG_STATE 4 /* pre-armv8 */ |
| 58 | #define THREAD_STATE_NONE 5 |
| 59 | #define ARM_THREAD_STATE64 6 |
| 60 | #define ARM_EXCEPTION_STATE64 7 |
| 61 | // ARM_THREAD_STATE_LAST 8 /* legacy */ |
| 62 | #define ARM_THREAD_STATE32 9 |
| 63 | #define ARM_EXCEPTION_STATE64_V2 10 |
| 64 | |
| 65 | |
| 66 | /* API */ |
| 67 | #define ARM_DEBUG_STATE32 14 |
| 68 | #define ARM_DEBUG_STATE64 15 |
| 69 | #define ARM_NEON_STATE 16 |
| 70 | #define ARM_NEON_STATE64 17 |
| 71 | #define ARM_CPMU_STATE64 18 |
| 72 | |
| 73 | |
| 74 | #define ARM_PAGEIN_STATE 27 |
| 75 | |
| 76 | /* API */ |
| 77 | #define ARM_SME_STATE 28 |
| 78 | #define ARM_SVE_Z_STATE1 29 |
| 79 | #define ARM_SVE_Z_STATE2 30 |
| 80 | #define ARM_SVE_P_STATE 31 |
| 81 | #define ARM_SME_ZA_STATE1 32 |
| 82 | #define ARM_SME_ZA_STATE2 33 |
| 83 | #define ARM_SME_ZA_STATE3 34 |
| 84 | #define ARM_SME_ZA_STATE4 35 |
| 85 | #define ARM_SME_ZA_STATE5 36 |
| 86 | #define ARM_SME_ZA_STATE6 37 |
| 87 | #define ARM_SME_ZA_STATE7 38 |
| 88 | #define ARM_SME_ZA_STATE8 39 |
| 89 | #define ARM_SME_ZA_STATE9 40 |
| 90 | #define ARM_SME_ZA_STATE10 41 |
| 91 | #define ARM_SME_ZA_STATE11 42 |
| 92 | #define ARM_SME_ZA_STATE12 43 |
| 93 | #define ARM_SME_ZA_STATE13 44 |
| 94 | #define ARM_SME_ZA_STATE14 45 |
| 95 | #define ARM_SME_ZA_STATE15 46 |
| 96 | #define ARM_SME_ZA_STATE16 47 |
| 97 | #define ARM_SME2_STATE 48 |
| 98 | |
| 99 | #define THREAD_STATE_FLAVORS 50 /* This must be updated to 1 more than the highest numerical state flavor */ |
| 100 | |
| 101 | #ifndef ARM_STATE_FLAVOR_IS_OTHER_VALID |
| 102 | #define ARM_STATE_FLAVOR_IS_OTHER_VALID(_flavor_) 0 |
| 103 | #endif |
| 104 | |
| 105 | #define FLAVOR_MODIFIES_CORE_CPU_REGISTERS(x) \ |
| 106 | ((x == ARM_THREAD_STATE) || \ |
| 107 | (x == ARM_THREAD_STATE32) || \ |
| 108 | (x == ARM_THREAD_STATE64)) |
| 109 | |
| 110 | #define VALID_THREAD_STATE_FLAVOR(x) \ |
| 111 | 	((x == ARM_THREAD_STATE) || \ |
| 112 | 	 (x == ARM_VFP_STATE) || \ |
| 113 | 	 (x == ARM_EXCEPTION_STATE) || \ |
| 114 | 	 (x == ARM_DEBUG_STATE) || \ |
| 115 | 	 (x == THREAD_STATE_NONE) || \ |
| 116 | 	 (x == ARM_THREAD_STATE32) || \ |
| 117 | 	 (x == ARM_THREAD_STATE64) || \ |
| 118 | 	 (x == ARM_EXCEPTION_STATE64) || \ |
| 119 | 	 (x == ARM_EXCEPTION_STATE64_V2) || \ |
| 120 | 	 (x == ARM_NEON_STATE) || \ |
| 121 | 	 (x == ARM_NEON_STATE64) || \ |
| 122 | 	 (x == ARM_DEBUG_STATE32) || \ |
| 123 | 	 (x == ARM_DEBUG_STATE64) || \ |
| 124 | 	 (x == ARM_PAGEIN_STATE) || \ |
| 125 | 	 (ARM_STATE_FLAVOR_IS_OTHER_VALID(x))) |
| 126 | /* |
| 127 | * VALID_THREAD_STATE_FLAVOR() intentionally excludes ARM_SME_STATE through |
| 128 | * ARM_SME2_STATE, since these are not currently supported inside Mach exception |
| 129 | * ports. |
| 130 | */ |
| 131 | |
| 132 | struct arm_state_hdr { |
| 133 | 	uint32_t flavor; |
| 134 | 	uint32_t count; |
| 135 | }; |
| 136 | typedef struct arm_state_hdr arm_state_hdr_t; |
| 137 | |
| 138 | typedef _STRUCT_ARM_THREAD_STATE arm_thread_state_t; |
| 139 | typedef _STRUCT_ARM_THREAD_STATE arm_thread_state32_t; |
| 140 | typedef _STRUCT_ARM_THREAD_STATE64 arm_thread_state64_t; |
| 141 | |
| 142 | #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL && defined(__arm64__) |
| 143 | |
| 144 | /* Accessor macros for arm_thread_state64_t pointer fields */ |
| 145 | |
| 146 | /* Return pc field of arm_thread_state64_t as a data pointer value */ |
| 147 | #define arm_thread_state64_get_pc(ts) \ |
| 148 | 	 __darwin_arm_thread_state64_get_pc(ts) |
| 149 | /* Return pc field of arm_thread_state64_t as a function pointer. May return |
| 150 | * NULL if a valid function pointer cannot be constructed, the caller should |
| 151 | * fall back to the arm_thread_state64_get_pc() macro in that case. */ |
| 152 | #define arm_thread_state64_get_pc_fptr(ts) \ |
| 153 | 	 __darwin_arm_thread_state64_get_pc_fptr(ts) |
| 154 | /* Set pc field of arm_thread_state64_t to a function pointer */ |
| 155 | #define arm_thread_state64_set_pc_fptr(ts, fptr) \ |
| 156 | 	 __darwin_arm_thread_state64_set_pc_fptr(ts, fptr) |
| 157 | /* Set pc field of arm_thread_state64_t to an already signed function pointer */ |
| 158 | #define arm_thread_state64_set_pc_presigned_fptr(ts, fptr) \ |
| 159 | 	 __darwin_arm_thread_state64_set_pc_presigned_fptr(ts, fptr) |
| 160 | /* Return lr field of arm_thread_state64_t as a data pointer value */ |
| 161 | #define arm_thread_state64_get_lr(ts) \ |
| 162 | 	 __darwin_arm_thread_state64_get_lr(ts) |
| 163 | /* Return lr field of arm_thread_state64_t as a function pointer. May return |
| 164 | * NULL if a valid function pointer cannot be constructed, the caller should |
| 165 | * fall back to the arm_thread_state64_get_lr() macro in that case. */ |
| 166 | #define arm_thread_state64_get_lr_fptr(ts) \ |
| 167 | 	 __darwin_arm_thread_state64_get_lr_fptr(ts) |
| 168 | /* Set lr field of arm_thread_state64_t to a function pointer */ |
| 169 | #define arm_thread_state64_set_lr_fptr(ts, fptr) \ |
| 170 | 	 __darwin_arm_thread_state64_set_lr_fptr(ts, fptr) |
| 171 | /* Set lr field of arm_thread_state64_t to an already signed function pointer */ |
| 172 | #define arm_thread_state64_set_lr_presigned_fptr(ts, fptr) \ |
| 173 | 	 __darwin_arm_thread_state64_set_lr_presigned_fptr(ts, fptr) |
| 174 | /* Return sp field of arm_thread_state64_t as a data pointer value */ |
| 175 | #define arm_thread_state64_get_sp(ts) \ |
| 176 | 	 __darwin_arm_thread_state64_get_sp(ts) |
| 177 | /* Set sp field of arm_thread_state64_t to a data pointer value */ |
| 178 | #define arm_thread_state64_set_sp(ts, ptr) \ |
| 179 | 	 __darwin_arm_thread_state64_set_sp(ts, ptr) |
| 180 | /* Return fp field of arm_thread_state64_t as a data pointer value */ |
| 181 | #define arm_thread_state64_get_fp(ts) \ |
| 182 | 	 __darwin_arm_thread_state64_get_fp(ts) |
| 183 | /* Set fp field of arm_thread_state64_t to a data pointer value */ |
| 184 | #define arm_thread_state64_set_fp(ts, ptr) \ |
| 185 | 	 __darwin_arm_thread_state64_set_fp(ts, ptr) |
| 186 | /* Strip ptr auth bits from pc, lr, sp and fp field of arm_thread_state64_t */ |
| 187 | #define arm_thread_state64_ptrauth_strip(ts) \ |
| 188 | 	 __darwin_arm_thread_state64_ptrauth_strip(ts) |
| 189 | |
| 190 | #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL && defined(__arm64__) */ |
| 191 | |
| 192 | struct arm_unified_thread_state { |
| 193 | 	arm_state_hdr_t ash; |
| 194 | 	union { |
| 195 | 		arm_thread_state32_t ts_32; |
| 196 | 		arm_thread_state64_t ts_64; |
| 197 | 	} uts; |
| 198 | }; |
| 199 | #define ts_32 uts.ts_32 |
| 200 | #define ts_64 uts.ts_64 |
| 201 | typedef struct arm_unified_thread_state arm_unified_thread_state_t; |
| 202 | |
| 203 | #define ARM_THREAD_STATE_COUNT ((mach_msg_type_number_t) \ |
| 204 | 	(sizeof (arm_thread_state_t)/sizeof(uint32_t))) |
| 205 | #define ARM_THREAD_STATE32_COUNT ((mach_msg_type_number_t) \ |
| 206 | 	(sizeof (arm_thread_state32_t)/sizeof(uint32_t))) |
| 207 | #define ARM_THREAD_STATE64_COUNT ((mach_msg_type_number_t) \ |
| 208 | 	(sizeof (arm_thread_state64_t)/sizeof(uint32_t))) |
| 209 | #define ARM_UNIFIED_THREAD_STATE_COUNT ((mach_msg_type_number_t) \ |
| 210 | 	(sizeof (arm_unified_thread_state_t)/sizeof(uint32_t))) |
| 211 | |
| 212 | |
| 213 | typedef _STRUCT_ARM_VFP_STATE arm_vfp_state_t; |
| 214 | typedef _STRUCT_ARM_NEON_STATE arm_neon_state_t; |
| 215 | typedef _STRUCT_ARM_NEON_STATE arm_neon_state32_t; |
| 216 | typedef _STRUCT_ARM_NEON_STATE64 arm_neon_state64_t; |
| 217 | |
| 218 | |
| 219 | typedef _STRUCT_ARM_EXCEPTION_STATE arm_exception_state_t; |
| 220 | typedef _STRUCT_ARM_EXCEPTION_STATE arm_exception_state32_t; |
| 221 | typedef _STRUCT_ARM_EXCEPTION_STATE64 arm_exception_state64_t; |
| 222 | typedef _STRUCT_ARM_EXCEPTION_STATE64_V2 arm_exception_state64_v2_t; |
| 223 | |
| 224 | typedef _STRUCT_ARM_DEBUG_STATE32 arm_debug_state32_t; |
| 225 | typedef _STRUCT_ARM_DEBUG_STATE64 arm_debug_state64_t; |
| 226 | |
| 227 | typedef _STRUCT_ARM_PAGEIN_STATE arm_pagein_state_t; |
| 228 | |
| 229 | typedef _STRUCT_ARM_SME_STATE arm_sme_state_t; |
| 230 | typedef _STRUCT_ARM_SVE_Z_STATE arm_sve_z_state_t; |
| 231 | typedef _STRUCT_ARM_SVE_P_STATE arm_sve_p_state_t; |
| 232 | typedef _STRUCT_ARM_SME_ZA_STATE arm_sme_za_state_t; |
| 233 | typedef _STRUCT_ARM_SME2_STATE arm_sme2_state_t; |
| 234 | |
| 235 | /* |
| 236 | * Otherwise not ARM64 kernel and we must preserve legacy ARM definitions of |
| 237 | * arm_debug_state for binary compatability of userland consumers of this file. |
| 238 | */ |
| 239 | #if defined(__arm__) |
| 240 | typedef _STRUCT_ARM_DEBUG_STATE arm_debug_state_t; |
| 241 | #elif defined(__arm64__) |
| 242 | typedef _STRUCT_ARM_LEGACY_DEBUG_STATE arm_debug_state_t; |
| 243 | #else /* defined(__arm__) */ |
| 244 | #error Undefined architecture |
| 245 | #endif /* defined(__arm__) */ |
| 246 | |
| 247 | #define ARM_VFP_STATE_COUNT ((mach_msg_type_number_t) \ |
| 248 | 	(sizeof (arm_vfp_state_t)/sizeof(uint32_t))) |
| 249 | |
| 250 | #define ARM_EXCEPTION_STATE_COUNT ((mach_msg_type_number_t) \ |
| 251 | 	(sizeof (arm_exception_state_t)/sizeof(uint32_t))) |
| 252 | |
| 253 | #define ARM_EXCEPTION_STATE64_COUNT ((mach_msg_type_number_t) \ |
| 254 | 	(sizeof (arm_exception_state64_t)/sizeof(uint32_t))) |
| 255 | |
| 256 | #define ARM_EXCEPTION_STATE64_V2_COUNT ((mach_msg_type_number_t) \ |
| 257 | 	(sizeof (arm_exception_state64_v2_t)/sizeof(uint32_t))) |
| 258 | |
| 259 | #define ARM_DEBUG_STATE_COUNT ((mach_msg_type_number_t) \ |
| 260 | 	(sizeof (arm_debug_state_t)/sizeof(uint32_t))) |
| 261 | |
| 262 | #define ARM_DEBUG_STATE32_COUNT ((mach_msg_type_number_t) \ |
| 263 | 	(sizeof (arm_debug_state32_t)/sizeof(uint32_t))) |
| 264 | |
| 265 | #define ARM_PAGEIN_STATE_COUNT ((mach_msg_type_number_t) \ |
| 266 | 	(sizeof (arm_pagein_state_t)/sizeof(uint32_t))) |
| 267 | |
| 268 | #define ARM_DEBUG_STATE64_COUNT ((mach_msg_type_number_t) \ |
| 269 | 	(sizeof (arm_debug_state64_t)/sizeof(uint32_t))) |
| 270 | |
| 271 | #define ARM_NEON_STATE_COUNT ((mach_msg_type_number_t) \ |
| 272 | 	(sizeof (arm_neon_state_t)/sizeof(uint32_t))) |
| 273 | |
| 274 | #define ARM_NEON_STATE64_COUNT ((mach_msg_type_number_t) \ |
| 275 | 	(sizeof (arm_neon_state64_t)/sizeof(uint32_t))) |
| 276 | |
| 277 | #define ARM_SME_STATE_COUNT ((mach_msg_type_number_t) \ |
| 278 | 	(sizeof (arm_sme_state_t)/sizeof(uint32_t))) |
| 279 | |
| 280 | #define ARM_SVE_Z_STATE_COUNT ((mach_msg_type_number_t) \ |
| 281 | 	(sizeof (arm_sve_z_state_t)/sizeof(uint32_t))) |
| 282 | |
| 283 | #define ARM_SVE_P_STATE_COUNT ((mach_msg_type_number_t) \ |
| 284 | 	(sizeof (arm_sve_p_state_t)/sizeof(uint32_t))) |
| 285 | |
| 286 | #define ARM_SME_ZA_STATE_COUNT ((mach_msg_type_number_t) \ |
| 287 | 	(sizeof (arm_sme_za_state_t)/sizeof(uint32_t))) |
| 288 | |
| 289 | #define ARM_SME2_STATE_COUNT ((mach_msg_type_number_t) \ |
| 290 | 	(sizeof (arm_sme2_state_t)/sizeof(uint32_t))) |
| 291 | |
| 292 | #define MACHINE_THREAD_STATE ARM_THREAD_STATE |
| 293 | #define MACHINE_THREAD_STATE_COUNT ARM_UNIFIED_THREAD_STATE_COUNT |
| 294 | |
| 295 | |
| 296 | /* |
| 297 | * Largest state on this machine: |
| 298 | */ |
| 299 | #define THREAD_MACHINE_STATE_MAX THREAD_STATE_MAX |
| 300 | |
| 301 | |
| 302 | #endif /* defined (__arm__) || defined (__arm64__) */ |
| 303 | |
| 304 | #endif /* _ARM_THREAD_STATUS_H_ */ |