From ad211de6153373320f829eec5166e3ad1f43bb7e Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Sun, 19 Nov 2017 14:16:33 +0100 Subject: [PATCH] Use linked list allocator instead of bump allocator --- Cargo.toml | 1 + src/lib.rs | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 18eb63b..b06c55d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,4 @@ multiboot2 = "0.1.0" bitflags = "0.7.0" x86_64 = "0.1.2" once = "0.3.3" +linked_list_allocator = "0.4.2" diff --git a/src/lib.rs b/src/lib.rs index 869923e..9690d5e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,6 +20,7 @@ extern crate bitflags; extern crate x86_64; #[macro_use] extern crate once; +extern crate linked_list_allocator; #[macro_use] mod vga_buffer; @@ -40,8 +41,13 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) { // set up guard page and map the heap pages memory::init(boot_info); - use alloc::boxed::Box; - let heap_test = Box::new(42); + unsafe { + HEAP_ALLOCATOR.lock().init(HEAP_START, HEAP_START + HEAP_SIZE); + } + + for i in 0..10000 { + format!("Some String"); + } println!("It did not crash!"); @@ -74,11 +80,10 @@ pub extern fn panic_fmt(fmt: core::fmt::Arguments, file: &'static str, line: u32 loop{} } -use memory::heap_allocator::BumpAllocator; +use linked_list_allocator::LockedHeap; pub const HEAP_START: usize = 0o_000_001_000_000_0000; pub const HEAP_SIZE: usize = 100 * 1024; // 100 KiB #[global_allocator] -static HEAP_ALLOCATOR: BumpAllocator = BumpAllocator::new(HEAP_START, - HEAP_START + HEAP_SIZE); +static HEAP_ALLOCATOR: LockedHeap = LockedHeap::empty();