1 use crate::include::bindings::bindings::{process_control_block, switch_proc}; 2 3 use core::sync::atomic::compiler_fence; 4 5 use super::fpu::{fp_state_restore, fp_state_save}; 6 7 /// @brief 切换进程的上下文(没有切换页表的动作) 8 /// 9 /// @param next 下一个进程的pcb 10 /// @param trap_frame 中断上下文的栈帧 11 #[inline(always)] switch_process( prev: &'static mut process_control_block, next: &'static mut process_control_block, )12pub fn switch_process( 13 prev: &'static mut process_control_block, 14 next: &'static mut process_control_block, 15 ) { 16 fp_state_save(prev); 17 fp_state_restore(next); 18 compiler_fence(core::sync::atomic::Ordering::SeqCst); 19 let new_address_space = next.address_space().unwrap_or_else(|| { 20 panic!( 21 "switch_process: next process:{} address space is null", 22 next.pid 23 ) 24 }); 25 unsafe { 26 // 加载页表 27 new_address_space.read().user_mapper.utable.make_current(); 28 switch_proc(prev, next); 29 } 30 compiler_fence(core::sync::atomic::Ordering::SeqCst); 31 } 32