sel4_panicking/count/
without_tls.rs

1//
2// Copyright 2023, Colias Group, LLC
3//
4// SPDX-License-Identifier: BSD-2-Clause
5//
6
7use core::fmt;
8use core::sync::atomic::{AtomicBool, Ordering};
9
10static PANICKING: AtomicBool = AtomicBool::new(false);
11
12pub(crate) enum MustAbort {
13    AlreadyPanicking,
14}
15
16impl fmt::Display for MustAbort {
17    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
18        match self {
19            Self::AlreadyPanicking => write!(f, "program is already panicking"),
20        }
21    }
22}
23
24pub(crate) fn count_panic() -> Option<MustAbort> {
25    if PANICKING.load(Ordering::SeqCst) {
26        Some(MustAbort::AlreadyPanicking)
27    } else {
28        None
29    }
30}
31
32pub(crate) fn count_panic_caught() {
33    PANICKING.store(false, Ordering::SeqCst);
34}