From 4a527cb374cf1f8328e7ce156c8ed92d12ae4742 Mon Sep 17 00:00:00 2001 From: Akshit Gaur Date: Mon, 23 Mar 2026 22:07:10 +0530 Subject: [PATCH] Add ProcCall --- bootstrap/src/procmgr.rs | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/bootstrap/src/procmgr.rs b/bootstrap/src/procmgr.rs index 24f4d01d5e..ce37d574c9 100644 --- a/bootstrap/src/procmgr.rs +++ b/bootstrap/src/procmgr.rs @@ -1067,6 +1067,26 @@ impl<'a> ProcScheme<'a> { // setrens is no longer implemented as procmgr call // FIXME remove this ProcCall variant ProcCall::Setrens => Response::ready_err(EINVAL, op), + ProcCall::SetProcPriority => { + let target_pid = NonZeroUsize::new(metadata[1] as usize).map_or(fd_pid, |n| ProcessId(n.get())); + + let new_prio = metadata[2] as u32; + + Ready(Response::new( + self.on_setprocprio(fd_pid, target_pid, new_prio).map(|()| 0), + op + )) + }, + ProcCall::GetProcPriority => { + let target_pid = NonZeroUsize::new(metadata[1] as usize) + .map_or(fd_pid, |n| ProcessId(n.get())); + + Ready(Response::new( + self.on_getprocprio(fd_pid, target_pid).map(|prio| prio as usize), + op, + )) + }, + } } Handle::Ps(_) => Response::ready_err(EOPNOTSUPP, op), @@ -2535,7 +2555,44 @@ impl<'a> ProcScheme<'a> { Ok(string.into_bytes()) } + + fn on_setprocprio( + &mut self, + caller_pid: ProcessId, + target_pid: ProcessId, + new_prio: u32, + ) -> Result<()> { + if new_prio >= 40 { + return Err(Error::new(EINVAL)); + } + + let caller_euid = self.processes.get(&caller_pid).ok_or(Error::new(ESRCH))?.borrow().euid; + + let target_rc = self.processes.get(&target_pid).ok_or(Error::new(ESRCH))?; + let mut target = target_rc.borrow_mut(); + + if caller_euid != 0 && caller_euid != target.euid { + return Err(Error::new(EPERM)); + } + + target.prio = new_prio; + + if let Err(err) = target.sync_kernel_attrs(&self.auth) { + log::warn!("Failed to sync proc attrs in setprocprio: {err}"); + } + Ok(()) + } + + fn on_getprocprio( + &self, + caller_pid: ProcessId, + target_pid: ProcessId, + ) -> Result { + let target_rc = self.processes.get(&target_pid).ok_or(Error::new(ESRCH))?; + Ok(target_rc.borrow().prio) + } } + #[derive(Clone, Copy, Debug)] enum KillMode { Idempotent,