unwind_sys/
lib.rs

1#![doc(html_root_url = "https://sfackler.github.io/rstack/doc")]
2#![allow(bad_style, improper_ctypes)] // x86_64 libunwind has empty structs before 1.2
3use libc::{c_char, c_int, c_void, size_t};
4
5pub use crate::native::*;
6#[cfg(feature = "ptrace")]
7pub use crate::ptrace::*;
8
9#[macro_use]
10mod macros;
11
12#[cfg_attr(target_arch = "x86", path = "x86.rs")]
13#[cfg_attr(target_arch = "x86_64", path = "x86_64.rs")]
14#[cfg_attr(target_arch = "aarch64", path = "aarch64.rs")]
15mod native;
16
17#[cfg(feature = "ptrace")]
18mod ptrace;
19
20pub const UNW_ESUCCESS: c_int = 0;
21pub const UNW_EUNSPEC: c_int = 1;
22pub const UNW_ENOMEM: c_int = 2;
23pub const UNW_EBADREG: c_int = 3;
24pub const UNW_EREADONLYREG: c_int = 4;
25pub const UNW_ESTOPUNWIND: c_int = 5;
26pub const UNW_EINVALIDIP: c_int = 6;
27pub const UNW_EBADFRAME: c_int = 7;
28pub const UNW_EINVAL: c_int = 8;
29pub const UNW_EBADVERSION: c_int = 9;
30pub const UNW_ENOINFO: c_int = 10;
31
32pub type unw_regnum_t = c_int;
33
34pub enum unw_addr_space {}
35pub type unw_addr_space_t = *mut unw_addr_space;
36
37#[repr(C)]
38pub enum unw_caching_policy_t {
39    UNW_CACHE_NONE,
40    UNW_CACHE_GLOBAL,
41    UNW_CACHE_PER_THREAD,
42}
43
44#[repr(C)]
45pub enum unw_save_loc_type_t {
46    UNW_SLT_NONE,
47    UNW_SLT_MEMORY,
48    UNW_SLT_REG,
49}
50
51#[repr(C)]
52#[derive(Copy, Clone)]
53pub struct unw_cursor_t {
54    pub opaque: [unw_word_t; UNW_TDEP_CURSOR_LEN as usize],
55}
56
57pub type unw_context_t = unw_tdep_context_t;
58
59#[repr(C)]
60#[derive(Copy, Clone)]
61pub struct unw_proc_info_t {
62    pub start_ip: unw_word_t,
63    pub end_ip: unw_word_t,
64    pub lsda: unw_word_t,
65    pub handler: unw_word_t,
66    pub gp: unw_word_t,
67    pub flags: unw_word_t,
68    pub format: c_int,
69    pub unwind_info_size: c_int,
70    pub unwind_info: *mut c_void,
71    pub extra: unw_tdep_proc_info_t,
72}
73
74#[repr(C)]
75pub struct unw_accessors_t {
76    pub find_proc_info: Option<
77        unsafe extern "C" fn(
78            asp: unw_addr_space_t,
79            ip: unw_word_t,
80            pip: *mut unw_proc_info_t,
81            need_unwind_info: c_int,
82            arg: *mut c_void,
83        ) -> c_int,
84    >,
85    pub put_unwind_info: Option<
86        unsafe extern "C" fn(
87            asp: unw_addr_space_t,
88            pip: *mut unw_proc_info_t,
89            arg: *mut c_void,
90        ) -> c_void,
91    >,
92    pub get_dyn_info_list_addr: Option<
93        unsafe extern "C" fn(
94            asp: unw_addr_space_t,
95            dilap: *mut unw_word_t,
96            arg: *mut c_void,
97        ) -> c_int,
98    >,
99    pub access_mem: Option<
100        unsafe extern "C" fn(
101            asp: unw_addr_space_t,
102            addr: unw_word_t,
103            valp: *mut unw_word_t,
104            write: c_int,
105            arg: *mut c_void,
106        ) -> c_int,
107    >,
108    pub access_reg: Option<
109        unsafe extern "C" fn(
110            asp: unw_addr_space_t,
111            regnum: unw_regnum_t,
112            valp: *mut unw_word_t,
113            write: c_int,
114            arg: *mut c_void,
115        ) -> c_int,
116    >,
117    // unw_fpreg_t is a long double :(
118    access_fpreg: Option<unsafe extern "C" fn()>,
119    pub resume: Option<
120        unsafe extern "C" fn(
121            asp: unw_addr_space_t,
122            cp: *mut unw_cursor_t,
123            arg: *mut c_void,
124        ) -> c_int,
125    >,
126    pub get_proc_name: Option<
127        unsafe extern "C" fn(
128            asp: unw_addr_space_t,
129            addr: unw_word_t,
130            bufp: *mut c_char,
131            buf_len: size_t,
132            offp: *mut unw_word_t,
133            arg: *mut c_void,
134        ) -> c_int,
135    >,
136}
137
138#[repr(C)]
139pub union unw_save_loc_t_u {
140    pub addr: unw_word_t,
141    pub regnum: unw_regnum_t,
142}
143
144#[repr(C)]
145pub struct unw_save_loc_t {
146    pub type_: unw_save_loc_type_t,
147    pub u: unw_save_loc_t_u,
148    pub extra: unw_tdep_save_loc_t,
149}
150
151pub const UNW_REG_IP: c_int = UNW_TDEP_IP;
152pub const UNW_REG_SP: c_int = UNW_TDEP_SP;
153pub const UNW_REG_EH: c_int = UNW_TDEP_EH;
154pub const UNW_REG_LAST: c_int = UNW_TDEP_LAST_REG;