MCPcopy Create free account
hub / github.com/Ruddle/Fomos / init_heap

Function init_heap

bootloader/kernel/src/allocator.rs:56–82  ·  view source on GitHub ↗
(
    mapper: &mut impl Mapper<Size4KiB>,
    frame_allocator: &mut impl FrameAllocator<Size4KiB>,
)

Source from the content-addressed store, hash-verified

54};
55
56pub 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}

Callers 1

kernel_mainFunction · 0.85

Calls 3

allocate_frameMethod · 0.80
flushMethod · 0.45
initMethod · 0.45

Tested by

no test coverage detected