From 67cf0997dc710707977c0075854c1410a7afcf22 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Thu, 7 Jul 2022 10:05:22 +0200 Subject: [PATCH] Remove clone() and Daemon abstraction. --- src/call.rs | 5 ----- src/daemon.rs | 62 --------------------------------------------------- src/lib.rs | 4 ---- src/number.rs | 1 - 4 files changed, 72 deletions(-) delete mode 100644 src/daemon.rs diff --git a/src/call.rs b/src/call.rs index 8cf2876..f42eaf9 100644 --- a/src/call.rs +++ b/src/call.rs @@ -38,11 +38,6 @@ pub fn chmod>(path: T, mode: usize) -> Result { unsafe { syscall3(SYS_CHMOD, path.as_ref().as_ptr() as usize, path.as_ref().len(), mode) } } -/// Produce a fork of the current process, or a new process thread -pub unsafe fn clone(flags: CloneFlags) -> Result { - syscall1(SYS_CLONE, flags.bits()) -} - /// Close a file pub fn close(fd: usize) -> Result { unsafe { syscall1(SYS_CLOSE, fd) } diff --git a/src/daemon.rs b/src/daemon.rs deleted file mode 100644 index 6433bcd..0000000 --- a/src/daemon.rs +++ /dev/null @@ -1,62 +0,0 @@ -use core::convert::Infallible; - -use super::{ - clone, - CloneFlags, - close, - EIO, - Error, - exit, - pipe2, - read, - Result, - write, -}; - -#[must_use = "Daemon::ready must be called"] -pub struct Daemon { - write_pipe: usize, -} - -impl Daemon { - pub fn new Infallible>(f: F) -> Result { - let mut pipes = [0; 2]; - pipe2(&mut pipes, 0)?; - - let [read_pipe, write_pipe] = pipes; - - if unsafe { clone(CloneFlags::empty())? } == 0 { - let _ = close(read_pipe); - - f(Daemon { - write_pipe, - }); - // TODO: Replace Infallible with the never type once it is stabilized. - unreachable!(); - } else { - let _ = close(write_pipe); - - let mut data = [0]; - let res = read(read_pipe, &mut data); - let _ = close(read_pipe); - - if res? == 1 { - exit(data[0] as usize)?; - unreachable!(); - } else { - Err(Error::new(EIO)) - } - } - } - - pub fn ready(self) -> Result<()> { - let res = write(self.write_pipe, &[0]); - let _ = close(self.write_pipe); - - if res? == 1 { - Ok(()) - } else { - Err(Error::new(EIO)) - } - } -} diff --git a/src/lib.rs b/src/lib.rs index 9c59398..3f6d884 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,6 @@ extern crate core; pub use self::arch::*; pub use self::call::*; -pub use self::daemon::*; pub use self::data::*; pub use self::error::*; pub use self::flag::*; @@ -43,9 +42,6 @@ pub mod call; /// Complex structures that are used for some system calls pub mod data; -/// Wrapper to make daemons easier to write -pub mod daemon; - /// All errors that can be generated by a system call pub mod error; diff --git a/src/number.rs b/src/number.rs index 1d6f17b..5cf50f7 100644 --- a/src/number.rs +++ b/src/number.rs @@ -41,7 +41,6 @@ pub const SYS_FUTIMENS: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 320; pub const SYS_EXEC: usize = 101; pub const SYS_CHDIR: usize = 12; pub const SYS_CLOCK_GETTIME: usize = 265; -pub const SYS_CLONE: usize = 120; pub const SYS_EXIT: usize = 1; pub const SYS_FUTEX: usize = 240; pub const SYS_GETCWD: usize = 183;