this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

[coredump] Implement WIP ARM64 Support

+115
+66
src/hosttools/include/coredump/arm64.h
··· 1 + #ifndef _DARLING_COREDUMP_ARM64_H_ 2 + #define _DARLING_COREDUMP_ARM64_H_ 3 + 4 + // Linux 5 + // Structs taken from <sys/user.h> 6 + 7 + struct nt_prstatus_registers_aarch64 8 + { 9 + unsigned long long regs[31]; 10 + unsigned long long sp; 11 + unsigned long long pc; 12 + unsigned long long pstate; 13 + }; 14 + 15 + // struct user_fpsimd_struct 16 + // { 17 + // __uint128_t vregs[32]; 18 + // unsigned int fpsr; 19 + // unsigned int fpcr; 20 + // }; 21 + 22 + // XNU 23 + // Taken from the following headers 24 + // * <mach/arm/_structs.h> 25 + // * <mach/arm/thread_status.h> 26 + 27 + typedef struct arm_thread_state64 28 + { 29 + __uint64_t x[29]; /* General purpose registers x0-x28 */ 30 + __uint64_t fp; /* Frame pointer x29 */ 31 + __uint64_t lr; /* Link register x30 */ 32 + __uint64_t sp; /* Stack pointer x31 */ 33 + __uint64_t pc; /* Program counter */ 34 + __uint32_t cpsr; /* Current program status register */ 35 + __uint32_t __pad; /* Same size for 32-bit or 64-bit clients */ 36 + } arm_thread_state64_t; 37 + 38 + // typedef struct arm_neon_state64 39 + // { 40 + // __uint128_t q[32]; 41 + // uint32_t fpsr; 42 + // uint32_t fpcr; 43 + // } arm_neon_state64_t; 44 + 45 + typedef struct arm_exception_state64 46 + { 47 + __uint64_t far; /* Virtual Fault Address */ 48 + __uint32_t esr; /* Exception syndrome */ 49 + __uint32_t exception; /* number of arm exception taken */ 50 + } arm_exception_state64_t; 51 + 52 + typedef unsigned int __darwin_natural_t; 53 + typedef __darwin_natural_t natural_t; 54 + typedef natural_t mach_msg_type_number_t; 55 + 56 + #define ARM_THREAD_STATE64 6 57 + #define ARM_EXCEPTION_STATE64 7 58 + 59 + // #define ARM_NEON_STATE64 17 60 + 61 + #define ARM_THREAD_STATE64_COUNT ((mach_msg_type_number_t) (sizeof (arm_thread_state64_t)/sizeof(uint32_t))) 62 + #define ARM_EXCEPTION_STATE64_COUNT ((mach_msg_type_number_t) (sizeof (arm_exception_state64_t)/sizeof(uint32_t))) 63 + // #define ARM_NEON_STATE64_COUNT ((mach_msg_type_number_t) (sizeof (arm_neon_state64_t)/sizeof(uint32_t))) 64 + 65 + 66 + #endif // _DARLING_COREDUMP_ARM64_H_
+49
src/hosttools/src/coredump/main.cpp
··· 23 23 #include <linux/time_types.h> 24 24 25 25 #include <coredump/x86_64.h> 26 + #include <coredump/arm64.h> 26 27 27 28 #include <darling-config.h> 28 29 ··· 92 93 93 94 union elf64_nt_prstatus_registers { 94 95 struct nt_prstatus_registers_x86_64 x86_64; 96 + struct nt_prstatus_registers_aarch64 aarch64; 95 97 }; 96 98 97 99 struct elf32_kernel_old_timeval { ··· 365 367 switch (get_elf_machine_type(&cprm)) { 366 368 case EM_X86_64: 367 369 case EM_386: 370 + case EM_AARCH64: 368 371 cprm.input_header = (const union Elf_Ehdr*)cprm.input_corefile_mapping; 369 372 break; 370 373 default: ··· 759 762 { 760 763 // TODO 761 764 memset(state, 0, sizeof(*state)); 765 + } 766 + 767 + static 768 + void fill_arm_thread_state64(arm_thread_state64_t* state, const struct thread_info* info) 769 + { 770 + for (int i = 0; i < sizeof(state->x); i++) { 771 + state->x[i] = info->prstatus->elf64.general_registers.aarch64.regs[i]; 772 + } 773 + 774 + state->fp = info->prstatus->elf64.general_registers.aarch64.regs[29]; 775 + state->lr = info->prstatus->elf64.general_registers.aarch64.regs[30]; 776 + state->sp = info->prstatus->elf64.general_registers.aarch64.sp; 777 + state->pc = info->prstatus->elf64.general_registers.aarch64.pc; 778 + 779 + state->cpsr = info->prstatus->elf64.general_registers.aarch64.pstate & 0xFFFFFFFF; 780 + state->__pad = (info->prstatus->elf64.general_registers.aarch64.pstate & 0xFFFFFFFF00000000) >> 32; 781 + } 782 + 783 + static 784 + void fill_arm_exception_state64(arm_exception_state64_t* state, const struct thread_info* info) { 785 + // TODO: Need to figure out where the exception state lives on an ELF ARM64 coredump 786 + memset(state, 0, sizeof(arm_exception_state64_t)); 762 787 } 763 788 764 789 static ··· 943 968 statesize += (DUMP_FLOAT_STATE ? sizeof(struct thread_flavor) + sizeof(x86_float_state64_t) : 0); 944 969 break; 945 970 971 + case EM_AARCH64: 972 + mh.cputype = CPU_TYPE_ARM64; 973 + mh.cpusubtype = CPU_SUBTYPE_ARM64_ALL; 974 + 975 + statesize = sizeof(struct thread_flavor) + sizeof(arm_thread_state64_t); 976 + statesize += sizeof(struct thread_flavor) + sizeof(arm_exception_state64_t); 977 + break; 978 + 946 979 default: 947 980 // Missing code for this arch 948 981 abort(); ··· 1038 1071 1039 1072 break; 1040 1073 1074 + case EM_AARCH64: 1075 + tf = (struct thread_flavor*)(tc+1); 1076 + tf->flavor = ARM_THREAD_STATE64; 1077 + tf->count = ARM_THREAD_STATE64_COUNT; 1078 + fill_arm_thread_state64((arm_thread_state64_t*)tf->state, thread_info); 1079 + 1080 + // DUMP_FLOAT_STATE 1081 + // For ARM64, the float state doesn't exist in LC_THREAD 1082 + 1083 + tf = (struct thread_flavor*) (tf->state + sizeof(arm_thread_state64_t)); 1084 + tf->flavor = ARM_EXCEPTION_STATE64; 1085 + tf->count = ARM_EXCEPTION_STATE64_COUNT; 1086 + fill_arm_exception_state64((arm_exception_state64_t*)tf->state, thread_info); 1087 + 1088 + break; 1089 + 1041 1090 default: 1042 1091 // Missing code for this arch 1043 1092 abort();