minibsod, fix clippy warning (#1424)
This commit is contained in:
parent
0be4847cb7
commit
bc42880274
@ -620,33 +620,18 @@ fn write_crash<W: Write>(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generates a mini-BSOD given a signal and context.
|
|
||||||
#[cfg(unix)]
|
|
||||||
#[allow(clippy::non_ascii_literal)]
|
|
||||||
pub fn generate_minibsod<W: Write>(
|
|
||||||
writer: &mut BufWriter<W>,
|
|
||||||
signal: Signal,
|
|
||||||
_siginfo: siginfo_t,
|
|
||||||
ucontext: &ucontext_t,
|
|
||||||
) -> Result<(), std::io::Error> {
|
|
||||||
writeln!(writer, "{:━^100}", " CRASH ")?;
|
|
||||||
write_crash(writer, signal, ucontext)?;
|
|
||||||
writeln!(writer, "{:━^100}", " REGISTERS ")?;
|
|
||||||
dump_registers(writer, ucontext)?;
|
|
||||||
writeln!(writer, "{:━^100}", " BACKTRACE ")?;
|
|
||||||
writeln!(writer, "{:?}", backtrace::Backtrace::new())?;
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
{
|
fn write_minibsod<W: Write>(writer: &mut BufWriter<W>) -> Result<(), std::io::Error> {
|
||||||
writeln!(writer, "{:━^100}", " MAPS ")?;
|
|
||||||
|
|
||||||
match std::fs::read_to_string("/proc/self/maps") {
|
match std::fs::read_to_string("/proc/self/maps") {
|
||||||
Ok(maps) => writer.write_all(maps.as_bytes())?,
|
Ok(maps) => writer.write_all(maps.as_bytes())?,
|
||||||
Err(e) => writeln!(writer, "Couldn't load mappings: {e:?}")?,
|
Err(e) => writeln!(writer, "Couldn't load mappings: {e:?}")?,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "freebsd")]
|
#[cfg(target_os = "freebsd")]
|
||||||
{
|
fn write_minibsod<W: Write>(writer: &mut BufWriter<W>) -> Result<(), std::io::Error> {
|
||||||
let mut s: usize = 0;
|
let mut s: usize = 0;
|
||||||
let arr = &[libc::CTL_KERN, libc::KERN_PROC, libc::KERN_PROC_VMMAP, -1];
|
let arr = &[libc::CTL_KERN, libc::KERN_PROC, libc::KERN_PROC_VMMAP, -1];
|
||||||
let mib = arr.as_ptr();
|
let mib = arr.as_ptr();
|
||||||
@ -694,10 +679,12 @@ pub fn generate_minibsod<W: Write>(
|
|||||||
} else {
|
} else {
|
||||||
return Err(std::io::Error::last_os_error());
|
return Err(std::io::Error::last_os_error());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "openbsd")]
|
#[cfg(target_os = "openbsd")]
|
||||||
{
|
fn write_minibsod<W: Write>(writer: &mut BufWriter<W>) -> Result<(), std::io::Error> {
|
||||||
let mut pentry = std::mem::MaybeUninit::<libc::kinfo_vmentry>::uninit();
|
let mut pentry = std::mem::MaybeUninit::<libc::kinfo_vmentry>::uninit();
|
||||||
let mut s = std::mem::size_of::<libc::kinfo_vmentry>();
|
let mut s = std::mem::size_of::<libc::kinfo_vmentry>();
|
||||||
let arr = &[libc::CTL_KERN, libc::KERN_PROC_VMMAP, unsafe {
|
let arr = &[libc::CTL_KERN, libc::KERN_PROC_VMMAP, unsafe {
|
||||||
@ -741,11 +728,41 @@ pub fn generate_minibsod<W: Write>(
|
|||||||
} else {
|
} else {
|
||||||
return Err(std::io::Error::last_os_error());
|
return Err(std::io::Error::last_os_error());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(any(
|
||||||
|
target_os = "freebsd",
|
||||||
|
target_os = "openbsd",
|
||||||
|
any(target_os = "linux", target_os = "android"),
|
||||||
|
)))]
|
||||||
|
fn write_minibsod<W: Write>(writer: &mut BufWriter<W>) -> Result<(), std::io::Error> {
|
||||||
|
// TODO for other platforms
|
||||||
|
// Note that for apple, types might not be entirely mapped in libc due to mach crate.
|
||||||
|
writeln!(writer, "{:━^100}", " / ")?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Generates a mini-BSOD given a signal and context.
|
||||||
|
#[cfg(unix)]
|
||||||
|
#[allow(clippy::non_ascii_literal)]
|
||||||
|
pub fn generate_minibsod<W: Write>(
|
||||||
|
writer: &mut BufWriter<W>,
|
||||||
|
signal: Signal,
|
||||||
|
_siginfo: siginfo_t,
|
||||||
|
ucontext: &ucontext_t,
|
||||||
|
) -> Result<(), std::io::Error> {
|
||||||
|
writeln!(writer, "{:━^100}", " CRASH ")?;
|
||||||
|
write_crash(writer, signal, ucontext)?;
|
||||||
|
writeln!(writer, "{:━^100}", " REGISTERS ")?;
|
||||||
|
dump_registers(writer, ucontext)?;
|
||||||
|
writeln!(writer, "{:━^100}", " BACKTRACE ")?;
|
||||||
|
writeln!(writer, "{:?}", backtrace::Backtrace::new())?;
|
||||||
|
writeln!(writer, "{:━^100}", " MAPS ")?;
|
||||||
|
write_minibsod(writer)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user