diff --git a/crate/memory/Cargo.toml b/crate/memory/Cargo.toml index fb4fe38..309f0a8 100644 --- a/crate/memory/Cargo.toml +++ b/crate/memory/Cargo.toml @@ -2,6 +2,7 @@ name = "ucore-memory" version = "0.1.0" authors = ["WangRunji "] +edition = "2018" [dependencies] log = "0.4" \ No newline at end of file diff --git a/crate/memory/src/addr.rs b/crate/memory/src/addr.rs index f38ec26..c5ea30d 100644 --- a/crate/memory/src/addr.rs +++ b/crate/memory/src/addr.rs @@ -1,9 +1,8 @@ use core::ops::{Add, AddAssign}; -use super::paging::*; -use super::memory_set::*; pub type VirtAddr = usize; pub type PhysAddr = usize; + pub const PAGE_SIZE: usize = 1 << 12; #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] @@ -80,13 +79,16 @@ impl Iterator for PageRange { /// frame for the swapmanager #[derive(Debug, Copy, Clone, PartialOrd, Ord)] #[repr(C)] -pub struct Frame { - page_table: usize, // the raw pointer for the frame's memory set's inactive page table - virtaddr: VirtAddr, // the virtual addr for the frame - token: usize, // the token for frame +pub struct Frame { + /// the raw pointer for the frame's memory set's inactive page table + page_table: usize, + /// the virtual addr for the frame + virtaddr: VirtAddr, + /// the token for frame + token: usize, } -impl Frame{ +impl Frame { pub fn get_page_table(&self) -> usize { self.page_table } @@ -95,25 +97,23 @@ impl Frame{ self.virtaddr } - pub fn get_token(&self) -> usize{ + pub fn get_token(&self) -> usize { self.token } - pub fn new(pt: usize, addr: VirtAddr, pttoken: usize) -> Self{ + pub fn new(pt: usize, addr: VirtAddr, pttoken: usize) -> Self { Frame { page_table: pt, virtaddr: addr, token: pttoken, } } -} +} -impl PartialEq for Frame{ +impl PartialEq for Frame { fn eq(&self, other: &Frame) -> bool { self.token == other.token && self.virtaddr == other.virtaddr } } -impl Eq for Frame{ - -} \ No newline at end of file +impl Eq for Frame {} \ No newline at end of file diff --git a/crate/memory/src/cow.rs b/crate/memory/src/cow.rs index aae8d5c..e616e42 100644 --- a/crate/memory/src/cow.rs +++ b/crate/memory/src/cow.rs @@ -206,7 +206,6 @@ impl FrameRcMap { pub mod test { use super::*; - use alloc::boxed::Box; #[test] fn test() { diff --git a/crate/memory/src/lib.rs b/crate/memory/src/lib.rs index 225d613..649d29d 100644 --- a/crate/memory/src/lib.rs +++ b/crate/memory/src/lib.rs @@ -1,15 +1,11 @@ -#![no_std] +#![cfg_attr(not(test), no_std)] #![feature(alloc)] #![feature(nll)] +#![feature(extern_crate_item_prelude)] +// import macros from log +use log::*; extern crate alloc; -#[macro_use] -extern crate log; - -// To use `println!` in test -#[cfg(test)] -#[macro_use] -extern crate std; pub mod paging; pub mod cow; @@ -17,4 +13,4 @@ pub mod swap; pub mod memory_set; mod addr; -pub use addr::*; \ No newline at end of file +pub use crate::addr::*; \ No newline at end of file diff --git a/crate/memory/src/memory_set.rs b/crate/memory/src/memory_set.rs index 1853f3b..92f2dfc 100644 --- a/crate/memory/src/memory_set.rs +++ b/crate/memory/src/memory_set.rs @@ -4,7 +4,7 @@ use alloc::vec::Vec; use core::fmt::{Debug, Error, Formatter}; use super::*; -use paging::*; +use crate::paging::*; /// an inactive page table /// Note: InactivePageTable is not a PageTable diff --git a/crate/memory/src/swap/enhanced_clock.rs b/crate/memory/src/swap/enhanced_clock.rs index 5d5d0bf..2651ba7 100644 --- a/crate/memory/src/swap/enhanced_clock.rs +++ b/crate/memory/src/swap/enhanced_clock.rs @@ -2,7 +2,7 @@ use alloc::collections::VecDeque; use super::*; -use paging::Entry; +use crate::paging::Entry; #[derive(Default)] pub struct EnhancedClockSwapManager { diff --git a/crate/memory/src/swap/mod.rs b/crate/memory/src/swap/mod.rs index ede0199..21a8259 100644 --- a/crate/memory/src/swap/mod.rs +++ b/crate/memory/src/swap/mod.rs @@ -10,7 +10,6 @@ use super::*; use super::paging::*; use super::memory_set::InactivePageTable; use super::addr::Frame; -use alloc::rc::Rc; use core::ops::{Deref, DerefMut}; //pub use self::fifo::FifoSwapManager;