diff options
author | Michael Neumann <mneumann@ntecs.de> | 2015-09-09 20:16:42 +0200 |
---|---|---|
committer | Michael Neumann <mneumann@ntecs.de> | 2015-09-09 20:16:42 +0200 |
commit | f37e45628e44d86c16a6f02b38ea0a9d68e8b3d4 (patch) | |
tree | 3757e147ff4e9b4d30f493e63dec27e2eeebd6a7 /src/sys | |
parent | fad667e4e2c72889b55bcc7a21d87fa72218e101 (diff) | |
download | nix-f37e45628e44d86c16a6f02b38ea0a9d68e8b3d4.zip |
Add/Fix support for DragonFly BSD
Diffstat (limited to 'src/sys')
-rw-r--r-- | src/sys/event.rs | 69 | ||||
-rw-r--r-- | src/sys/mman.rs | 12 | ||||
-rw-r--r-- | src/sys/mod.rs | 4 | ||||
-rw-r--r-- | src/sys/signal.rs | 21 | ||||
-rw-r--r-- | src/sys/socket/consts.rs | 75 | ||||
-rw-r--r-- | src/sys/termios.rs | 18 |
6 files changed, 192 insertions, 7 deletions
diff --git a/src/sys/event.rs b/src/sys/event.rs index e4297c04..23d8c679 100644 --- a/src/sys/event.rs +++ b/src/sys/event.rs @@ -38,6 +38,7 @@ mod ffi { } } +#[cfg(not(target_os = "dragonfly"))] #[repr(i16)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum EventFilter { @@ -56,6 +57,22 @@ pub enum EventFilter { EVFILT_SYSCOUNT = 13 } +#[cfg(target_os = "dragonfly")] +#[repr(i16)] // u_short +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum EventFilter { + EVFILT_READ = -1, + EVFILT_WRITE = -2, + EVFILT_AIO = -3, + EVFILT_VNODE = -4, + EVFILT_PROC = -5, + EVFILT_SIGNAL = -6, + EVFILT_TIMER = -7, + EVFILT_EXCEPT = -8, + EVFILT_USER = -9, +} + +#[cfg(not(target_os = "dragonfly"))] bitflags!( flags EventFlag: u16 { const EV_ADD = 0x0001, @@ -74,6 +91,25 @@ bitflags!( } ); +#[cfg(target_os = "dragonfly")] +bitflags!( + flags EventFlag: u16 { + const EV_ADD = 0x0001, + const EV_DELETE = 0x0002, + const EV_ENABLE = 0x0004, + const EV_DISABLE = 0x0008, + const EV_RECEIPT = 0x0040, + const EV_ONESHOT = 0x0010, + const EV_CLEAR = 0x0020, + const EV_SYSFLAGS = 0xF000, + const EV_NODATA = 0x1000, + const EV_FLAG1 = 0x2000, + const EV_EOF = 0x8000, + const EV_ERROR = 0x4000 + } +); + +#[cfg(not(target_os = "dragonfly"))] bitflags!( flags FilterFlag: u32 { const NOTE_TRIGGER = 0x01000000, @@ -121,7 +157,40 @@ bitflags!( } ); +#[cfg(target_os = "dragonfly")] +bitflags!( + flags FilterFlag: u32 { + const NOTE_TRIGGER = 0x01000000, + const NOTE_FFNOP = 0x00000000, + const NOTE_FFAND = 0x40000000, + const NOTE_FFOR = 0x80000000, + const NOTE_FFCOPY = 0xc0000000, + const NOTE_FFCTRLMASK = 0xc0000000, + const NOTE_FFLAGSMASK = 0x00ffffff, + const NOTE_LOWAT = 0x00000001, + const NOTE_DELETE = 0x00000001, + const NOTE_WRITE = 0x00000002, + const NOTE_EXTEND = 0x00000004, + const NOTE_ATTRIB = 0x00000008, + const NOTE_LINK = 0x00000010, + const NOTE_RENAME = 0x00000020, + const NOTE_REVOKE = 0x00000040, + const NOTE_EXIT = 0x80000000, + const NOTE_FORK = 0x40000000, + const NOTE_EXEC = 0x20000000, + const NOTE_SIGNAL = 0x08000000, + const NOTE_PDATAMASK = 0x000fffff, + const NOTE_PCTRLMASK = 0xf0000000, // NOTE: FreeBSD uses 0xfff00000, + const NOTE_TRACK = 0x00000001, + const NOTE_TRACKERR = 0x00000002, + const NOTE_CHILD = 0x00000004 + } +); + +#[cfg(not(target_os = "dragonfly"))] pub const EV_POLL: EventFlag = EV_FLAG0; + +#[cfg(not(target_os = "dragonfly"))] pub const EV_OOBAND: EventFlag = EV_FLAG1; pub fn kqueue() -> Result<RawFd> { diff --git a/src/sys/mman.rs b/src/sys/mman.rs index 54f256b2..ad29a015 100644 --- a/src/sys/mman.rs +++ b/src/sys/mman.rs @@ -113,7 +113,7 @@ mod consts { pub const MAP_FAILED: isize = -1; } -#[cfg(any(target_os = "freebsd", target_os = "openbsd"))] +#[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd"))] mod consts { use libc::c_int; @@ -150,14 +150,24 @@ mod consts { pub const MADV_AUTOSYNC : MmapAdvise = 7; /* refert to default flushing strategy */ pub const MADV_NOCORE : MmapAdvise = 8; /* do not include these pages in a core file */ pub const MADV_CORE : MmapAdvise = 9; /* revert to including pages in a core file */ + #[cfg(not(target_os = "dragonfly"))] pub const MADV_PROTECT : MmapAdvise = 10; /* protect process from pageout kill */ + #[cfg(target_os = "dragonfly")] + pub const MADV_INVAL : MmapAdvise = 10; /* virt page tables have changed, inval pmap */ + #[cfg(target_os = "dragonfly")] + pub const MADV_SETMAP : MmapAdvise = 11; /* set page table directory page for map */ pub type MmapSync = c_int; pub const MS_ASYNC : MmapSync = 0x0001; /* [MF|SIO] return immediately */ pub const MS_INVALIDATE : MmapSync = 0x0002; /* [MF|SIO] invalidate all cached data */ + #[cfg(not(target_os = "dragonfly"))] pub const MS_SYNC : MmapSync = 0x0010; /* [MF|SIO] msync synchronously */ + #[cfg(target_os = "dragonfly")] + pub const MS_SYNC : MmapSync = 0x0000; /* [MF|SIO] msync synchronously */ + #[cfg(not(target_os = "dragonfly"))] pub const MS_KILLPAGES : MmapSync = 0x0004; /* invalidate pages, leave mapped */ + #[cfg(not(target_os = "dragonfly"))] pub const MS_DEACTIVATE : MmapSync = 0x0008; /* deactivate pages, leave mapped */ pub const MAP_FAILED: isize = -1; diff --git a/src/sys/mod.rs b/src/sys/mod.rs index 3df06c44..235449a0 100644 --- a/src/sys/mod.rs +++ b/src/sys/mod.rs @@ -2,7 +2,7 @@ #[cfg(any(target_os = "linux", target_os = "android"))] pub mod epoll; -#[cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "openbsd"))] +#[cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd"))] pub mod event; // TODO: switch from feature flags to conditional builds @@ -12,7 +12,7 @@ pub mod eventfd; #[cfg(target_os = "linux")] pub mod memfd; -#[cfg(not(any(target_os = "ios", target_os = "freebsd")))] +#[cfg(not(any(target_os = "ios", target_os = "freebsd", target_os = "dragonfly")))] pub mod ioctl; pub mod signal; diff --git a/src/sys/signal.rs b/src/sys/signal.rs index 4a54c5d4..5f51bd11 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -241,15 +241,22 @@ pub mod signal { #[cfg(any(target_os = "macos", target_os = "ios", target_os = "openbsd"))] pub type sigset_t = u32; - #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] + #[cfg(target_os = "freebsd")] #[repr(C)] #[derive(Clone, Copy)] pub struct sigset_t { bits: [u32; 4], } + #[cfg(target_os = "dragonfly")] + #[repr(C)] + #[derive(Clone, Copy)] + pub struct sigset_t { + bits: [libc::c_uint; 4], + } // This structure has more fields, but we're not all that interested in // them. + #[cfg(not(target_os = "dragonfly"))] #[repr(C)] #[derive(Clone, Copy)] pub struct siginfo { @@ -261,6 +268,18 @@ pub mod signal { pub status: libc::c_int, } + #[cfg(target_os = "dragonfly")] + #[repr(C)] + #[derive(Clone, Copy)] + pub struct siginfo { + pub si_signo: libc::c_int, + pub si_errno: libc::c_int, + pub si_code: libc::c_int, + pub pid: libc::c_int, + pub uid: libc::c_uint, + pub status: libc::c_int, + } + #[cfg(any(target_os = "macos", target_os = "ios"))] #[repr(C)] #[allow(missing_copy_implementations)] diff --git a/src/sys/socket/consts.rs b/src/sys/socket/consts.rs index ddd77c05..4deb9f59 100644 --- a/src/sys/socket/consts.rs +++ b/src/sys/socket/consts.rs @@ -205,6 +205,81 @@ mod os { pub const SHUT_RDWR: c_int = 2; } +#[cfg(target_os = "dragonfly")] +mod os { + use libc::{c_int, uint8_t}; + + pub const AF_UNIX: c_int = 1; + pub const AF_LOCAL: c_int = AF_UNIX; + pub const AF_INET: c_int = 2; + pub const AF_INET6: c_int = 28; + + pub const SOCK_STREAM: c_int = 1; + pub const SOCK_DGRAM: c_int = 2; + pub const SOCK_SEQPACKET: c_int = 5; + pub const SOCK_RAW: c_int = 3; + pub const SOCK_RDM: c_int = 4; + + pub const SOL_SOCKET: c_int = 0xffff; + pub const IPPROTO_IP: c_int = 0; + pub const IPPROTO_IPV6: c_int = 41; + pub const IPPROTO_TCP: c_int = 6; + pub const IPPROTO_UDP: c_int = 17; + + pub const SO_ACCEPTCONN: c_int = 0x0002; + pub const SO_BROADCAST: c_int = 0x0020; + pub const SO_DEBUG: c_int = 0x0001; + pub const SO_ERROR: c_int = 0x1007; + pub const SO_DONTROUTE: c_int = 0x0010; + pub const SO_KEEPALIVE: c_int = 0x0008; + pub const SO_LINGER: c_int = 0x0080; + pub const SO_NOSIGPIPE: c_int = 0x0800; // different value! + pub const SO_OOBINLINE: c_int = 0x0100; + pub const SO_RCVBUF: c_int = 0x1002; + pub const SO_RCVLOWAT: c_int = 0x1004; + pub const SO_SNDLOWAT: c_int = 0x1003; + pub const SO_RCVTIMEO: c_int = 0x1006; + pub const SO_SNDTIMEO: c_int = 0x1005; + pub const SO_REUSEADDR: c_int = 0x0004; + pub const SO_REUSEPORT: c_int = 0x0200; + pub const SO_SNDBUF: c_int = 0x1001; + pub const SO_TIMESTAMP: c_int = 0x0400; + pub const SO_TYPE: c_int = 0x1008; + + // Socket options for TCP sockets + pub const TCP_NODELAY: c_int = 1; + pub const TCP_MAXSEG: c_int = 2; + pub const TCP_KEEPIDLE: c_int = 0x100; + + // Socket options for the IP layer of the socket + pub const IP_MULTICAST_IF: c_int = 9; + + pub type IpMulticastTtl = uint8_t; + + pub const IP_MULTICAST_TTL: c_int = 10; + pub const IP_MULTICAST_LOOP: c_int = 11; + pub const IP_ADD_MEMBERSHIP: c_int = 12; + pub const IP_DROP_MEMBERSHIP: c_int = 13; + + pub type InAddrT = u32; + + // Declarations of special addresses + pub const INADDR_ANY: InAddrT = 0; + pub const INADDR_NONE: InAddrT = 0xffffffff; + pub const INADDR_BROADCAST: InAddrT = 0xffffffff; + + pub type SockMessageFlags = i32; + // Flags for send/recv and their relatives + pub const MSG_OOB: SockMessageFlags = 0x1; + pub const MSG_PEEK: SockMessageFlags = 0x2; + pub const MSG_DONTWAIT: SockMessageFlags = 0x80; + + // shutdown flags + pub const SHUT_RD: c_int = 0; + pub const SHUT_WR: c_int = 1; + pub const SHUT_RDWR: c_int = 2; +} + #[cfg(test)] mod test { use super::*; diff --git a/src/sys/termios.rs b/src/sys/termios.rs index a9fd41ec..1ecac547 100644 --- a/src/sys/termios.rs +++ b/src/sys/termios.rs @@ -12,7 +12,7 @@ pub use self::ffi::consts::FlowArg::*; mod ffi { pub use self::consts::*; - #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "openbsd", target_os = "linux"))] + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd", target_os = "linux"))] mod non_android { use super::consts::*; use libc::c_int; @@ -36,7 +36,7 @@ mod ffi { } } - #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "openbsd", target_os = "linux"))] + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd", target_os = "linux"))] pub use self::non_android::*; // On Android before 5.0, Bionic directly inline these to ioctl() calls. @@ -95,13 +95,24 @@ mod ffi { pub use self::android::*; - #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "openbsd"))] + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd"))] pub mod consts { + #[cfg(not(target_os = "dragonfly"))] use libc::{c_int, c_ulong, c_uchar}; + #[cfg(target_os = "dragonfly")] + use libc::{c_int, c_uint, c_uchar}; + #[cfg(not(target_os = "dragonfly"))] pub type tcflag_t = c_ulong; + #[cfg(target_os = "dragonfly")] + pub type tcflag_t = c_uint; + pub type cc_t = c_uchar; + + #[cfg(not(target_os = "dragonfly"))] pub type speed_t = c_ulong; + #[cfg(target_os = "dragonfly")] + pub type speed_t = c_uint; #[repr(C)] #[derive(Clone, Copy)] @@ -150,6 +161,7 @@ mod ffi { const IXOFF = 0x00000400, const IXANY = 0x00000800, const IMAXBEL = 0x00002000, + #[cfg(not(target_os = "dragonfly"))] const IUTF8 = 0x00004000, } } |