Verified Commit 87ffd8b8 authored by Jeremy Soller's avatar Jeremy Soller
Browse files

0.2.11 - add daemon abstraction

parent 14796acf
Pipeline #10024 failed with stages
in 4 minutes and 3 seconds
[package]
name = "redox_syscall"
version = "0.2.10"
version = "0.2.11"
description = "A Rust library to access raw Redox system calls"
license = "MIT"
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
......
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) -> !>(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,
});
} 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))
}
}
}
#![feature(asm)]
#![feature(llvm_asm)]
#![feature(never_type)]
#![cfg_attr(not(test), no_std)]
#[cfg(test)]
......@@ -7,6 +8,7 @@ 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::*;
......@@ -44,6 +46,9 @@ 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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment