mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-08 21:06:48 +00:00
Relax AnyFrameMeta
's requirement of Debug
and 'static
This commit is contained in:
parent
d366043876
commit
fdbe52c2ee
@ -147,7 +147,7 @@ const_assert!(size_of::<MetaSlot>() == META_SLOT_SIZE);
|
||||
///
|
||||
/// If `on_drop` reads the page using the provided `VmReader`, the
|
||||
/// implementer must ensure that the frame is safe to read.
|
||||
pub unsafe trait AnyFrameMeta: Any + Send + Sync + Debug + 'static {
|
||||
pub unsafe trait AnyFrameMeta: Any + Send + Sync {
|
||||
/// Called when the last handle to the frame is dropped.
|
||||
fn on_drop(&mut self, _reader: &mut VmReader<Infallible>) {}
|
||||
|
||||
|
@ -62,7 +62,6 @@ static MAX_PADDR: AtomicUsize = AtomicUsize::new(0);
|
||||
/// Frames are associated with metadata. The type of the metadata `M` is
|
||||
/// determines the kind of the frame. If `M` implements [`AnyUFrameMeta`], the
|
||||
/// frame is a untyped frame. Otherwise, it is a typed frame.
|
||||
#[derive(Debug)]
|
||||
#[repr(transparent)]
|
||||
pub struct Frame<M: AnyFrameMeta + ?Sized> {
|
||||
ptr: *const MetaSlot,
|
||||
@ -73,6 +72,12 @@ unsafe impl<M: AnyFrameMeta + ?Sized> Send for Frame<M> {}
|
||||
|
||||
unsafe impl<M: AnyFrameMeta + ?Sized> Sync for Frame<M> {}
|
||||
|
||||
impl<M: AnyFrameMeta + ?Sized> core::fmt::Debug for Frame<M> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
write!(f, "Frame({:#x})", self.start_paddr())
|
||||
}
|
||||
}
|
||||
|
||||
impl<M: AnyFrameMeta> Frame<M> {
|
||||
/// Gets a [`Frame`] with a specific usage from a raw, unused page.
|
||||
///
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
//! A contiguous range of frames.
|
||||
|
||||
use core::{mem::ManuallyDrop, ops::Range, sync::atomic::Ordering};
|
||||
use core::{fmt::Debug, mem::ManuallyDrop, ops::Range, sync::atomic::Ordering};
|
||||
|
||||
use super::{
|
||||
inc_frame_ref_count,
|
||||
@ -23,13 +23,18 @@ use crate::mm::{AnyUFrameMeta, Paddr, PAGE_SIZE};
|
||||
///
|
||||
/// All the metadata of the frames are homogeneous, i.e., they are of the same
|
||||
/// type.
|
||||
#[derive(Debug)]
|
||||
#[repr(transparent)]
|
||||
pub struct Segment<M: AnyFrameMeta + ?Sized> {
|
||||
range: Range<Paddr>,
|
||||
_marker: core::marker::PhantomData<M>,
|
||||
}
|
||||
|
||||
impl<M: AnyFrameMeta + ?Sized> Debug for Segment<M> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
write!(f, "Segment({:#x}..{:#x})", self.range.start, self.range.end)
|
||||
}
|
||||
}
|
||||
|
||||
/// A contiguous range of homogeneous untyped physical memory frames that have any metadata.
|
||||
///
|
||||
/// In other words, the metadata of the frames are of the same type, and they
|
||||
|
@ -14,7 +14,6 @@ use crate::mm::{frame::mapping, Paddr, PagingConsts, PagingLevel, PAGE_SIZE};
|
||||
///
|
||||
/// Unlike [`Frame`], the frame pointed to by this pointer is not shared with
|
||||
/// others. So a mutable reference to the metadata is available for the frame.
|
||||
#[derive(Debug)]
|
||||
#[repr(transparent)]
|
||||
pub struct UniqueFrame<M: AnyFrameMeta + ?Sized> {
|
||||
ptr: *const MetaSlot,
|
||||
@ -25,6 +24,12 @@ unsafe impl<M: AnyFrameMeta + ?Sized> Send for UniqueFrame<M> {}
|
||||
|
||||
unsafe impl<M: AnyFrameMeta + ?Sized> Sync for UniqueFrame<M> {}
|
||||
|
||||
impl<M: AnyFrameMeta + ?Sized> core::fmt::Debug for UniqueFrame<M> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
write!(f, "UniqueFrame({:#x})", self.start_paddr())
|
||||
}
|
||||
}
|
||||
|
||||
impl<M: AnyFrameMeta> UniqueFrame<M> {
|
||||
/// Gets a [`UniqueFrame`] with a specific usage from a raw, unused page.
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user