From 4138b681177bb0dc3771d0852b415782e9cfc7d7 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Fri, 27 Dec 2024 21:22:01 +0100 Subject: [PATCH] Implement setrens and waitpid using procmgr. --- redox-rt/src/lib.rs | 3 +-- redox-rt/src/protocol.rs | 2 ++ redox-rt/src/sys.rs | 29 +++++++++++++++++++++-------- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/redox-rt/src/lib.rs b/redox-rt/src/lib.rs index 3ee2ec1d1b..63eb549487 100644 --- a/redox-rt/src/lib.rs +++ b/redox-rt/src/lib.rs @@ -245,12 +245,11 @@ pub(crate) fn static_proc_info() -> &'static StaticProcInfo { unsafe { &*STATIC_PROC_INFO.get() } } #[inline] -#[cfg(feature = "proc")] pub fn current_proc_fd() -> &'static FdGuard { static_proc_info() .proc_fd .as_ref() - .expect("must be present with proc feature") + .expect("proc fd must be present") } struct ChildHookCommonArgs { diff --git a/redox-rt/src/protocol.rs b/redox-rt/src/protocol.rs index 05672aa3b8..20ac56a8ec 100644 --- a/redox-rt/src/protocol.rs +++ b/redox-rt/src/protocol.rs @@ -16,12 +16,14 @@ unsafe impl plain::Plain for ProcMeta {} #[repr(usize)] pub enum ProcCall { Waitpid = 0, + Setrens = 1, } impl ProcCall { pub fn try_from_raw(raw: usize) -> Option { Some(match raw { 0 => Self::Waitpid, + 1 => Self::Setrens, _ => return None, }) } diff --git a/redox-rt/src/sys.rs b/redox-rt/src/sys.rs index e2355f04de..61d87bf980 100644 --- a/redox-rt/src/sys.rs +++ b/redox-rt/src/sys.rs @@ -114,17 +114,25 @@ pub unsafe fn sys_futex_wake(addr: *mut u32, num: u32) -> Result { ) .map(|awoken| awoken as u32) } -pub fn sys_waitpid(pid: usize, status: &mut usize, flags: usize) -> Result { - wrapper(true, || unsafe { - let metadata = [ProcCall::Waitpid as usize, pid, flags]; +fn proc_call(payload: &mut [u8], flags: CallFlags, metadata: &[usize]) -> Result { + unsafe { syscall::syscall5( syscall::SYS_CALL, **crate::current_proc_fd(), - status as *mut usize as usize, - size_of::(), - metadata.len() | CallFlags::empty().bits(), + payload.as_mut_ptr() as usize, + payload.len(), + metadata.len() | flags.bits(), metadata.as_ptr() as usize, ) + } +} +pub fn sys_waitpid(pid: usize, status: &mut usize, flags: usize) -> Result { + wrapper(true, || { + proc_call( + unsafe { plain::as_mut_bytes(status) }, + CallFlags::empty(), + &[ProcCall::Waitpid as usize, pid, flags], + ) }) } pub fn posix_kill_thread(thread_fd: usize, signal: u32) -> Result<()> { @@ -171,10 +179,15 @@ pub fn posix_getegid() -> u32 { DYNAMIC_PROC_INFO.lock().egid } pub fn posix_exit(status: i32) -> ! { - todo!("posix_exit") + todo!() } pub fn setrens(rns: usize, ens: usize) -> Result<()> { - todo!("setrens") + proc_call( + &mut [], + CallFlags::empty(), + &[ProcCall::Setrens as usize, rns, ens], + )?; + Ok(()) } pub fn posix_getpgid(pid: usize) -> Result { todo!("posix_getpgid")