diff --git a/Cargo.lock b/Cargo.lock index 4d14db1..ec9c1a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9,6 +9,7 @@ dependencies = [ "arrayvec", "bootloader", "lazy_static", + "linked_list_allocator", "pc-keyboard", "pic8259", "spin", @@ -49,6 +50,24 @@ dependencies = [ "spin", ] +[[package]] +name = "linked_list_allocator" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0b725207570aa16096962d0b20c79f8a543df2280bd3c903022b9b0b4d7ea68" +dependencies = [ + "spinning_top", +] + +[[package]] +name = "lock_api" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109" +dependencies = [ + "scopeguard", +] + [[package]] name = "pc-keyboard" version = "0.5.1" @@ -64,12 +83,27 @@ dependencies = [ "x86_64", ] +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + [[package]] name = "spin" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +[[package]] +name = "spinning_top" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75adad84ee84b521fb2cca2d4fd0f1dab1d8d026bda3c5bea4ca63b5f9f9293c" +dependencies = [ + "lock_api", +] + [[package]] name = "volatile" version = "0.2.7" diff --git a/Cargo.toml b/Cargo.toml index 4f76c5e..545d336 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ spin = "0.5.2" x86_64 = "0.14.2" pic8259 = "0.10.1" pc-keyboard = "0.5.0" +linked_list_allocator = "0.9.0" [dependencies.lazy_static] version = "1.0" diff --git a/src/allocator.rs b/src/allocator.rs index 16c4e0c..8780fc1 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -1,6 +1,7 @@ use alloc::alloc::{GlobalAlloc, Layout}; use x86_64::{VirtAddr, structures::paging::{FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB, mapper::MapToError}}; use core::ptr::null_mut; +use linked_list_allocator::LockedHeap; pub struct Dummy; @@ -15,7 +16,7 @@ unsafe impl GlobalAlloc for Dummy { } #[global_allocator] -static ALLOCATOR: Dummy = Dummy; +static ALLOCATOR: LockedHeap = LockedHeap::empty(); pub const HEAP_START: usize = 0x_4444_4444_0000; pub const HEAP_SIZE: usize = 100 * 1024; // 100 KiB @@ -37,5 +38,9 @@ pub fn init_heap(mapper: &mut impl Mapper, frame_allocator: &mut impl } } + unsafe { + ALLOCATOR.lock().init(HEAP_START, HEAP_SIZE); + } + Ok(()) }