mirror of
https://github.com/panpaul/tiny_os
synced 2024-09-20 09:45:19 +08:00
chore: kernel/objects: extract as_object*
This commit is contained in:
parent
163813fbde
commit
db7fa2ba58
@ -14,11 +14,13 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use crate::arch::layout::mmap_phys_to_virt;
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
use uapi::{
|
use uapi::{
|
||||||
cap::ObjectType,
|
cap::ObjectType,
|
||||||
error::{SysError, SysResult},
|
error::{SysError, SysResult},
|
||||||
};
|
};
|
||||||
|
use utils::addr::AddressOps;
|
||||||
|
|
||||||
pub mod cap;
|
pub mod cap;
|
||||||
pub mod cnode;
|
pub mod cnode;
|
||||||
@ -65,6 +67,22 @@ impl<'a, T: KernelObject + ?Sized> Cap<'a, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, T: KernelObject> Cap<'a, T> {
|
||||||
|
pub fn as_object(&self) -> &T {
|
||||||
|
unsafe {
|
||||||
|
let virt = mmap_phys_to_virt(self.cte.cap.ptr);
|
||||||
|
&*(virt.as_const_ptr())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn as_object_mut(&mut self) -> &mut T {
|
||||||
|
unsafe {
|
||||||
|
let virt = mmap_phys_to_virt(self.cte.cap.ptr);
|
||||||
|
&mut *(virt.as_mut_ptr())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// KernelObject is the base trait for all kernel objects
|
/// KernelObject is the base trait for all kernel objects
|
||||||
pub trait KernelObject {
|
pub trait KernelObject {
|
||||||
const OBJ_TYPE: ObjectType;
|
const OBJ_TYPE: ObjectType;
|
||||||
|
@ -155,20 +155,6 @@ impl<'a> TcbCap<'a> {
|
|||||||
pub fn mint(ptr: PhysAddr) -> RawCap {
|
pub fn mint(ptr: PhysAddr) -> RawCap {
|
||||||
RawCap::new(0, 0, ptr, ObjectType::TCB)
|
RawCap::new(0, 0, ptr, ObjectType::TCB)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_object(&self) -> &TcbObject {
|
|
||||||
unsafe {
|
|
||||||
let virt = mmap_phys_to_virt(self.cte.cap.ptr);
|
|
||||||
&*(virt.as_const_ptr())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn as_object_mut(&mut self) -> &mut TcbObject {
|
|
||||||
unsafe {
|
|
||||||
let virt = mmap_phys_to_virt(self.cte.cap.ptr);
|
|
||||||
&mut *(virt.as_mut_ptr())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for TcbCap<'_> {
|
impl Debug for TcbCap<'_> {
|
||||||
|
Loading…
Reference in New Issue
Block a user