diff --git a/src/allocator/frame/buddy.rs b/src/allocator/frame/buddy.rs
index a1bb8d99f2..654a8fb0e4 100644
--- a/src/allocator/frame/buddy.rs
+++ b/src/allocator/frame/buddy.rs
@@ -39,7 +39,6 @@ struct BuddyMapFooter {
pub struct BuddyAllocator {
table_virt: VirtualAddress,
- clear_frees: bool,
phantom: PhantomData,
}
@@ -48,7 +47,7 @@ impl BuddyAllocator {
const MAP_PAGE_BYTES: usize = (A::PAGE_SIZE - mem::size_of::());
const MAP_PAGE_BITS: usize = Self::MAP_PAGE_BYTES * 8;
- pub unsafe fn new(mut bump_allocator: BumpAllocator, clear_frees: bool) -> Option {
+ pub unsafe fn new(mut bump_allocator: BumpAllocator) -> Option {
// Allocate buddy table
let table_phys = bump_allocator.allocate_one()?;
let table_virt = A::phys_to_virt(table_phys);
@@ -59,7 +58,6 @@ impl BuddyAllocator {
let mut allocator = Self {
table_virt,
- clear_frees,
phantom: PhantomData,
};
@@ -159,6 +157,8 @@ impl FrameAllocator for BuddyAllocator {
value &= !(1 << bit);
A::write(map_byte_virt, value);
let page_phys = entry.base.add(offset + bit * A::PAGE_SIZE);
+ let page_virt = A::phys_to_virt(page_phys);
+ A::write_bytes(page_virt, 0, A::PAGE_SIZE);
return Some(page_phys);
}
}
@@ -182,12 +182,6 @@ impl FrameAllocator for BuddyAllocator {
//TODO: Correct logic
for page in 0 .. count.data() {
let page_base = base.add(page * A::PAGE_SIZE);
-
- if self.clear_frees {
- let page_virt = A::phys_to_virt(page_base);
- A::write_bytes(page_virt, 0, A::PAGE_SIZE);
- }
-
let index = (page_base.data() - entry.base.data()) / A::PAGE_SIZE;
let mut map_page = index / Self::MAP_PAGE_BITS;
let map_bit = index % Self::MAP_PAGE_BITS;
diff --git a/src/allocator/frame/bump.rs b/src/allocator/frame/bump.rs
index af9822104f..7f4a2a2243 100644
--- a/src/allocator/frame/bump.rs
+++ b/src/allocator/frame/bump.rs
@@ -42,8 +42,11 @@ impl FrameAllocator for BumpAllocator {
let mut offset = self.offset;
for area in self.areas.iter() {
if offset < area.size {
+ let page_phys = area.base.add(offset);
+ let page_virt = A::phys_to_virt(page_phys);
+ A::write_bytes(page_virt, 0, A::PAGE_SIZE);
self.offset += A::PAGE_SIZE;
- return Some(area.base.add(offset));
+ return Some(page_phys);
}
offset -= area.size;
}
diff --git a/src/lib.rs b/src/lib.rs
index f100557a34..e0b4f6de08 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -60,7 +60,7 @@ impl VirtualAddress {
}
}
-#[derive(Debug)]
+#[derive(Clone, Copy, Debug)]
pub struct MemoryArea {
pub base: PhysicalAddress,
pub size: usize,
diff --git a/src/main.rs b/src/main.rs
index 9d7f3f2f18..31ed6150af 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -200,7 +200,7 @@ unsafe fn new_tables(areas: &'static [MemoryArea]) {
let offset = bump_allocator.offset();
println!("Permanently used: {}", format_size(offset));
- let mut allocator = BuddyAllocator::::new(bump_allocator, true).unwrap();
+ let mut allocator = BuddyAllocator::::new(bump_allocator).unwrap();
for i in 0..16 {
let phys_opt = allocator.allocate_one();
println!("page {}: {:X?}", i, phys_opt);