Skip to content

Commit

Permalink
Move #[global_allocator] into allocator module (#714)
Browse files Browse the repository at this point in the history
The Rust issue that the #[global_allocator] cannot be defined in submodules was fixed.
  • Loading branch information
phil-opp authored Jan 8, 2020
1 parent 817267e commit 869a69e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/allocator.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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>,
Expand All @@ -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(())
Expand Down
4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
extern crate alloc;

use core::panic::PanicInfo;
use linked_list_allocator::LockedHeap;

pub mod allocator;
pub mod gdt;
Expand All @@ -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();
Expand Down

0 comments on commit 869a69e

Please sign in to comment.