Add linked list allocator with automatic resizing

Fix memory leaks in exec
Remove warnings
This commit is contained in:
Jeremy Soller
2018-01-29 21:29:24 -07:00
parent 015b79430e
commit 761fe30bf3
12 changed files with 255 additions and 117 deletions
-1
View File
@@ -10,7 +10,6 @@ use spin::Mutex;
pub mod bump;
pub mod recycle;
pub mod slab;
/// The current memory map. It's size is maxed out to 512 entries, due to it being
/// from 0x500 to 0x5000 (800 is the absolute total)
-41
View File
@@ -1,41 +0,0 @@
use alloc::heap::{Alloc, AllocErr, Layout};
use spin::Mutex;
use slab_allocator::Heap;
static HEAP: Mutex<Option<Heap>> = Mutex::new(None);
pub unsafe fn init_heap(offset: usize, size: usize) {
*HEAP.lock() = Some(Heap::new(offset, size));
}
pub struct Allocator;
unsafe impl<'a> Alloc for &'a Allocator {
unsafe fn alloc(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> {
if let Some(ref mut heap) = *HEAP.lock() {
heap.allocate(layout)
} else {
panic!("__rust_allocate: heap not initialized");
}
}
unsafe fn dealloc(&mut self, ptr: *mut u8, layout: Layout) {
if let Some(ref mut heap) = *HEAP.lock() {
heap.deallocate(ptr, layout)
} else {
panic!("__rust_deallocate: heap not initialized");
}
}
fn oom(&mut self, error: AllocErr) -> ! {
panic!("Out of memory: {:?}", error);
}
fn usable_size(&self, layout: &Layout) -> (usize, usize) {
if let Some(ref mut heap) = *HEAP.lock() {
heap.usable_size(layout)
} else {
panic!("__rust_usable_size: heap not initialized");
}
}
}