diff --git a/Cargo.lock b/Cargo.lock index 2ad7d0fc1c..0ac6eeabe5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -256,9 +256,9 @@ checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" [[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", @@ -472,9 +472,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", ] diff --git a/Cargo.toml b/Cargo.toml index 2be8a02e5a..f855dbfde7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,8 +67,8 @@ bitflags = "2" ioslice = { version = "0.6", default-features = false } plain = "0.2" redox-path = "0.3" -redox_protocols = { package = "libredox", version = "0.1.14", default-features = false, features = ["protocol"] } -redox_syscall = "0.7.3" +redox_protocols = { package = "libredox", version = "0.1.16", default-features = false, features = ["protocol"] } +redox_syscall = "0.7.4" [build-dependencies] cc = "1" diff --git a/redox-rt/src/proc.rs b/redox-rt/src/proc.rs index 05e427571f..48cce3453d 100644 --- a/redox-rt/src/proc.rs +++ b/redox-rt/src/proc.rs @@ -1119,7 +1119,7 @@ pub fn new_child_process(args: &ForkArgs<'_>) -> Result { pid: 0, euid: 0, egid: 0, - ens: 1, + prio: !0, // Value is overwritten later debug_name: { let mut buf = [0; 32]; let src = b"[init]"; diff --git a/redox-rt/src/sys.rs b/redox-rt/src/sys.rs index 60b6fd282c..f0363a39a9 100644 --- a/redox-rt/src/sys.rs +++ b/redox-rt/src/sys.rs @@ -110,6 +110,37 @@ pub fn posix_getppid() -> u32 { this_proc_call(&mut [], CallFlags::empty(), &[ProcCall::Getppid as u64]).expect("cannot fail") as u32 } + +#[inline] +pub fn posix_setpriority(which: i32, who: u32, prio: u32) -> Result<(), syscall::Error> { + if which != 0 { + return Err(syscall::Error::new(syscall::EINVAL)); // TODO: Add support for PRIO_PGRP and PRIO_PROCESS + } + + this_proc_call( + &mut [], + CallFlags::empty(), + &[ProcCall::SetProcPriority as u64, who as u64, prio as u64], + )?; + + Ok(()) +} + +#[inline] +pub fn posix_getpriority(which: i32, who: u32) -> Result { + if which != 0 { + return Err(syscall::Error::new(syscall::EINVAL)); + } + + let res = this_proc_call( + &mut [], + CallFlags::empty(), + &[ProcCall::GetProcPriority as u64, who as u64], + )?; + + Ok(res as u32) +} + #[inline] pub unsafe fn sys_futex_wait(addr: *mut u32, val: u32, deadline: Option<&TimeSpec>) -> Result<()> { wrapper(true, false, || { diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs index c68b00c865..dc04059870 100644 --- a/src/platform/redox/mod.rs +++ b/src/platform/redox/mod.rs @@ -634,8 +634,13 @@ impl Pal for Sys { } fn getpriority(which: c_int, who: id_t) -> Result { - todo_skip!(0, "getpriority({}, {}): not implemented", which, who); - Err(Errno(ENOSYS)) + match redox_rt::sys::posix_getpriority(which, who as u32) { + Ok(kernel_prio) => { + let posix_prio = (kernel_prio as i32 * -1) + 40 as i32; + Ok(posix_prio) + } + Err(e) => Err(Errno(e.errno)), + } } fn getrandom(buf: &mut [u8], flags: c_uint) -> Result { @@ -1197,15 +1202,13 @@ impl Pal for Sys { } fn setpriority(which: c_int, who: id_t, prio: c_int) -> Result<()> { - // TODO - todo_skip!( - 0, - "setpriority({}, {}, {}): not implemented", - which, - who, - prio - ); - Err(Errno(ENOSYS)) + let clamped_prio = prio.clamp(-20, 19); + let kernel_prio = (20 + clamped_prio) as u32; + + match redox_rt::sys::posix_setpriority(which, who as u32, kernel_prio) { + Ok(_) => Ok(()), + Err(e) => Err(Errno(e.errno)), + } } fn setsid() -> Result {