diff options
Diffstat (limited to 'vendor/unwinding/src/util.rs')
-rw-r--r-- | vendor/unwinding/src/util.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/vendor/unwinding/src/util.rs b/vendor/unwinding/src/util.rs new file mode 100644 index 000000000..7c66e81fa --- /dev/null +++ b/vendor/unwinding/src/util.rs @@ -0,0 +1,41 @@ +use gimli::{EndianSlice, NativeEndian, Pointer}; + +pub type StaticSlice = EndianSlice<'static, NativeEndian>; + +pub unsafe fn get_unlimited_slice<'a>(start: *const u8) -> &'a [u8] { + // Create the largest possible slice for this address. + let start = start as usize; + let end = start.saturating_add(isize::MAX as _); + let len = end - start; + unsafe { core::slice::from_raw_parts(start as *const _, len) } +} + +pub unsafe fn deref_pointer(ptr: Pointer) -> usize { + match ptr { + Pointer::Direct(x) => x as _, + Pointer::Indirect(x) => unsafe { *(x as *const _) }, + } +} + +#[cfg(feature = "libc")] +pub use libc::c_int; + +#[cfg(not(feature = "libc"))] +#[allow(non_camel_case_types)] +pub type c_int = i32; + +#[cfg(all( + any(feature = "panic", feature = "panic-handler-dummy"), + feature = "libc" +))] +pub fn abort() -> ! { + unsafe { libc::abort() }; +} + +#[cfg(all( + any(feature = "panic", feature = "panic-handler-dummy"), + not(feature = "libc") +))] +pub fn abort() -> ! { + core::intrinsics::abort(); +} |