| 1 |
use super::CrashContext; |
| 2 |
use crate::{minidump_cpu::RawContextCPU, minidump_format::format::ContextFlagsX86}; |
| 3 |
use libc::{ |
| 4 |
REG_CS, REG_DS, REG_EAX, REG_EBP, REG_EBX, REG_ECX, REG_EDI, REG_EDX, REG_EFL, REG_EIP, REG_ES, |
| 5 |
REG_ESI, REG_ESP, REG_FS, REG_GS, REG_SS, REG_UESP, |
| 6 |
}; |
| 7 |
impl CrashContext { |
| 8 |
pub fn get_instruction_pointer(&self) -> usize { |
| 9 |
self.inner.context.uc_mcontext.gregs[REG_EIP as usize] as usize |
| 10 |
} |
| 11 |
|
| 12 |
pub fn get_stack_pointer(&self) -> usize { |
| 13 |
self.inner.context.uc_mcontext.gregs[REG_ESP as usize] as usize |
| 14 |
} |
| 15 |
|
| 16 |
pub fn fill_cpu_context(&self, out: &mut RawContextCPU) { |
| 17 |
out.context_flags = ContextFlagsX86::CONTEXT_X86_FULL.bits() |
| 18 |
| ContextFlagsX86::CONTEXT_X86_FLOATING_POINT.bits(); |
| 19 |
|
| 20 |
{ |
| 21 |
let gregs = &self.inner.context.uc_mcontext.gregs; |
| 22 |
out.gs = gregs[REG_GS as usize] as u32; |
| 23 |
out.fs = gregs[REG_FS as usize] as u32; |
| 24 |
out.es = gregs[REG_ES as usize] as u32; |
| 25 |
out.ds = gregs[REG_DS as usize] as u32; |
| 26 |
|
| 27 |
out.edi = gregs[REG_EDI as usize] as u32; |
| 28 |
out.esi = gregs[REG_ESI as usize] as u32; |
| 29 |
out.ebx = gregs[REG_EBX as usize] as u32; |
| 30 |
out.edx = gregs[REG_EDX as usize] as u32; |
| 31 |
out.ecx = gregs[REG_ECX as usize] as u32; |
| 32 |
out.eax = gregs[REG_EAX as usize] as u32; |
| 33 |
|
| 34 |
out.ebp = gregs[REG_EBP as usize] as u32; |
| 35 |
out.eip = gregs[REG_EIP as usize] as u32; |
| 36 |
out.cs = gregs[REG_CS as usize] as u32; |
| 37 |
out.eflags = gregs[REG_EFL as usize] as u32; |
| 38 |
out.esp = gregs[REG_UESP as usize] as u32; |
| 39 |
out.ss = gregs[REG_SS as usize] as u32; |
| 40 |
} |
| 41 |
|
| 42 |
{ |
| 43 |
let fs = &self.inner.float_state; |
| 44 |
let out = &mut out.float_save; |
| 45 |
out.control_word = fs.cw; |
| 46 |
out.status_word = fs.sw; |
| 47 |
out.tag_word = fs.tag; |
| 48 |
out.error_offset = fs.ipoff; |
| 49 |
out.error_selector = fs.cssel; |
| 50 |
out.data_offset = fs.dataoff; |
| 51 |
out.data_selector = fs.datasel; |
| 52 |
|
| 53 |
debug_assert_eq!(fs._st.len() * std::mem::size_of::<libc::_libc_fpreg>(), 80); |
| 54 |
out.register_area.copy_from_slice(unsafe { |
| 55 |
std::slice::from_raw_parts( |
| 56 |
fs._st.as_ptr().cast(), |
| 57 |
fs._st.len() * std::mem::size_of::<libc::_libc_fpreg>(), |
| 58 |
) |
| 59 |
}); |
| 60 |
} |
| 61 |
} |
| 62 |
} |