kernel/object/
memory_object.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use super::{alloc_kernel_object_id, KernelObject, KernelObjectId, KernelObjectType};
use alloc::sync::Arc;
use hal::memory::{Flags, PAddr};
use seed::boot_info::Segment;

#[derive(Debug)]
pub struct MemoryObject {
    pub id: KernelObjectId,
    pub owner: KernelObjectId,
    pub physical_address: PAddr,
    /// Size of this MemoryObject in bytes.
    pub size: usize,
    pub flags: Flags,
}

impl MemoryObject {
    pub fn new(owner: KernelObjectId, physical_address: PAddr, size: usize, flags: Flags) -> Arc<MemoryObject> {
        Arc::new(MemoryObject { id: alloc_kernel_object_id(), owner, physical_address, size, flags })
    }

    pub fn from_boot_info(owner: KernelObjectId, segment: &Segment) -> Arc<MemoryObject> {
        Arc::new(MemoryObject {
            id: alloc_kernel_object_id(),
            owner,
            physical_address: segment.physical_address,
            size: segment.size,
            flags: segment.flags,
        })
    }
}

impl KernelObject for MemoryObject {
    fn id(&self) -> KernelObjectId {
        self.id
    }

    fn typ(&self) -> KernelObjectType {
        KernelObjectType::MemoryObject
    }
}