1 #ifndef _INCLUDE_XNU_THREADS_H_ 2 #define _INCLUDE_XNU_THREADS_H_ 3 4 #if __POWERPC__ 5 //TODO add better support for PPC 6 # define R_REG_T ppc_thread_state_t 7 # define R_REG_STATE_T PPC_THREAD_STATE 8 # define R_REG_STATE_SZ PPC_THREAD_STATE_SZ 9 10 #elif __arm || __arm64 || __aarch64 11 # include <mach/arm/thread_status.h> 12 # ifndef ARM_THREAD_STATE 13 # define ARM_THREAD_STATE 1 14 # endif 15 # ifndef ARM_THREAD_STATE64 16 # define ARM_THREAD_STATE64 6 17 # endif 18 # define R_REG_T arm_unified_thread_state_t 19 # define R_REG_STATE_T MACHINE_THREAD_STATE 20 # define R_REG_STATE_SZ MACHINE_THREAD_STATE_COUNT 21 #elif __x86_64__ || __i386__ 22 # define R_REG_T x86_thread_state_t 23 # define R_REG_STATE_T MACHINE_THREAD_STATE 24 # define R_REG_STATE_SZ MACHINE_THREAD_STATE_COUNT 25 #endif 26 27 #define RETURN_ON_MACH_ERROR(msg, retval)\ 28 if (kr != KERN_SUCCESS) {mach_error (msg, kr); return ((retval));} 29 30 typedef struct _exception_info { 31 exception_mask_t masks[EXC_TYPES_COUNT]; 32 mach_port_t ports[EXC_TYPES_COUNT]; 33 exception_behavior_t behaviors[EXC_TYPES_COUNT]; 34 thread_state_flavor_t flavors[EXC_TYPES_COUNT]; 35 mach_msg_type_number_t count; 36 pthread_t thread; 37 mach_port_t exception_port; 38 } xnu_exception_info; 39 40 41 //XXX use radare types 42 typedef struct _xnu_thread { 43 thread_t port; //mach_port // XXX bad naming here 44 char *name; //name of thread 45 thread_basic_info_data_t basic_info; //need this? 46 ut8 stepping; // thread is stepping or not //TODO implement stepping 47 R_REG_T gpr; // type R_REG_T using unified API XXX bad naming 48 void *state; 49 ut32 state_size; 50 #if __arm64 || __aarch64 || __arm64__ || __aarch64__ 51 union { 52 arm_debug_state32_t drx32; 53 arm_debug_state64_t drx64; 54 } debug; 55 #elif __arm__ || __arm || __armv7__ 56 union { 57 arm_debug_state_t drx; 58 } debug; 59 #elif __x86_64__ || __i386__ 60 x86_debug_state_t drx; 61 #endif 62 ut16 flavor; 63 ut32 count; 64 } xnu_thread_t; 65 66 typedef struct _exc_msg { 67 mach_msg_header_t hdr; 68 /* start of the kernel processed data */ 69 mach_msg_body_t msg_body; 70 mach_msg_port_descriptor_t thread; 71 mach_msg_port_descriptor_t task; 72 /* end of the kernel processed data */ 73 NDR_record_t NDR; 74 exception_type_t exception; 75 mach_msg_type_number_t code_cnt; 76 #if !__POWERPC__ 77 mach_exception_data_t code; 78 #endif 79 /* some times RCV_TO_LARGE probs */ 80 char pad[512]; 81 } exc_msg; 82 83 typedef struct _rep_msg { 84 mach_msg_header_t hdr; 85 NDR_record_t NDR; 86 kern_return_t ret_code; 87 } rep_msg; 88 89 90 #endif 91