unwinding/
util.rs

1use gimli::{EndianSlice, NativeEndian, Pointer};
2
3pub type StaticSlice = EndianSlice<'static, NativeEndian>;
4
5pub unsafe fn get_unlimited_slice<'a>(start: *const u8) -> &'a [u8] {
6    // Create the largest possible slice for this address.
7    let start = start as usize;
8    let end = start.saturating_add(isize::MAX as _);
9    let len = end - start;
10    unsafe { core::slice::from_raw_parts(start as *const _, len) }
11}
12
13pub unsafe fn deref_pointer(ptr: Pointer) -> usize {
14    match ptr {
15        Pointer::Direct(x) => x as _,
16        Pointer::Indirect(x) => unsafe { *(x as *const _) },
17    }
18}
19
20#[cfg(feature = "libc")]
21pub use libc::c_int;
22
23#[cfg(not(feature = "libc"))]
24#[allow(non_camel_case_types)]
25pub type c_int = i32;
26
27#[cfg(all(
28    any(feature = "panic", feature = "panic-handler-dummy"),
29    feature = "libc"
30))]
31pub fn abort() -> ! {
32    unsafe { libc::abort() };
33}
34
35#[cfg(all(
36    any(feature = "panic", feature = "panic-handler-dummy"),
37    not(feature = "libc")
38))]
39pub fn abort() -> ! {
40    core::intrinsics::abort();
41}