Skip to content

Commit

Permalink
Add Redox support for most of the modules
Browse files Browse the repository at this point in the history
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 rust-lang/libc#1438
  • Loading branch information
AdminXVII committed Jul 22, 2019
1 parent 38de042 commit 18fd073
Show file tree
Hide file tree
Showing 12 changed files with 464 additions and 61 deletions.
7 changes: 6 additions & 1 deletion src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use {Error, NixPath, Result};
use errno::Errno;
use fcntl::{self, OFlag};
use libc;
use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
use std::os::unix::io::{IntoRawFd, RawFd};
#[cfg(not(target_os = "redox"))]
use std::os::unix::io::AsRawFd;
use std::{ffi, ptr};
use sys;

Expand Down Expand Up @@ -77,6 +79,7 @@ impl Dir {
// `Dir` is safe to pass from one thread to another, as it's not reference-counted.
unsafe impl Send for Dir {}

#[cfg(not(target_os = "redox"))]
impl AsRawFd for Dir {
fn as_raw_fd(&self) -> RawFd {
unsafe { libc::dirfd(self.0.as_ptr()) }
Expand Down Expand Up @@ -149,6 +152,7 @@ impl Entry {
target_os = "l4re",
target_os = "linux",
target_os = "macos",
target_os = "redox",
target_os = "solaris"))]
pub fn ino(&self) -> u64 {
self.0.d_ino as u64
Expand All @@ -163,6 +167,7 @@ impl Entry {
target_os = "l4re",
target_os = "linux",
target_os = "macos",
target_os = "redox",
target_os = "solaris")))]
pub fn ino(&self) -> u64 {
self.0.d_fileno as u64
Expand Down
241 changes: 224 additions & 17 deletions src/errno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cfg_if! {
unsafe fn errno_location() -> *mut c_int {
libc::__errno()
}
} else if #[cfg(target_os = "linux")] {
} else if #[cfg(any(target_os = "linux", target_os = "redox"))] {
unsafe fn errno_location() -> *mut c_int {
libc::__errno_location()
}
Expand Down Expand Up @@ -336,7 +336,8 @@ fn desc(errno: Errno) -> &'static str {
#[cfg(any(target_os = "linux", target_os = "android"))]
EUSERS => "Too many users",

#[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "netbsd", target_os = "redox"))]
EOPNOTSUPP => "Operation not supported on transport endpoint",

#[cfg(any(target_os = "linux", target_os = "android"))]
Expand Down Expand Up @@ -397,10 +398,10 @@ fn desc(errno: Errno) -> &'static str {
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
EDOOFUS => "Programming error",

#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
#[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "redox"))]
EMULTIHOP => "Multihop attempted",

#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
#[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "redox"))]
ENOLINK => "Link has been severed",

#[cfg(target_os = "freebsd")]
Expand All @@ -416,12 +417,13 @@ fn desc(errno: Errno) -> &'static str {

#[cfg(any(target_os = "macos", target_os = "freebsd",
target_os = "dragonfly", target_os = "ios",
target_os = "openbsd", target_os = "netbsd"))]
target_os = "openbsd", target_os = "netbsd",
target_os = "redox"))]
EOVERFLOW => "Value too large to be stored in data type",

#[cfg(any(target_os = "macos", target_os = "freebsd",
target_os = "dragonfly", target_os = "ios",
target_os = "netbsd"))]
target_os = "netbsd", target_os = "redox"))]
EILSEQ => "Illegal byte sequence",

#[cfg(any(target_os = "macos", target_os = "freebsd",
Expand All @@ -431,12 +433,14 @@ fn desc(errno: Errno) -> &'static str {

#[cfg(any(target_os = "macos", target_os = "freebsd",
target_os = "dragonfly", target_os = "ios",
target_os = "openbsd", target_os = "netbsd"))]
target_os = "openbsd", target_os = "netbsd",
target_os = "redox"))]
EBADMSG => "Bad message",

