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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use alloc::vec::Vec;
use crate::error::KernelError;
use crate::paging::PAGE_SIZE;
pub mod physical_mem_region;
pub use self::physical_mem_region::{PhysicalMemRegion, PhysicalMemRegionIter};
mod i386;
pub use self::i386::{FrameAllocator, init, mark_frame_bootstrap_allocated};
pub trait FrameAllocatorTrait: FrameAllocatorTraitPrivate {
fn allocate_region(length: usize) -> Result<PhysicalMemRegion, KernelError>;
fn allocate_frames_fragmented(length: usize) -> Result<Vec<PhysicalMemRegion>, KernelError>;
fn allocate_frame() -> Result<PhysicalMemRegion, KernelError> {
Self::allocate_region(PAGE_SIZE)
}
}
use self::private::FrameAllocatorTraitPrivate;
mod private {
use super::PhysicalMemRegion;
use crate::mem::PhysicalAddress;
pub trait FrameAllocatorTraitPrivate {
fn free_region(region: &PhysicalMemRegion);
fn check_is_allocated(address: PhysicalAddress, length: usize) -> bool;
fn check_is_reserved(region: PhysicalAddress, length: usize) -> bool;
}
}