From d9fb718b861e0d5a84a41c08a7ef0751136f3af0 Mon Sep 17 00:00:00 2001 From: Asya Date: Sat, 11 Feb 2023 11:22:46 +0300 Subject: [PATCH] Zeroed page allocation --- kernel/src/memory.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kernel/src/memory.rs b/kernel/src/memory.rs index f5903f7f..265f2be1 100644 --- a/kernel/src/memory.rs +++ b/kernel/src/memory.rs @@ -20,6 +20,14 @@ impl MemoryManager { self.get_free_pages(order).map(|addr| addr as *mut u8) } + pub fn zallocate_pages(&mut self, order: usize) -> Option<*mut u8> { + let ptr = self.allocate_pages(order)?; + unsafe { + ptr.write_bytes(0, PAGE_SIZE << order); + } + Some(ptr) + } + /// # Safety /// This method assumes that `address` is in range of this allocator pub unsafe fn deallocate_pages(&mut self, address: *mut u8, order: usize) {