#[cfg(any(target_os = "macos", target_os = "freebsd",
target_os = "dragonfly", target_os = "ios",
target_os = "openbsd", target_os = "netbsd"))]
target_os = "openbsd", target_os = "netbsd",
target_os = "redox"))]
EPROTO => "Protocol error",

#[cfg(any(target_os = "macos", target_os = "freebsd",
Expand All @@ -459,22 +463,26 @@ fn desc(errno: Errno) -> &'static str {

#[cfg(any(target_os = "macos", target_os = "freebsd",
target_os = "dragonfly", target_os = "ios",
target_os = "openbsd", target_os = "netbsd"))]
target_os = "openbsd", target_os = "netbsd",
target_os = "redox"))]
EUSERS => "Too many users",

#[cfg(any(target_os = "macos", target_os = "freebsd",
target_os = "dragonfly", target_os = "ios",
target_os = "openbsd", target_os = "netbsd"))]
target_os = "openbsd", target_os = "netbsd",
target_os = "redox"))]
EDQUOT => "Disc quota exceeded",

#[cfg(any(target_os = "macos", target_os = "freebsd",
target_os = "dragonfly", target_os = "ios",
target_os = "openbsd", target_os = "netbsd"))]
target_os = "openbsd", target_os = "netbsd",
target_os = "redox"))]
ESTALE => "Stale NFS file handle",

#[cfg(any(target_os = "macos", target_os = "freebsd",
target_os = "dragonfly", target_os = "ios",
target_os = "openbsd", target_os = "netbsd"))]
target_os = "openbsd", target_os = "netbsd",
target_os = "redox"))]
EREMOTE => "Too many levels of remote in path",

#[cfg(any(target_os = "macos", target_os = "freebsd",
Expand Down Expand Up @@ -514,7 +522,8 @@ fn desc(errno: Errno) -> &'static str {

#[cfg(any(target_os = "macos", target_os = "freebsd",
target_os = "dragonfly", target_os = "ios",
target_os = "openbsd", target_os = "netbsd"))]
target_os = "openbsd", target_os = "netbsd",
target_os = "redox"))]
ECANCELED => "Operation canceled",

#[cfg(any(target_os = "macos", target_os = "ios"))]
Expand All @@ -538,19 +547,23 @@ fn desc(errno: Errno) -> &'static str {
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "netbsd"))]
EMULTIHOP => "Reserved",

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "netbsd"))]
#[cfg(any(target_os = "macos", target_os = "ios",
target_os = "netbsd", target_os = "redox"))]
ENODATA => "No message available on STREAM",

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "netbsd"))]
ENOLINK => "Reserved",

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "netbsd"))]
#[cfg(any(target_os = "macos", target_os = "ios",
target_os = "netbsd", target_os = "redox"))]
ENOSR => "No STREAM resources",

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "netbsd"))]
#[cfg(any(target_os = "macos", target_os = "ios",
target_os = "netbsd", target_os = "redox"))]
ENOSTR => "Not a STREAM",

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "netbsd"))]
#[cfg(any(target_os = "macos", target_os = "ios",
target_os = "netbsd", target_os = "redox"))]
ETIME => "STREAM ioctl timeout",

#[cfg(any(target_os = "macos", target_os = "ios"))]
Expand Down Expand Up @@ -1961,3 +1974,197 @@ mod consts {
}
}
}

