mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-24 01:43:22 +00:00
Remove syncronizations for the VmSpace
PF handler
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
7407cc8091
commit
52f1787d35
@ -229,7 +229,7 @@ impl Vmar_ {
|
|||||||
vm_mappings: BTreeMap::new(),
|
vm_mappings: BTreeMap::new(),
|
||||||
free_regions,
|
free_regions,
|
||||||
};
|
};
|
||||||
let vm_space = VmSpace::new();
|
let mut vm_space = VmSpace::new();
|
||||||
vm_space.register_page_fault_handler(handle_page_fault_wrapper);
|
vm_space.register_page_fault_handler(handle_page_fault_wrapper);
|
||||||
Vmar_::new(vmar_inner, Arc::new(vm_space), 0, ROOT_VMAR_CAP_ADDR, None)
|
Vmar_::new(vmar_inner, Arc::new(vm_space), 0, ROOT_VMAR_CAP_ADDR, None)
|
||||||
}
|
}
|
||||||
@ -661,7 +661,7 @@ impl Vmar_ {
|
|||||||
let vm_space = if let Some(parent) = parent {
|
let vm_space = if let Some(parent) = parent {
|
||||||
parent.vm_space().clone()
|
parent.vm_space().clone()
|
||||||
} else {
|
} else {
|
||||||
let new_space = VmSpace::new();
|
let mut new_space = VmSpace::new();
|
||||||
new_space.register_page_fault_handler(handle_page_fault_wrapper);
|
new_space.register_page_fault_handler(handle_page_fault_wrapper);
|
||||||
Arc::new(new_space)
|
Arc::new(new_space)
|
||||||
};
|
};
|
||||||
|
@ -15,8 +15,6 @@ use core::{
|
|||||||
sync::atomic::{AtomicPtr, Ordering},
|
sync::atomic::{AtomicPtr, Ordering},
|
||||||
};
|
};
|
||||||
|
|
||||||
use spin::Once;
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
io::Fallible,
|
io::Fallible,
|
||||||
kspace::KERNEL_PAGE_TABLE,
|
kspace::KERNEL_PAGE_TABLE,
|
||||||
@ -56,7 +54,7 @@ use crate::{
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct VmSpace {
|
pub struct VmSpace {
|
||||||
pt: PageTable<UserMode>,
|
pt: PageTable<UserMode>,
|
||||||
page_fault_handler: Once<fn(&VmSpace, &CpuExceptionInfo) -> core::result::Result<(), ()>>,
|
page_fault_handler: Option<fn(&VmSpace, &CpuExceptionInfo) -> core::result::Result<(), ()>>,
|
||||||
/// A CPU can only activate a `VmSpace` when no mutable cursors are alive.
|
/// A CPU can only activate a `VmSpace` when no mutable cursors are alive.
|
||||||
/// Cursors hold read locks and activation require a write lock.
|
/// Cursors hold read locks and activation require a write lock.
|
||||||
activation_lock: RwLock<()>,
|
activation_lock: RwLock<()>,
|
||||||
@ -67,7 +65,7 @@ impl VmSpace {
|
|||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
pt: KERNEL_PAGE_TABLE.get().unwrap().create_user_page_table(),
|
pt: KERNEL_PAGE_TABLE.get().unwrap().create_user_page_table(),
|
||||||
page_fault_handler: Once::new(),
|
page_fault_handler: None,
|
||||||
activation_lock: RwLock::new(()),
|
activation_lock: RwLock::new(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,21 +154,18 @@ impl VmSpace {
|
|||||||
&self,
|
&self,
|
||||||
info: &CpuExceptionInfo,
|
info: &CpuExceptionInfo,
|
||||||
) -> core::result::Result<(), ()> {
|
) -> core::result::Result<(), ()> {
|
||||||
if let Some(func) = self.page_fault_handler.get() {
|
if let Some(func) = self.page_fault_handler {
|
||||||
return func(self, info);
|
return func(self, info);
|
||||||
}
|
}
|
||||||
Err(())
|
Err(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Registers the page fault handler in this `VmSpace`.
|
/// Registers the page fault handler in this `VmSpace`.
|
||||||
///
|
|
||||||
/// The page fault handler of a `VmSpace` can only be initialized once.
|
|
||||||
/// If it has been initialized before, calling this method will have no effect.
|
|
||||||
pub fn register_page_fault_handler(
|
pub fn register_page_fault_handler(
|
||||||
&self,
|
&mut self,
|
||||||
func: fn(&VmSpace, &CpuExceptionInfo) -> core::result::Result<(), ()>,
|
func: fn(&VmSpace, &CpuExceptionInfo) -> core::result::Result<(), ()>,
|
||||||
) {
|
) {
|
||||||
self.page_fault_handler.call_once(|| func);
|
self.page_fault_handler = Some(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a reader to read data from the user space of the current task.
|
/// Creates a reader to read data from the user space of the current task.
|
||||||
|
Reference in New Issue
Block a user