Implement setrens and waitpid using procmgr.

This commit is contained in:
4lDO2
2024-12-27 21:22:01 +01:00
parent 0c1835a545
commit 4138b68117
3 changed files with 24 additions and 10 deletions
+1 -2
View File
@@ -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 {
+2
View File
@@ -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<Self> {
Some(match raw {
0 => Self::Waitpid,
1 => Self::Setrens,
_ => return None,
})
}
+21 -8
View File
@@ -114,17 +114,25 @@ pub unsafe fn sys_futex_wake(addr: *mut u32, num: u32) -> Result<u32> {
)
.map(|awoken| awoken as u32)
}
pub fn sys_waitpid(pid: usize, status: &mut usize, flags: usize) -> Result<usize> {
wrapper(true, || unsafe {
let metadata = [ProcCall::Waitpid as usize, pid, flags];
fn proc_call(payload: &mut [u8], flags: CallFlags, metadata: &[usize]) -> Result<usize> {
unsafe {
syscall::syscall5(
syscall::SYS_CALL,
**crate::current_proc_fd(),
status as *mut usize as usize,
size_of::<usize>(),
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<usize> {
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<usize> {
todo!("posix_getpgid")