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:
Philipp Oppermann
2020-01-08 12:38:06 +01:00
committed by GitHub
parent 817267e51c
commit 869a69e531
2 changed files with 5 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
use alloc::alloc::{GlobalAlloc, Layout}; use alloc::alloc::{GlobalAlloc, Layout};
use core::ptr::null_mut; use core::ptr::null_mut;
use linked_list_allocator::LockedHeap;
use x86_64::{ use x86_64::{
structures::paging::{ structures::paging::{
mapper::MapToError, FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB, 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_START: usize = 0x_4444_4444_0000;
pub const HEAP_SIZE: usize = 100 * 1024; // 100 KiB pub const HEAP_SIZE: usize = 100 * 1024; // 100 KiB
#[global_allocator]
static ALLOCATOR: LockedHeap = LockedHeap::empty();
pub fn init_heap( pub fn init_heap(
mapper: &mut impl Mapper<Size4KiB>, mapper: &mut impl Mapper<Size4KiB>,
frame_allocator: &mut impl FrameAllocator<Size4KiB>, frame_allocator: &mut impl FrameAllocator<Size4KiB>,
@@ -31,7 +35,7 @@ pub fn init_heap(
} }
unsafe { unsafe {
super::ALLOCATOR.lock().init(HEAP_START, HEAP_SIZE); ALLOCATOR.lock().init(HEAP_START, HEAP_SIZE);
} }
Ok(()) Ok(())

View File

@@ -9,7 +9,6 @@
extern crate alloc; extern crate alloc;
use core::panic::PanicInfo; use core::panic::PanicInfo;
use linked_list_allocator::LockedHeap;
pub mod allocator; pub mod allocator;
pub mod gdt; pub mod gdt;
@@ -18,9 +17,6 @@ pub mod memory;
pub mod serial; pub mod serial;
pub mod vga_buffer; pub mod vga_buffer;
#[global_allocator]
static ALLOCATOR: LockedHeap = LockedHeap::empty();
pub fn init() { pub fn init() {
gdt::init(); gdt::init();
interrupts::init_idt(); interrupts::init_idt();