mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-24 09:53:24 +00:00
Polish the doc and rename variables in ostd::mm
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
f332797084
commit
983a6af3cc
@ -54,7 +54,7 @@ use ostd::{
|
||||
///
|
||||
/// The generic parameter `M` of `SafePtr<_, M, _>` must implement the `VmIo`
|
||||
/// trait. The most important `VmIo` types are `Vmar`, `Vmo`, `IoMem`, and
|
||||
/// `DynUFrame`. The blanket implementations of `VmIo` also include pointer-like
|
||||
/// `UFrame`. The blanket implementations of `VmIo` also include pointer-like
|
||||
/// types that refer to a `VmIo` type. Some examples are `&Vmo`, `Box<Vmar>`,
|
||||
/// and `Arc<IoMem>`.
|
||||
///
|
||||
|
@ -2,41 +2,41 @@
|
||||
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
//! Provides [`SegmentSlice`] for quick duplication and slicing over [`DynUSegment`].
|
||||
//! Provides [`SegmentSlice`] for quick duplication and slicing over [`USegment`].
|
||||
|
||||
use alloc::sync::Arc;
|
||||
use core::ops::Range;
|
||||
|
||||
use ostd::{
|
||||
mm::{
|
||||
DynUFrame, DynUSegment, FallibleVmRead, FallibleVmWrite, Infallible, Paddr, UntypedMem,
|
||||
VmIo, VmReader, VmWriter, PAGE_SIZE,
|
||||
FallibleVmRead, FallibleVmWrite, Infallible, Paddr, UFrame, USegment, UntypedMem, VmIo,
|
||||
VmReader, VmWriter, PAGE_SIZE,
|
||||
},
|
||||
Error, Result,
|
||||
};
|
||||
|
||||
/// A reference to a slice of a [`DynUSegment`].
|
||||
/// A reference to a slice of a [`USegment`].
|
||||
///
|
||||
/// Cloning a [`SegmentSlice`] is cheap, as it only increments one reference
|
||||
/// count. While cloning a [`DynUSegment`] will increment the reference count of
|
||||
/// count. While cloning a [`USegment`] will increment the reference count of
|
||||
/// many underlying pages.
|
||||
///
|
||||
/// The downside is that the [`SegmentSlice`] requires heap allocation. Also,
|
||||
/// if any [`SegmentSlice`] of the original [`DynUSegment`] is alive, all pages in
|
||||
/// the original [`DynUSegment`], including the pages that are not referenced, will
|
||||
/// if any [`SegmentSlice`] of the original [`USegment`] is alive, all pages in
|
||||
/// the original [`USegment`], including the pages that are not referenced, will
|
||||
/// not be freed.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SegmentSlice {
|
||||
inner: Arc<DynUSegment>,
|
||||
inner: Arc<USegment>,
|
||||
range: Range<usize>,
|
||||
}
|
||||
|
||||
impl SegmentSlice {
|
||||
/// Returns a part of the `DynUSegment`.
|
||||
/// Returns a part of the `USegment`.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// If `range` is not within the range of this `DynUSegment`,
|
||||
/// If `range` is not within the range of this `USegment`,
|
||||
/// then the method panics.
|
||||
pub fn range(&self, range: Range<usize>) -> Self {
|
||||
let orig_range = &self.range;
|
||||
@ -124,8 +124,8 @@ impl VmIo for SegmentSlice {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DynUSegment> for SegmentSlice {
|
||||
fn from(segment: DynUSegment) -> Self {
|
||||
impl From<USegment> for SegmentSlice {
|
||||
fn from(segment: USegment) -> Self {
|
||||
let range = 0..segment.size() / PAGE_SIZE;
|
||||
Self {
|
||||
inner: Arc::new(segment),
|
||||
@ -134,7 +134,7 @@ impl From<DynUSegment> for SegmentSlice {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SegmentSlice> for DynUSegment {
|
||||
impl From<SegmentSlice> for USegment {
|
||||
fn from(slice: SegmentSlice) -> Self {
|
||||
let start = slice.range.start * PAGE_SIZE;
|
||||
let end = slice.range.end * PAGE_SIZE;
|
||||
@ -142,8 +142,8 @@ impl From<SegmentSlice> for DynUSegment {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DynUFrame> for SegmentSlice {
|
||||
fn from(frame: DynUFrame) -> Self {
|
||||
SegmentSlice::from(DynUSegment::from(frame))
|
||||
impl From<UFrame> for SegmentSlice {
|
||||
fn from(frame: UFrame) -> Self {
|
||||
SegmentSlice::from(USegment::from(frame))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user