diff --git a/Cargo.lock b/Cargo.lock index 91185a1f01..3986e77567 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,7 +13,7 @@ dependencies = [ "pcid", "redox-scheme", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "scheme-utils", "spin", ] @@ -48,7 +48,7 @@ dependencies = [ "plain", "redox-scheme", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "ron", "rustc-hash", "scheme-utils", @@ -68,7 +68,7 @@ dependencies = [ "log", "pcid", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", ] [[package]] @@ -181,7 +181,7 @@ dependencies = [ "libc", "libredox", "redox-scheme", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "scheme-utils", ] @@ -213,7 +213,7 @@ dependencies = [ "fdt 0.2.0-alpha1", "libredox", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", ] [[package]] @@ -411,7 +411,7 @@ dependencies = [ "libredox", "log", "redox-log", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", ] [[package]] @@ -501,7 +501,7 @@ dependencies = [ "libc", "libredox", "redox-scheme", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", ] [[package]] @@ -569,7 +569,7 @@ dependencies = [ "log", "partitionlib", "redox-scheme", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "scheme-utils", ] @@ -586,7 +586,7 @@ dependencies = [ "log", "redox-ioctl", "redox-scheme", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "scheme-utils", ] @@ -597,7 +597,7 @@ dependencies = [ "daemon", "libredox", "redox-scheme", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "scheme-utils", ] @@ -654,7 +654,7 @@ dependencies = [ "log", "pcid", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", ] [[package]] @@ -734,7 +734,7 @@ dependencies = [ "ransid", "redox-scheme", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", ] [[package]] @@ -753,7 +753,7 @@ dependencies = [ "ransid", "redox-scheme", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "scheme-utils", ] @@ -1044,7 +1044,7 @@ dependencies = [ "log", "pcid", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", ] [[package]] @@ -1059,7 +1059,7 @@ dependencies = [ "pcid", "redox-scheme", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "scheme-utils", "spin", ] @@ -1082,7 +1082,7 @@ dependencies = [ "range-alloc", "redox-scheme", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "void", ] @@ -1106,7 +1106,7 @@ dependencies = [ "libc", "libredox", "plain", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "serde", "serde_json", "toml", @@ -1123,7 +1123,7 @@ dependencies = [ "log", "orbclient", "redox-scheme", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "scheme-utils", ] @@ -1148,7 +1148,7 @@ dependencies = [ "rand 0.10.1", "redox-scheme", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "scheme-utils", ] @@ -1175,7 +1175,7 @@ dependencies = [ "libredox", "pcid", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", ] [[package]] @@ -1208,15 +1208,15 @@ checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" [[package]] name = "libredox" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ddbf48fd451246b1f8c2610bd3b4ac0cc6e149d89832867093ab69a17194f08" +checksum = "e02f3bb43d335493c96bf3fd3a321600bf6bd07ed34bc64118e9293bdffea46c" dependencies = [ "bitflags 2.11.0", "ioslice", "libc", "plain", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", ] [[package]] @@ -1240,7 +1240,7 @@ dependencies = [ "driver-block", "libredox", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", ] [[package]] @@ -1265,7 +1265,7 @@ dependencies = [ "daemon", "libredox", "redox-scheme", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "scheme-utils", ] @@ -1362,7 +1362,7 @@ dependencies = [ "partitionlib", "pcid", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "smallvec 1.15.1", ] @@ -1489,7 +1489,7 @@ dependencies = [ "pico-args", "plain", "redox-scheme", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "scheme-utils", "serde", ] @@ -1505,7 +1505,7 @@ dependencies = [ "log", "pcid", "pico-args", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "serde", "toml", ] @@ -1591,7 +1591,7 @@ dependencies = [ "orbclient", "redox-scheme", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", ] [[package]] @@ -1602,7 +1602,7 @@ dependencies = [ "libredox", "redox-scheme", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "redox_termios", ] @@ -1635,7 +1635,7 @@ dependencies = [ "indexmap", "libredox", "redox-scheme", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "scheme-utils", "slab", ] @@ -1741,7 +1741,7 @@ dependencies = [ "rand_core 0.5.1", "raw-cpuid", "redox-scheme", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "scheme-utils", "sha2", ] @@ -1806,7 +1806,7 @@ version = "0.1.0" source = "git+https://gitlab.redox-os.org/redox-os/relibc.git#18e6c9f5c17b4db1361e536cd59e902a2080c4c0" dependencies = [ "drm-sys", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", ] [[package]] @@ -1827,7 +1827,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e58cb7dee1058575f320f9bfa32c7c0eda857e285c2a163a0eb595d37add09cd" dependencies = [ "libredox", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", ] [[package]] @@ -1851,7 +1851,7 @@ dependencies = [ "redox-log", "redox-scheme", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "scheme-utils", "smoltcp", ] @@ -1867,9 +1867,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce70a74e890531977d37e532c34d45e9055d2409ed08ddba14529471ed0be16" +checksum = "f450ad9c3b1da563fb6948a8e0fb0fb9269711c9c73d9ea1de5058c79c8d643a" dependencies = [ "bitflags 2.11.0", ] @@ -1889,7 +1889,7 @@ dependencies = [ "libredox", "qemu-exit", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "redox_termios", ] @@ -1965,7 +1965,7 @@ dependencies = [ "log", "pcid", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", ] [[package]] @@ -1980,7 +1980,7 @@ dependencies = [ "log", "pcid", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", ] [[package]] @@ -2019,7 +2019,7 @@ dependencies = [ "log", "redox-scheme", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "scheme-utils", "spin", ] @@ -2029,7 +2029,7 @@ name = "scheme-utils" version = "0.0.0" dependencies = [ "libredox", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", ] [[package]] @@ -2418,7 +2418,7 @@ dependencies = [ "inputd", "log", "orbclient", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "rehid", "xhcid", ] @@ -2429,7 +2429,7 @@ version = "0.1.0" dependencies = [ "common", "log", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "xhcid", ] @@ -2443,7 +2443,7 @@ dependencies = [ "libredox", "plain", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "thiserror 2.0.18", "xhcid", ] @@ -2481,7 +2481,7 @@ dependencies = [ "orbclient", "pcid", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", ] [[package]] @@ -2502,7 +2502,7 @@ dependencies = [ "orbclient", "ransid", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", ] [[package]] @@ -2518,7 +2518,7 @@ dependencies = [ "log", "pcid", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "spin", "static_assertions", "thiserror 2.0.18", @@ -2537,7 +2537,7 @@ dependencies = [ "log", "pcid", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "static_assertions", "thiserror 2.0.18", ] @@ -2557,7 +2557,7 @@ dependencies = [ "orbclient", "pcid", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "spin", "static_assertions", "virtio-core", @@ -2574,7 +2574,7 @@ dependencies = [ "libredox", "log", "pcid", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "static_assertions", "virtio-core", ] @@ -2907,7 +2907,7 @@ dependencies = [ "plain", "redox-scheme", "redox_event", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", "regex", "serde", "serde_json", @@ -2943,7 +2943,7 @@ dependencies = [ "daemon", "libredox", "redox-scheme", - "redox_syscall 0.7.3", + "redox_syscall 0.7.4", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 63e2b9a6b2..cdc14bbcee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -83,7 +83,7 @@ edid = "0.3.0" #TODO: edid is abandoned, fork it and maintain? fdt = "0.1.5" libc = "0.2.181" log = "0.4" -libredox = "0.1.15" +libredox = "0.1.16" orbclient = "0.3.51" parking_lot = "0.12" pico-args = "0.5" @@ -94,7 +94,7 @@ redox-ioctl = { git = "https://gitlab.redox-os.org/redox-os/relibc.git" } redox-log = { git = "https://gitlab.redox-os.org/redox-os/redox-log.git" } redox-rt = { git = "https://gitlab.redox-os.org/redox-os/relibc.git", default-features = false } redox-scheme = "0.11.0" -redox_syscall = "0.7.3" +redox_syscall = "0.7.4" redox_termios = "0.1.3" ron = "0.8.1" serde = { version = "1", features = ["derive"] } diff --git a/bootstrap/Cargo.lock b/bootstrap/Cargo.lock index 8a49dff49c..e738c973d9 100644 --- a/bootstrap/Cargo.lock +++ b/bootstrap/Cargo.lock @@ -41,13 +41,12 @@ checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" [[package]] name = "generic-rt" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/relibc.git#fccd849d2230b23e5fbb2cb5b24e5237d37eb8f1" [[package]] name = "goblin" -version = "0.7.1" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f27c1b4369c2cd341b5de549380158b105a04c331be5db9110eef7b6d2742134" +checksum = "983a6aafb3b12d4c41ea78d39e189af4298ce747353945ff5105b54a056e5cd9" dependencies = [ "log", "plain", @@ -77,9 +76,9 @@ checksum = "459427e2af2b9c839b132acb702a1c654d95e10f8c326bfc2ad11310e458b1c5" [[package]] name = "libredox" -version = "0.1.14" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1744e39d1d6a9948f4f388969627434e31128196de472883b39f148769bfe30a" +checksum = "e02f3bb43d335493c96bf3fd3a321600bf6bd07ed34bc64118e9293bdffea46c" dependencies = [ "bitflags", "libc", @@ -151,12 +150,12 @@ checksum = "436d45c2b6a5b159d43da708e62b25be3a4a3d5550d654b72216ade4c4bfd717" [[package]] name = "redox-rt" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/relibc.git#fccd849d2230b23e5fbb2cb5b24e5237d37eb8f1" dependencies = [ "bitflags", "generic-rt", "goblin", "ioslice", + "libredox", "plain", "redox-path", "redox_syscall", @@ -174,9 +173,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce70a74e890531977d37e532c34d45e9055d2409ed08ddba14529471ed0be16" +checksum = "f450ad9c3b1da563fb6948a8e0fb0fb9269711c9c73d9ea1de5058c79c8d643a" dependencies = [ "bitflags", ] @@ -189,18 +188,18 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "scroll" -version = "0.11.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04c565b551bafbef4157586fa379538366e4385d42082f255bfd96e4fe8519da" +checksum = "c1257cd4248b4132760d6524d6dda4e053bc648c9070b960929bf50cfb1e7add" dependencies = [ "scroll_derive", ] [[package]] name = "scroll_derive" -version = "0.11.1" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1db149f81d46d2deba7cd3c50772474707729550221e69588478ebf9ada425ae" +checksum = "ed76efe62313ab6610570951494bdaa81568026e0318eaa55f167de70eeea67d" dependencies = [ "proc-macro2", "quote", diff --git a/bootstrap/Cargo.toml b/bootstrap/Cargo.toml index a9f2864422..82120c213d 100644 --- a/bootstrap/Cargo.toml +++ b/bootstrap/Cargo.toml @@ -12,11 +12,11 @@ hashbrown = { version = "0.15", default-features = false, features = [ "default-hasher", ] } linked_list_allocator = "0.10" -libredox = { version = "0.1.14", default-features = false, features = ["protocol"] } +libredox = { version = "0.1.16", default-features = false, features = ["protocol"] } log = { version = "0.4", default-features = false } plain = "0.2" redox-initfs = { path = "../initfs", default-features = false } -redox_syscall = "0.7.3" +redox_syscall = "0.7.4" redox-scheme = { version = "0.11.0", default-features = false } redox-path = "0.3.1" slab = { version = "0.4.9", default-features = false } diff --git a/bootstrap/src/procmgr.rs b/bootstrap/src/procmgr.rs index 5e65a92664..ce37d574c9 100644 --- a/bootstrap/src/procmgr.rs +++ b/bootstrap/src/procmgr.rs @@ -381,6 +381,7 @@ struct Process { pgid: ProcessId, sid: ProcessId, name: ArrayString, + prio: u32, ruid: u32, euid: u32, @@ -636,6 +637,7 @@ impl<'a> ProcScheme<'a> { egid: 0, sgid: 0, name: ArrayString::<32>::from_str("[init]").unwrap(), + prio: 20, status: ProcessStatus::PossiblyRunnable, disabled_setpgid: false, @@ -678,6 +680,7 @@ impl<'a> ProcScheme<'a> { egid, sgid, name, + prio, .. } = *proc_guard.borrow(); @@ -710,6 +713,7 @@ impl<'a> ProcScheme<'a> { egid, sgid, name, + prio, status: ProcessStatus::PossiblyRunnable, disabled_setpgid: false, @@ -723,7 +727,7 @@ impl<'a> ProcScheme<'a> { })); if let Err(err) = new_process .borrow_mut() - .sync_kernel_attrs(child_pid, &self.auth) + .sync_kernel_attrs(&self.auth) { log::warn!("Failed to set kernel attrs when forking: {err}"); } @@ -753,7 +757,7 @@ impl<'a> ProcScheme<'a> { pid: pid.0 as u32, euid: proc.euid, egid: proc.egid, - ens: 0, + prio: proc.prio, debug_name: arraystring_to_bytes(proc.name), })?; @@ -1063,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), @@ -1589,7 +1613,7 @@ impl<'a> ProcScheme<'a> { if let Some(new_sgid) = new_sgid { proc.sgid = new_sgid; } - if let Err(err) = proc.sync_kernel_attrs(pid, &self.auth) { + if let Err(err) = proc.sync_kernel_attrs(&self.auth) { log::warn!("Failed to sync proc attrs in setresugid: {err}"); } Ok(()) @@ -2371,7 +2395,7 @@ impl<'a> ProcScheme<'a> { .borrow_mut(); proc.name = ArrayString::from_str(&new_name[..new_name.len().min(NAME_CAPAC)]).unwrap(); - if let Err(err) = proc.sync_kernel_attrs(pid, &self.auth) { + if let Err(err) = proc.sync_kernel_attrs(&self.auth) { log::warn!("Failed to set kernel attrs when renaming proc: {err}"); } Ok(()) @@ -2531,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, @@ -2548,22 +2609,30 @@ fn arraystring_to_bytes(s: ArrayString) -> [u8; C] { buf[..min].copy_from_slice(&s.as_bytes()[..min]); buf } + impl Process { - fn sync_kernel_attrs(&mut self, my_pid: ProcessId, auth: &FdGuard) -> Result<()> { + fn sync_kernel_attrs(&mut self, auth: &FdGuard) -> Result<()> { // TODO: continue with other threads if one fails? for thread_rc in &self.threads { - let thread = thread_rc.borrow(); - let attr_fd = thread - .fd - .dup(alloc::format!("auth-{}-attrs", auth.as_raw_fd()).as_bytes())?; - attr_fd.write(&ProcSchemeAttrs { - pid: my_pid.0 as u32, - euid: self.euid, - egid: self.egid, - ens: 0, - debug_name: arraystring_to_bytes(self.name), - })?; + let mut thread = thread_rc.borrow_mut(); + thread.sync_kernel_attrs(self, auth)?; } Ok(()) } } + +impl Thread { + fn sync_kernel_attrs(&mut self, process: &Process, auth: &FdGuard) -> Result<()> { + let attr_fd = self + .fd + .dup(alloc::format!("auth-{}-attrs", auth.as_raw_fd()).as_bytes())?; + attr_fd.write(&ProcSchemeAttrs { + pid: process.pid.0 as u32, + euid: process.euid, + egid: process.egid, + prio: process.prio, + debug_name: arraystring_to_bytes(process.name), + })?; + Ok(()) + } +}