#[cfg(target_os = "redox")]
mod consts {
use libc;

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(i32)]
pub enum Errno {
UnknownErrno = 0,
EPERM = libc::EPERM,
ENOENT = libc::ENOENT,
ESRCH = libc::ESRCH,
EINTR = libc::EINTR,
EIO = libc::EIO,
ENXIO = libc::ENXIO,
E2BIG = libc::E2BIG,
ENOEXEC = libc::ENOEXEC,
EBADF = libc::EBADF,
ECHILD = libc::ECHILD,
EDEADLK = libc::EDEADLK,
ENOMEM = libc::ENOMEM,
EACCES = libc::EACCES,
EFAULT = libc::EFAULT,
ENOTBLK = libc::ENOTBLK,
EBUSY = libc::EBUSY,
EEXIST = libc::EEXIST,
EXDEV = libc::EXDEV,
ENODEV = libc::ENODEV,
ENOTDIR = libc::ENOTDIR,
EISDIR = libc::EISDIR,
EINVAL = libc::EINVAL,
ENFILE = libc::ENFILE,
EMFILE = libc::EMFILE,
ENOTTY = libc::ENOTTY,
ETXTBSY = libc::ETXTBSY,
EFBIG = libc::EFBIG,
ENOSPC = libc::ENOSPC,
ESPIPE = libc::ESPIPE,
EROFS = libc::EROFS,
EMLINK = libc::EMLINK,
EPIPE = libc::EPIPE,
EDOM = libc::EDOM,
ERANGE = libc::ERANGE,
EAGAIN = libc::EAGAIN,
EINPROGRESS = libc::EINPROGRESS,
EALREADY = libc::EALREADY,
ENOTSOCK = libc::ENOTSOCK,
EDESTADDRREQ = libc::EDESTADDRREQ,
EMSGSIZE = libc::EMSGSIZE,
EPROTOTYPE = libc::EPROTOTYPE,
ENOPROTOOPT = libc::ENOPROTOOPT,
EPROTONOSUPPORT = libc::EPROTONOSUPPORT,
ESOCKTNOSUPPORT = libc::ESOCKTNOSUPPORT,
EOPNOTSUPP = libc::EOPNOTSUPP,
EPFNOSUPPORT = libc::EPFNOSUPPORT,
EAFNOSUPPORT = libc::EAFNOSUPPORT,
EADDRINUSE = libc::EADDRINUSE,
EADDRNOTAVAIL = libc::EADDRNOTAVAIL,
ENETDOWN = libc::ENETDOWN,
ENETUNREACH = libc::ENETUNREACH,
ENETRESET = libc::ENETRESET,
ECONNABORTED = libc::ECONNABORTED,
ECONNRESET = libc::ECONNRESET,
ENOBUFS = libc::ENOBUFS,
EISCONN = libc::EISCONN,
ENOTCONN = libc::ENOTCONN,
ESHUTDOWN = libc::ESHUTDOWN,
ETOOMANYREFS = libc::ETOOMANYREFS,
ETIMEDOUT = libc::ETIMEDOUT,
ECONNREFUSED = libc::ECONNREFUSED,
ELOOP = libc::ELOOP,
ENAMETOOLONG = libc::ENAMETOOLONG,
EHOSTDOWN = libc::EHOSTDOWN,
EHOSTUNREACH = libc::EHOSTUNREACH,
ENOTEMPTY = libc::ENOTEMPTY,
EUSERS = libc::EUSERS,
EDQUOT = libc::EDQUOT,
ESTALE = libc::ESTALE,
EREMOTE = libc::EREMOTE,
ENOLCK = libc::ENOLCK,
ENOSYS = libc::ENOSYS,
EIDRM = libc::EIDRM,
ENOMSG = libc::ENOMSG,
EOVERFLOW = libc::EOVERFLOW,
EILSEQ = libc::EILSEQ,
ECANCELED = libc::ECANCELED,
EBADMSG = libc::EBADMSG,
ENODATA = libc::ENODATA,
ENOSR = libc::ENOSR,
ENOSTR = libc::ENOSTR,
ETIME = libc::ETIME,
EMULTIHOP = libc::EMULTIHOP,
ENOLINK = libc::ENOLINK,
EPROTO = libc::EPROTO,
}

pub const ELAST: Errno = Errno::UnknownErrno;
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;

pub const EL2NSYNC: Errno = Errno::UnknownErrno;

