Add rustfmt from relibc and apply it with cargo fmt
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
use core::alloc::{GlobalAlloc, Layout};
|
||||
use core::ptr::{self, NonNull};
|
||||
use core::{
|
||||
alloc::{GlobalAlloc, Layout},
|
||||
ptr::{self, NonNull},
|
||||
};
|
||||
use linked_list_allocator::Heap;
|
||||
use spin::Mutex;
|
||||
|
||||
@@ -21,10 +23,18 @@ unsafe impl GlobalAlloc for Allocator {
|
||||
match heap.allocate_first_fit(layout) {
|
||||
Err(()) => {
|
||||
let size = heap.size();
|
||||
super::map_heap(&mut KernelMapper::lock(), crate::KERNEL_HEAP_OFFSET + size, crate::KERNEL_HEAP_SIZE);
|
||||
super::map_heap(
|
||||
&mut KernelMapper::lock(),
|
||||
crate::KERNEL_HEAP_OFFSET + size,
|
||||
crate::KERNEL_HEAP_SIZE,
|
||||
);
|
||||
heap.extend(crate::KERNEL_HEAP_SIZE);
|
||||
},
|
||||
other => return other.ok().map_or(ptr::null_mut(), |allocation| allocation.as_ptr()),
|
||||
}
|
||||
other => {
|
||||
return other
|
||||
.ok()
|
||||
.map_or(ptr::null_mut(), |allocation| allocation.as_ptr())
|
||||
}
|
||||
}
|
||||
}
|
||||
panic!("__rust_allocate: heap not initialized");
|
||||
|
||||
+16
-8
@@ -1,26 +1,34 @@
|
||||
use crate::paging::{mapper::PageFlushAll, KernelMapper, Page, PageFlags, VirtualAddress};
|
||||
use rmm::Flusher;
|
||||
use crate::paging::{KernelMapper, Page, PageFlags, VirtualAddress, mapper::PageFlushAll};
|
||||
|
||||
#[cfg(not(feature="slab"))]
|
||||
#[cfg(not(feature = "slab"))]
|
||||
pub use self::linked_list::Allocator;
|
||||
|
||||
#[cfg(feature="slab")]
|
||||
#[cfg(feature = "slab")]
|
||||
pub use self::slab::Allocator;
|
||||
|
||||
#[cfg(not(feature="slab"))]
|
||||
#[cfg(not(feature = "slab"))]
|
||||
mod linked_list;
|
||||
|
||||
#[cfg(feature="slab")]
|
||||
#[cfg(feature = "slab")]
|
||||
mod slab;
|
||||
|
||||
unsafe fn map_heap(mapper: &mut KernelMapper, offset: usize, size: usize) {
|
||||
let mapper = mapper.get_mut().expect("failed to obtain exclusive access to KernelMapper while extending heap");
|
||||
let mapper = mapper
|
||||
.get_mut()
|
||||
.expect("failed to obtain exclusive access to KernelMapper while extending heap");
|
||||
let mut flush_all = PageFlushAll::new();
|
||||
|
||||
let heap_start_page = Page::containing_address(VirtualAddress::new(offset));
|
||||
let heap_end_page = Page::containing_address(VirtualAddress::new(offset + size-1));
|
||||
let heap_end_page = Page::containing_address(VirtualAddress::new(offset + size - 1));
|
||||
for page in Page::range_inclusive(heap_start_page, heap_end_page) {
|
||||
let result = mapper.map(page.start_address(), PageFlags::new().write(true).global(cfg!(not(feature = "pti"))))
|
||||
let result = mapper
|
||||
.map(
|
||||
page.start_address(),
|
||||
PageFlags::new()
|
||||
.write(true)
|
||||
.global(cfg!(not(feature = "pti"))),
|
||||
)
|
||||
.expect("failed to map kernel heap");
|
||||
flush_all.consume(result);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use core::alloc::{Alloc, AllocErr, Layout};
|
||||
use spin::Mutex;
|
||||
use slab_allocator::Heap;
|
||||
use spin::Mutex;
|
||||
|
||||
static HEAP: Mutex<Option<Heap>> = Mutex::new(None);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user