mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Create a memory manager for convenience
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
pub use self::area_frame_allocator::AreaFrameAllocator;
|
pub use self::area_frame_allocator::AreaFrameAllocator;
|
||||||
pub use self::paging::remap_the_kernel;
|
pub use self::paging::remap_the_kernel;
|
||||||
|
pub use self::stack_allocator::Stack;
|
||||||
use self::paging::PhysicalAddress;
|
use self::paging::PhysicalAddress;
|
||||||
use multiboot2::BootInformation;
|
use multiboot2::BootInformation;
|
||||||
|
|
||||||
@@ -100,3 +101,19 @@ pub trait FrameAllocator {
|
|||||||
fn allocate_frame(&mut self) -> Option<Frame>;
|
fn allocate_frame(&mut self) -> Option<Frame>;
|
||||||
fn deallocate_frame(&mut self, frame: Frame);
|
fn deallocate_frame(&mut self, frame: Frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct MemoryController {
|
||||||
|
active_table: paging::ActivePageTable,
|
||||||
|
frame_allocator: AreaFrameAllocator,
|
||||||
|
stack_allocator: stack_allocator::StackAllocator,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MemoryController {
|
||||||
|
pub fn alloc_stack(&mut self, size_in_pages: usize) -> Option<Stack> {
|
||||||
|
let &mut MemoryController { ref mut active_table,
|
||||||
|
ref mut frame_allocator,
|
||||||
|
ref mut stack_allocator } = self;
|
||||||
|
stack_allocator.alloc_stack(active_table, frame_allocator,
|
||||||
|
size_in_pages)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user