mirror of
https://github.com/panpaul/tiny_os
synced 2024-09-20 09:45:19 +08:00
feat: cap: update size info
This commit is contained in:
parent
3b3c68a203
commit
c013478d0b
@ -21,8 +21,6 @@ pub struct RawCap {
|
|||||||
pub ptr: PhysAddr,
|
pub ptr: PhysAddr,
|
||||||
/// cap_type: every capability links to one specific object
|
/// cap_type: every capability links to one specific object
|
||||||
pub cap_type: ObjectType,
|
pub cap_type: ObjectType,
|
||||||
/// _padding: padding to align the size of RawCap to power of 2
|
|
||||||
pub _padding: [usize; 2],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RawCap {
|
impl RawCap {
|
||||||
@ -31,7 +29,6 @@ impl RawCap {
|
|||||||
args: [arg0, arg1],
|
args: [arg0, arg1],
|
||||||
ptr,
|
ptr,
|
||||||
cap_type,
|
cap_type,
|
||||||
_padding: [0, 0],
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -43,8 +40,6 @@ pub struct CapEntry {
|
|||||||
|
|
||||||
LinkHelperImpl!(CapEntry: link);
|
LinkHelperImpl!(CapEntry: link);
|
||||||
|
|
||||||
const_assert_eq!(core::mem::size_of::<CapEntry>(), ObjectType::CNode.size(0));
|
|
||||||
|
|
||||||
impl CapEntry {
|
impl CapEntry {
|
||||||
pub fn new(cap: RawCap) -> Self {
|
pub fn new(cap: RawCap) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -12,6 +12,8 @@ use utils::MASK;
|
|||||||
/// The size of the array is stored in CNodeCap
|
/// The size of the array is stored in CNodeCap
|
||||||
pub type CNodeObject = [CapEntry];
|
pub type CNodeObject = [CapEntry];
|
||||||
|
|
||||||
|
const_assert!(core::mem::size_of::<CapEntry>() <= ObjectType::CNode.size(0));
|
||||||
|
|
||||||
impl KernelObject for CNodeObject {
|
impl KernelObject for CNodeObject {
|
||||||
const OBJ_TYPE: ObjectType = ObjectType::CNode;
|
const OBJ_TYPE: ObjectType = ObjectType::CNode;
|
||||||
}
|
}
|
||||||
@ -157,11 +159,11 @@ mod tests {
|
|||||||
|
|
||||||
#[test_case]
|
#[test_case]
|
||||||
fn test_cnode_resolve() {
|
fn test_cnode_resolve() {
|
||||||
let create_cnode = |radix: usize, guard_size: usize, guard: usize| {
|
let create_cnode = |radix_bits: usize, guard_bits: usize, guard: usize| {
|
||||||
let size = ObjectType::CNode.size(radix);
|
let size = ObjectType::CNode.size(radix_bits);
|
||||||
let layout = Layout::from_size_align(size, 1).unwrap();
|
let layout = Layout::from_size_align(size, 1).unwrap();
|
||||||
let ptr = RAM_ALLOCATOR.lock().alloc(layout).unwrap();
|
let ptr = RAM_ALLOCATOR.lock().alloc(layout).unwrap();
|
||||||
let raw = CNodeCap::mint(radix, guard_size, guard, ptr);
|
let raw = CNodeCap::mint(radix_bits, guard_bits, guard, ptr);
|
||||||
CapEntry::new(raw)
|
CapEntry::new(raw)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ use uapi::{
|
|||||||
use utils::{addr::*, MASK};
|
use utils::{addr::*, MASK};
|
||||||
|
|
||||||
/// TableObject is an object that represents a page table
|
/// TableObject is an object that represents a page table
|
||||||
pub struct TableObject([usize]);
|
pub struct TableObject([u8]);
|
||||||
impl KernelObject for TableObject {
|
impl KernelObject for TableObject {
|
||||||
const OBJ_TYPE: ObjectType = ObjectType::PageTable;
|
const OBJ_TYPE: ObjectType = ObjectType::PageTable;
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,9 @@ pub struct TcbObject {
|
|||||||
|
|
||||||
LinkHelperImpl!(TcbObject:link);
|
LinkHelperImpl!(TcbObject:link);
|
||||||
|
|
||||||
|
const_assert_eq!(ObjectType::TCB.size(0), ObjectType::TCB.size(0x42));
|
||||||
|
const_assert!(core::mem::size_of::<TcbObject>() <= ObjectType::TCB.size(0));
|
||||||
|
|
||||||
impl TcbObject {
|
impl TcbObject {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -3,14 +3,13 @@ pub enum ObjectType {
|
|||||||
Null = 0,
|
Null = 0,
|
||||||
CNode = 1,
|
CNode = 1,
|
||||||
TCB = 2,
|
TCB = 2,
|
||||||
SchedCtx = 3,
|
Endpoint = 3,
|
||||||
Endpoint = 4,
|
Reply = 4,
|
||||||
Reply = 5,
|
Notification = 5,
|
||||||
Notification = 6,
|
Frame = 6,
|
||||||
Frame = 7,
|
PageTable = 7,
|
||||||
PageTable = 8,
|
Interrupt = 8,
|
||||||
Interrupt = 9,
|
Untyped = 9,
|
||||||
Untyped = 10,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ObjectType {
|
impl Default for ObjectType {
|
||||||
@ -20,7 +19,8 @@ impl Default for ObjectType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ObjectType {
|
impl ObjectType {
|
||||||
const CNODE_BITS: usize = 6;
|
const CNODE_BITS: usize = 6; // 48 bytes
|
||||||
|
const TCB_BITS: usize = 10; // 672 bytes
|
||||||
|
|
||||||
pub const fn size(&self, user_obj_bits: usize) -> usize {
|
pub const fn size(&self, user_obj_bits: usize) -> usize {
|
||||||
1 << self.bits(user_obj_bits)
|
1 << self.bits(user_obj_bits)
|
||||||
@ -29,15 +29,14 @@ impl ObjectType {
|
|||||||
pub const fn bits(&self, user_obj_bits: usize) -> usize {
|
pub const fn bits(&self, user_obj_bits: usize) -> usize {
|
||||||
#![rustfmt::skip]
|
#![rustfmt::skip]
|
||||||
match self {
|
match self {
|
||||||
ObjectType::Null => 0, // TODO: fill it!
|
ObjectType::Null => 0,
|
||||||
ObjectType::CNode => Self::CNODE_BITS + user_obj_bits,
|
ObjectType::CNode => Self::CNODE_BITS + user_obj_bits,
|
||||||
ObjectType::TCB => 0, // TODO: fill it!
|
ObjectType::TCB => Self::TCB_BITS,
|
||||||
ObjectType::SchedCtx => 0, // TODO: fill it!
|
|
||||||
ObjectType::Endpoint => 0, // TODO: fill it!
|
ObjectType::Endpoint => 0, // TODO: fill it!
|
||||||
ObjectType::Reply => 0, // TODO: fill it!
|
ObjectType::Reply => 0, // TODO: fill it!
|
||||||
ObjectType::Notification => 0, // TODO: fill it!
|
ObjectType::Notification => 0, // TODO: fill it!
|
||||||
ObjectType::Frame => 0, // TODO: fill it!
|
ObjectType::Frame => user_obj_bits,
|
||||||
ObjectType::PageTable => 0, // TODO: fill it!
|
ObjectType::PageTable => user_obj_bits, // arch dependent page table size
|
||||||
ObjectType::Interrupt => 0, // TODO: fill it!
|
ObjectType::Interrupt => 0, // TODO: fill it!
|
||||||
ObjectType::Untyped => user_obj_bits,
|
ObjectType::Untyped => user_obj_bits,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user