pub fn from_i32(e: i32) -> Errno {
use self::Errno::*;

match e {
libc::EPERM => EPERM,
libc::ENOENT => ENOENT,
libc::ESRCH => ESRCH,
libc::EINTR => EINTR,
libc::EIO => EIO,
libc::ENXIO => ENXIO,
libc::E2BIG => E2BIG,
libc::ENOEXEC => ENOEXEC,
libc::EBADF => EBADF,
libc::ECHILD => ECHILD,
libc::EDEADLK => EDEADLK,
libc::ENOMEM => ENOMEM,
libc::EACCES => EACCES,
libc::EFAULT => EFAULT,
libc::ENOTBLK => ENOTBLK,
libc::EBUSY => EBUSY,
libc::EEXIST => EEXIST,
libc::EXDEV => EXDEV,
libc::ENODEV => ENODEV,
libc::ENOTDIR => ENOTDIR,
libc::EISDIR => EISDIR,
libc::EINVAL => EINVAL,
libc::ENFILE => ENFILE,
libc::EMFILE => EMFILE,
libc::ENOTTY => ENOTTY,
libc::ETXTBSY => ETXTBSY,
libc::EFBIG => EFBIG,
libc::ENOSPC => ENOSPC,
libc::ESPIPE => ESPIPE,
libc::EROFS => EROFS,
libc::EMLINK => EMLINK,
libc::EPIPE => EPIPE,
libc::EDOM => EDOM,
libc::ERANGE => ERANGE,
libc::EAGAIN => EAGAIN,
libc::EINPROGRESS => EINPROGRESS,
libc::EALREADY => EALREADY,
libc::ENOTSOCK => ENOTSOCK,
libc::EDESTADDRREQ => EDESTADDRREQ,
libc::EMSGSIZE => EMSGSIZE,
libc::EPROTOTYPE => EPROTOTYPE,
libc::ENOPROTOOPT => ENOPROTOOPT,
libc::EPROTONOSUPPORT => EPROTONOSUPPORT,
libc::ESOCKTNOSUPPORT => ESOCKTNOSUPPORT,
libc::EOPNOTSUPP => EOPNOTSUPP,
libc::EPFNOSUPPORT => EPFNOSUPPORT,
libc::EAFNOSUPPORT => EAFNOSUPPORT,
libc::EADDRINUSE => EADDRINUSE,
libc::EADDRNOTAVAIL => EADDRNOTAVAIL,
libc::ENETDOWN => ENETDOWN,
libc::ENETUNREACH => ENETUNREACH,
libc::ENETRESET => ENETRESET,
libc::ECONNABORTED => ECONNABORTED,
libc::ECONNRESET => ECONNRESET,
libc::ENOBUFS => ENOBUFS,
libc::EISCONN => EISCONN,
libc::ENOTCONN => ENOTCONN,
libc::ESHUTDOWN => ESHUTDOWN,
libc::ETOOMANYREFS => ETOOMANYREFS,
libc::ETIMEDOUT => ETIMEDOUT,
libc::ECONNREFUSED => ECONNREFUSED,
libc::ELOOP => ELOOP,
libc::ENAMETOOLONG => ENAMETOOLONG,
libc::EHOSTDOWN => EHOSTDOWN,
libc::EHOSTUNREACH => EHOSTUNREACH,
libc::ENOTEMPTY => ENOTEMPTY,
libc::EUSERS => EUSERS,
libc::EDQUOT => EDQUOT,
libc::ESTALE => ESTALE,
libc::EREMOTE => EREMOTE,
libc::ENOLCK => ENOLCK,
libc::ENOSYS => ENOSYS,
libc::EIDRM => EIDRM,
libc::ENOMSG => ENOMSG,
libc::EOVERFLOW => EOVERFLOW,
libc::EILSEQ => EILSEQ,
libc::ECANCELED => ECANCELED,
libc::EBADMSG => EBADMSG,
libc::ENODATA => ENODATA,
libc::ENOSR => ENOSR,
libc::ENOSTR => ENOSTR,
libc::ETIME => ETIME,
libc::EMULTIHOP => EMULTIHOP,
libc::ENOLINK => ENOLINK,
libc::EPROTO => EPROTO,
_ => UnknownErrno,
}
}
}
Loading

0 comments on commit 18fd073

Please sign in to comment.