1 use crate::{ 2 arch::{ 3 asm::current::current_pcb, 4 context::switch_process, 5 interrupt::{cli, sti}, 6 }, 7 syscall::{Syscall, SystemError}, 8 }; 9 10 use super::core::do_sched; 11 12 impl Syscall { 13 /// @brief 让系统立即运行调度器的系统调用 14 /// 请注意,该系统调用不能由ring3的程序发起 15 #[inline(always)] 16 pub fn sched(from_user: bool) -> Result<usize, SystemError> { 17 cli(); 18 // 进行权限校验,拒绝用户态发起调度 19 if from_user { 20 return Err(SystemError::EPERM); 21 } 22 // 根据调度结果统一进行切换 23 let pcb = do_sched(); 24 25 if pcb.is_some() { 26 switch_process(current_pcb(), pcb.unwrap()); 27 } 28 sti(); 29 return Ok(0); 30 } 31 } 32