Change the return value of dup() for Vmo<Rights>

This commit is contained in:
LI Qing
2024-05-16 14:59:09 +08:00
committed by Tate, Hongliang Tian
parent e6b0fd8aa3
commit 770a123415
5 changed files with 13 additions and 16 deletions

View File

@ -270,7 +270,7 @@ impl ExfatDentrySet {
} }
pub(super) fn read_from(page_cache: Vmo<Full>, offset: usize) -> Result<Self> { pub(super) fn read_from(page_cache: Vmo<Full>, offset: usize) -> Result<Self> {
let mut iter = ExfatDentryIterator::new(page_cache.dup().unwrap(), offset, None)?; let mut iter = ExfatDentryIterator::new(page_cache, offset, None)?;
let primary_dentry_result = iter.next(); let primary_dentry_result = iter.next();
if primary_dentry_result.is_none() { if primary_dentry_result.is_none() {

View File

@ -45,7 +45,7 @@ impl PageCache {
// TODO: The capability is too highrestrict it to eliminate the possibility of misuse. // TODO: The capability is too highrestrict it to eliminate the possibility of misuse.
// For example, the `resize` api should be forbidded. // For example, the `resize` api should be forbidded.
pub fn pages(&self) -> Vmo<Full> { pub fn pages(&self) -> Vmo<Full> {
self.pages.dup().unwrap() self.pages.dup()
} }
/// Evict the data within a specified range from the page cache and persist /// Evict the data within a specified range from the page cache and persist

View File

@ -325,7 +325,7 @@ fn init_segment_vmo(program_header: &ProgramHeader64, elf_file: &Dentry) -> Resu
start..end start..end
}; };
debug_assert!(vmo_size >= (program_header.file_size as usize).align_up(PAGE_SIZE)); debug_assert!(vmo_size >= (program_header.file_size as usize).align_up(PAGE_SIZE));
page_cache_vmo.new_cow_child(parent_range)?.alloc()? page_cache_vmo.new_cow_child(parent_range).alloc()?
}; };
let anonymous_map_size: usize = if vmo_size > segment_vmo.size() { let anonymous_map_size: usize = if vmo_size > segment_vmo.size() {

View File

@ -513,7 +513,7 @@ mod test {
#[ktest] #[ktest]
fn slice_child() { fn slice_child() {
let parent = VmoOptions::<Full>::new(2 * PAGE_SIZE).alloc().unwrap(); let parent = VmoOptions::<Full>::new(2 * PAGE_SIZE).alloc().unwrap();
let parent_dup = parent.dup().unwrap(); let parent_dup = parent.dup();
let slice_child = VmoChildOptions::new_slice(parent_dup, 0..PAGE_SIZE) let slice_child = VmoChildOptions::new_slice(parent_dup, 0..PAGE_SIZE)
.alloc() .alloc()
.unwrap(); .unwrap();
@ -530,7 +530,7 @@ mod test {
let parent = VmoOptions::<Full>::new(2 * PAGE_SIZE).alloc().unwrap(); let parent = VmoOptions::<Full>::new(2 * PAGE_SIZE).alloc().unwrap();
parent.write_val(1, &42u8).unwrap(); parent.write_val(1, &42u8).unwrap();
parent.write_val(2, &16u8).unwrap(); parent.write_val(2, &16u8).unwrap();
let parent_dup = parent.dup().unwrap(); let parent_dup = parent.dup();
let cow_child = VmoChildOptions::new_cow(parent_dup, 0..10 * PAGE_SIZE) let cow_child = VmoChildOptions::new_cow(parent_dup, 0..10 * PAGE_SIZE)
.alloc() .alloc()
.unwrap(); .unwrap();

View File

@ -36,9 +36,9 @@ impl<R: TRights> Vmo<TRightSet<R>> {
pub fn new_slice_child( pub fn new_slice_child(
&self, &self,
range: Range<usize>, range: Range<usize>,
) -> Result<VmoChildOptions<TRightSet<R>, VmoSliceChild>> { ) -> VmoChildOptions<TRightSet<R>, VmoSliceChild> {
let dup_self = self.dup()?; let dup_self = self.dup();
Ok(VmoChildOptions::new_slice(dup_self, range)) VmoChildOptions::new_slice(dup_self, range)
} }
/// Creates a new COW VMO through a set of VMO child options. /// Creates a new COW VMO through a set of VMO child options.
@ -62,12 +62,9 @@ impl<R: TRights> Vmo<TRightSet<R>> {
/// The child will be given the access rights of the parent /// The child will be given the access rights of the parent
/// plus the Write right. /// plus the Write right.
#[require(R > Dup)] #[require(R > Dup)]
pub fn new_cow_child( pub fn new_cow_child(&self, range: Range<usize>) -> VmoChildOptions<TRightSet<R>, VmoCowChild> {
&self, let dup_self = self.dup();
range: Range<usize>, VmoChildOptions::new_cow(dup_self, range)
) -> Result<VmoChildOptions<TRightSet<R>, VmoCowChild>> {
let dup_self = self.dup()?;
Ok(VmoChildOptions::new_cow(dup_self, range))
} }
/// commit a page at specific offset /// commit a page at specific offset
@ -135,8 +132,8 @@ impl<R: TRights> Vmo<TRightSet<R>> {
/// ///
/// The method requires the Dup right. /// The method requires the Dup right.
#[require(R > Dup)] #[require(R > Dup)]
pub fn dup(&self) -> Result<Self> { pub fn dup(&self) -> Self {
Ok(Vmo(self.0.clone(), self.1)) Vmo(self.0.clone(), self.1)
} }
/// Strict the access rights. /// Strict the access rights.