From d7484ab48b740a5a9171b2ef622889aee9630e30 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 26 Jun 2019 15:05:57 +0200 Subject: [PATCH] Use linked_list_allocator crate instead of dummy allocator --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + src/allocator.rs | 4 ++++ src/lib.rs | 3 ++- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index be6694de..c52c589a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,6 +24,7 @@ version = "0.1.0" dependencies = [ "bootloader 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "linked_list_allocator 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "pc-keyboard 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "pic8259_simple 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -99,6 +100,14 @@ name = "libc" version = "0.2.51" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "linked_list_allocator" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "llvm-tools" version = "0.1.1" @@ -349,6 +358,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "0a7292d30132fb5424b354f5dc02512a86e4c516fe544bb7a25e7f266951b797" "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" "checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917" +"checksum linked_list_allocator 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "47314ec1d29aa869ee7cb5a5be57be9b1055c56567d59c3fb6689926743e0bea" "checksum llvm-tools 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "955be5d0ca0465caf127165acb47964f911e2bc26073e865deb8be7189302faf" "checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum os_bootinfo 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "66481dbeb5e773e7bd85b63cd6042c30786f834338288c5ec4f3742673db360a" diff --git a/Cargo.toml b/Cargo.toml index f7d9d20a..46e66f6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ x86_64 = "0.7.0" uart_16550 = "0.2.0" pic8259_simple = "0.1.1" pc-keyboard = "0.3.1" +linked_list_allocator = "0.6.4" [dependencies.lazy_static] version = "1.0" diff --git a/src/allocator.rs b/src/allocator.rs index cf85bd6d..0d1f3b73 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -30,6 +30,10 @@ pub fn init_heap( unsafe { mapper.map_to(page, frame, flags, frame_allocator)?.flush() }; } + unsafe { + super::ALLOCATOR.lock().init(HEAP_START, HEAP_SIZE); + } + Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index 3e7673a5..f416c1e5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,7 @@ extern crate alloc; use core::panic::PanicInfo; +use linked_list_allocator::LockedHeap; pub mod allocator; pub mod gdt; @@ -18,7 +19,7 @@ pub mod serial; pub mod vga_buffer; #[global_allocator] -static ALLOCATOR: allocator::Dummy = allocator::Dummy; +static ALLOCATOR: LockedHeap = LockedHeap::empty(); pub fn init() { gdt::init();