From 5846ae2afd76ba1ffaddb9d08f91dfbed30243c4 Mon Sep 17 00:00:00 2001 From: Amanda Tait Date: Wed, 5 Aug 2020 13:25:03 -0400 Subject: Add fuchsia support Allow nix to compile on Fuchsia by conditionally avoiding libc functionality that does not exist for Fuchsia. --- src/sys/signal.rs | 61 +++++++++++++++++++++++++++++++++++--------------- src/sys/socket/addr.rs | 8 ++++--- 2 files changed, 48 insertions(+), 21 deletions(-) (limited to 'src/sys') diff --git a/src/sys/signal.rs b/src/sys/signal.rs index 710e65f5..2f8b5fa8 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -39,8 +39,10 @@ libc_enum!{ SIGPIPE, SIGALRM, SIGTERM, - #[cfg(all(any(target_os = "android", target_os = "emscripten", target_os = "linux"), - not(any(target_arch = "mips", target_arch = "mips64", target_arch = "sparc64"))))] + #[cfg(all(any(target_os = "android", target_os = "emscripten", + target_os = "fuchsia", target_os = "linux"), + not(any(target_arch = "mips", target_arch = "mips64", + target_arch = "sparc64"))))] SIGSTKFLT, SIGCHLD, SIGCONT, @@ -55,14 +57,17 @@ libc_enum!{ SIGPROF, SIGWINCH, SIGIO, - #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))] + #[cfg(any(target_os = "android", target_os = "emscripten", + target_os = "fuchsia", target_os = "linux"))] SIGPWR, SIGSYS, #[cfg(not(any(target_os = "android", target_os = "emscripten", - target_os = "linux", target_os = "redox")))] + target_os = "fuchsia", target_os = "linux", + target_os = "redox")))] SIGEMT, #[cfg(not(any(target_os = "android", target_os = "emscripten", - target_os = "linux", target_os = "redox")))] + target_os = "fuchsia", target_os = "linux", + target_os = "redox")))] SIGINFO, } } @@ -86,8 +91,10 @@ impl FromStr for Signal { "SIGPIPE" => Signal::SIGPIPE, "SIGALRM" => Signal::SIGALRM, "SIGTERM" => Signal::SIGTERM, - #[cfg(all(any(target_os = "android", target_os = "emscripten", target_os = "linux"), - not(any(target_arch = "mips", target_arch = "mips64", target_arch = "sparc64"))))] + #[cfg(all(any(target_os = "android", target_os = "emscripten", + target_os = "fuchsia", target_os = "linux"), + not(any(target_arch = "mips", target_arch = "mips64", + target_arch = "sparc64"))))] "SIGSTKFLT" => Signal::SIGSTKFLT, "SIGCHLD" => Signal::SIGCHLD, "SIGCONT" => Signal::SIGCONT, @@ -102,14 +109,17 @@ impl FromStr for Signal { "SIGPROF" => Signal::SIGPROF, "SIGWINCH" => Signal::SIGWINCH, "SIGIO" => Signal::SIGIO, - #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))] + #[cfg(any(target_os = "android", target_os = "emscripten", + target_os = "fuchsia", target_os = "linux"))] "SIGPWR" => Signal::SIGPWR, "SIGSYS" => Signal::SIGSYS, #[cfg(not(any(target_os = "android", target_os = "emscripten", - target_os = "linux", target_os = "redox")))] + target_os = "fuchsia", target_os = "linux", + target_os = "redox")))] "SIGEMT" => Signal::SIGEMT, #[cfg(not(any(target_os = "android", target_os = "emscripten", - target_os = "linux", target_os = "redox")))] + target_os = "fuchsia", target_os = "linux", + target_os = "redox")))] "SIGINFO" => Signal::SIGINFO, _ => return Err(Error::invalid_argument()), }) @@ -139,7 +149,8 @@ impl Signal { Signal::SIGPIPE => "SIGPIPE", Signal::SIGALRM => "SIGALRM", Signal::SIGTERM => "SIGTERM", - #[cfg(all(any(target_os = "android", target_os = "emscripten", target_os = "linux"), + #[cfg(all(any(target_os = "android", target_os = "emscripten", + target_os = "fuchsia", target_os = "linux"), not(any(target_arch = "mips", target_arch = "mips64", target_arch = "sparc64"))))] Signal::SIGSTKFLT => "SIGSTKFLT", Signal::SIGCHLD => "SIGCHLD", @@ -155,14 +166,17 @@ impl Signal { Signal::SIGPROF => "SIGPROF", Signal::SIGWINCH => "SIGWINCH", Signal::SIGIO => "SIGIO", - #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))] + #[cfg(any(target_os = "android", target_os = "emscripten", + target_os = "fuchsia", target_os = "linux"))] Signal::SIGPWR => "SIGPWR", Signal::SIGSYS => "SIGSYS", #[cfg(not(any(target_os = "android", target_os = "emscripten", - target_os = "linux", target_os = "redox")))] + target_os = "fuchsia", target_os = "linux", + target_os = "redox")))] Signal::SIGEMT => "SIGEMT", #[cfg(not(any(target_os = "android", target_os = "emscripten", - target_os = "linux", target_os = "redox")))] + target_os = "fuchsia", target_os = "linux", + target_os = "redox")))] Signal::SIGINFO => "SIGINFO", } } @@ -213,7 +227,10 @@ const SIGNALS: [Signal; 29] = [ 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"))))] +#[cfg(all(any(target_os = "linux", target_os = "android", + target_os = "emscripten", target_os = "fuchsia"), + not(any(target_arch = "mips", target_arch = "mips64", + target_arch = "sparc64"))))] const SIGNALS: [Signal; 31] = [ SIGHUP, SIGINT, @@ -246,7 +263,10 @@ const SIGNALS: [Signal; 31] = [ SIGIO, SIGPWR, SIGSYS]; -#[cfg(all(any(target_os = "linux", target_os = "android", target_os = "emscripten"), any(target_arch = "mips", target_arch = "mips64", target_arch = "sparc64")))] +#[cfg(all(any(target_os = "linux", target_os = "android", + target_os = "emscripten", target_os = "fuchsia"), + any(target_arch = "mips", target_arch = "mips64", + target_arch = "sparc64")))] const SIGNALS: [Signal; 30] = [ SIGHUP, SIGINT, @@ -279,7 +299,8 @@ const SIGNALS: [Signal; 30] = [ SIGPWR, SIGSYS]; #[cfg(not(any(target_os = "linux", target_os = "android", - target_os = "emscripten", target_os = "redox")))] + target_os = "fuchsia", target_os = "emscripten", + target_os = "redox")))] const SIGNALS: [Signal; 31] = [ SIGHUP, SIGINT, @@ -749,6 +770,7 @@ pub fn kill>>(pid: Pid, signal: T) -> Result<()> { /// If `pgrp` less then or equal 1, the behavior is platform-specific. /// If `signal` is `None`, `killpg` will only preform error checking and won't /// send any signal. +#[cfg(not(target_os = "fuchsia"))] pub fn killpg>>(pgrp: Pid, signal: T) -> Result<()> { let res = unsafe { libc::killpg(pgrp.into(), match signal.into() { @@ -829,7 +851,10 @@ mod sigevent { /// `SIGEV_SIGNAL`. That field is part of a union that shares space with the /// more genuinely useful `sigev_notify_thread_id` pub fn new(sigev_notify: SigevNotify) -> SigEvent { - let mut sev = unsafe { mem::zeroed::()}; + // NB: This uses MaybeUninit rather than mem::zeroed because libc::sigevent contains a + // function pointer on Fuchsia as of https://github.com/rust-lang/libc/commit/2f59370, + // and function pointers must not be null. + let mut sev = unsafe { mem::MaybeUninit::::zeroed().assume_init() }; sev.sigev_notify = match sigev_notify { SigevNotify::SigevNone => libc::SIGEV_NONE, SigevNotify::SigevSignal{..} => libc::SIGEV_SIGNAL, diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 8784a37b..2299c57d 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -21,7 +21,8 @@ use crate::sys::socket::addr::sys_control::SysControlAddr; target_os = "linux", target_os = "macos", target_os = "netbsd", - target_os = "openbsd"))] + target_os = "openbsd", + target_os = "fuchsia"))] pub use self::datalink::LinkAddr; #[cfg(any(target_os = "android", target_os = "linux"))] pub use self::vsock::VsockAddr; @@ -41,7 +42,7 @@ pub enum AddressFamily { #[cfg(any(target_os = "android", target_os = "linux"))] Netlink = libc::AF_NETLINK, /// Low level packet interface (see [`packet(7)`](http://man7.org/linux/man-pages/man7/packet.7.html)) - #[cfg(any(target_os = "android", target_os = "linux"))] + #[cfg(any(target_os = "android", target_os = "linux", target_os = "fuchsia"))] Packet = libc::AF_PACKET, /// KEXT Controls and Notifications #[cfg(any(target_os = "ios", target_os = "macos"))] @@ -718,6 +719,7 @@ impl SockAddr { /// /// unsafe because it takes a raw pointer as argument. The caller must /// ensure that the pointer is valid. + #[cfg(not(target_os = "fuchsia"))] pub(crate) unsafe fn from_libc_sockaddr(addr: *const libc::sockaddr) -> Option { if addr.is_null() { None @@ -1045,7 +1047,7 @@ pub mod sys_control { } -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(any(target_os = "android", target_os = "linux", target_os = "fuchsia"))] mod datalink { use super::{fmt, AddressFamily}; -- cgit v1.2.3