Extract TRights into crate jinux_rights

This commit is contained in:
Yuke Peng
2023-05-30 04:09:20 -07:00
committed by Tate, Hongliang Tian
parent 3471843793
commit 0c9495b726
29 changed files with 122 additions and 70 deletions

View File

@ -10,10 +10,10 @@ use typeflags_util::{SetExtend, SetExtendOp};
use crate::prelude::*;
use crate::rights::{Dup, Rights, TRights, Write};
use crate::vm::vmo::InheritedPages;
use crate::vm::vmo::VmoType;
use crate::vm::vmo::{VmoInner, Vmo_};
use jinux_rights::{Dup, Rights, TRightSet, TRights, Write};
use super::VmoRightsOp;
use super::{Pager, Vmo, VmoFlags};
@ -105,14 +105,14 @@ impl VmoOptions<Rights> {
}
}
impl<R: TRights> VmoOptions<R> {
impl<R: TRights> VmoOptions<TRightSet<R>> {
/// Allocates the VMO according to the specified options.
///
/// # Access rights
///
/// The VMO is initially assigned the access rights represented
/// by `R: TRights`.
pub fn alloc(self) -> Result<Vmo<R>> {
pub fn alloc(self) -> Result<Vmo<TRightSet<R>>> {
let VmoOptions {
size,
flags,
@ -120,7 +120,7 @@ impl<R: TRights> VmoOptions<R> {
pager,
} = self;
let vmo_ = alloc_vmo_(size, flags, pager)?;
Ok(Vmo(Arc::new(vmo_), R::new()))
Ok(Vmo(Arc::new(vmo_), TRightSet(R::new())))
}
}
@ -252,7 +252,7 @@ pub struct VmoChildOptions<R, C> {
marker: PhantomData<C>,
}
impl<R: TRights> VmoChildOptions<R, VmoSliceChild> {
impl<R: TRights> VmoChildOptions<TRightSet<R>, VmoSliceChild> {
/// Creates a default set of options for creating a slice VMO child.
///
/// A slice child of a VMO, which has direct access to a range of memory
@ -261,7 +261,7 @@ impl<R: TRights> VmoChildOptions<R, VmoSliceChild> {
///
/// The range of a child must be within that of the parent.
#[require(R > Dup)]
pub fn new_slice(parent: Vmo<R>, range: Range<usize>) -> Self {
pub fn new_slice(parent: Vmo<TRightSet<R>>, range: Range<usize>) -> Self {
Self {
flags: parent.flags() & Self::PARENT_FLAGS_MASK,
parent,
@ -373,13 +373,13 @@ impl VmoChildOptions<Rights, VmoCowChild> {
}
}
impl<R: TRights> VmoChildOptions<R, VmoSliceChild> {
impl<R: TRights> VmoChildOptions<TRightSet<R>, VmoSliceChild> {
/// Allocates the child VMO.
///
/// # Access rights
///
/// The child VMO is initially assigned all the parent's access rights.
pub fn alloc(self) -> Result<Vmo<R>> {
pub fn alloc(self) -> Result<Vmo<TRightSet<R>>> {
let VmoChildOptions {
parent,
range,
@ -392,14 +392,14 @@ impl<R: TRights> VmoChildOptions<R, VmoSliceChild> {
}
}
impl<R: TRights> VmoChildOptions<R, VmoCowChild> {
impl<R: TRights> VmoChildOptions<TRightSet<R>, VmoCowChild> {
/// Allocates the child VMO.
///
/// # Access rights
///
/// The child VMO is initially assigned all the parent's access rights
/// plus the Write right.
pub fn alloc(self) -> Result<Vmo<SetExtendOp<R, Write>>>
pub fn alloc(self) -> Result<Vmo<TRightSet<SetExtendOp<R, Write>>>>
where
R: SetExtend<Write>,
SetExtendOp<R, Write>: TRights,
@ -413,7 +413,7 @@ impl<R: TRights> VmoChildOptions<R, VmoCowChild> {
let Vmo(parent_vmo_, _) = parent;
let child_vmo_ = alloc_child_vmo_(parent_vmo_, range, flags, ChildType::Cow)?;
let right = SetExtendOp::<R, Write>::new();
Ok(Vmo(Arc::new(child_vmo_), right))
Ok(Vmo(Arc::new(child_vmo_), TRightSet(right)))
}
}
@ -501,8 +501,8 @@ impl VmoChildType for VmoCowChild {}
#[cfg(test)]
mod test {
use super::*;
use crate::rights::Full;
use jinux_frame::vm::VmIo;
use jinux_rights::Full;
#[test]
fn alloc_vmo() {