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 * Support for determining the state of a thread 45 */ 46 47 48 /* 49 * Flavors 50 */ 51 52 #define ARM_THREAD_STATE 1 53 #define ARM_UNIFIED_THREAD_STATE ARM_THREAD_STATE 54 #define ARM_VFP_STATE 2 55 #define ARM_EXCEPTION_STATE 3 56 #define ARM_DEBUG_STATE 4 /* pre-armv8 */ 57 #define THREAD_STATE_NONE 5 58 #define ARM_THREAD_STATE64 6 59 #define ARM_EXCEPTION_STATE64 7 60 // ARM_THREAD_STATE_LAST 8 /* legacy */ 61 #define ARM_THREAD_STATE32 9 62 63 64 /* API */ 65 #define ARM_DEBUG_STATE32 14 66 #define ARM_DEBUG_STATE64 15 67 #define ARM_NEON_STATE 16 68 #define ARM_NEON_STATE64 17 69 #define ARM_CPMU_STATE64 18 70 71 72 #define ARM_PAGEIN_STATE 27 73 74 #ifndef ARM_STATE_FLAVOR_IS_OTHER_VALID 75 #define ARM_STATE_FLAVOR_IS_OTHER_VALID(_flavor_) 0 76 #endif 77 78 #define VALID_THREAD_STATE_FLAVOR(x) \ 79 ((x == ARM_THREAD_STATE) || \ 80 (x == ARM_VFP_STATE) || \ 81 (x == ARM_EXCEPTION_STATE) || \ 82 (x == ARM_DEBUG_STATE) || \ 83 (x == THREAD_STATE_NONE) || \ 84 (x == ARM_THREAD_STATE32) || \ 85 (x == ARM_THREAD_STATE64) || \ 86 (x == ARM_EXCEPTION_STATE64) || \ 87 (x == ARM_NEON_STATE) || \ 88 (x == ARM_NEON_STATE64) || \ 89 (x == ARM_DEBUG_STATE32) || \ 90 (x == ARM_DEBUG_STATE64) || \ 91 (x == ARM_PAGEIN_STATE) || \ 92 (ARM_STATE_FLAVOR_IS_OTHER_VALID(x))) 93 94 struct arm_state_hdr { 95 uint32_t flavor; 96 uint32_t count; 97 }; 98 typedef struct arm_state_hdr arm_state_hdr_t; 99 100 typedef _STRUCT_ARM_THREAD_STATE arm_thread_state_t; 101 typedef _STRUCT_ARM_THREAD_STATE arm_thread_state32_t; 102 typedef _STRUCT_ARM_THREAD_STATE64 arm_thread_state64_t; 103 104 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL && defined(__arm64__) 105 106 /* Accessor macros for arm_thread_state64_t pointer fields */ 107 108 /* Return pc field of arm_thread_state64_t as a data pointer value */ 109 #define arm_thread_state64_get_pc(ts) \ 110 __darwin_arm_thread_state64_get_pc(ts) 111 /* Return pc field of arm_thread_state64_t as a function pointer. May return 112 * NULL if a valid function pointer cannot be constructed, the caller should 113 * fall back to the arm_thread_state64_get_pc() macro in that case. */ 114 #define arm_thread_state64_get_pc_fptr(ts) \ 115 __darwin_arm_thread_state64_get_pc_fptr(ts) 116 /* Set pc field of arm_thread_state64_t to a function pointer */ 117 #define arm_thread_state64_set_pc_fptr(ts, fptr) \ 118 __darwin_arm_thread_state64_set_pc_fptr(ts, fptr) 119 /* Return lr field of arm_thread_state64_t as a data pointer value */ 120 #define arm_thread_state64_get_lr(ts) \ 121 __darwin_arm_thread_state64_get_lr(ts) 122 /* Return lr field of arm_thread_state64_t as a function pointer. May return 123 * NULL if a valid function pointer cannot be constructed, the caller should 124 * fall back to the arm_thread_state64_get_lr() macro in that case. */ 125 #define arm_thread_state64_get_lr_fptr(ts) \ 126 __darwin_arm_thread_state64_get_lr_fptr(ts) 127 /* Set lr field of arm_thread_state64_t to a function pointer */ 128 #define arm_thread_state64_set_lr_fptr(ts, fptr) \ 129 __darwin_arm_thread_state64_set_lr_fptr(ts, fptr) 130 /* Return sp field of arm_thread_state64_t as a data pointer value */ 131 #define arm_thread_state64_get_sp(ts) \ 132 __darwin_arm_thread_state64_get_sp(ts) 133 /* Set sp field of arm_thread_state64_t to a data pointer value */ 134 #define arm_thread_state64_set_sp(ts, ptr) \ 135 __darwin_arm_thread_state64_set_sp(ts, ptr) 136 /* Return fp field of arm_thread_state64_t as a data pointer value */ 137 #define arm_thread_state64_get_fp(ts) \ 138 __darwin_arm_thread_state64_get_fp(ts) 139 /* Set fp field of arm_thread_state64_t to a data pointer value */ 140 #define arm_thread_state64_set_fp(ts, ptr) \ 141 __darwin_arm_thread_state64_set_fp(ts, ptr) 142 /* Strip ptr auth bits from pc, lr, sp and fp field of arm_thread_state64_t */ 143 #define arm_thread_state64_ptrauth_strip(ts) \ 144 __darwin_arm_thread_state64_ptrauth_strip(ts) 145 146 #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL && defined(__arm64__) */ 147 148 struct arm_unified_thread_state { 149 arm_state_hdr_t ash; 150 union { 151 arm_thread_state32_t ts_32; 152 arm_thread_state64_t ts_64; 153 } uts; 154 }; 155 #define ts_32 uts.ts_32 156 #define ts_64 uts.ts_64 157 typedef struct arm_unified_thread_state arm_unified_thread_state_t; 158 159 #define ARM_THREAD_STATE_COUNT ((mach_msg_type_number_t) \ 160 (sizeof (arm_thread_state_t)/sizeof(uint32_t))) 161 #define ARM_THREAD_STATE32_COUNT ((mach_msg_type_number_t) \ 162 (sizeof (arm_thread_state32_t)/sizeof(uint32_t))) 163 #define ARM_THREAD_STATE64_COUNT ((mach_msg_type_number_t) \ 164 (sizeof (arm_thread_state64_t)/sizeof(uint32_t))) 165 #define ARM_UNIFIED_THREAD_STATE_COUNT ((mach_msg_type_number_t) \ 166 (sizeof (arm_unified_thread_state_t)/sizeof(uint32_t))) 167 168 169 typedef _STRUCT_ARM_VFP_STATE arm_vfp_state_t; 170 typedef _STRUCT_ARM_NEON_STATE arm_neon_state_t; 171 typedef _STRUCT_ARM_NEON_STATE arm_neon_state32_t; 172 typedef _STRUCT_ARM_NEON_STATE64 arm_neon_state64_t; 173 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 /* 228 * Largest state on this machine: 229 */ 230 #define THREAD_MACHINE_STATE_MAX THREAD_STATE_MAX 231 232 233 #endif /* defined (__arm__) || defined (__arm64__) */ 234 235 #endif /* _ARM_THREAD_STATUS_H_ */