From 8eebd501790ea8317e23cefb3f736e547ea04eec Mon Sep 17 00:00:00 2001 From: able Date: Sun, 28 May 2023 02:01:11 -0500 Subject: [PATCH] ALLOCATOR: misc --- kernel/src/allocator.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/kernel/src/allocator.rs b/kernel/src/allocator.rs index 8dcd3ed6..6e162f69 100644 --- a/kernel/src/allocator.rs +++ b/kernel/src/allocator.rs @@ -150,7 +150,8 @@ impl Heap { #[cfg(debug_assertions)] trace!("Allocating {:?}", ptr); } - // FIXME: zero or scrub memory? + // FIXME: zero out memory to prevent leaking data + assert!(ptr.is_aligned_to(alignment)); NonNull::new(ptr) } @@ -166,7 +167,7 @@ impl Heap { let size = unsafe { (*header).size_in_chunks }; self.bitmap_set_range(start, size, false); self.allocated_chunks -= size; - // FIXME: zero or scrub memory? + // FIXME: zero out memory to prevent leaking data } /// Finds first hole that can fit an allocation of `size` chunks, returns the start of the @@ -248,7 +249,10 @@ impl Heap { return Some(start_of_free_chunks); } } - trace!("No first fit found"); + #[cfg(debug_assertions)] + { + trace!("No first fit found"); + } None } @@ -334,6 +338,8 @@ impl Heap { unsafe impl Send for Heap {} #[alloc_error_handler] -fn alloc_error_handler(_layout: alloc::alloc::Layout) -> ! { +fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! { + log::error!("allocation error: {:?}", layout); + // Todo: Maybe panic here instead crate::arch::sloop() }