mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Move #[global_allocator] into allocator module (#714)
The Rust issue that the #[global_allocator] cannot be defined in submodules was fixed.
This commit is contained in:
committed by
GitHub
parent
817267e51c
commit
869a69e531
@@ -1,5 +1,6 @@
|
||||
use alloc::alloc::{GlobalAlloc, Layout};
|
||||
use core::ptr::null_mut;
|
||||
use linked_list_allocator::LockedHeap;
|
||||
use x86_64::{
|
||||
structures::paging::{
|
||||
mapper::MapToError, FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB,
|
||||
@@ -10,6 +11,9 @@ use x86_64::{
|
||||
pub const HEAP_START: usize = 0x_4444_4444_0000;
|
||||
pub const HEAP_SIZE: usize = 100 * 1024; // 100 KiB
|
||||
|
||||
#[global_allocator]
|
||||
static ALLOCATOR: LockedHeap = LockedHeap::empty();
|
||||
|
||||
pub fn init_heap(
|
||||
mapper: &mut impl Mapper<Size4KiB>,
|
||||
frame_allocator: &mut impl FrameAllocator<Size4KiB>,
|
||||
@@ -31,7 +35,7 @@ pub fn init_heap(
|
||||
}
|
||||
|
||||
unsafe {
|
||||
super::ALLOCATOR.lock().init(HEAP_START, HEAP_SIZE);
|
||||
ALLOCATOR.lock().init(HEAP_START, HEAP_SIZE);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
extern crate alloc;
|
||||
|
||||
use core::panic::PanicInfo;
|
||||
use linked_list_allocator::LockedHeap;
|
||||
|
||||
pub mod allocator;
|
||||
pub mod gdt;
|
||||
@@ -18,9 +17,6 @@ pub mod memory;
|
||||
pub mod serial;
|
||||
pub mod vga_buffer;
|
||||
|
||||
#[global_allocator]
|
||||
static ALLOCATOR: LockedHeap = LockedHeap::empty();
|
||||
|
||||
pub fn init() {
|
||||
gdt::init();
|
||||
interrupts::init_idt();
|
||||
|
||||
Reference in New Issue
Block a user