Remove clone() and Daemon abstraction.

This commit is contained in:
4lDO2
2022-07-07 10:05:22 +02:00
parent 8e4529ae7c
commit 67cf0997dc
4 changed files with 0 additions and 72 deletions

View File

@@ -38,11 +38,6 @@ pub fn chmod<T: AsRef<str>>(path: T, mode: usize) -> Result<usize> {
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<usize> {
syscall1(SYS_CLONE, flags.bits())
}
/// Close a file
pub fn close(fd: usize) -> Result<usize> {
unsafe { syscall1(SYS_CLOSE, fd) }

View File

@@ -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<F: FnOnce(Daemon) -> Infallible>(f: F) -> Result<Infallible> {
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))
}
}
}

View File

@@ -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;

View File

@@ -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;