Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SGX target: change re-entry abort logic #60027

Merged
merged 1 commit into from
Apr 17, 2019
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
14 changes: 3 additions & 11 deletions src/libstd/sys/sgx/abi/entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ IMAGE_BASE:
/* The size in bytes of enclacve EH_FRM_HDR section */
globvar EH_FRM_HDR_SIZE 8

.Lreentry_panic_msg:
.asciz "Re-entered aborted enclave!"
.Lreentry_panic_msg_end:

.org .Lxsave_clear+512
.Lxsave_header:
.int 0, 0 /* XSTATE_BV */
Expand Down Expand Up @@ -210,10 +206,8 @@ sgx_entry:
/* end sgx_entry */

.Lreentry_panic:
lea .Lreentry_panic_msg(%rip),%rdi
mov $.Lreentry_panic_msg_end-.Lreentry_panic_msg,%esi
orq $8,%rsp
jmp panic_msg
jmp abort_reentry

/* This *MUST* be called with 6 parameters, otherwise register information */
/* might leak! */
Expand Down Expand Up @@ -279,10 +273,8 @@ usercall:
/*
The following functions need to be defined externally:
```
// Called by entry code when it needs to panic
extern "C" fn panic_msg(msg: &'static str) -> ! {
panic!(msg)
}
// Called by entry code on re-entry after exit
extern "C" fn abort_reentry() -> !;

// Called once when a TCS is first entered
extern "C" fn tcs_init(secondary: bool);
Expand Down
8 changes: 7 additions & 1 deletion src/libstd/sys/sgx/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ unsafe extern "C" fn tcs_init(secondary: bool) {
static RELOC_STATE: AtomicUsize = AtomicUsize::new(UNINIT);

if secondary && RELOC_STATE.load(Ordering::Relaxed) != DONE {
panic::panic_msg("Entered secondary TCS before main TCS!")
rtabort!("Entered secondary TCS before main TCS!")
}

// Try to atomically swap UNINIT with BUSY. The returned state can be:
Expand Down Expand Up @@ -92,3 +92,9 @@ pub(super) fn exit_with_code(code: isize) -> ! {
}
usercalls::exit(code != 0);
}

#[cfg(not(test))]
#[no_mangle]
extern "C" fn abort_reentry() -> ! {
usercalls::exit(false)
}
8 changes: 1 addition & 7 deletions src/libstd/sys/sgx/abi/panic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::usercalls::{alloc::UserRef, self};
use super::usercalls::alloc::UserRef;
use crate::cmp;
use crate::io::{self, Write};
use crate::mem;
Expand Down Expand Up @@ -48,9 +48,3 @@ impl Write for SgxPanicOutput {
Ok(())
}
}

#[cfg_attr(not(test), no_mangle)]
pub extern "C" fn panic_msg(msg: &str) -> ! {
let _ = SgxPanicOutput::new().map(|mut out| out.write(msg.as_bytes()));
usercalls::exit(true)
}