Skip to content

Commit

Permalink
Add kernel-mode equivalent (part of #1 fix)
Browse files Browse the repository at this point in the history
kennystrawnmusic committed Aug 13, 2022
1 parent 4b60a88 commit cecb201
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/cralloc/kphysalloc.rs
Original file line number Diff line number Diff line change
@@ -29,4 +29,21 @@ pub fn kphysalloc(size: usize) -> usize {

// return the start address
virt_clone as usize
}

pub fn kphysfree(size: usize) {
// same as before: use a test page to determine proper alignment
let test_addr = VirtAddr::new(size as u64);
let test_page = Page::<Size4KiB>::containing_address(test_addr);
let mut virt = (test_page.start_address().as_u64() as usize) + crate::page_align(size as u64, test_addr.as_u64());

for _ in (size / crate::page_align(size as u64, test_addr.as_u64()))..0 {
map_page!(
size,
virt,
Size4KiB,
PageTableFlags::empty() // mapping with empty flags = freeing, does it not?
);
virt -= test_page.size() as usize; // reverse order
}
}

0 comments on commit cecb201

Please sign in to comment.