#[allow(dead_code)] pub type KResult = Result; macro_rules! dont_check { ($arg:expr) => { match $arg { Ok(_) => (), Err(_) => (), } }; } use alloc::sync::Arc; #[allow(unused_imports)] pub(crate) use dont_check; #[allow(unused_imports)] pub use crate::bindings::root as bindings; #[allow(unused_imports)] pub(crate) use crate::kernel::console::{ print, println, println_debug, println_fatal, println_info, println_warn, }; #[allow(unused_imports)] pub(crate) use crate::sync::might_sleep; #[allow(unused_imports)] pub(crate) use alloc::{boxed::Box, string::String, vec, vec::Vec}; #[allow(unused_imports)] pub(crate) use core::{any::Any, fmt::Write, marker::PhantomData, str}; use core::{mem::ManuallyDrop, ops::Deref}; pub use crate::sync::{Mutex, RwSemaphore, Semaphore, Spin, Locked}; pub struct BorrowedArc<'lt, T: ?Sized> { arc: ManuallyDrop>, _phantom: PhantomData<&'lt ()>, } impl<'lt, T: ?Sized> BorrowedArc<'lt, T> { pub fn from_raw(ptr: *const T) -> Self { assert!(!ptr.is_null()); Self { arc: ManuallyDrop::new(unsafe { Arc::from_raw(ptr) }), _phantom: PhantomData, } } pub fn new(ptr: &'lt *const T) -> Self { assert!(!ptr.is_null()); Self { arc: ManuallyDrop::new(unsafe { Arc::from_raw(*ptr) }), _phantom: PhantomData, } } } impl<'lt, T: ?Sized> Deref for BorrowedArc<'lt, T> { type Target = Arc; fn deref(&self) -> &Self::Target { &self.arc } } impl<'lt, T: ?Sized> AsRef> for BorrowedArc<'lt, T> { fn as_ref(&self) -> &Arc { &self.arc } } pub trait AsAny: Send + Sync { fn as_any(&self) -> &dyn Any; fn as_any_mut(&mut self) -> &mut dyn Any; } macro_rules! impl_any { ($t:ty) => { impl AsAny for $t { fn as_any(&self) -> &dyn Any { self } fn as_any_mut(&mut self) -> &mut dyn Any { self } } }; } macro_rules! addr_of_mut_field { ($pointer:expr, $field:ident) => { core::ptr::addr_of_mut!((*$pointer).$field) }; } pub(crate) use {addr_of_mut_field, impl_any};