Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ gimli = { version = "0.16.0", optional = true }
memmap = { version = "0.7.0", optional = true }
object = { version = "0.9.0", optional = true }

[target.'cfg(unix)'.dependencies]
[target.'cfg(any(unix, target_env = "sgx"))'.dependencies]
libc = { version = "0.2.45", default-features = false }

[target.'cfg(windows)'.dependencies]
Expand Down
5 changes: 3 additions & 2 deletions src/backtrace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ impl fmt::Debug for Frame {
}

cfg_if! {
if #[cfg(all(unix,
if #[cfg(any(all(unix,
not(target_os = "emscripten"),
not(all(target_os = "ios", target_arch = "arm")),
feature = "libunwind"))] {
feature = "libunwind"),
target_env="sgx"))] {
mod libunwind;
use self::libunwind::trace as trace_imp;
use self::libunwind::Frame as FrameImp;
Expand Down
17 changes: 16 additions & 1 deletion src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,22 @@ impl fmt::Debug for Backtrace {
};

for (idx, frame) in iter.enumerate() {
let ip = frame.ip();
// To reduce TCB size in Sgx enclave, we do not want to implement symbol resolution functionality.
// Rather, we can print the offset of the address here, which could be later mapped to
// correct function.
let ip: *mut c_void;
#[cfg(target_env = "sgx")]
{
ip = usize::wrapping_sub(
frame.ip() as _,
std::os::fortanix_sgx::mem::image_base() as _,
) as _;
}
#[cfg(not(target_env = "sgx"))]
{
ip = frame.ip();
}

write!(fmt, "\n{:4}: ", idx)?;

let symbols = match frame.symbols {
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@
#![doc(html_root_url = "https://docs.rs/backtrace")]
#![deny(missing_docs)]
#![no_std]
#![cfg_attr(target_env = "sgx", feature(sgx_platform))]

#[cfg(feature = "std")]
#[macro_use] extern crate std;

#[cfg(unix)]
#[cfg(any(unix, target_env = "sgx"))]
extern crate libc;
#[cfg(windows)]
extern crate winapi;
Expand Down