From 79fc952f530369a8820790e6e13008de13fd02f2 Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Sat, 29 Oct 2022 08:40:25 +0100 Subject: [PATCH] Add dump_register/write_crash for freebsd arm64 (#870) Co-authored-by: Dominik Maier --- libafl/src/bolts/minibsod.rs | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/libafl/src/bolts/minibsod.rs b/libafl/src/bolts/minibsod.rs index 28721c1e92..7dbc891197 100644 --- a/libafl/src/bolts/minibsod.rs +++ b/libafl/src/bolts/minibsod.rs @@ -97,6 +97,30 @@ pub fn dump_registers( Ok(()) } +/// Write the content of all important registers +#[cfg(all(target_vendor = "freebsd", target_arch = "aarch64"))] +#[allow(clippy::similar_names)] +pub fn dump_registers( + writer: &mut BufWriter, + ucontext: &ucontext_t, +) -> Result<(), std::io::Error> { + let mcontext = unsafe { &*ucontext.uc_mcontext }; + for reg in 0..29_u8 { + writeln!( + writer, + "x{:02}: 0x{:016x} ", + reg, mcontext.mc_gpregs.gp_x[reg as usize] + )?; + if reg % 4 == 3 { + writeln!(writer)?; + } + } + write!(writer, "lr: 0x{:016x} ", mcontext.mc_gpregs.gp_lr)?; + write!(writer, "sp: 0x{:016x} ", mcontext.mc_gpregs.gp_sp)?; + + Ok(()) +} + /// Write the content of all important registers #[cfg(all(target_vendor = "apple", target_arch = "aarch64"))] #[allow(clippy::similar_names)] @@ -394,6 +418,21 @@ fn write_crash( Ok(()) } +#[cfg(all(target_os = "freebsd", target_arch = "aarch64"))] +fn write_crash( + writer: &mut BufWriter, + signal: Signal, + ucontext: &ucontext_t, +) -> Result<(), std::io::Error> { + writeln!( + writer, + "Received signal {} at 0x{:016x}", + signal, ucontext.uc_mcontext.mc_gpregs.gp_elr + )?; + + Ok(()) +} + #[cfg(all(target_vendor = "apple", target_arch = "aarch64"))] #[allow(clippy::similar_names)] fn write_crash(