Skip to content

Commit c915e7a

Browse files
author
Vardhan Thigle
committed
Supporting Backtrace crate for x86_64-fortanix-unknown-sgx.
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.
1 parent b8d8d94 commit c915e7a

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ gimli = { version = "0.16.0", optional = true }
3232
memmap = { version = "0.7.0", optional = true }
3333
object = { version = "0.9.0", optional = true }
3434

35-
[target.'cfg(unix)'.dependencies]
35+
[target.'cfg(any(unix, all(target_vendor="fortanix", target_env="sgx")))'.dependencies]
3636
libc = { version = "0.2.45", default-features = false }
3737

3838
[target.'cfg(windows)'.dependencies]

src/backtrace/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,11 @@ impl fmt::Debug for Frame {
104104
}
105105

106106
cfg_if! {
107-
if #[cfg(all(unix,
107+
if #[cfg(any(all(unix,
108108
not(target_os = "emscripten"),
109109
not(all(target_os = "ios", target_arch = "arm")),
110-
feature = "libunwind"))] {
110+
feature = "libunwind"),
111+
target_env="sgx"))] {
111112
mod libunwind;
112113
use self::libunwind::trace as trace_imp;
113114
use self::libunwind::Frame as FrameImp;

src/capture.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,15 @@ impl fmt::Debug for Backtrace {
229229
};
230230

231231
for (idx, frame) in iter.enumerate() {
232-
let ip = frame.ip();
232+
// To reduce TCB size in Sgx enclave, we do not want to implement symbol resolution functionality.
233+
// Rather, we can print the offset of the address here, which could be later mapped to
234+
// correct function.
235+
let ip = if cfg!(target_env="sgx") {
236+
usize::wrapping_sub(frame.ip() as _, std::os::fortanix_sgx::mem::image_base() as _) as _
237+
} else {
238+
frame.ip()
239+
};
240+
233241
write!(fmt, "\n{:4}: ", idx)?;
234242

235243
let symbols = match frame.symbols {

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@
7272
#![deny(missing_docs)]
7373
#![no_std]
7474

75+
#![cfg_attr(target_env="sgx", feature(sgx_platform))]
76+
7577
#[cfg(feature = "std")]
7678
#[macro_use] extern crate std;
7779

78-
#[cfg(unix)]
80+
#[cfg(any(unix, target_env="sgx"))]
7981
extern crate libc;
8082
#[cfg(windows)]
8183
extern crate winapi;

0 commit comments

Comments
 (0)