From 8ab991ebe123d51e56756e03a6fde030f26007dd Mon Sep 17 00:00:00 2001 From: WangRunji Date: Sat, 2 Mar 2019 11:18:15 +0800 Subject: [PATCH] remove global ActivePageTable, because it's CPU local --- kernel/src/fs/mod.rs | 2 +- kernel/src/memory.rs | 32 +++++++++++++++----------------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/kernel/src/fs/mod.rs b/kernel/src/fs/mod.rs index 1d06536..468329b 100644 --- a/kernel/src/fs/mod.rs +++ b/kernel/src/fs/mod.rs @@ -23,7 +23,7 @@ lazy_static! { let device = { #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] { - Box::new(drivers::DRIVERS.lock().iter() + Box::new(crate::drivers::DRIVERS.lock().iter() .map(|device| device.deref().as_any().downcast_ref::()) .find(|maybe_blk| maybe_blk.is_some()) .expect("VirtIOBlk not found") diff --git a/kernel/src/memory.rs b/kernel/src/memory.rs index ce1f577..e6357ff 100644 --- a/kernel/src/memory.rs +++ b/kernel/src/memory.rs @@ -33,15 +33,22 @@ lazy_static! { pub static ref FRAME_ALLOCATOR: SpinNoIrqLock = SpinNoIrqLock::new(FrameAlloc::default()); } -lazy_static! { - static ref ACTIVE_TABLE: SpinNoIrqLock> = SpinNoIrqLock::new(unsafe { - CowExt::new(ActivePageTable::new()) - }); -} - /// The only way to get active page table -pub fn active_table() -> MutexGuard<'static, CowExt, SpinNoIrq> { - ACTIVE_TABLE.lock() +/// +/// ## CHANGE LOG +/// +/// In the past, this function returns a `MutexGuard` of a global +/// `Mutex` object, which means only one CPU core +/// can access its active table at a time. +/// +/// But given that a page table is ** process local **, and being active +/// when and only when a thread of the process is running. +/// The ownership of this page table is in the `MemorySet` object. +/// So it's safe to access the active table inside `MemorySet`. +/// But the shared parts is readonly, e.g. all pages mapped in +/// `InactivePageTable::map_kernel()`. +pub fn active_table() -> ActivePageTable { + unsafe { ActivePageTable::new() } } @@ -123,12 +130,3 @@ impl rcore_memory::no_mmu::NoMMUSupport for NoMMUSupportImpl { pub fn page_fault_handler(_addr: usize) -> bool { unreachable!() } - - -//pub mod test { -// pub fn cow() { -// use super::*; -// use rcore_memory::cow::test::test_with; -// test_with(&mut active_table()); -// } -//}