feat: objects: untyped: use bits instead of size

This commit is contained in:
Paul Pan 2024-06-15 16:14:33 +08:00
parent e3be1c56cd
commit 0af7025264
2 changed files with 5 additions and 6 deletions

View File

@ -52,10 +52,8 @@ impl<'a> FrameCap<'a> {
const VM_RIGHT_MASK: usize = MASK!(Self::VM_RIGHT_BITS); const VM_RIGHT_MASK: usize = MASK!(Self::VM_RIGHT_BITS);
const VM_RIGHT_OFFSET: usize = 0; const VM_RIGHT_OFFSET: usize = 0;
pub fn mint(ptr: PhysAddr, size: usize, attr: MapAttr, is_device: bool) -> RawCap { pub fn mint(ptr: PhysAddr, size_bits: usize, attr: MapAttr, is_device: bool) -> RawCap {
let size_bits = size.ilog2() as usize; debug_assert!(size_bits <= MASK!(Self::FRAME_SIZE_BITS)); // 1<<63
debug_assert!(size_bits <= FrameCap::FRAME_SIZE_BITS);
assert!(size >= PAGE_SIZE);
let arg0 = 0 let arg0 = 0
| ((attr.bits() & Self::VM_RIGHT_MASK) << Self::VM_RIGHT_OFFSET) | ((attr.bits() & Self::VM_RIGHT_MASK) << Self::VM_RIGHT_OFFSET)

View File

@ -1,7 +1,8 @@
use super::cap::RawCap; use super::cap::RawCap;
use super::cnode::{CNodeCap, CNodeObject}; use super::cnode::{CNodeCap, CNodeObject};
use super::null::NullCap; use super::null::NullCap;
use super::{Cap, KernelObject, TableCap, TcbCap}; use super::{Cap, FrameCap, KernelObject, TableCap, TcbCap};
use crate::vspace::MapAttr;
use core::fmt::Debug; use core::fmt::Debug;
use uapi::cap::ObjectType; use uapi::cap::ObjectType;
use uapi::error::{SysError, SysResult}; use uapi::error::{SysError, SysResult};
@ -107,7 +108,6 @@ impl UntypedCap<'_> {
// Check whether we are handling device memory // Check whether we are handling device memory
if self.is_device() && obj_type != ObjectType::Frame && obj_type != ObjectType::Untyped { if self.is_device() && obj_type != ObjectType::Frame && obj_type != ObjectType::Untyped {
// TODO: we might split frame into tera, giga, mega, kilo...
return Err(SysError::InvalidArgument); return Err(SysError::InvalidArgument);
} }
@ -119,6 +119,7 @@ impl UntypedCap<'_> {
ObjectType::CNode => CNodeCap::mint(user_obj_bits, 0, 0, addr), ObjectType::CNode => CNodeCap::mint(user_obj_bits, 0, 0, addr),
ObjectType::TCB => TcbCap::mint(addr), ObjectType::TCB => TcbCap::mint(addr),
ObjectType::Table => TableCap::mint(addr), ObjectType::Table => TableCap::mint(addr),
ObjectType::Frame => FrameCap::mint(addr, user_obj_bits, MapAttr::empty(), self.is_device()),
// TODO: other object types // TODO: other object types
_ => return Err(SysError::InvalidArgument), _ => return Err(SysError::InvalidArgument),
}; };