diff --git a/src/arch/riscv64/mod.rs b/src/arch/riscv64/mod.rs index 464994c4..2add36e6 100644 --- a/src/arch/riscv64/mod.rs +++ b/src/arch/riscv64/mod.rs @@ -47,7 +47,7 @@ fn find_kernel_multiboot(chosen: &FdtNode<'_, '_>) -> Option<&'static [u8]> { let initrd_start = sptr::from_exposed_addr_mut::(addr); // SAFETY: We trust the raw pointer from the firmware - return Some(unsafe { slice::from_raw_parts(initrd_start, len) }); + Some(unsafe { slice::from_raw_parts(initrd_start, len) }) } pub fn find_kernel() -> &'static [u8] { diff --git a/src/arch/x86_64/physicalmem.rs b/src/arch/x86_64/physicalmem.rs index 547c62eb..3de31bba 100644 --- a/src/arch/x86_64/physicalmem.rs +++ b/src/arch/x86_64/physicalmem.rs @@ -1,9 +1,10 @@ use core::num::NonZeroUsize; use log::debug; +use one_shot_mutex::OneShotMutex; use x86_64::structures::paging::{FrameAllocator, FrameDeallocator, PageSize, PhysFrame, Size4KiB}; -static mut PHYS_ALLOC: Option = None; +static PHYS_ALLOC: OneShotMutex> = OneShotMutex::new(None); struct PhysAllocInner { next: NonZeroUsize, @@ -27,14 +28,13 @@ pub struct PhysAlloc; impl PhysAlloc { pub fn init(addr: usize) { - unsafe { - assert!(PHYS_ALLOC.is_none()); - PHYS_ALLOC.replace(PhysAllocInner::new(addr.try_into().unwrap())); - } + let mut phys_alloc = PHYS_ALLOC.lock(); + assert!(phys_alloc.is_none()); + phys_alloc.replace(PhysAllocInner::new(addr.try_into().unwrap())); } pub fn allocate(size: usize) -> usize { - unsafe { PHYS_ALLOC.as_mut().unwrap().allocate(size) } + PHYS_ALLOC.lock().as_mut().unwrap().allocate(size) } } diff --git a/src/fdt.rs b/src/fdt.rs index 1f49212b..320e8c14 100644 --- a/src/fdt.rs +++ b/src/fdt.rs @@ -136,7 +136,7 @@ mod uefi { inner: &'a T, } - impl<'a, T> fmt::Display for MemoryMapDisplay<'a, T> + impl fmt::Display for MemoryMapDisplay<'_, T> where T: MemoryMap, { @@ -169,7 +169,7 @@ mod uefi { inner: &'a MemoryDescriptor, } - impl<'a> fmt::Display for MemoryDescriptorDisplay<'a> { + impl fmt::Display for MemoryDescriptorDisplay<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f,