mc_sgx_panic/
lib.rs

1// Copyright (c) 2022-2023 The MobileCoin Foundation
2
3#![doc = include_str!("../README.md")]
4#![deny(missing_docs, missing_debug_implementations)]
5#![no_std]
6
7#[cfg(not(test))]
8use core::panic::PanicInfo;
9#[cfg(not(test))]
10use mc_sgx_panic_sys::panic_count;
11
12#[cfg(feature = "log")]
13mod log;
14
15#[cfg(not(test))]
16#[panic_handler]
17fn panic(_info: &PanicInfo) -> ! {
18    extern "C" {
19        fn abort() -> !;
20    }
21
22    let panics = panic_count::increase();
23
24    // If we entered the panic handler more than once then we must have panicked
25    // while trying to handle the panic. Fail hard in these instances, nothing
26    // more we can do.
27    if panics > 1 {
28        unsafe { abort() }
29    }
30
31    #[cfg(feature = "log")]
32    log::log_panic_info(_info);
33
34    unsafe { abort() }
35}