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 #include <mach/machine/_structs.h> 37 #include <mach/message.h> 38 #include <mach/vm_types.h> 39 #include <mach/arm/thread_state.h> 40 41 /* 42 * Support for determining the state of a thread 43 */ 44 45 46 /* 47 * Flavors 48 */ 49 50 #define ARM_THREAD_STATE 1 51 #define ARM_UNIFIED_THREAD_STATE ARM_THREAD_STATE 52 #define ARM_VFP_STATE 2 53 #define ARM_EXCEPTION_STATE 3 54 #define ARM_DEBUG_STATE 4 /* pre-armv8 */ 55 #define THREAD_STATE_NONE 5 56 #define ARM_THREAD_STATE64 6 57 #define ARM_EXCEPTION_STATE64 7 58 // ARM_THREAD_STATE_LAST 8 /* legacy */ 59 #define ARM_THREAD_STATE32 9 60 61 62 /* API */ 63 #define ARM_DEBUG_STATE32 14 64 #define ARM_DEBUG_STATE64 15 65 #define ARM_NEON_STATE 16 66 #define ARM_NEON_STATE64 17 67 #define ARM_CPMU_STATE64 18 68 69 70 /* API */ 71 #define ARM_AMX_STATE 24 72 #define ARM_AMX_STATE_V1 25 73 #define ARM_STATE_FLAVOR_IS_OTHER_VALID(_flavor_) \ 74 ((_flavor_) == ARM_AMX_STATE_V1) 75 #define ARM_PAGEIN_STATE 27 76 77 #define VALID_THREAD_STATE_FLAVOR(x) \ 78 ((x == ARM_THREAD_STATE) || \ 79 (x == ARM_VFP_STATE) || \ 80 (x == ARM_EXCEPTION_STATE) || \ 81 (x == ARM_DEBUG_STATE) || \ 82 (x == THREAD_STATE_NONE) || \ 83 (x == ARM_THREAD_STATE32) || \ 84 (x == ARM_THREAD_STATE64) || \ 85 (x == ARM_EXCEPTION_STATE64) || \ 86 (x == ARM_NEON_STATE) || \ 87 (x == ARM_NEON_STATE64) || \ 88 (x == ARM_DEBUG_STATE32) || \ 89 (x == ARM_DEBUG_STATE64) || \ 90 (x == ARM_PAGEIN_STATE) || \ 91 (ARM_STATE_FLAVOR_IS_OTHER_VALID(x))) 92 93 struct arm_state_hdr { 94 uint32_t flavor; 95 uint32_t count; 96 }; 97 typedef struct arm_state_hdr arm_state_hdr_t; 98 99 typedef _STRUCT_ARM_THREAD_STATE arm_thread_state_t; 100 typedef _STRUCT_ARM_THREAD_STATE arm_thread_state32_t; 101 typedef _STRUCT_ARM_THREAD_STATE64 arm_thread_state64_t; 102 103 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL && defined(__arm64__) 104 105 /* Accessor macros for arm_thread_state64_t pointer fields */ 106 107 /* Return pc field of arm_thread_state64_t as a data pointer value */ 108 #define arm_thread_state64_get_pc(ts) \ 109 __darwin_arm_thread_state64_get_pc(ts) 110 /* Return pc field of arm_thread_state64_t as a function pointer. May return 111 * NULL if a valid function pointer cannot be constructed, the caller should 112 * fall back to the arm_thread_state64_get_pc() macro in that case. */ 113 #define arm_thread_state64_get_pc_fptr(ts) \ 114 __darwin_arm_thread_state64_get_pc_fptr(ts) 115 /* Set pc field of arm_thread_state64_t to a function pointer */ 116 #define arm_thread_state64_set_pc_fptr(ts, fptr) \ 117 __darwin_arm_thread_state64_set_pc_fptr(ts, fptr) 118 /* Return lr field of arm_thread_state64_t as a data pointer value */ 119 #define arm_thread_state64_get_lr(ts) \ 120 __darwin_arm_thread_state64_get_lr(ts) 121 /* Return lr field of arm_thread_state64_t as a function pointer. May return 122 * NULL if a valid function pointer cannot be constructed, the caller should 123 * fall back to the arm_thread_state64_get_lr() macro in that case. */ 124 #define arm_thread_state64_get_lr_fptr(ts) \ 125 __darwin_arm_thread_state64_get_lr_fptr(ts) 126 /* Set lr field of arm_thread_state64_t to a function pointer */ 127 #define arm_thread_state64_set_lr_fptr(ts, fptr) \ 128 __darwin_arm_thread_state64_set_lr_fptr(ts, fptr) 129 /* Return sp field of arm_thread_state64_t as a data pointer value */ 130 #define arm_thread_state64_get_sp(ts) \ 131 __darwin_arm_thread_state64_get_sp(ts) 132 /* Set sp field of arm_thread_state64_t to a data pointer value */ 133 #define arm_thread_state64_set_sp(ts, ptr) \ 134 __darwin_arm_thread_state64_set_sp(ts, ptr) 135 /* Return fp field of arm_thread_state64_t as a data pointer value */ 136 #define arm_thread_state64_get_fp(ts) \ 137 __darwin_arm_thread_state64_get_fp(ts) 138 /* Set fp field of arm_thread_state64_t to a data pointer value */ 139 #define arm_thread_state64_set_fp(ts, ptr) \ 140 __darwin_arm_thread_state64_set_fp(ts, ptr) 141 /* Strip ptr auth bits from pc, lr, sp and fp field of arm_thread_state64_t */ 142 #define arm_thread_state64_ptrauth_strip(ts) \ 143 __darwin_arm_thread_state64_ptrauth_strip(ts) 144 145 #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL && defined(__arm64__) */ 146 147 struct arm_unified_thread_state { 148 arm_state_hdr_t ash; 149 union { 150 arm_thread_state32_t ts_32; 151 arm_thread_state64_t ts_64; 152 } uts; 153 }; 154 #define ts_32 uts.ts_32 155 #define ts_64 uts.ts_64 156 typedef struct arm_unified_thread_state arm_unified_thread_state_t; 157 158 #define ARM_THREAD_STATE_COUNT ((mach_msg_type_number_t) \ 159 (sizeof (arm_thread_state_t)/sizeof(uint32_t))) 160 #define ARM_THREAD_STATE32_COUNT ((mach_msg_type_number_t) \ 161 (sizeof (arm_thread_state32_t)/sizeof(uint32_t))) 162 #define ARM_THREAD_STATE64_COUNT ((mach_msg_type_number_t) \ 163 (sizeof (arm_thread_state64_t)/sizeof(uint32_t))) 164 #define ARM_UNIFIED_THREAD_STATE_COUNT ((mach_msg_type_number_t) \ 165 (sizeof (arm_unified_thread_state_t)/sizeof(uint32_t))) 166 167 168 typedef _STRUCT_ARM_VFP_STATE arm_vfp_state_t; 169 typedef _STRUCT_ARM_NEON_STATE arm_neon_state_t; 170 typedef _STRUCT_ARM_NEON_STATE arm_neon_state32_t; 171 typedef _STRUCT_ARM_NEON_STATE64 arm_neon_state64_t; 172 173 typedef _STRUCT_ARM_AMX_STATE_V1 arm_amx_state_v1_t; 174 175 typedef _STRUCT_ARM_EXCEPTION_STATE arm_exception_state_t; 176 typedef _STRUCT_ARM_EXCEPTION_STATE arm_exception_state32_t; 177 typedef _STRUCT_ARM_EXCEPTION_STATE64 arm_exception_state64_t; 178 179 typedef _STRUCT_ARM_DEBUG_STATE32 arm_debug_state32_t; 180 typedef _STRUCT_ARM_DEBUG_STATE64 arm_debug_state64_t; 181 182 typedef _STRUCT_ARM_PAGEIN_STATE arm_pagein_state_t; 183 184 /* 185 * Otherwise not ARM64 kernel and we must preserve legacy ARM definitions of 186 * arm_debug_state for binary compatability of userland consumers of this file. 187 */ 188 #if defined(__arm__) 189 typedef _STRUCT_ARM_DEBUG_STATE arm_debug_state_t; 190 #elif defined(__arm64__) 191 typedef _STRUCT_ARM_LEGACY_DEBUG_STATE arm_debug_state_t; 192 #else /* defined(__arm__) */ 193 #error Undefined architecture 194 #endif /* defined(__arm__) */ 195 196 #define ARM_VFP_STATE_COUNT ((mach_msg_type_number_t) \ 197 (sizeof (arm_vfp_state_t)/sizeof(uint32_t))) 198 199 #define ARM_EXCEPTION_STATE_COUNT ((mach_msg_type_number_t) \ 200 (sizeof (arm_exception_state_t)/sizeof(uint32_t))) 201 202 #define ARM_EXCEPTION_STATE64_COUNT ((mach_msg_type_number_t) \ 203 (sizeof (arm_exception_state64_t)/sizeof(uint32_t))) 204 205 #define ARM_DEBUG_STATE_COUNT ((mach_msg_type_number_t) \ 206 (sizeof (arm_debug_state_t)/sizeof(uint32_t))) 207 208 #define ARM_DEBUG_STATE32_COUNT ((mach_msg_type_number_t) \ 209 (sizeof (arm_debug_state32_t)/sizeof(uint32_t))) 210 211 #define ARM_PAGEIN_STATE_COUNT ((mach_msg_type_number_t) \ 212 (sizeof (arm_pagein_state_t)/sizeof(uint32_t))) 213 214 #define ARM_DEBUG_STATE64_COUNT ((mach_msg_type_number_t) \ 215 (sizeof (arm_debug_state64_t)/sizeof(uint32_t))) 216 217 #define ARM_NEON_STATE_COUNT ((mach_msg_type_number_t) \ 218 (sizeof (arm_neon_state_t)/sizeof(uint32_t))) 219 220 #define ARM_NEON_STATE64_COUNT ((mach_msg_type_number_t) \ 221 (sizeof (arm_neon_state64_t)/sizeof(uint32_t))) 222 223 #define MACHINE_THREAD_STATE ARM_THREAD_STATE 224 #define MACHINE_THREAD_STATE_COUNT ARM_UNIFIED_THREAD_STATE_COUNT 225 226 227 struct arm_amx_state { 228 arm_state_hdr_t ash; 229 union { 230 arm_amx_state_v1_t as_v1; 231 } uas; 232 }; 233 #define as_v1 uas.as_v1 234 typedef struct arm_amx_state arm_amx_state_t; 235 236 #define ARM_AMX_STATE_V1_COUNT ((mach_msg_type_number_t) \ 237 (sizeof(arm_amx_state_v1_t)/sizeof(unsigned int))) 238 239 #define ARM_AMX_STATE_COUNT ((mach_msg_type_number_t) \ 240 (sizeof(arm_amx_state_t)/sizeof(unsigned int))) 241 242 243 /* 244 * Largest state on this machine: 245 */ 246 #define THREAD_MACHINE_STATE_MAX THREAD_STATE_MAX 247 248 249 #endif /* _ARM_THREAD_STATUS_H_ */