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