Skip to content

Commit

Permalink
Supporting Backtrace crate for x86_64-fortanix-unknown-sgx.
Browse files Browse the repository at this point in the history
1. Backtracing is supported via libunwind which is linked to x86_64-fortanix-unknown-sgx.
2. To reduce enclave TCB size, we do not support symbol resolution for this target.
   We rather, display the offset of each function, which could be resolved later.
  • Loading branch information
Vardhan Thigle committed Jan 10, 2019
1 parent b8d8d94 commit c943c15
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
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, all(target_vendor="fortanix", 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"),
all(target_vendor="fortanix", target_env="sgx")))] {
mod libunwind;
use self::libunwind::trace as trace_imp;
use self::libunwind::Frame as FrameImp;
Expand Down
10 changes: 9 additions & 1 deletion src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,15 @@ 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 = if cfg!(all(target_vendor="fortanix", target_env="sgx")) {
frame.ip().wrapping_offset_from(std::os::fortanix_sgx::mem::image_base() as _) as *const libc::c_void
} else {
frame.ip()
};

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

let symbols = match frame.symbols {
Expand Down
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,15 @@
#![deny(missing_docs)]
#![no_std]

#![feature(cfg_target_vendor)]

#![cfg_attr(all(target_vendor="fortanix", target_env="sgx"), feature(sgx_platform))]
#![cfg_attr(all(target_vendor="fortanix", target_env="sgx"), feature(ptr_wrapping_offset_from))]

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

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

0 comments on commit c943c15

Please sign in to comment.