1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-22 08:06:17 +04:00

Fix page switching problem

This commit is contained in:
Jiajie Chen 2020-06-19 11:01:11 +08:00
parent 990bb6a4a1
commit 274addfc34

View File

@ -50,7 +50,7 @@ pub unsafe fn current_thread() -> &'static mut Thread {
}
pub fn spawn(thread: Arc<Thread>) {
let vmtoken = thread.vm.lock().token();
let temp = thread.clone();
let future = async move {
loop {
let mut cx = thread.begin_running();
@ -90,27 +90,29 @@ pub fn spawn(thread: Arc<Thread>) {
}
};
spawn_thread(Box::pin(future), vmtoken);
spawn_thread(Box::pin(future), temp);
}
fn spawn_thread(future: Pin<Box<dyn Future<Output = ()> + Send + 'static>>, vmtoken: usize) {
fn spawn_thread(future: Pin<Box<dyn Future<Output = ()> + Send + 'static>>, thread: Arc<Thread>) {
executor::spawn(PageTableSwitchWrapper {
inner: Mutex::new(future),
vmtoken,
thread,
});
}
struct PageTableSwitchWrapper {
inner: Mutex<Pin<Box<dyn Future<Output = ()> + Send>>>,
vmtoken: usize,
thread: Arc<Thread>,
}
impl Future for PageTableSwitchWrapper {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
// vmtoken might change upon sys_exec
let vmtoken = self.thread.vm.lock().token();
unsafe {
Cr3::write(
PhysFrame::containing_address(PhysAddr::new(self.vmtoken as u64)),
PhysFrame::containing_address(PhysAddr::new(vmtoken as u64)),
Cr3Flags::empty(),
);
}