diff options
-rw-r--r-- | src/errno.rs | 346 | ||||
-rw-r--r-- | src/fcntl.rs | 39 | ||||
-rw-r--r-- | src/features.rs | 2 | ||||
-rw-r--r-- | src/sys/mman.rs | 49 | ||||
-rw-r--r-- | src/sys/mod.rs | 4 | ||||
-rw-r--r-- | src/sys/signal.rs | 1 | ||||
-rw-r--r-- | src/sys/socket/consts.rs | 3 | ||||
-rw-r--r-- | src/sys/termios.rs | 4 |
8 files changed, 401 insertions, 47 deletions
diff --git a/src/errno.rs b/src/errno.rs index 30d3b33e..9ed3d7d6 100644 --- a/src/errno.rs +++ b/src/errno.rs @@ -327,47 +327,86 @@ fn desc(errno: Errno) -> &'static str { #[cfg(target_os = "linux")] EHWPOISON => "Memory page has hardware error", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(target_os = "freebsd")] + EDOOFUS => "Programming error", + + #[cfg(target_os = "freebsd")] + EMULTIHOP => "Multihop attempted", + + #[cfg(target_os = "freebsd")] + ENOLINK => "Link has been severed", + + #[cfg(target_os = "freebsd")] + ENOTCAPABLE => "Capabilities insufficient", + + #[cfg(target_os = "freebsd")] + ECAPMODE => "Not permitted in capability mode", + + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] + ENEEDAUTH => "Need authenticator", + + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] + EOVERFLOW => "Value too large to be stored in data type", + + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] + EILSEQ => "Illegal byte sequence", + + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] + ENOATTR => "Attribute not found", + + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] + EBADMSG => "Bad message", + + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] + EPROTO => "Protocol error", + + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] + ENOTRECOVERABLE => "State not recoverable", + + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] + EOWNERDEAD => "Previous owner died", + + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] ENOTSUP => "Operation not supported", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] EPROCLIM => "Too many processes", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] EUSERS => "Too many users", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] EDQUOT => "Disc quota exceeded", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] ESTALE => "Stale NFS file handle", - #[cfg(any(target_os = "macos", target_os = "ios"))] - EREMOTE => "Stale NFS file handle", + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] + EREMOTE => "Too many levels of remote in path", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] EBADRPC => "RPC struct is bad", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] ERPCMISMATCH => "RPC version wrong", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] EPROGUNAVAIL => "RPC prog. not avail", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] EPROGMISMATCH => "Program version wrong", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] EPROCUNAVAIL => "Bad procedure for program", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] EFTYPE => "Inappropriate file type or format", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] EAUTH => "Authentication error", - #[cfg(any(target_os = "macos", target_os = "ios"))] - ENEEDAUTH => "Need authenticator", + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] + ECANCELED => "Operation canceled", #[cfg(any(target_os = "macos", target_os = "ios"))] EPWROFF => "Device power is off", @@ -376,9 +415,6 @@ fn desc(errno: Errno) -> &'static str { EDEVERR => "Device error, e.g. paper out", #[cfg(any(target_os = "macos", target_os = "ios"))] - EOVERFLOW => "Value too large to be stored in data type", - - #[cfg(any(target_os = "macos", target_os = "ios"))] EBADEXEC => "Bad executable", #[cfg(any(target_os = "macos", target_os = "ios"))] @@ -391,18 +427,6 @@ fn desc(errno: Errno) -> &'static str { EBADMACHO => "Malformed Macho file", #[cfg(any(target_os = "macos", target_os = "ios"))] - ECANCELED => "Operation canceled", - - #[cfg(any(target_os = "macos", target_os = "ios"))] - EILSEQ => "Illegal byte sequence", - - #[cfg(any(target_os = "macos", target_os = "ios"))] - ENOATTR => "Attribute not found", - - #[cfg(any(target_os = "macos", target_os = "ios"))] - EBADMSG => "Bad message", - - #[cfg(any(target_os = "macos", target_os = "ios"))] EMULTIHOP => "Reserved", #[cfg(any(target_os = "macos", target_os = "ios"))] @@ -418,9 +442,6 @@ fn desc(errno: Errno) -> &'static str { ENOSTR => "Not a STREAM", #[cfg(any(target_os = "macos", target_os = "ios"))] - EPROTO => "Protocol error", - - #[cfg(any(target_os = "macos", target_os = "ios"))] ETIME => "STREAM ioctl timeout", #[cfg(any(target_os = "macos", target_os = "ios"))] @@ -430,12 +451,6 @@ fn desc(errno: Errno) -> &'static str { ENOPOLICY => "No such policy registered", #[cfg(any(target_os = "macos", target_os = "ios"))] - ENOTRECOVERABLE => "State not recoverable", - - #[cfg(any(target_os = "macos", target_os = "ios"))] - EOWNERDEAD => "Previous owner died", - - #[cfg(any(target_os = "macos", target_os = "ios"))] EQFULL => "Interface output queue is full", } } @@ -967,6 +982,225 @@ mod consts { } } +#[cfg(target_os = "freebsd")] +mod consts { + #[derive(Copy, Debug, Clone, PartialEq)] + pub enum Errno { + UnknownErrno = 0, + EPERM = 1, + ENOENT = 2, + ESRCH = 3, + EINTR = 4, + EIO = 5, + ENXIO = 6, + E2BIG = 7, + ENOEXEC = 8, + EBADF = 9, + ECHILD = 10, + EDEADLK = 11, + ENOMEM = 12, + EACCES = 13, + EFAULT = 14, + ENOTBLK = 15, + EBUSY = 16, + EEXIST = 17, + EXDEV = 18, + ENODEV = 19, + ENOTDIR = 20, + EISDIR = 21, + EINVAL = 22, + ENFILE = 23, + EMFILE = 24, + ENOTTY = 25, + ETXTBSY = 26, + EFBIG = 27, + ENOSPC = 28, + ESPIPE = 29, + EROFS = 30, + EMLINK = 31, + EPIPE = 32, + EDOM = 33, + ERANGE = 34, + EAGAIN = 35, + EINPROGRESS = 36, + EALREADY = 37, + ENOTSOCK = 38, + EDESTADDRREQ = 39, + EMSGSIZE = 40, + EPROTOTYPE = 41, + ENOPROTOOPT = 42, + EPROTONOSUPPORT = 43, + ESOCKTNOSUPPORT = 44, + ENOTSUP = 45, + EPFNOSUPPORT = 46, + EAFNOSUPPORT = 47, + EADDRINUSE = 48, + EADDRNOTAVAIL = 49, + ENETDOWN = 50, + ENETUNREACH = 51, + ENETRESET = 52, + ECONNABORTED = 53, + ECONNRESET = 54, + ENOBUFS = 55, + EISCONN = 56, + ENOTCONN = 57, + ESHUTDOWN = 58, + ETOOMANYREFS = 59, + ETIMEDOUT = 60, + ECONNREFUSED = 61, + ELOOP = 62, + ENAMETOOLONG = 63, + EHOSTDOWN = 64, + EHOSTUNREACH = 65, + ENOTEMPTY = 66, + EPROCLIM = 67, + EUSERS = 68, + EDQUOT = 69, + ESTALE = 70, + EREMOTE = 71, + EBADRPC = 72, + ERPCMISMATCH = 73, + EPROGUNAVAIL = 74, + EPROGMISMATCH = 75, + EPROCUNAVAIL = 76, + ENOLCK = 77, + ENOSYS = 78, + EFTYPE = 79, + EAUTH = 80, + ENEEDAUTH = 81, + EIDRM = 82, + ENOMSG = 83, + EOVERFLOW = 84, + ECANCELED = 85, + EILSEQ = 86, + ENOATTR = 87, + EDOOFUS = 88, + EBADMSG = 89, + EMULTIHOP = 90, + ENOLINK = 91, + EPROTO = 92, + ENOTCAPABLE = 93, + ECAPMODE = 94, + ENOTRECOVERABLE = 95, + EOWNERDEAD = 96 + + } + + impl_errno!(Errno); + + pub const ELAST: Errno = Errno::EOWNERDEAD; + pub const EWOULDBLOCK: Errno = Errno::EAGAIN; + pub const EDEADLOCK: Errno = Errno::EDEADLK; + + pub const EL2NSYNC: Errno = Errno::UnknownErrno; + + pub fn from_i32(e: i32) -> Errno { + use self::Errno::*; + + match e { + 0 => UnknownErrno, + 1 => EPERM, + 2 => ENOENT, + 3 => ESRCH, + 4 => EINTR, + 5 => EIO, + 6 => ENXIO, + 7 => E2BIG, + 8 => ENOEXEC, + 9 => EBADF, + 10 => ECHILD, + 11 => EDEADLK, + 12 => ENOMEM, + 13 => EACCES, + 14 => EFAULT, + 15 => ENOTBLK, + 16 => EBUSY, + 17 => EEXIST, + 18 => EXDEV, + 19 => ENODEV, + 20 => ENOTDIR, + 21 => EISDIR, + 22 => EINVAL, + 23 => ENFILE, + 24 => EMFILE, + 25 => ENOTTY, + 26 => ETXTBSY, + 27 => EFBIG, + 28 => ENOSPC, + 29 => ESPIPE, + 30 => EROFS, + 31 => EMLINK, + 32 => EPIPE, + 33 => EDOM, + 34 => ERANGE, + 35 => EAGAIN, + 36 => EINPROGRESS, + 37 => EALREADY, + 38 => ENOTSOCK, + 39 => EDESTADDRREQ, + 40 => EMSGSIZE, + 41 => EPROTOTYPE, + 42 => ENOPROTOOPT, + 43 => EPROTONOSUPPORT, + 44 => ESOCKTNOSUPPORT, + 45 => ENOTSUP, + 46 => EPFNOSUPPORT, + 47 => EAFNOSUPPORT, + 48 => EADDRINUSE, + 49 => EADDRNOTAVAIL, + 50 => ENETDOWN, + 51 => ENETUNREACH, + 52 => ENETRESET, + 53 => ECONNABORTED, + 54 => ECONNRESET, + 55 => ENOBUFS, + 56 => EISCONN, + 57 => ENOTCONN, + 58 => ESHUTDOWN, + 59 => ETOOMANYREFS, + 60 => ETIMEDOUT, + 61 => ECONNREFUSED, + 62 => ELOOP, + 63 => ENAMETOOLONG, + 64 => EHOSTDOWN, + 65 => EHOSTUNREACH, + 66 => ENOTEMPTY, + 67 => EPROCLIM, + 68 => EUSERS, + 69 => EDQUOT, + 70 => ESTALE, + 71 => EREMOTE, + 72 => EBADRPC, + 73 => ERPCMISMATCH, + 74 => EPROGUNAVAIL, + 75 => EPROGMISMATCH, + 76 => EPROCUNAVAIL, + 77 => ENOLCK, + 78 => ENOSYS, + 79 => EFTYPE, + 80 => EAUTH, + 81 => ENEEDAUTH, + 82 => EIDRM, + 83 => ENOMSG, + 84 => EOVERFLOW, + 85 => ECANCELED, + 86 => EILSEQ, + 87 => ENOATTR, + 88 => EDOOFUS, + 89 => EBADMSG, + 90 => EMULTIHOP, + 91 => ENOLINK, + 92 => EPROTO, + 93 => ENOTCAPABLE, + 94 => ECAPMODE, + 95 => ENOTRECOVERABLE, + 96 => EOWNERDEAD, + _ => UnknownErrno, + } + } +} + + #[cfg(test)] mod test { use super::*; @@ -1130,6 +1364,38 @@ mod test { } #[test] + #[cfg(target_os = "freebsd")] + pub fn test_freebsd_errnos() { + check_errno!( + EDOOFUS, + EMULTIHOP, + ENOLINK, + ENOTCAPABLE, + ECAPMODE, + ENEEDAUTH, + EOVERFLOW, + EILSEQ, + ENOATTR, + EBADMSG, + EPROTO, + ENOTRECOVERABLE, + EOWNERDEAD, + ENOTSUP, + EPROCLIM, + EUSERS, + EDQUOT, + ESTALE, + EREMOTE, + EBADRPC, + ERPCMISMATCH, + EPROGUNAVAIL, + EPROGMISMATCH, + EPROCUNAVAIL, + ETYPE, + EAUTH); + } + + #[test] #[cfg(any(target_os = "macos", target_os = "ios"))] pub fn test_darwin_errnos() { check_errno!( diff --git a/src/fcntl.rs b/src/fcntl.rs index 2e2d8aa2..73c0619c 100644 --- a/src/fcntl.rs +++ b/src/fcntl.rs @@ -42,7 +42,7 @@ mod ffi { pub const F_GETLK: c_int = 5; } - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] mod os { use libc::{c_int, c_short, off_t, pid_t}; @@ -191,3 +191,40 @@ mod consts { } ); } + +#[cfg(target_os = "freebsd")] +mod consts { + use libc::c_int; + + bitflags!( + flags OFlag: c_int { + const O_ACCMODE = 0x0000003, + const O_RDONLY = 0x0000000, + const O_WRONLY = 0x0000001, + const O_RDWR = 0x0000002, + const O_CREAT = 0x0000200, + const O_EXCL = 0x0000800, + const O_NOCTTY = 0x0008000, + const O_TRUNC = 0x0000400, + const O_APPEND = 0x0000008, + const O_NONBLOCK = 0x0000004, + const O_DIRECTORY = 0x0020000, + const O_NOFOLLOW = 0x0000100, + const O_CLOEXEC = 0x0100000, + const O_SYNC = 0x0000080, + const O_NDELAY = O_NONBLOCK.bits, + const O_FSYNC = O_SYNC.bits, + const O_SHLOCK = 0x0000080, + const O_EXLOCK = 0x0000020, + const O_DIRECT = 0x0010000, + const O_EXEC = 0x0040000, + const O_TTY_INIT = 0x0080000 + } + ); + + bitflags!( + flags FdFlag: c_int { + const FD_CLOEXEC = 1 + } + ); +} diff --git a/src/features.rs b/src/features.rs index 60022995..34c41b32 100644 --- a/src/features.rs +++ b/src/features.rs @@ -92,7 +92,7 @@ mod os { } } -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] mod os { pub fn socket_atomic_cloexec() -> bool { false diff --git a/src/sys/mman.rs b/src/sys/mman.rs index a905744d..d3f3b7ae 100644 --- a/src/sys/mman.rs +++ b/src/sys/mman.rs @@ -112,6 +112,55 @@ mod consts { pub const MAP_FAILED: isize = -1; } +#[cfg(target_os = "freebsd")] +mod consts { + use libc::c_int; + + pub type MmapFlag = c_int; + + pub const MAP_SHARED: MmapFlag = 0x00001; + pub const MAP_PRIVATE: MmapFlag = 0x00002; + pub const MAP_FIXED: MmapFlag = 0x00010; + + pub const MAP_RENAME: MmapFlag = 0x00020; + pub const MAP_NORESERVE: MmapFlag = 0x00040; + pub const MAP_HASSEMAPHORE: MmapFlag = 0x00200; + pub const MAP_STACK: MmapFlag = 0x00400; + pub const MAP_NOSYNC: MmapFlag = 0x00800; + pub const MAP_FILE: MmapFlag = 0x00000; + pub const MAP_ANON: MmapFlag = 0x01000; + + pub type MmapProt = c_int; + + pub const PROT_READ: MmapProt = 0x1; + pub const PROT_WRITE: MmapProt = 0x2; + pub const PROT_EXEC: MmapProt = 0x4; + pub const PROT_NONE: MmapProt = 0x0; + + pub type MmapAdvise = c_int; + + pub const MADV_NORMAL : MmapAdvise = 0; /* No further special treatment. */ + pub const MADV_RANDOM : MmapAdvise = 1; /* Expect random page references. */ + pub const MADV_SEQUENTIAL : MmapAdvise = 2; /* Expect sequential page references. */ + pub const MADV_WILLNEED : MmapAdvise = 3; /* Will need these pages. */ + pub const MADV_DONTNEED : MmapAdvise = 4; /* Don't need these pages. */ + pub const MADV_FREE : MmapAdvise = 5; /* pages unneeded, discard contents */ + pub const MADV_NOSYNC : MmapAdvise = 6; /* try to avoid flushes to physical media*/ + 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 */ + pub const MADV_PROTECT : MmapAdvise = 10; /* protect process from pageout kill */ + + 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 */ + pub const MS_SYNC : MmapSync = 0x0010; /* [MF|SIO] msync synchronously */ + pub const MS_KILLPAGES : MmapSync = 0x0004; /* invalidate pages, leave mapped */ + pub const MS_DEACTIVATE : MmapSync = 0x0008; /* deactivate pages, leave mapped */ + + pub const MAP_FAILED: isize = -1; +} mod ffi { use libc::{c_void, size_t, c_int, c_char, mode_t}; diff --git a/src/sys/mod.rs b/src/sys/mod.rs index f25aecb4..f0fda20a 100644 --- a/src/sys/mod.rs +++ b/src/sys/mod.rs @@ -2,14 +2,14 @@ #[cfg(any(target_os = "linux", target_os = "android"))] pub mod epoll; -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd"))] pub mod event; // TODO: switch from feature flags to conditional builds #[cfg(feature = "eventfd")] pub mod eventfd; -#[cfg(not(target_os = "ios"))] +#[cfg(not(any(target_os = "ios", target_os = "freebsd")))] pub mod ioctl; pub mod signal; diff --git a/src/sys/signal.rs b/src/sys/signal.rs index 112a7bcd..8f3ecdcf 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -242,6 +242,7 @@ pub mod signal { pub type sigset_t = u32; #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] #[repr(C)] + #[derive(Clone, Copy)] pub struct sigset_t { bits: [u32; 4], } diff --git a/src/sys/socket/consts.rs b/src/sys/socket/consts.rs index 539c50e9..a2bb535b 100644 --- a/src/sys/socket/consts.rs +++ b/src/sys/socket/consts.rs @@ -90,7 +90,8 @@ mod os { pub const MSG_DONTWAIT: SockMessageFlags = 0x40; } -#[cfg(any(target_os = "macos", target_os = "ios"))] +// Not all of these constants exist on freebsd +#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios"))] mod os { use libc::{c_int, uint8_t}; diff --git a/src/sys/termios.rs b/src/sys/termios.rs index 57612f0b..0c636e77 100644 --- a/src/sys/termios.rs +++ b/src/sys/termios.rs @@ -17,7 +17,7 @@ mod ffi { // `Termios` contains bitflags which are not considered // `foreign-function-safe` by the compiler. #[allow(improper_ctypes)] - #[cfg(any(target_os = "macos", target_os = "linux"))] + #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "linux"))] extern { pub fn cfgetispeed(termios: *const Termios) -> speed_t; pub fn cfgetospeed(termios: *const Termios) -> speed_t; @@ -89,7 +89,7 @@ mod ffi { pub use self::android::*; - #[cfg(target_os = "macos")] + #[cfg(any(target_os = "macos", target_os = "freebsd"))] pub mod consts { use libc::{c_int, c_ulong, c_uchar}; |