]> git.proxmox.com Git - rustc.git/blob - vendor/unwinding/src/util.rs
New upstream version 1.76.0+dfsg1
[rustc.git] / vendor / unwinding / src / util.rs
1 use gimli::{EndianSlice, NativeEndian, Pointer};
2
3 pub type StaticSlice = EndianSlice<'static, NativeEndian>;
4
5 pub 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
13 pub 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")]
21 pub use libc::c_int;
22
23 #[cfg(not(feature = "libc"))]
24 #[allow(non_camel_case_types)]
25 pub type c_int = i32;
26
27 #[cfg(all(
28 any(feature = "panic", feature = "panic-handler-dummy"),
29 feature = "libc"
30 ))]
31 pub fn abort() -> ! {
32 unsafe { libc::abort() };
33 }
34
35 #[cfg(all(
36 any(feature = "panic", feature = "panic-handler-dummy"),
37 not(feature = "libc")
38 ))]
39 pub fn abort() -> ! {
40 core::intrinsics::abort();
41 }