1pub type UnwContext = libc::ucontext_t;
5
6pub type UnwWord = u64;
7
8#[repr(C)]
10#[derive(Debug, Copy, Clone)]
11pub struct UnwCursor {
12 pub opaque: [UnwWord; 250],
13}
14
15extern "C" {
16 #[link_name = "_ULaarch64_init_local2"]
17 pub fn unw_init_local2(cursor: *mut UnwCursor, context: *mut UnwContext, flag: i32) -> i32;
18 #[link_name = "_ULaarch64_step"]
19 pub fn unw_step(cursor: *mut UnwCursor) -> i32;
20 #[link_name = "_ULaarch64_get_reg"]
21 pub fn unw_get_reg(cursor: *mut UnwCursor, reg: i32, valp: *mut UnwWord) -> i32;
22 #[link_name = "_ULaarch64_get_proc_name"]
23 pub fn unw_get_proc_name(
24 cursor: *mut UnwCursor,
25 name: *mut libc::c_char,
26 len: usize,
27 offset: *mut u64,
28 ) -> i32;
29 #[link_name = "unw_backtrace2"]
30 pub fn unw_backtrace2(
31 buffer: *mut *mut ::std::os::raw::c_void,
32 size: i32,
33 context: *mut UnwContext,
34 flag: i32,
35 ) -> i32;
36}
37
38pub const UNW_REG_IP: i32 = 30; pub const UNW_REG_SP: i32 = 31; pub const UNW_REG_FP: i32 = 29; pub const UNW_INIT_LOCAL_ONLY_IP: i32 = 1;
42
43#[cfg(test)]
52#[inline(always)]
53pub unsafe fn getcontext(context: *mut UnwContext) -> i32 {
54 let base = core::ptr::addr_of_mut!((*context).uc_mcontext.regs) as u64;
55 let ret: u64;
56 core::arch::asm!(
57 "stp x0, x1, [x0, #0]",
58 "stp x2, x3, [x0, #16]",
59 "stp x4, x5, [x0, #32]",
60 "stp x6, x7, [x0, #48]",
61 "stp x8, x9, [x0, #64]",
62 "stp x10, x11, [x0, #80]",
63 "stp x12, x13, [x0, #96]",
64 "stp x14, x15, [x0, #112]",
65 "stp x16, x17, [x0, #128]",
66 "stp x18, x19, [x0, #144]",
67 "stp x20, x21, [x0, #160]",
68 "stp x22, x23, [x0, #176]",
69 "stp x24, x25, [x0, #192]",
70 "stp x26, x27, [x0, #208]",
71 "stp x28, x29, [x0, #224]",
72 "mov x1, sp",
73 "stp x30, x1, [x0, #240]",
74 "adr x1, 2f",
75 "str x1, [x0, #256]",
76 "mov x0, #0",
77 "2:",
78 inout("x0") base => ret,
79 out("x1") _,
80 options(nostack, preserves_flags),
81 );
82 ret as i32
83}