-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8590d9f
commit 7566b0b
Showing
6 changed files
with
92 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use x86_64::{ | ||
structures::paging::{ | ||
mapper::MapToError, FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB, | ||
}, | ||
VirtAddr, | ||
}; | ||
use linked_list_allocator::LockedHeap; | ||
|
||
#[global_allocator] | ||
static ALLOCATOR: LockedHeap = LockedHeap::empty(); | ||
|
||
pub fn init_heap( | ||
mapper: &mut impl Mapper<Size4KiB>, | ||
frame_allocator: &mut impl FrameAllocator<Size4KiB>, | ||
) -> Result<(), MapToError<Size4KiB>> { | ||
let page_range = { | ||
let heap_start = VirtAddr::new(HEAP_START as u64); | ||
let heap_end = heap_start + HEAP_SIZE - 1u64; | ||
let heap_start_page = Page::containing_address(heap_start); | ||
let heap_end_page = Page::containing_address(heap_end); | ||
Page::range_inclusive(heap_start_page, heap_end_page) | ||
}; | ||
|
||
for page in page_range { | ||
let frame = frame_allocator | ||
.allocate_frame() | ||
.ok_or(MapToError::FrameAllocationFailed)?; | ||
let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE; | ||
unsafe { | ||
mapper.map_to(page, frame, flags, frame_allocator)?.flush() | ||
}; | ||
} | ||
|
||
// Initialize the allocator with the correct bounds | ||
unsafe { | ||
ALLOCATOR.lock().init(HEAP_START, HEAP_SIZE); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
pub const HEAP_START: usize = 0x_4444_4444_0000; | ||
pub const HEAP_SIZE: usize = 100 * 1024; // 100 KiB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters