diff --git a/build/os.iso b/build/os.iso index b03452b..dc5f994 100644 Binary files a/build/os.iso and b/build/os.iso differ diff --git a/src/allocator/mod.rs b/src/allocator/mod.rs index 22870c8..19176eb 100644 --- a/src/allocator/mod.rs +++ b/src/allocator/mod.rs @@ -1,4 +1,4 @@ -use crate::memory::area_frame_allocator; +use crate::memory::area_frame_allocator::AreaFrameAllocator; use linked_list::LinkedListAllocator; use x86_64::VirtAddr; use x86_64::structures::paging::mapper::MapToError; @@ -10,7 +10,7 @@ pub const HEAP_START: usize = 0x_4444_4444_0000; pub const HEAP_SIZE: usize = 100 * 1024; // 100KiB #[global_allocator] -static ALLOCATOR: Locked = Locked::new(LinkedListAllocator::new()); +static ALLOCATOR: Locked = Locked::new(AreaFrameAllocator::new()); pub struct Locked { inner: spin::Mutex, @@ -31,6 +31,7 @@ impl Locked { pub fn init_heap( mapper: &mut impl Mapper, frame_allocator: &mut impl FrameAllocator, + multiboot_information_address: usize, ) -> Result<(), MapToError> { let page_range = { let heap_start = VirtAddr::new(HEAP_START as u64); @@ -47,7 +48,7 @@ pub fn init_heap( unsafe { mapper.map_to(page, frame, flags, frame_allocator)?.flush() }; } unsafe { - ALLOCATOR.lock().init(HEAP_START, HEAP_SIZE); + ALLOCATOR.lock().init(multiboot_information_address); } Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index bfc8ff3..eb718fe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,6 +13,7 @@ mod vga_buffer; use core::panic::PanicInfo; use multiboot2::{BootInformation, BootInformationHeader}; +use x86_64::VirtAddr; #[unsafe(no_mangle)] pub extern "C" fn rust_main(multiboot_information_address: usize) { @@ -68,6 +69,7 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) { multiboot_end, multiboot_end - multiboot_start ); + //init(); halt() } diff --git a/src/memory/area_frame_allocator.rs b/src/memory/area_frame_allocator.rs index aa95adf..950b47f 100644 --- a/src/memory/area_frame_allocator.rs +++ b/src/memory/area_frame_allocator.rs @@ -63,9 +63,14 @@ impl AreaFrameAllocator { } } - fn find_frame(&mut self, size: usize, align: usize) -> Option<(Frame, usize)> { + fn add_frame(&mut self) { + self.next_free_frame.number += 1; + } + fn find_frame(&mut self, size: usize, _align: usize) -> Option<(Frame, usize)> { let next_addr = self.next_free_frame.number * PAGE_SIZE + HEAP_START; - if &next_addr + core::mem::align_of::() <= PAGE_SIZE + HEAP_START { + if &next_addr + core::mem::align_of::() <= PAGE_SIZE + HEAP_START + && size < core::mem::align_of::() + { Some((Frame::containing_address(next_addr), next_addr)) } else { None @@ -91,5 +96,5 @@ unsafe impl GlobalAlloc for Locked { None => ptr::null_mut(), } } - unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {} + unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {} }