MCPcopy Index your code
hub / github.com/LibertyOS-Development/kernel / palloc

Function palloc

src/allocator/mod.rs:73–110  ·  view source on GitHub ↗

Allocate pages

(address: u64, size: u64)

Source from the content-addressed store, hash-verified

71
72// Allocate pages
73pub fn palloc(address: u64, size: u64)
74{
75 let mut mapper = unsafe
76 {
77 crate::mem::mapper(VirtAddr::new(crate::mem::PMEM_OFFSET))
78 };
79
80 let mut framealloc = unsafe
81 {
82 crate::mem::BootInfoFrameAllocator::init(crate::mem::MEMMAP.unwrap())
83 };
84
85 let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE | PageTableFlags::USER_ACCESSIBLE;
86
87 let pages =
88 {
89 let spage = Page::containing_address(VirtAddr::new(address));
90 let epage = Page::containing_address(VirtAddr::new(address + size));
91 Page::range_inclusive(spage, epage)
92 };
93
94 for page in pages
95 {
96 let frame = framealloc.allocate_frame().unwrap();
97
98 unsafe
99 {
100 if let Ok(mapping) = mapper.map_to(page, frame, flags, &mut framealloc)
101 {
102 mapping.flush();
103 }
104 else
105 {
106 print!("[ERR] UNABLE TO MAP {:?}", page);
107 }
108 }
109 }
110}
111
112
113// Deallocate pages

Callers 1

createMethod · 0.85

Calls 4

mapperFunction · 0.85
allocate_frameMethod · 0.80
flushMethod · 0.80
initFunction · 0.50

Tested by

no test coverage detected