| 1 |
use super::{CommonThreadInfo, NT_Elf}; |
| 2 |
use crate::{errors::ThreadInfoError, minidump_cpu::RawContextCPU, Pid}; |
| 3 |
use nix::sys::ptrace; |
| 4 |
|
| 5 |
type Result<T> = std::result::Result<T, ThreadInfoError>; |
| 6 |
|
| 7 |
// Not defined by libc because this works only for cores support VFP |
| 8 |
#[allow(non_camel_case_types)] |
| 9 |
#[repr(C)] |
| 10 |
#[derive(Debug, Eq, Hash, PartialEq, Copy, Clone, Default)] |
| 11 |
pub struct user_fpregs_struct { |
| 12 |
pub fpregs: [u64; 32], |
| 13 |
pub fpscr: u32, |
| 14 |
} |
| 15 |
|
| 16 |
#[repr(C)] |
| 17 |
#[derive(Debug, Eq, Hash, PartialEq, Copy, Clone, Default)] |
| 18 |
pub struct user_regs_struct { |
| 19 |
uregs: [u32; 18], |
| 20 |
} |
| 21 |
|
| 22 |
#[derive(Debug)] |
| 23 |
pub struct ThreadInfoArm { |
| 24 |
pub stack_pointer: usize, |
| 25 |
pub tgid: Pid, // thread group id |
| 26 |
pub ppid: Pid, // parent process |
| 27 |
pub regs: user_regs_struct, |
| 28 |
pub fpregs: user_fpregs_struct, |
| 29 |
} |
| 30 |
|
| 31 |
impl CommonThreadInfo for ThreadInfoArm {} |
| 32 |
|
| 33 |
impl ThreadInfoArm { |
| 34 |
// nix currently doesn't support PTRACE_GETFPREGS, so we have to do it ourselves |
| 35 |
fn getfpregs(pid: Pid) -> Result<user_fpregs_struct> { |
| 36 |
Self::ptrace_get_data_via_io( |
| 37 |
0x4204 as ptrace::RequestType, // PTRACE_GETREGSET |
| 38 |
Some(NT_Elf::NT_ARM_VFP), |
| 39 |
nix::unistd::Pid::from_raw(pid), |
| 40 |
) |
| 41 |
} |
| 42 |
|
| 43 |
// nix currently doesn't support PTRACE_GETREGS, so we have to do it ourselves |
| 44 |
fn getregs(pid: Pid) -> Result<user_regs_struct> { |
| 45 |
Self::ptrace_get_data::<user_regs_struct>( |
| 46 |
ptrace::Request::PTRACE_GETREGS as ptrace::RequestType, |
| 47 |
None, |
| 48 |
nix::unistd::Pid::from_raw(pid), |
| 49 |
) |
| 50 |
} |
| 51 |
|
| 52 |
pub fn get_instruction_pointer(&self) -> usize { |
| 53 |
self.regs.uregs[15] as usize |
| 54 |
} |
| 55 |
|
| 56 |
pub fn fill_cpu_context(&self, out: &mut RawContextCPU) { |
| 57 |
out.context_flags = |
| 58 |
crate::minidump_format::format::ContextFlagsArm::CONTEXT_ARM_FULL.bits(); |
| 59 |
|
| 60 |
out.iregs.copy_from_slice(&self.regs.uregs[..16]); |
| 61 |
out.cpsr = self.regs.uregs[16]; |
| 62 |
out.float_save.fpscr = self.fpregs.fpscr as u64; |
| 63 |
out.float_save.regs = self.fpregs.fpregs; |
| 64 |
} |
| 65 |
|
| 66 |
pub fn create_impl(_pid: Pid, tid: Pid) -> Result<Self> { |
| 67 |
let (ppid, tgid) = Self::get_ppid_and_tgid(tid)?; |
| 68 |
let regs = Self::getregs(tid)?; |
| 69 |
let fpregs = Self::getfpregs(tid).unwrap_or(Default::default()); |
| 70 |
|
| 71 |
let stack_pointer = regs.uregs[13] as usize; |
| 72 |
|
| 73 |
Ok(ThreadInfoArm { |
| 74 |
stack_pointer, |
| 75 |
tgid, |
| 76 |
ppid, |
| 77 |
regs, |
| 78 |
fpregs, |
| 79 |
}) |
| 80 |
} |
| 81 |
} |