From daa0436cc4a3817376bbc29bad75652cd66d15f2 Mon Sep 17 00:00:00 2001 From: Celve Date: Tue, 12 Mar 2024 14:33:42 +0800 Subject: [PATCH] fix: solve issues caused by removing const traits According to https://github.com/rust-lang/rust/issues/110395, const traits cannot be used anymore. --- allocator/src/buddy_allocator.rs | 6 +++++- allocator/src/lib.rs | 1 - kernel/src/main.rs | 2 -- kernel/src/mem/normal/allocator.rs | 4 ++-- kernel/src/mem/normal/mod.rs | 7 +++++-- kernel/src/mem/slab/allocator.rs | 6 +++++- kernel/src/mem/table.rs | 4 ++-- kernel/src/mm/address.rs | 6 +++--- 8 files changed, 22 insertions(+), 14 deletions(-) diff --git a/allocator/src/buddy_allocator.rs b/allocator/src/buddy_allocator.rs index ca3b6e6..5b8e51d 100644 --- a/allocator/src/buddy_allocator.rs +++ b/allocator/src/buddy_allocator.rs @@ -64,7 +64,11 @@ impl BuddyAllocatorInner { user: 0, allocated: 0, total: 0, - gran: max(gran, size_of::()), + gran: if gran > size_of::() { + gran + } else { + size_of::() + }, } } diff --git a/allocator/src/lib.rs b/allocator/src/lib.rs index a837df2..859e24c 100644 --- a/allocator/src/lib.rs +++ b/allocator/src/lib.rs @@ -1,5 +1,4 @@ #![no_std] -#![feature(const_cmp)] pub mod buddy_allocator; pub mod linked_list; diff --git a/kernel/src/main.rs b/kernel/src/main.rs index f417d09..f13a4d8 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -11,8 +11,6 @@ const_trait_impl, const_for, const_mut_refs, - const_convert, - const_default_impls, sync_unsafe_cell )] diff --git a/kernel/src/mem/normal/allocator.rs b/kernel/src/mem/normal/allocator.rs index a11de5e..1bd7466 100644 --- a/kernel/src/mem/normal/allocator.rs +++ b/kernel/src/mem/normal/allocator.rs @@ -14,7 +14,7 @@ pub struct FrameAllocatorInner { recycled: Vec, } -impl const Default for FrameAllocatorInner { +impl Default for FrameAllocatorInner { fn default() -> Self { Self { start: PhyPageNum(0), @@ -24,7 +24,7 @@ impl const Default for FrameAllocatorInner { } } -impl const Default for FrameAllocator { +impl Default for FrameAllocator { fn default() -> Self { Self { inner: Spin::new(FrameAllocatorInner::default()), diff --git a/kernel/src/mem/normal/mod.rs b/kernel/src/mem/normal/mod.rs index 72f06b3..338a210 100644 --- a/kernel/src/mem/normal/mod.rs +++ b/kernel/src/mem/normal/mod.rs @@ -1,11 +1,14 @@ -use crate::{config::MEMORY_END, mem::allocator::PageAllocator}; +use lazy_static::lazy_static; use self::allocator::FrameAllocator; +use crate::{config::MEMORY_END, mem::allocator::PageAllocator}; pub mod allocator; pub mod page; -pub static FRAME_ALLOCATOR: FrameAllocator = FrameAllocator::default(); +lazy_static! { + pub static ref FRAME_ALLOCATOR: FrameAllocator = FrameAllocator::default(); +} pub fn init_frame_allocator() { extern "C" { diff --git a/kernel/src/mem/slab/allocator.rs b/kernel/src/mem/slab/allocator.rs index 85dac63..296c39e 100644 --- a/kernel/src/mem/slab/allocator.rs +++ b/kernel/src/mem/slab/allocator.rs @@ -88,7 +88,11 @@ impl BuddyAllocatorInner { user: 0, allocated: 0, total: 0, - gran: max(gran, size_of::()), + gran: if gran > size_of::() { + gran + } else { + size_of::() + }, } } diff --git a/kernel/src/mem/table.rs b/kernel/src/mem/table.rs index 0c1b349..4a689fd 100644 --- a/kernel/src/mem/table.rs +++ b/kernel/src/mem/table.rs @@ -36,7 +36,7 @@ impl MemTable { } } -impl const Default for MemTable { +impl Default for MemTable { fn default() -> Self { Self { units: Default::default(), @@ -59,7 +59,7 @@ impl MemUnit { } } -impl const Default for MemUnit { +impl Default for MemUnit { fn default() -> Self { Self { start_ppn: PhyPageNum(0), diff --git a/kernel/src/mm/address.rs b/kernel/src/mm/address.rs index 4765a29..7aa89c8 100644 --- a/kernel/src/mm/address.rs +++ b/kernel/src/mm/address.rs @@ -71,7 +71,7 @@ impl From for VirAddr { } } -impl const From for PhyPageNum { +impl From for PhyPageNum { fn from(value: usize) -> Self { Self(truncate_page_num!(truncate_phy_addr!(value)) >> PAGE_SIZE_BITS) } @@ -91,7 +91,7 @@ impl From for GenOffset { // from any to usize -impl const From for usize { +impl From for usize { fn from(value: PhyAddr) -> Self { value.0 } @@ -372,7 +372,7 @@ impl ops::Sub for PhyPageNum { } } -impl const ops::Sub for PhyPageNum { +impl ops::Sub for PhyPageNum { type Output = usize; fn sub(self, rhs: PhyPageNum) -> Self::Output {