Relax AnyFrameMeta's requirement of Debug and 'static

This commit is contained in:
Zhang Junyang 2025-01-13 10:12:17 +08:00 committed by Tate, Hongliang Tian
parent d366043876
commit fdbe52c2ee
4 changed files with 20 additions and 5 deletions

View File

@ -147,7 +147,7 @@ const_assert!(size_of::<MetaSlot>() == META_SLOT_SIZE);
/// ///
/// If `on_drop` reads the page using the provided `VmReader`, the /// If `on_drop` reads the page using the provided `VmReader`, the
/// implementer must ensure that the frame is safe to read. /// 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. /// Called when the last handle to the frame is dropped.
fn on_drop(&mut self, _reader: &mut VmReader<Infallible>) {} fn on_drop(&mut self, _reader: &mut VmReader<Infallible>) {}

View File

@ -62,7 +62,6 @@ static MAX_PADDR: AtomicUsize = AtomicUsize::new(0);
/// Frames are associated with metadata. The type of the metadata `M` is /// Frames are associated with metadata. The type of the metadata `M` is
/// determines the kind of the frame. If `M` implements [`AnyUFrameMeta`], the /// determines the kind of the frame. If `M` implements [`AnyUFrameMeta`], the
/// frame is a untyped frame. Otherwise, it is a typed frame. /// frame is a untyped frame. Otherwise, it is a typed frame.
#[derive(Debug)]
#[repr(transparent)] #[repr(transparent)]
pub struct Frame<M: AnyFrameMeta + ?Sized> { pub struct Frame<M: AnyFrameMeta + ?Sized> {
ptr: *const MetaSlot, 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> {} 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> { impl<M: AnyFrameMeta> Frame<M> {
/// Gets a [`Frame`] with a specific usage from a raw, unused page. /// Gets a [`Frame`] with a specific usage from a raw, unused page.
/// ///

View File

@ -2,7 +2,7 @@
//! A contiguous range of frames. //! 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::{ use super::{
inc_frame_ref_count, 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 /// All the metadata of the frames are homogeneous, i.e., they are of the same
/// type. /// type.
#[derive(Debug)]
#[repr(transparent)] #[repr(transparent)]
pub struct Segment<M: AnyFrameMeta + ?Sized> { pub struct Segment<M: AnyFrameMeta + ?Sized> {
range: Range<Paddr>, range: Range<Paddr>,
_marker: core::marker::PhantomData<M>, _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. /// 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 /// In other words, the metadata of the frames are of the same type, and they

View File

@ -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 /// 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. /// others. So a mutable reference to the metadata is available for the frame.
#[derive(Debug)]
#[repr(transparent)] #[repr(transparent)]
pub struct UniqueFrame<M: AnyFrameMeta + ?Sized> { pub struct UniqueFrame<M: AnyFrameMeta + ?Sized> {
ptr: *const MetaSlot, 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> {} 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> { impl<M: AnyFrameMeta> UniqueFrame<M> {
/// Gets a [`UniqueFrame`] with a specific usage from a raw, unused page. /// Gets a [`UniqueFrame`] with a specific usage from a raw, unused page.
/// ///