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

Prevent recursive panics from happening #50

Merged
merged 1 commit into from
Feb 1, 2023
Merged
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
5 changes: 3 additions & 2 deletions panic/Cargo.toml
Original file line number Diff line number Diff line change
@@ -15,5 +15,6 @@ keywords = ["sgx", "no-std", "panic"]
log = ["dep:mc-sgx-io", "dep:mc-sgx-sync"]

[dependencies]
mc-sgx-io = { path = "../io", version = "0.1.0", optional = true }
mc-sgx-sync = { path = "../sync", version = "0.1.0", optional = true }
mc-sgx-io = { path = "../io", version = "=0.1.0", optional = true }
mc-sgx-panic-sys = { path = "sys", version = "=0.1.0" }
mc-sgx-sync = { path = "../sync", version = "=0.1.0", optional = true }
17 changes: 14 additions & 3 deletions panic/src/lib.rs
Original file line number Diff line number Diff line change
@@ -6,19 +6,30 @@

#[cfg(not(test))]
use core::panic::PanicInfo;
#[cfg(not(test))]
use mc_sgx_panic_sys::panic_count;

#[cfg(feature = "log")]
mod log;

#[cfg(not(test))]
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
#[cfg(feature = "log")]
log::log_panic_info(_info);

extern "C" {
fn abort() -> !;
}

let panics = panic_count::increase();

// If we entered the panic handler more than once then we must have panicked
// while trying to handle the panic. Fail hard in these instances, nothing
// more we can do.
if panics > 1 {
unsafe { abort() }
}

#[cfg(feature = "log")]
log::log_panic_info(_info);

unsafe { abort() }
}
1 change: 1 addition & 0 deletions panic/sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -6,3 +6,4 @@

mod panicking;
pub mod thread;
pub use panicking::panic_count;
2 changes: 1 addition & 1 deletion panic/sys/src/panicking.rs
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ pub(crate) fn panicking() -> bool {
!panic_count::count_is_zero()
}

pub(crate) mod panic_count {
pub mod panic_count {
//! Number of panics that are currently being handled on the current thread
//!
//! This deviates from