aboutsummaryrefslogtreecommitdiff
path: root/ctr-std/src/sys/cloudabi/backtrace.rs
diff options
context:
space:
mode:
authorVivian Lim <[email protected]>2021-02-06 22:11:59 -0800
committerVivian Lim <[email protected]>2021-02-06 22:11:59 -0800
commit64423f0e34cc4a7d78c15b345b3b8f58243d8286 (patch)
treecc20e2e7f0fc35abf470e20e61d3d48f0d954f3b /ctr-std/src/sys/cloudabi/backtrace.rs
parentSupport libctru 2.0 (diff)
downloadarchived-ctru-rs-64423f0e34cc4a7d78c15b345b3b8f58243d8286.tar.xz
archived-ctru-rs-64423f0e34cc4a7d78c15b345b3b8f58243d8286.zip
Delete ctr-std to use my fork of the rust repo instead
Diffstat (limited to 'ctr-std/src/sys/cloudabi/backtrace.rs')
-rw-r--r--ctr-std/src/sys/cloudabi/backtrace.rs124
1 files changed, 0 insertions, 124 deletions
diff --git a/ctr-std/src/sys/cloudabi/backtrace.rs b/ctr-std/src/sys/cloudabi/backtrace.rs
deleted file mode 100644
index 2c43b59..0000000
--- a/ctr-std/src/sys/cloudabi/backtrace.rs
+++ /dev/null
@@ -1,124 +0,0 @@
-// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use error::Error;
-use ffi::CStr;
-use intrinsics;
-use io;
-use libc;
-use sys_common::backtrace::Frame;
-use unwind as uw;
-
-pub struct BacktraceContext;
-
-struct Context<'a> {
- idx: usize,
- frames: &'a mut [Frame],
-}
-
-#[derive(Debug)]
-struct UnwindError(uw::_Unwind_Reason_Code);
-
-impl Error for UnwindError {
- fn description(&self) -> &'static str {
- "unexpected return value while unwinding"
- }
-}
-
-impl ::fmt::Display for UnwindError {
- fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
- write!(f, "{}: {:?}", self.description(), self.0)
- }
-}
-
-#[inline(never)] // if we know this is a function call, we can skip it when
- // tracing
-pub fn unwind_backtrace(frames: &mut [Frame]) -> io::Result<(usize, BacktraceContext)> {
- let mut cx = Context { idx: 0, frames };
- let result_unwind =
- unsafe { uw::_Unwind_Backtrace(trace_fn, &mut cx as *mut Context as *mut libc::c_void) };
- // See libunwind:src/unwind/Backtrace.c for the return values.
- // No, there is no doc.
- match result_unwind {
- // These return codes seem to be benign and need to be ignored for backtraces
- // to show up properly on all tested platforms.
- uw::_URC_END_OF_STACK | uw::_URC_FATAL_PHASE1_ERROR | uw::_URC_FAILURE => {
- Ok((cx.idx, BacktraceContext))
- }
- _ => Err(io::Error::new(
- io::ErrorKind::Other,
- UnwindError(result_unwind),
- )),
- }
-}
-
-extern "C" fn trace_fn(
- ctx: *mut uw::_Unwind_Context,
- arg: *mut libc::c_void,
-) -> uw::_Unwind_Reason_Code {
- let cx = unsafe { &mut *(arg as *mut Context) };
- if cx.idx >= cx.frames.len() {
- return uw::_URC_NORMAL_STOP;
- }
-
- let mut ip_before_insn = 0;
- let mut ip = unsafe { uw::_Unwind_GetIPInfo(ctx, &mut ip_before_insn) as *mut libc::c_void };
- if !ip.is_null() && ip_before_insn == 0 {
- // this is a non-signaling frame, so `ip` refers to the address
- // after the calling instruction. account for that.
- ip = (ip as usize - 1) as *mut _;
- }
-
- let symaddr = unsafe { uw::_Unwind_FindEnclosingFunction(ip) };
- cx.frames[cx.idx] = Frame {
- symbol_addr: symaddr as *mut u8,
- exact_position: ip as *mut u8,
- inline_context: 0,
- };
- cx.idx += 1;
-
- uw::_URC_NO_REASON
-}
-
-pub fn foreach_symbol_fileline<F>(_: Frame, _: F, _: &BacktraceContext) -> io::Result<bool>
-where
- F: FnMut(&[u8], u32) -> io::Result<()>,
-{
- // No way to obtain this information on CloudABI.
- Ok(false)
-}
-
-pub fn resolve_symname<F>(frame: Frame, callback: F, _: &BacktraceContext) -> io::Result<()>
-where
- F: FnOnce(Option<&str>) -> io::Result<()>,
-{
- unsafe {
- let mut info: Dl_info = intrinsics::init();
- let symname =
- if dladdr(frame.exact_position as *mut _, &mut info) == 0 || info.dli_sname.is_null() {
- None
- } else {
- CStr::from_ptr(info.dli_sname).to_str().ok()
- };
- callback(symname)
- }
-}
-
-#[repr(C)]
-struct Dl_info {
- dli_fname: *const libc::c_char,
- dli_fbase: *mut libc::c_void,
- dli_sname: *const libc::c_char,
- dli_saddr: *mut libc::c_void,
-}
-
-extern "C" {
- fn dladdr(addr: *const libc::c_void, info: *mut Dl_info) -> libc::c_int;
-}