Next Generation WASM Microkernel Operating System
at trap_handler 115 lines 3.8 kB view raw
1// Copyright 2025 Jonas Kruckenberg 2// 3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or 4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or 5// http://opensource.org/licenses/MIT>, at your option. This file may not be 6// copied, modified, or distributed except according to those terms. 7 8use cfg_if::cfg_if; 9 10cfg_if! { 11 if #[cfg(loom)] { 12 pub(crate) use loom::sync; 13 pub(crate) use loom::cell; 14 pub(crate) use loom::model; 15 #[cfg(test)] 16 pub(crate) use loom::thread; 17 pub(crate) use loom::lazy_static; 18 pub(crate) use loom::thread_local; 19 } else { 20 #[cfg(any(test, feature = "__bench"))] 21 pub(crate) use std::thread; 22 #[cfg(any(test, feature = "__bench"))] 23 pub(crate) use std::thread_local; 24 #[cfg(test)] 25 pub(crate) use lazy_static::lazy_static; 26 27 #[cfg(test)] 28 #[inline(always)] 29 pub(crate) fn model<R>(f: impl FnOnce() -> R) -> R { 30 f() 31 } 32 33 pub(crate) mod sync { 34 pub use core::sync::*; 35 #[cfg(any(test, feature = "__bench"))] 36 pub(crate) use std::sync::*; 37 } 38 39 pub(crate) mod cell { 40 #[derive(Debug)] 41 pub(crate) struct UnsafeCell<T>(core::cell::UnsafeCell<T>); 42 43 impl<T> UnsafeCell<T> { 44 pub(crate) const fn new(data: T) -> UnsafeCell<T> { 45 UnsafeCell(core::cell::UnsafeCell::new(data)) 46 } 47 48 #[inline(always)] 49 pub(crate) fn with<R>(&self, f: impl FnOnce(*const T) -> R) -> R { 50 f(self.0.get()) 51 } 52 53 #[inline(always)] 54 pub(crate) fn with_mut<R>(&self, f: impl FnOnce(*mut T) -> R) -> R { 55 f(self.0.get()) 56 } 57 } 58 } 59 } 60} 61 62// #[derive(Debug)] 63// #[pin_project::pin_project] 64// pub(crate) struct TrackFuture<F> { 65// #[pin] 66// inner: F, 67// track: Arc<()>, 68// } 69// 70// impl<F: Future> Future for TrackFuture<F> { 71// type Output = TrackFuture<F::Output>; 72// fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { 73// let this = self.project(); 74// this.inner.poll(cx).map(|inner| TrackFuture { 75// inner, 76// track: this.track.clone(), 77// }) 78// } 79// } 80// 81// impl<F> TrackFuture<F> { 82// /// Wrap a `Future` in a `TrackFuture` that participates in Loom's 83// /// leak checking. 84// #[track_caller] 85// pub(crate) fn new(inner: F) -> Self { 86// Self { 87// inner, 88// track: Arc::new(()), 89// } 90// } 91// 92// /// Stop tracking this future, and return the inner value. 93// pub(crate) fn into_inner(self) -> F { 94// self.inner 95// } 96// } 97// 98// #[track_caller] 99// pub(crate) fn track_future<F: Future>(inner: F) -> TrackFuture<F> { 100// TrackFuture::new(inner) 101// } 102// 103// // PartialEq impl so that `assert_eq!(..., Ok(...))` works 104// impl<F: PartialEq> PartialEq for TrackFuture<F> { 105// fn eq(&self, other: &Self) -> bool { 106// self.inner == other.inner 107// } 108// } 109// } 110// } else { 111 112// 113// 114// } 115// }