Skip to content

Commit 3804dac

Browse files
dingelishalexcrichton
authored andcommitted
Bound target_env = sgx with target_vendor = fortanix (#266)
* Bound target_env = sgx with target_vendor = fortanix * cargo fmt
1 parent d4bc045 commit 3804dac

File tree

6 files changed

+79
-66
lines changed

6 files changed

+79
-66
lines changed

src/backtrace/dbghelp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
2222
#![allow(bad_style)]
2323

24-
use core::ffi::c_void;
25-
use core::mem;
2624
use crate::dbghelp;
2725
use crate::windows::*;
26+
use core::ffi::c_void;
27+
use core::mem;
2828

2929
#[derive(Clone, Copy)]
3030
pub enum Frame {

src/backtrace/libunwind.rs

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ impl Frame {
4848
Frame::Raw(ctx) => ctx,
4949
Frame::Cloned { ip, .. } => return ip,
5050
};
51-
unsafe {
52-
uw::_Unwind_GetIP(ctx) as *mut c_void
53-
}
51+
unsafe { uw::_Unwind_GetIP(ctx) as *mut c_void }
5452
}
5553

5654
pub fn symbol_address(&self) -> *mut c_void {
@@ -87,8 +85,10 @@ impl Clone for Frame {
8785
pub unsafe fn trace(mut cb: &mut FnMut(&super::Frame) -> bool) {
8886
uw::_Unwind_Backtrace(trace_fn, &mut cb as *mut _ as *mut _);
8987

90-
extern fn trace_fn(ctx: *mut uw::_Unwind_Context,
91-
arg: *mut c_void) -> uw::_Unwind_Reason_Code {
88+
extern "C" fn trace_fn(
89+
ctx: *mut uw::_Unwind_Context,
90+
arg: *mut c_void,
91+
) -> uw::_Unwind_Reason_Code {
9292
let cb = unsafe { &mut *(arg as *mut &mut FnMut(&super::Frame) -> bool) };
9393
let cx = super::Frame {
9494
inner: Frame::Raw(ctx),
@@ -136,36 +136,40 @@ mod uw {
136136
pub enum _Unwind_Context {}
137137

138138
pub type _Unwind_Trace_Fn =
139-
extern fn(ctx: *mut _Unwind_Context,
140-
arg: *mut c_void) -> _Unwind_Reason_Code;
139+
extern "C" fn(ctx: *mut _Unwind_Context, arg: *mut c_void) -> _Unwind_Reason_Code;
141140

142-
extern {
141+
extern "C" {
143142
// No native _Unwind_Backtrace on iOS
144143
#[cfg(not(all(target_os = "ios", target_arch = "arm")))]
145-
pub fn _Unwind_Backtrace(trace: _Unwind_Trace_Fn,
146-
trace_argument: *mut c_void)
147-
-> _Unwind_Reason_Code;
144+
pub fn _Unwind_Backtrace(
145+
trace: _Unwind_Trace_Fn,
146+
trace_argument: *mut c_void,
147+
) -> _Unwind_Reason_Code;
148148

149149
// available since GCC 4.2.0, should be fine for our purpose
150-
#[cfg(all(not(all(target_os = "android", target_arch = "arm")),
151-
not(all(target_os = "freebsd", target_arch = "arm")),
152-
not(all(target_os = "linux", target_arch = "arm"))))]
153-
pub fn _Unwind_GetIP(ctx: *mut _Unwind_Context)
154-
-> libc::uintptr_t;
155-
156-
#[cfg(all(not(target_os = "android"),
157-
not(all(target_os = "freebsd", target_arch = "arm")),
158-
not(all(target_os = "linux", target_arch = "arm"))))]
159-
pub fn _Unwind_FindEnclosingFunction(pc: *mut c_void)
160-
-> *mut c_void;
150+
#[cfg(all(
151+
not(all(target_os = "android", target_arch = "arm")),
152+
not(all(target_os = "freebsd", target_arch = "arm")),
153+
not(all(target_os = "linux", target_arch = "arm"))
154+
))]
155+
pub fn _Unwind_GetIP(ctx: *mut _Unwind_Context) -> libc::uintptr_t;
156+
157+
#[cfg(all(
158+
not(target_os = "android"),
159+
not(all(target_os = "freebsd", target_arch = "arm")),
160+
not(all(target_os = "linux", target_arch = "arm"))
161+
))]
162+
pub fn _Unwind_FindEnclosingFunction(pc: *mut c_void) -> *mut c_void;
161163
}
162164

