Add linked list allocator with automatic resizing
Fix memory leaks in exec Remove warnings
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user