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> {
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();
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.
// For example, the `resize` api should be forbidded.
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

View File

@ -325,7 +325,7 @@ fn init_segment_vmo(program_header: &ProgramHeader64, elf_file: &Dentry) -> Resu
start..end
};
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() {

View File

@ -513,7 +513,7 @@ mod test {
#[ktest]
fn slice_child() {
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)
.alloc()
.unwrap();
@ -530,7 +530,7 @@ mod test {
let parent = VmoOptions::<Full>::new(2 * PAGE_SIZE).alloc().unwrap();
parent.write_val(1, &42u8).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)
.alloc()
.unwrap();

View File

@ -36,9 +36,9 @@ impl<R: TRights> Vmo<TRightSet<R>> {
pub fn new_slice_child(
&self,
range: Range<usize>,
) -> Result<VmoChildOptions<TRightSet<R>, VmoSliceChild>> {
let dup_self = self.dup()?;
Ok(VmoChildOptions::new_slice(dup_self, range))
) -> VmoChildOptions<TRightSet<R>, VmoSliceChild> {
let dup_self = self.dup();
VmoChildOptions::new_slice(dup_self, range)
}
/// 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
/// plus the Write right.
#[require(R > Dup)]
pub fn new_cow_child(
&self,
range: Range<usize>,
) -> Result<VmoChildOptions<TRightSet<R>, VmoCowChild>> {
let dup_self = self.dup()?;
Ok(VmoChildOptions::new_cow(dup_self, range))
pub fn new_cow_child(&self, range: Range<usize>) -> VmoChildOptions<TRightSet<R>, VmoCowChild> {
let dup_self = self.dup();
VmoChildOptions::new_cow(dup_self, range)
}
/// commit a page at specific offset
@ -135,8 +132,8 @@ impl<R: TRights> Vmo<TRightSet<R>> {
///
/// The method requires the Dup right.
#[require(R > Dup)]
pub fn dup(&self) -> Result<Self> {
Ok(Vmo(self.0.clone(), self.1))
pub fn dup(&self) -> Self {
Vmo(self.0.clone(), self.1)
}
/// Strict the access rights.