Add unwind ABI defs

This commit is contained in:
Gary Guo 2021-08-26 02:02:13 +01:00
parent 61275d40b8
commit 69f47111a0
3 changed files with 69 additions and 1 deletions

65
src/abi.rs Normal file
View File

@ -0,0 +1,65 @@
use libc::{c_int, c_void};
use crate::frame::Frame;
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct UnwindReasonCode(c_int);
#[allow(unused)]
impl UnwindReasonCode {
pub const NO_REASON: Self = Self(0);
pub const FOREIGN_EXCEPTION_CAUGHT: Self = Self(1);
pub const FATAL_PHASE2_ERROR: Self = Self(2);
pub const FATAL_PHASE1_ERROR: Self = Self(3);
pub const NORMAL_STOP: Self = Self(4);
pub const END_OF_STACK: Self = Self(5);
pub const HANDLER_FOUND: Self = Self(6);
pub const INSTALL_CONTEXT: Self = Self(7);
pub const CONTINUE_UNWIND: Self = Self(8);
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct UnwindAction(c_int);
#[allow(unused)]
impl UnwindAction {
pub const SEARCH_PHASE: Self = Self(1);
pub const CLEANUP_PHASE: Self = Self(2);
pub const HANDLER_FRAME: Self = Self(4);
pub const FORCE_UNWIND: Self = Self(8);
pub const END_OF_STACK: Self = Self(16);
}
pub type UnwindExceptionCleanupFn = extern "C" fn(UnwindReasonCode, *mut UnwindException);
pub type UnwindStopFn = extern "C" fn(
c_int,
UnwindAction,
u64,
*mut UnwindException,
*mut UnwindContext<'_>,
*mut c_void,
);
#[repr(C)]
pub struct UnwindException {
pub exception_class: u64,
pub exception_cleanup: Option<UnwindExceptionCleanupFn>,
}
pub type UnwindTraceFn =
extern "C" fn(ctx: &mut UnwindContext<'_>, arg: *mut c_void) -> UnwindReasonCode;
pub struct UnwindContext<'a> {
frame: &'a Frame,
}
pub type PersonalityRoutine = extern "C" fn(
c_int,
UnwindAction,
u64,
*mut UnwindException,
*mut UnwindContext<'_>,
) -> UnwindReasonCode;

View File

@ -6,6 +6,7 @@ use gimli::{
use crate::arch::*;
use crate::find_fde::{self, FDEFinder, FDESearchResult};
use crate::util::*;
use crate::abi::PersonalityRoutine;
#[derive(Debug)]
pub struct Frame {
@ -121,11 +122,12 @@ impl Frame {
&self.fde_result.bases
}
pub fn personality(&self) -> Option<usize> {
pub fn personality(&self) -> Option<PersonalityRoutine> {
self.fde_result
.fde
.personality()
.map(|x| unsafe { deref_pointer(x) })
.map(|x| unsafe { core::mem::transmute(x) })
}
pub fn lsda(&self) -> usize {

View File

@ -4,6 +4,7 @@
#![warn(rust_2018_idioms)]
#![warn(unsafe_op_in_unsafe_fn)]
mod abi;
mod arch;
mod find_fde;
mod frame;