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