Skip to content

Commit

Permalink
Merge #1098
Browse files Browse the repository at this point in the history
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 rust-lang/libc#1438

Co-authored-by: Xavier L'Heureux <xavier.lheureux@icloud.com>
Co-authored-by: Xavier L'Heureux <dev.xlheureux@gmail.com>
  • Loading branch information
3 people authored May 20, 2020
2 parents d3fef37 + b05c3dc commit d950c48
Show file tree
Hide file tree
Showing 27 changed files with 718 additions and 165 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ matrix:
script:
- cargo update -Zminimal-versions
- cargo check
- language: generic
name: redox
script:
- docker pull redoxos/redoxer
- docker run -v $(pwd):$(pwd) -w $(pwd) redoxos/redoxer sh -c 'rm -rf ~/.redoxer && redoxer test'

before_install: set -e

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ name = "test-mount"
path = "test/test_mount.rs"
harness = false

[[test]]
[[target.'cfg(not(target_os = "redox"))'.test]]
name = "test-ptymaster-drop"
path = "test/test_ptymaster_drop.rs"
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ Tier 2:
* x86_64-linux-android
* x86_64-unknown-netbsd

Tier 3:
* x86_64-unknown-redox

## Usage

`nix` requires Rust 1.36.0 or newer.
Expand Down
3 changes: 2 additions & 1 deletion src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use errno::Errno;
use fcntl::{self, OFlag};
use libc;
use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
use std::{ffi, ptr};
use std::ptr;
use std::ffi;
use sys;

#[cfg(target_os = "linux")]
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 @@ -332,7 +332,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 @@ -393,10 +394,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 @@ -412,12 +413,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 @@ -427,12 +429,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 @@ -455,22 +459,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 @@ -510,7 +518,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 @@ -534,19 +543,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 @@ -1957,3 +1970,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 d950c48

Please sign in to comment.