2 use slice::from_raw_parts_mut;
5 fn take_debug_panic_buf_ptr() -> *mut u8;
9 pub(crate) struct SgxPanicOutput(Option<&'static mut [u8]>);
12 pub(crate) fn new() -> Option<Self> {
13 if unsafe { DEBUG == 0 } {
16 Some(SgxPanicOutput(None))
20 fn init(&mut self) -> &mut &'static mut [u8] {
21 self.0.get_or_insert_with(|| unsafe {
22 let ptr = take_debug_panic_buf_ptr();
26 from_raw_parts_mut(ptr, 1024)
32 impl Write for SgxPanicOutput {
33 fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
34 self.init().write(buf)
37 fn flush(&mut self) -> io::Result<()> {
43 pub extern "C" fn panic_msg(msg: &str) -> ! {
44 let _ = SgxPanicOutput::new().map(|mut out| out.write(msg.as_bytes()));
45 unsafe { panic_exit(); }
48 extern "C" { pub fn panic_exit() -> !; }