summaryrefslogtreecommitdiff
path: root/src/sys/signal.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-05-20 03:03:32 +0000
committerGitHub <noreply@github.com>2020-05-20 03:03:32 +0000
commitd950c481abe5fb11cdbd648c67c8022c6c209664 (patch)
treea7b59c4359517d11228a5220c99aca4bb4e5396a /src/sys/signal.rs
parentd3fef370b843e0ffd6fc6df6e80d9bbe0d024863 (diff)
parentb05c3dc9d86f5957ad8963491cf735b74ea2c70d (diff)
downloadnix-d950c481abe5fb11cdbd648c67c8022c6c209664.zip
Merge #1098
1098: Add Redox support for most of the modules r=asomers a=AdminXVII 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 Co-authored-by: Xavier L'Heureux <xavier.lheureux@icloud.com> Co-authored-by: Xavier L'Heureux <dev.xlheureux@gmail.com>
Diffstat (limited to 'src/sys/signal.rs')
-rw-r--r--src/sys/signal.rs105
1 files changed, 92 insertions, 13 deletions
diff --git a/src/sys/signal.rs b/src/sys/signal.rs
index b746b3d4..2b36c957 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;
@@ -421,6 +464,7 @@ impl SigSet {
/// Suspends execution of the calling thread until one of the signals in the
/// signal mask becomes pending, and returns the accepted signal.
+ #[cfg(not(target_os = "redox"))] // RedoxFS does not yet support sigwait
pub fn wait(&self) -> Result<Signal> {
let mut signum = mem::MaybeUninit::uninit();
let res = unsafe { libc::sigwait(&self.sigset as *const libc::sigset_t, signum.as_mut_ptr()) };
@@ -449,6 +493,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 +510,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 +556,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 +566,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 +661,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 +800,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;
@@ -819,6 +891,7 @@ mod sigevent {
#[cfg(test)]
mod tests {
+ #[cfg(not(target_os = "redox"))]
use std::thread;
use super::*;
@@ -874,6 +947,7 @@ mod tests {
}
#[test]
+ #[cfg(not(target_os = "redox"))]
fn test_thread_signal_set_mask() {
thread::spawn(|| {
let prev_mask = SigSet::thread_get_mask()
@@ -894,6 +968,7 @@ mod tests {
}
#[test]
+ #[cfg(not(target_os = "redox"))]
fn test_thread_signal_block() {
thread::spawn(|| {
let mut mask = SigSet::empty();
@@ -906,6 +981,7 @@ mod tests {
}
#[test]
+ #[cfg(not(target_os = "redox"))]
fn test_thread_signal_unblock() {
thread::spawn(|| {
let mut mask = SigSet::empty();
@@ -918,6 +994,7 @@ mod tests {
}
#[test]
+ #[cfg(not(target_os = "redox"))]
fn test_thread_signal_swap() {
thread::spawn(|| {
let mut mask = SigSet::empty();
@@ -940,6 +1017,7 @@ mod tests {
}
#[test]
+ #[cfg(not(target_os = "redox"))]
fn test_sigaction() {
use libc;
thread::spawn(|| {
@@ -978,6 +1056,7 @@ mod tests {
}
#[test]
+ #[cfg(not(target_os = "redox"))]
fn test_sigwait() {
thread::spawn(|| {
let mut mask = SigSet::empty();