summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
authorXavier L'Heureux <xavier.lheureux@icloud.com>2019-07-12 16:27:24 -0400
committerXavier L'Heureux <dev.xlheureux@gmail.com>2020-05-17 21:05:45 -0400
commit0259f9d51718b90118bbd1d792c88781d0aa98f7 (patch)
treec8d067b61393cb1628890790def3c6691c70bab6 /src/sys
parentd3fef370b843e0ffd6fc6df6e80d9bbe0d024863 (diff)
downloadnix-0259f9d51718b90118bbd1d792c88781d0aa98f7.zip
Add Redox support for most of the modules
Some things are not implemented yet in redox, so a lot of annotations were added to remove functions when compiling for redox. Those functions will hopefully be added in time, but for now it's better to have partial support than none. Blocked by https://github.com/rust-lang/libc/pull/1438
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/mod.rs4
-rw-r--r--src/sys/signal.rs111
-rw-r--r--src/sys/stat.rs4
-rw-r--r--src/sys/statvfs.rs2
-rw-r--r--src/sys/wait.rs9
5 files changed, 111 insertions, 19 deletions
diff --git a/src/sys/mod.rs b/src/sys/mod.rs
index d3c2f92b..98339b0f 100644
--- a/src/sys/mod.rs
+++ b/src/sys/mod.rs
@@ -34,6 +34,7 @@ pub mod ioctl;
#[cfg(target_os = "linux")]
pub mod memfd;
+#[cfg(not(target_os = "redox"))]
pub mod mman;
pub mod pthread;
@@ -53,6 +54,7 @@ pub mod quota;
#[cfg(any(target_os = "linux"))]
pub mod reboot;
+#[cfg(not(target_os = "redox"))]
pub mod select;
#[cfg(any(target_os = "android",
@@ -67,6 +69,7 @@ pub mod signal;
#[cfg(any(target_os = "android", target_os = "linux"))]
pub mod signalfd;
+#[cfg(not(target_os = "redox"))]
pub mod socket;
pub mod stat;
@@ -86,6 +89,7 @@ pub mod statvfs;
#[cfg(any(target_os = "android", target_os = "linux"))]
pub mod sysinfo;
+#[cfg(not(target_os = "redox"))]
pub mod termios;
pub mod time;
diff --git a/src/sys/signal.rs b/src/sys/signal.rs
index b746b3d4..ad5cc031 100644
--- a/src/sys/signal.rs
+++ b/src/sys/signal.rs
@@ -14,7 +14,7 @@ use std::str::FromStr;
use std::os::unix::io::RawFd;
use std::ptr;
-#[cfg(not(target_os = "openbsd"))]
+#[cfg(not(any(target_os = "openbsd", target_os = "redox")))]
pub use self::sigevent::*;
libc_enum!{
@@ -58,9 +58,11 @@ libc_enum!{
#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))]
SIGPWR,
SIGSYS,
- #[cfg(not(any(target_os = "android", target_os = "emscripten", target_os = "linux")))]
+ #[cfg(not(any(target_os = "android", target_os = "emscripten",
+ target_os = "linux", target_os = "redox")))]
SIGEMT,
- #[cfg(not(any(target_os = "android", target_os = "emscripten", target_os = "linux")))]
+ #[cfg(not(any(target_os = "android", target_os = "emscripten",
+ target_os = "linux", target_os = "redox")))]
SIGINFO,
}
}
@@ -103,9 +105,11 @@ impl FromStr for Signal {
#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))]
"SIGPWR" => Signal::SIGPWR,
"SIGSYS" => Signal::SIGSYS,
- #[cfg(not(any(target_os = "android", target_os = "emscripten", target_os = "linux")))]
+ #[cfg(not(any(target_os = "android", target_os = "emscripten",
+ target_os = "linux", target_os = "redox")))]
"SIGEMT" => Signal::SIGEMT,
- #[cfg(not(any(target_os = "android", target_os = "emscripten", target_os = "linux")))]
+ #[cfg(not(any(target_os = "android", target_os = "emscripten",
+ target_os = "linux", target_os = "redox")))]
"SIGINFO" => Signal::SIGINFO,
_ => return Err(Error::invalid_argument()),
})
@@ -154,9 +158,11 @@ impl Signal {
#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))]
Signal::SIGPWR => "SIGPWR",
Signal::SIGSYS => "SIGSYS",
- #[cfg(not(any(target_os = "android", target_os = "emscripten", target_os = "linux")))]
+ #[cfg(not(any(target_os = "android", target_os = "emscripten",
+ target_os = "linux", target_os = "redox")))]
Signal::SIGEMT => "SIGEMT",
- #[cfg(not(any(target_os = "android", target_os = "emscripten", target_os = "linux")))]
+ #[cfg(not(any(target_os = "android", target_os = "emscripten",
+ target_os = "linux", target_os = "redox")))]
Signal::SIGINFO => "SIGINFO",
}
}
@@ -176,6 +182,37 @@ impl fmt::Display for Signal {
pub use self::Signal::*;
+#[cfg(target_os = "redox")]
+const SIGNALS: [Signal; 29] = [
+ SIGHUP,
+ SIGINT,
+ SIGQUIT,
+ SIGILL,
+ SIGTRAP,
+ SIGABRT,
+ SIGBUS,
+ SIGFPE,
+ SIGKILL,
+ SIGUSR1,
+ SIGSEGV,
+ SIGUSR2,
+ SIGPIPE,
+ SIGALRM,
+ SIGTERM,
+ SIGCHLD,
+ SIGCONT,
+ SIGSTOP,
+ SIGTSTP,
+ SIGTTIN,
+ SIGTTOU,
+ SIGURG,
+ SIGXCPU,
+ SIGXFSZ,
+ SIGVTALRM,
+ SIGPROF,
+ SIGWINCH,
+ SIGIO,
+ SIGSYS];
#[cfg(all(any(target_os = "linux", target_os = "android", target_os = "emscripten"), not(any(target_arch = "mips", target_arch = "mips64", target_arch = "sparc64"))))]
const SIGNALS: [Signal; 31] = [
SIGHUP,
@@ -241,7 +278,8 @@ const SIGNALS: [Signal; 30] = [
SIGIO,
SIGPWR,
SIGSYS];
-#[cfg(not(any(target_os = "linux", target_os = "android", target_os = "emscripten")))]
+#[cfg(not(any(target_os = "linux", target_os = "android",
+ target_os = "emscripten", target_os = "redox")))]
const SIGNALS: [Signal; 31] = [
SIGHUP,
SIGINT,
@@ -318,8 +356,13 @@ pub const SIGIOT : Signal = SIGABRT;
pub const SIGPOLL : Signal = SIGIO;
pub const SIGUNUSED : Signal = SIGSYS;
+#[cfg(not(target_os = "redox"))]
+type SaFlags_t = libc::c_int;
+#[cfg(target_os = "redox")]
+type SaFlags_t = libc::c_ulong;
+
libc_bitflags!{
- pub struct SaFlags: libc::c_int {
+ pub struct SaFlags: SaFlags_t {
SA_NOCLDSTOP;
SA_NOCLDWAIT;
SA_NODEFER;
@@ -449,6 +492,7 @@ pub enum SigHandler {
Handler(extern fn(libc::c_int)),
/// Use the given signal-catching function, which takes in the signal, information about how
/// the signal was generated, and a pointer to the threads `ucontext_t`.
+ #[cfg(not(target_os = "redox"))]
SigAction(extern fn(libc::c_int, *mut libc::siginfo_t, *mut libc::c_void))
}
@@ -465,16 +509,31 @@ impl SigAction {
/// is the `SigAction` variant). `mask` specifies other signals to block during execution of
/// the signal-catching function.
pub fn new(handler: SigHandler, flags: SaFlags, mask: SigSet) -> SigAction {
- let mut s = mem::MaybeUninit::<libc::sigaction>::uninit();
- unsafe {
- let p = s.as_mut_ptr();
+ #[cfg(target_os = "redox")]
+ unsafe fn install_sig(p: *mut libc::sigaction, handler: SigHandler) {
+ (*p).sa_handler = match handler {
+ SigHandler::SigDfl => libc::SIG_DFL,
+ SigHandler::SigIgn => libc::SIG_IGN,
+ SigHandler::Handler(f) => f as *const extern fn(libc::c_int) as usize,
+ };
+ }
+
+ #[cfg(not(target_os = "redox"))]
+ unsafe fn install_sig(p: *mut libc::sigaction, handler: SigHandler) {
(*p).sa_sigaction = match handler {
SigHandler::SigDfl => libc::SIG_DFL,
SigHandler::SigIgn => libc::SIG_IGN,
SigHandler::Handler(f) => f as *const extern fn(libc::c_int) as usize,
SigHandler::SigAction(f) => f as *const extern fn(libc::c_int, *mut libc::siginfo_t, *mut libc::c_void) as usize,
};
+ }
+
+ let mut s = mem::MaybeUninit::<libc::sigaction>::uninit();
+ unsafe {
+ let p = s.as_mut_ptr();
+ install_sig(p, handler);
(*p).sa_flags = match handler {
+ #[cfg(not(target_os = "redox"))]
SigHandler::SigAction(_) => (flags | SaFlags::SA_SIGINFO).bits(),
_ => (flags - SaFlags::SA_SIGINFO).bits(),
};
@@ -496,6 +555,7 @@ impl SigAction {
}
/// Returns the action's handler.
+ #[cfg(not(target_os = "redox"))]
pub fn handler(&self) -> SigHandler {
match self.sigaction.sa_sigaction {
libc::SIG_DFL => SigHandler::SigDfl,
@@ -505,6 +565,16 @@ impl SigAction {
f => SigHandler::Handler( unsafe { mem::transmute(f) } ),
}
}
+
+ /// Returns the action's handler.
+ #[cfg(target_os = "redox")]
+ pub fn handler(&self) -> SigHandler {
+ match self.sigaction.sa_handler {
+ libc::SIG_DFL => SigHandler::SigDfl,
+ libc::SIG_IGN => SigHandler::SigIgn,
+ f => SigHandler::Handler( unsafe { mem::transmute(f) } ),
+ }
+ }
}
/// Changes the action taken by a process on receipt of a specific signal.
@@ -590,6 +660,7 @@ pub unsafe fn signal(signal: Signal, handler: SigHandler) -> Result<SigHandler>
SigHandler::SigDfl => libc::signal(signal, libc::SIG_DFL),
SigHandler::SigIgn => libc::signal(signal, libc::SIG_IGN),
SigHandler::Handler(handler) => libc::signal(signal, handler as libc::sighandler_t),
+ #[cfg(not(target_os = "redox"))]
SigHandler::SigAction(_) => return Err(Error::UnsupportedOperation),
};
Errno::result(res).map(|oldhandler| {
@@ -728,7 +799,7 @@ pub enum SigevNotify {
si_value: libc::intptr_t },
}
-#[cfg(not(target_os = "openbsd"))]
+#[cfg(not(any(target_os = "openbsd", target_os = "redox")))]
mod sigevent {
use libc;
use std::mem;
@@ -944,9 +1015,19 @@ mod tests {
use libc;
thread::spawn(|| {
extern fn test_sigaction_handler(_: libc::c_int) {}
+ #[cfg(not(target_os = "redox"))]
extern fn test_sigaction_action(_: libc::c_int,
_: *mut libc::siginfo_t, _: *mut libc::c_void) {}
+ #[cfg(not(target_os = "redox"))]
+ fn test_sigaction_sigaction(flags: SaFlags, mask: SigSet) {
+ let handler_act = SigHandler::SigAction(test_sigaction_action);
+ let action_act = SigAction::new(handler_act, flags, mask);
+ assert_eq!(action_act.handler(), handler_act);
+ }
+ #[cfg(target_os = "redox")]
+ fn test_sigaction_sigaction() {}
+
let handler_sig = SigHandler::Handler(test_sigaction_handler);
let flags = SaFlags::SA_ONSTACK | SaFlags::SA_RESTART |
@@ -965,9 +1046,7 @@ mod tests {
assert!(mask.contains(SIGUSR1));
assert!(!mask.contains(SIGUSR2));
- let handler_act = SigHandler::SigAction(test_sigaction_action);
- let action_act = SigAction::new(handler_act, flags, mask);
- assert_eq!(action_act.handler(), handler_act);
+ test_sigaction_sigaction(flags, mask);
let action_dfl = SigAction::new(SigHandler::SigDfl, flags, mask);
assert_eq!(action_dfl.handler(), SigHandler::SigDfl);
diff --git a/src/sys/stat.rs b/src/sys/stat.rs
index 29582251..5d426844 100644
--- a/src/sys/stat.rs
+++ b/src/sys/stat.rs
@@ -3,6 +3,7 @@ pub use libc::stat as FileStat;
use {Result, NixPath};
use errno::Errno;
+#[cfg(not(target_os = "redox"))]
use fcntl::{AtFlags, at_rawfd};
use libc;
use std::mem;
@@ -112,6 +113,7 @@ pub fn fstat(fd: RawFd) -> Result<FileStat> {
Ok(unsafe{dst.assume_init()})
}
+#[cfg(not(target_os = "redox"))]
pub fn fstatat<P: ?Sized + NixPath>(dirfd: RawFd, pathname: &P, f: AtFlags) -> Result<FileStat> {
let mut dst = mem::MaybeUninit::uninit();
let res = pathname.with_nix_path(|cstr| {
@@ -157,6 +159,7 @@ pub enum FchmodatFlags {
/// # References
///
/// [fchmodat(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/fchmodat.html).
+#[cfg(not(target_os = "redox"))]
pub fn fchmodat<P: ?Sized + NixPath>(
dirfd: Option<RawFd>,
path: &P,
@@ -260,6 +263,7 @@ pub enum UtimensatFlags {
/// # References
///
/// [utimensat(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/utimens.html).
+#[cfg(not(target_os = "redox"))]
pub fn utimensat<P: ?Sized + NixPath>(
dirfd: Option<RawFd>,
path: &P,
diff --git a/src/sys/statvfs.rs b/src/sys/statvfs.rs
index 26147803..8e8d367c 100644
--- a/src/sys/statvfs.rs
+++ b/src/sys/statvfs.rs
@@ -10,6 +10,7 @@ use libc::{self, c_ulong};
use {Result, NixPath};
use errno::Errno;
+#[cfg(not(target_os = "redox"))]
libc_bitflags!(
/// File system mount Flags
#[repr(C)]
@@ -108,6 +109,7 @@ impl Statvfs {
}
/// Get the mount flags
+ #[cfg(not(target_os = "redox"))]
pub fn flags(&self) -> FsFlags {
FsFlags::from_bits_truncate(self.0.f_flag)
}
diff --git a/src/sys/wait.rs b/src/sys/wait.rs
index d18c3757..252ef28d 100644
--- a/src/sys/wait.rs
+++ b/src/sys/wait.rs
@@ -15,6 +15,7 @@ libc_bitflags!(
target_os = "haiku",
target_os = "ios",
target_os = "linux",
+ target_os = "redox",
target_os = "macos",
target_os = "netbsd"))]
WEXITED;
@@ -24,6 +25,7 @@ libc_bitflags!(
target_os = "haiku",
target_os = "ios",
target_os = "linux",
+ target_os = "redox",
target_os = "macos",
target_os = "netbsd"))]
WSTOPPED;
@@ -33,16 +35,17 @@ libc_bitflags!(
target_os = "haiku",
target_os = "ios",
target_os = "linux",
+ target_os = "redox",
target_os = "macos",
target_os = "netbsd"))]
WNOWAIT;
/// Don't wait on children of other threads in this group
- #[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg(any(target_os = "android", target_os = "linux", target_os = "redox"))]
__WNOTHREAD;
/// Wait on all children, regardless of type
- #[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg(any(target_os = "android", target_os = "linux", target_os = "redox"))]
__WALL;
- #[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg(any(target_os = "android", target_os = "linux", target_os = "redox"))]
__WCLONE;
}
);