From c6bfb07832a6ec5de98e9faba9bebae64a4ee7fc Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Sun, 20 Aug 2023 11:01:04 +0100 Subject: [PATCH] bolts write_minibsod netbsd implementation. (#1428) pretty close to freebsd for the most part. --- libafl_bolts/src/minibsod.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/libafl_bolts/src/minibsod.rs b/libafl_bolts/src/minibsod.rs index 67120d1dbb..a616247ec6 100644 --- a/libafl_bolts/src/minibsod.rs +++ b/libafl_bolts/src/minibsod.rs @@ -630,10 +630,19 @@ fn write_minibsod(writer: &mut BufWriter) -> Result<(), std::io::Er Ok(()) } -#[cfg(target_os = "freebsd")] +#[cfg(any(target_os = "freebsd", target_os = "netbsd"))] fn write_minibsod(writer: &mut BufWriter) -> Result<(), std::io::Error> { let mut s: usize = 0; + #[cfg(target_os = "freebsd")] let arr = &[libc::CTL_KERN, libc::KERN_PROC, libc::KERN_PROC_VMMAP, -1]; + #[cfg(target_os = "netbsd")] + let arr = &[ + libc::CTL_VM, + libc::VM_PROC, + libc::VM_PROC_MAP, + -1, + std::mem::size_of::() as i32, + ]; let mib = arr.as_ptr(); let miblen = arr.len() as u32; if unsafe { @@ -657,7 +666,10 @@ fn write_minibsod(writer: &mut BufWriter) -> Result<(), std::io::Er unsafe { while start < end { let entry = start as *mut u8 as *mut libc::kinfo_vmentry; - let sz = (*entry).kve_structsize; + #[cfg(target_os = "freebsd")] + let sz = (*entry).kve_structsize as usize; + #[cfg(target_os = "netbsd")] + let sz = std::mem::size_of::(); if sz == 0 { break; } @@ -670,7 +682,7 @@ fn write_minibsod(writer: &mut BufWriter) -> Result<(), std::io::Er ); writer.write(&i.into_bytes())?; - start = start + sz as usize; + start = start + sz; } } } else { @@ -779,6 +791,7 @@ fn write_minibsod(writer: &mut BufWriter) -> Result<(), std::io::Er #[cfg(not(any( target_os = "freebsd", target_os = "openbsd", + target_os = "netbsd", target_env = "apple", any(target_os = "linux", target_os = "android"), )))]