1 use super::usercalls::{alloc::UserRef, self};
7 fn take_debug_panic_buf_ptr() -> *mut u8;
11 pub(crate) struct SgxPanicOutput(Option<&'static mut UserRef<[u8]>>);
13 fn empty_user_slice() -> &'static mut UserRef<[u8]> {
14 unsafe { UserRef::from_raw_parts_mut(1 as *mut u8, 0) }
18 pub(crate) fn new() -> Option<Self> {
19 if unsafe { DEBUG == 0 } {
22 Some(SgxPanicOutput(None))
26 fn init(&mut self) -> &mut &'static mut UserRef<[u8]> {
27 self.0.get_or_insert_with(|| unsafe {
28 let ptr = take_debug_panic_buf_ptr();
32 UserRef::from_raw_parts_mut(ptr, 1024)
38 impl Write for SgxPanicOutput {
39 fn write(&mut self, src: &[u8]) -> io::Result<usize> {
40 let dst = mem::replace(self.init(), empty_user_slice());
41 let written = cmp::min(src.len(), dst.len());
42 dst[..written].copy_from_enclave(&src[..written]);
43 self.0 = Some(&mut dst[written..]);
47 fn flush(&mut self) -> io::Result<()> {
53 pub extern "C" fn panic_msg(msg: &str) -> ! {
54 let _ = SgxPanicOutput::new().map(|mut out| out.write(msg.as_bytes()));