(
mapper: &mut impl Mapper<Size4KiB>,
frame_allocator: &mut impl FrameAllocator<Size4KiB>,
)
| 54 | }; |
| 55 | |
| 56 | pub fn init_heap( |
| 57 | mapper: &mut impl Mapper<Size4KiB>, |
| 58 | frame_allocator: &mut impl FrameAllocator<Size4KiB>, |
| 59 | ) -> Result<(), MapToError<Size4KiB>> { |
| 60 | let page_range = { |
| 61 | let heap_start = VirtAddr::new(HEAP_START as u64); |
| 62 | let heap_end = heap_start + HEAP_SIZE - 1u64; |
| 63 | let heap_start_page = Page::containing_address(heap_start); |
| 64 | let heap_end_page = Page::containing_address(heap_end); |
| 65 | Page::range_inclusive(heap_start_page, heap_end_page) |
| 66 | }; |
| 67 | |
| 68 | for page in page_range { |
| 69 | let frame = frame_allocator |
| 70 | .allocate_frame() |
| 71 | .ok_or(MapToError::FrameAllocationFailed)?; |
| 72 | let flags = |
| 73 | PageTableFlags::PRESENT | PageTableFlags::WRITABLE | PageTableFlags::USER_ACCESSIBLE; |
| 74 | unsafe { mapper.map_to(page, frame, flags, frame_allocator)?.flush() }; |
| 75 | } |
| 76 | |
| 77 | unsafe { |
| 78 | ALLOCATOR.lock().init(HEAP_START, HEAP_SIZE); |
| 79 | } |
| 80 | |
| 81 | Ok(()) |
| 82 | } |
no test coverage detected