163165
// On android, the function _Unwind_GetIP is a macro, and this is the
164166
// expansion of the macro. This is all copy/pasted directly from the
165167
// header file with the definition of _Unwind_GetIP.
166-
#[cfg(any(all(target_os = "android", target_arch = "arm"),
167-
all(target_os = "freebsd", target_arch = "arm"),
168-
all(target_os = "linux", target_arch = "arm")))]
168+
#[cfg(any(
169+
all(target_os = "android", target_arch = "arm"),
170+
all(target_os = "freebsd", target_arch = "arm"),
171+
all(target_os = "linux", target_arch = "arm")
172+
))]
169173
pub unsafe fn _Unwind_GetIP(ctx: *mut _Unwind_Context) -> libc::uintptr_t {
170174
#[repr(C)]
171175
enum _Unwind_VRS_Result {
@@ -192,33 +196,36 @@ mod uw {
192196
}
193197

194198
type _Unwind_Word = libc::c_uint;
195-
extern {
196-
fn _Unwind_VRS_Get(ctx: *mut _Unwind_Context,
197-
klass: _Unwind_VRS_RegClass,
198-
word: _Unwind_Word,
199-
repr: _Unwind_VRS_DataRepresentation,
200-
data: *mut c_void)
201-
-> _Unwind_VRS_Result;
199+
extern "C" {
200+
fn _Unwind_VRS_Get(
201+
ctx: *mut _Unwind_Context,
202+
klass: _Unwind_VRS_RegClass,
203+
word: _Unwind_Word,
204+
repr: _Unwind_VRS_DataRepresentation,
205+
data: *mut c_void,
206+
) -> _Unwind_VRS_Result;
202207
}
203208

204209
let mut val: _Unwind_Word = 0;
205210
let ptr = &mut val as *mut _Unwind_Word;
206-
let _ = _Unwind_VRS_Get(ctx, _Unwind_VRS_RegClass::_UVRSC_CORE, 15,
207-
_Unwind_VRS_DataRepresentation::_UVRSD_UINT32,
208-
ptr as *mut c_void);
211+
let _ = _Unwind_VRS_Get(
212+
ctx,
213+
_Unwind_VRS_RegClass::_UVRSC_CORE,
214+
15,
215+
_Unwind_VRS_DataRepresentation::_UVRSD_UINT32,
216+
ptr as *mut c_void,
217+
);
209218
(val & !1) as libc::uintptr_t
210219
}
211220

212221
// This function also doesn't exist on Android or ARM/Linux, so make it
213222
// a no-op
214-
#[cfg(any(target_os = "android",
215-
all(target_os = "freebsd", target_arch = "arm"),
216-
all(target_os = "linux", target_arch = "arm")))]
217-
pub unsafe fn _Unwind_FindEnclosingFunction(pc: *mut c_void)
218-
-> *mut c_void
219-
{
223+
#[cfg(any(
224+
target_os = "android",
225+
all(target_os = "freebsd", target_arch = "arm"),
226+
all(target_os = "linux", target_arch = "arm")
227+
))]
228+
pub unsafe fn _Unwind_FindEnclosingFunction(pc: *mut c_void) -> *mut c_void {
220229
pc
221230
}
222231
}
223-
224-

src/backtrace/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ cfg_if::cfg_if! {
121121
not(all(target_os = "ios", target_arch = "arm")),
122122
feature = "libunwind",
123123
),
124-
target_env = "sgx",
124+
all(
125+
target_env = "sgx",
126+
target_vendor = "fortanix",
127+
),
125128
)
126129
)] {
127130
mod libunwind;

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@
6565
#![doc(html_root_url = "https://docs.rs/backtrace")]
6666
#![deny(missing_docs)]
6767
#![no_std]
68-
#![cfg_attr(all(feature = "std", target_env = "sgx"), feature(sgx_platform))]
68+
#![cfg_attr(
69+
all(feature = "std", target_env = "sgx", target_vendor = "fortanix"),
70+
feature(sgx_platform)
71+
)]
6972
#![allow(bare_trait_objects)] // TODO: remove when updating to 2018 edition
7073
#![allow(rust_2018_idioms)] // TODO: remove when updating to 2018 edition
7174

src/print.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl BacktraceFrameFmt<'_, '_, '_> {
196196
// To reduce TCB size in Sgx enclave, we do not want to implement symbol
197197
// resolution functionality. Rather, we can print the offset of the
198198
// address here, which could be later mapped to correct function.
199-
#[cfg(all(feature = "std", target_env = "sgx"))]
199+
#[cfg(all(feature = "std", target_env = "sgx", target_vendor = "fortanix"))]
200200
{
201201
let image_base = std::os::fortanix_sgx::mem::image_base();
202202
frame_ip = usize::wrapping_sub(frame_ip as usize, image_base as _) as _;

src/symbolize/libbacktrace.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -38,8 +38,8 @@ extern crate backtrace_sys as bt;
3838
use core::{ptr, slice};
3939
use libc::{self, c_char, c_int, c_void, uintptr_t};
4040

41-
use crate::symbolize::{ResolveWhat, SymbolName};
4241
use crate::symbolize::dladdr;
42+
use crate::symbolize::{ResolveWhat, SymbolName};
4343
use crate::types::BytesOrWideString;
4444

4545
pub enum Symbol<'a> {
@@ -59,22 +59,22 @@ pub enum Symbol<'a> {
5959

6060
impl Symbol<'_> {
6161
pub fn name(&self) -> Option<SymbolName> {
62-
let symbol = |ptr: *const c_char| {
63-
unsafe {
64-
if ptr.is_null() {
65-
None
66-
} else {
67-
let len = libc::strlen(ptr);
68-
Some(SymbolName::new(slice::from_raw_parts(
69-
ptr as *const u8,
70-
len,
71-
)))
72-
}
62+
let symbol = |ptr: *const c_char| unsafe {
63+
if ptr.is_null() {
64+
None
65+
} else {
66+
let len = libc::strlen(ptr);
67+
Some(SymbolName::new(slice::from_raw_parts(
68+
ptr as *const u8,
69+
len,
70+
)))
7371
}
7472
};
7573
match *self {
7674
Symbol::Syminfo { symname, .. } => symbol(symname),
77-
Symbol::Pcinfo { function, symname, .. } => {
75+
Symbol::Pcinfo {
76+
function, symname, ..
77+
} => {
7878
// If possible prefer the `function` name which comes from
7979
// debuginfo and can typically be more accurate for inline
8080
// frames for example. If that's not present though fall back to
@@ -85,7 +85,7 @@ impl Symbol<'_> {
8585
// isntead of `std::panicking::try::do_call`. It's not really
8686
// clear why, but overall the `function` name seems more accurate.
8787
if let Some(sym) = symbol(function) {
88-
return Some(sym)
88+
return Some(sym);
8989
}
9090
symbol(symname)
9191
}
@@ -401,7 +401,7 @@ unsafe fn init_state() -> *mut bt::backtrace_state {
401401
lpExeName: LPSTR,
402402
lpdwSize: PDWORD,
403403
) -> BOOL = mem::transmute(ptrQueryFullProcessImageNameA);
404-
404+
405405
let rc = pfnQueryFullProcessImageNameA(p1, 0, buf.as_mut_ptr(), &mut len);
406406
CloseHandle(p1);
407407

@@ -422,10 +422,10 @@ unsafe fn init_state() -> *mut bt::backtrace_state {
422422
unsafe fn load_filename() -> *const libc::c_char {
423423
use libc;
424424
use core::mem;
425-
425+
426426
const N: usize = libc::VX_RTP_NAME_LENGTH as usize + 1;
427427
static mut BUF: [libc::c_char; N] = [0; N];
428-
428+
429429
let mut rtp_desc : libc::RTP_DESC = mem::zeroed();
430430
if (libc::rtpInfoGet(0, &mut rtp_desc as *mut libc::RTP_DESC) == 0) {
431431
BUF.copy_from_slice(&rtp_desc.pathName);

0 commit comments

Comments
 (0)