make dump_registers method public (#367)
* make dump_registers method public * be smart about getting the ucontext * more docu
This commit is contained in:
parent
a80126681e
commit
8ec8be1ce5
@ -1,12 +1,16 @@
|
||||
//! Implements a mini-bsod generator
|
||||
//! It dumps all important registers and prints a stacktrace.
|
||||
//! You may use the [`crate::bolts::os::unix_signals::ucontext`]
|
||||
//! function to get a [`ucontext_t`].
|
||||
|
||||
use libc::siginfo_t;
|
||||
use std::io::{BufWriter, Write};
|
||||
|
||||
use crate::bolts::os::unix_signals::{ucontext_t, Signal};
|
||||
|
||||
/// Write the contens of all important registers
|
||||
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
|
||||
fn dump_registers<W: Write>(
|
||||
pub fn dump_registers<W: Write>(
|
||||
writer: &mut BufWriter<W>,
|
||||
ucontext: &ucontext_t,
|
||||
) -> Result<(), std::io::Error> {
|
||||
@ -39,11 +43,12 @@ fn dump_registers<W: Write>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Write the contens of all important registers
|
||||
#[cfg(all(
|
||||
any(target_os = "linux", target_os = "android"),
|
||||
target_arch = "aarch64"
|
||||
))]
|
||||
fn dump_registers<W: Write>(
|
||||
pub fn dump_registers<W: Write>(
|
||||
writer: &mut BufWriter<W>,
|
||||
ucontext: &ucontext_t,
|
||||
) -> Result<(), std::io::Error> {
|
||||
@ -62,8 +67,9 @@ fn dump_registers<W: Write>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Write the contens of all important registers
|
||||
#[cfg(all(target_vendor = "apple", target_arch = "aarch64"))]
|
||||
fn dump_registers<W: Write>(
|
||||
pub fn dump_registers<W: Write>(
|
||||
writer: &mut BufWriter<W>,
|
||||
ucontext: &ucontext_t,
|
||||
) -> Result<(), std::io::Error> {
|
||||
@ -85,9 +91,10 @@ fn dump_registers<W: Write>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Write the contens of all important registers
|
||||
#[allow(clippy::unnecessary_wraps, clippy::similar_names)]
|
||||
#[cfg(all(target_vendor = "apple", target_arch = "x86_64"))]
|
||||
fn dump_registers<W: Write>(
|
||||
pub fn dump_registers<W: Write>(
|
||||
writer: &mut BufWriter<W>,
|
||||
ucontext: &ucontext_t,
|
||||
) -> Result<(), std::io::Error> {
|
||||
|
@ -3,9 +3,7 @@ use alloc::vec::Vec;
|
||||
use core::{
|
||||
cell::UnsafeCell,
|
||||
fmt::{self, Display, Formatter},
|
||||
mem,
|
||||
mem::MaybeUninit,
|
||||
ptr,
|
||||
mem, ptr,
|
||||
ptr::write_volatile,
|
||||
sync::atomic::{compiler_fence, Ordering},
|
||||
};
|
||||
@ -244,11 +242,15 @@ pub unsafe fn setup_signal_handler<T: 'static + Handler>(handler: &mut T) -> Res
|
||||
|
||||
/// Function to get the current [`ucontext_t`] for this process.
|
||||
/// This calls the libc `getcontext` function under the hood.
|
||||
/// It can be useful, for example for `dump_regs`.
|
||||
/// Note that calling this method may, of course, alter the state.
|
||||
/// We wrap it here, as it seems to be (currently)
|
||||
/// not available on `MacOS` in the `libc` crate.
|
||||
#[cfg(unix)]
|
||||
#[allow(clippy::inline_always)] // we assume that inlining will destroy less state
|
||||
#[inline(always)]
|
||||
pub fn ucontext() -> Result<ucontext_t, Error> {
|
||||
let mut ucontext = unsafe { MaybeUninit::zeroed().assume_init() };
|
||||
let mut ucontext = unsafe { mem::zeroed() };
|
||||
if unsafe { getcontext(&mut ucontext) } == 0 {
|
||||
Ok(ucontext)
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user