Skip to content

Commit d950c48

Browse files
bors[bot]AdminXVII
andauthored
Merge #1098
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 <[email protected]> Co-authored-by: Xavier L'Heureux <[email protected]>
2 parents d3fef37 + b05c3dc commit d950c48

27 files changed

+718
-165
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ matrix:
9595
script:
9696
- cargo update -Zminimal-versions
9797
- cargo check
98+
- language: generic
99+
name: redox
100+
script:
101+
- docker pull redoxos/redoxer
102+
- docker run -v $(pwd):$(pwd) -w $(pwd) redoxos/redoxer sh -c 'rm -rf ~/.redoxer && redoxer test'
98103

99104
before_install: set -e
100105

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ name = "test-mount"
5757
path = "test/test_mount.rs"
5858
harness = false
5959

60-
[[test]]
60+
[[target.'cfg(not(target_os = "redox"))'.test]]
6161
name = "test-ptymaster-drop"
6262
path = "test/test_ptymaster_drop.rs"

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ Tier 2:
8181
* x86_64-linux-android
8282
* x86_64-unknown-netbsd
8383

84+
Tier 3:
85+
* x86_64-unknown-redox
86+
8487
## Usage
8588

8689
`nix` requires Rust 1.36.0 or newer.

src/dir.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use errno::Errno;
33
use fcntl::{self, OFlag};
44
use libc;
55
use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
6-
use std::{ffi, ptr};
6+
use std::ptr;
7+
use std::ffi;
78
use sys;
89

910
#[cfg(target_os = "linux")]

src/errno.rs

Lines changed: 224 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ cfg_if! {
3838
unsafe fn errno_location() -> *mut c_int {
3939
libc::__errno()
4040
}
41-
} else if #[cfg(target_os = "linux")] {
41+
} else if #[cfg(any(target_os = "linux", target_os = "redox"))] {
4242
unsafe fn errno_location() -> *mut c_int {
4343
libc::__errno_location()
4444
}
@@ -332,7 +332,8 @@ fn desc(errno: Errno) -> &'static str {
332332
#[cfg(any(target_os = "linux", target_os = "android"))]
333333
EUSERS => "Too many users",
334334

335-
#[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))]
335+
#[cfg(any(target_os = "linux", target_os = "android",
336+
target_os = "netbsd", target_os = "redox"))]
336337
EOPNOTSUPP => "Operation not supported on transport endpoint",
337338

338339
#[cfg(any(target_os = "linux", target_os = "android"))]
@@ -393,10 +394,10 @@ fn desc(errno: Errno) -> &'static str {
393394
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
394395
EDOOFUS => "Programming error",
395396

396-
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
397+
#[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "redox"))]
397398
EMULTIHOP => "Multihop attempted",
398399

399-
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
400+
#[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "redox"))]
400401
ENOLINK => "Link has been severed",
401402

402403
#[cfg(target_os = "freebsd")]
@@ -412,12 +413,13 @@ fn desc(errno: Errno) -> &'static str {
412413

413414
#[cfg(any(target_os = "macos", target_os = "freebsd",
414415
target_os = "dragonfly", target_os = "ios",
415-
target_os = "openbsd", target_os = "netbsd"))]
416+
target_os = "openbsd", target_os = "netbsd",
417+
target_os = "redox"))]
416418
EOVERFLOW => "Value too large to be stored in data type",
417419

418420
#[cfg(any(target_os = "macos", target_os = "freebsd",
419421
target_os = "dragonfly", target_os = "ios",
420-
target_os = "netbsd"))]
422+
target_os = "netbsd", target_os = "redox"))]
421423
EILSEQ => "Illegal byte sequence",
422424

423425
#[cfg(any(target_os = "macos", target_os = "freebsd",
@@ -427,12 +429,14 @@ fn desc(errno: Errno) -> &'static str {
427429

428430
#[cfg(any(target_os = "macos", target_os = "freebsd",
429431
target_os = "dragonfly", target_os = "ios",
430-
target_os = "openbsd", target_os = "netbsd"))]
432+
target_os = "openbsd", target_os = "netbsd",
433+
target_os = "redox"))]
431434
EBADMSG => "Bad message",
432435

433436
#[cfg(any(target_os = "macos", target_os = "freebsd",
434437
target_os = "dragonfly", target_os = "ios",
435-
target_os = "openbsd", target_os = "netbsd"))]
438+
target_os = "openbsd", target_os = "netbsd",
439+
target_os = "redox"))]
436440
EPROTO => "Protocol error",
437441

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

456460
#[cfg(any(target_os = "macos", target_os = "freebsd",
457461
target_os = "dragonfly", target_os = "ios",
458-
target_os = "openbsd", target_os = "netbsd"))]
462+
target_os = "openbsd", target_os = "netbsd",
463+
target_os = "redox"))]
459464
EUSERS => "Too many users",
460465

461466
#[cfg(any(target_os = "macos", target_os = "freebsd",
462467
target_os = "dragonfly", target_os = "ios",
463-
target_os = "openbsd", target_os = "netbsd"))]
468+
target_os = "openbsd", target_os = "netbsd",
469+
target_os = "redox"))]
464470
EDQUOT => "Disc quota exceeded",
465471

466472
#[cfg(any(target_os = "macos", target_os = "freebsd",
467473
target_os = "dragonfly", target_os = "ios",
468-
target_os = "openbsd", target_os = "netbsd"))]
474+
target_os = "openbsd", target_os = "netbsd",
475+
target_os = "redox"))]
469476
ESTALE => "Stale NFS file handle",
470477

471478
#[cfg(any(target_os = "macos", target_os = "freebsd",
472479
target_os = "dragonfly", target_os = "ios",
473-
target_os = "openbsd", target_os = "netbsd"))]
480+
target_os = "openbsd", target_os = "netbsd",
481+
target_os = "redox"))]
474482
EREMOTE => "Too many levels of remote in path",
475483

476484
#[cfg(any(target_os = "macos", target_os = "freebsd",
@@ -510,7 +518,8 @@ fn desc(errno: Errno) -> &'static str {
510518

511519
#[cfg(any(target_os = "macos", target_os = "freebsd",
512520
target_os = "dragonfly", target_os = "ios",
513-
target_os = "openbsd", target_os = "netbsd"))]
521+
target_os = "openbsd", target_os = "netbsd",
522+
target_os = "redox"))]
514523
ECANCELED => "Operation canceled",
515524

516525
#[cfg(any(target_os = "macos", target_os = "ios"))]
@@ -534,19 +543,23 @@ fn desc(errno: Errno) -> &'static str {
534543
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "netbsd"))]
535544
EMULTIHOP => "Reserved",
536545

537-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "netbsd"))]
546+
#[cfg(any(target_os = "macos", target_os = "ios",
547+
target_os = "netbsd", target_os = "redox"))]
538548
ENODATA => "No message available on STREAM",
539549

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

543-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "netbsd"))]
553+
#[cfg(any(target_os = "macos", target_os = "ios",
554+
target_os = "netbsd", target_os = "redox"))]
544555
ENOSR => "No STREAM resources",
545556

546-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "netbsd"))]
557+
#[cfg(any(target_os = "macos", target_os = "ios",
558+
target_os = "netbsd", target_os = "redox"))]
547559
ENOSTR => "Not a STREAM",
548560

549-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "netbsd"))]
561+
#[cfg(any(target_os = "macos", target_os = "ios",
562+
target_os = "netbsd", target_os = "redox"))]
550563
ETIME => "STREAM ioctl timeout",
551564

552565
#[cfg(any(target_os = "macos", target_os = "ios"))]
@@ -1957,3 +1970,197 @@ mod consts {
19571970
}
19581971
}
19591972
}
1973+
1974+
#[cfg(target_os = "redox")]
1975+
mod consts {
1976+
use libc;
1977+
1978+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1979+
#[repr(i32)]
1980+
pub enum Errno {
1981+
UnknownErrno = 0,
1982+
EPERM = libc::EPERM,
1983+
ENOENT = libc::ENOENT,
1984+
ESRCH = libc::ESRCH,
1985+
EINTR = libc::EINTR,
1986+
EIO = libc::EIO,
1987+
ENXIO = libc::ENXIO,
1988+
E2BIG = libc::E2BIG,
1989+
ENOEXEC = libc::ENOEXEC,
1990+
EBADF = libc::EBADF,
1991+
ECHILD = libc::ECHILD,
1992+
EDEADLK = libc::EDEADLK,
1993+
ENOMEM = libc::ENOMEM,
1994+
EACCES = libc::EACCES,
1995+
EFAULT = libc::EFAULT,
1996+
ENOTBLK = libc::ENOTBLK,
1997+
EBUSY = libc::EBUSY,
1998+
EEXIST = libc::EEXIST,
1999+
EXDEV = libc::EXDEV,
2000+
ENODEV = libc::ENODEV,
2001+
ENOTDIR = libc::ENOTDIR,
2002+
EISDIR = libc::EISDIR,
2003+
EINVAL = libc::EINVAL,
2004+
ENFILE = libc::ENFILE,
2005+
EMFILE = libc::EMFILE,
2006+
ENOTTY = libc::ENOTTY,
2007+
ETXTBSY = libc::ETXTBSY,
2008+
EFBIG = libc::EFBIG,
2009+
ENOSPC = libc::ENOSPC,
2010+
ESPIPE = libc::ESPIPE,
2011+
EROFS = libc::EROFS,
2012+
EMLINK = libc::EMLINK,
2013+
EPIPE = libc::EPIPE,
2014+
EDOM = libc::EDOM,
2015+
ERANGE = libc::ERANGE,
2016+
EAGAIN = libc::EAGAIN,
2017+
EINPROGRESS = libc::EINPROGRESS,
2018+
EALREADY = libc::EALREADY,
2019+
ENOTSOCK = libc::ENOTSOCK,
2020+
EDESTADDRREQ = libc::EDESTADDRREQ,
2021+
EMSGSIZE = libc::EMSGSIZE,
2022+
EPROTOTYPE = libc::EPROTOTYPE,
2023+
ENOPROTOOPT = libc::ENOPROTOOPT,
2024+
EPROTONOSUPPORT = libc::EPROTONOSUPPORT,
2025+
ESOCKTNOSUPPORT = libc::ESOCKTNOSUPPORT,
2026+
EOPNOTSUPP = libc::EOPNOTSUPP,
2027+
EPFNOSUPPORT = libc::EPFNOSUPPORT,
2028+
EAFNOSUPPORT = libc::EAFNOSUPPORT,
2029+
EADDRINUSE = libc::EADDRINUSE,
2030+
EADDRNOTAVAIL = libc::EADDRNOTAVAIL,
2031+
ENETDOWN = libc::ENETDOWN,
2032+
ENETUNREACH = libc::ENETUNREACH,
2033+
ENETRESET = libc::ENETRESET,
2034+
ECONNABORTED = libc::ECONNABORTED,
2035+
ECONNRESET = libc::ECONNRESET,
2036+
ENOBUFS = libc::ENOBUFS,
2037+
EISCONN = libc::EISCONN,
2038+
ENOTCONN = libc::ENOTCONN,
2039+
ESHUTDOWN = libc::ESHUTDOWN,
2040+
ETOOMANYREFS = libc::ETOOMANYREFS,
2041+
ETIMEDOUT = libc::ETIMEDOUT,
2042+
ECONNREFUSED = libc::ECONNREFUSED,
2043+
ELOOP = libc::ELOOP,
2044+
ENAMETOOLONG = libc::ENAMETOOLONG,
2045+
EHOSTDOWN = libc::EHOSTDOWN,
2046+
EHOSTUNREACH = libc::EHOSTUNREACH,
2047+
ENOTEMPTY = libc::ENOTEMPTY,
2048+
EUSERS = libc::EUSERS,
2049+
EDQUOT = libc::EDQUOT,
2050+
ESTALE = libc::ESTALE,
2051+
EREMOTE = libc::EREMOTE,
2052+
ENOLCK = libc::ENOLCK,
2053+
ENOSYS = libc::ENOSYS,
2054+
EIDRM = libc::EIDRM,
2055+
ENOMSG = libc::ENOMSG,
2056+
EOVERFLOW = libc::EOVERFLOW,
2057+
EILSEQ = libc::EILSEQ,
2058+
ECANCELED = libc::ECANCELED,
2059+
EBADMSG = libc::EBADMSG,
2060+
ENODATA = libc::ENODATA,
2061+
ENOSR = libc::ENOSR,
2062+
ENOSTR = libc::ENOSTR,
2063+
ETIME = libc::ETIME,
2064+
EMULTIHOP = libc::EMULTIHOP,
2065+
ENOLINK = libc::ENOLINK,
2066+
EPROTO = libc::EPROTO,
2067+
}
2068+
2069+
pub const ELAST: Errno = Errno::UnknownErrno;
2070+
pub const EWOULDBLOCK: Errno = Errno::EAGAIN;
2071+
2072+
pub const EL2NSYNC: Errno = Errno::UnknownErrno;
2073+
2074+
pub fn from_i32(e: i32) -> Errno {
2075+
use self::Errno::*;
2076+
2077+
match e {
2078+
libc::EPERM => EPERM,
2079+
libc::ENOENT => ENOENT,
2080+
libc::ESRCH => ESRCH,
2081+
libc::EINTR => EINTR,
2082+
libc::EIO => EIO,
2083+
libc::ENXIO => ENXIO,
2084+
libc::E2BIG => E2BIG,
2085+
libc::ENOEXEC => ENOEXEC,
2086+
libc::EBADF => EBADF,
2087+
libc::ECHILD => ECHILD,
2088+
libc::EDEADLK => EDEADLK,
2089+
libc::ENOMEM => ENOMEM,
2090+
libc::EACCES => EACCES,
2091+
libc::EFAULT => EFAULT,
2092+
libc::ENOTBLK => ENOTBLK,
2093+
libc::EBUSY => EBUSY,
2094+
libc::EEXIST => EEXIST,
2095+
libc::EXDEV => EXDEV,
2096+
libc::ENODEV => ENODEV,
2097+
libc::ENOTDIR => ENOTDIR,
2098+
libc::EISDIR => EISDIR,
2099+
libc::EINVAL => EINVAL,
2100+
libc::ENFILE => ENFILE,
2101+
libc::EMFILE => EMFILE,
2102+
libc::ENOTTY => ENOTTY,
2103+
libc::ETXTBSY => ETXTBSY,
2104+
libc::EFBIG => EFBIG,
2105+
libc::ENOSPC => ENOSPC,
2106+
libc::ESPIPE => ESPIPE,
2107+
libc::EROFS => EROFS,
2108+
libc::EMLINK => EMLINK,
2109+
libc::EPIPE => EPIPE,
2110+
libc::EDOM => EDOM,
2111+
libc::ERANGE => ERANGE,
2112+
libc::EAGAIN => EAGAIN,
2113+
libc::EINPROGRESS => EINPROGRESS,
2114+
libc::EALREADY => EALREADY,
2115+
libc::ENOTSOCK => ENOTSOCK,
2116+
libc::EDESTADDRREQ => EDESTADDRREQ,
2117+
libc::EMSGSIZE => EMSGSIZE,
2118+
libc::EPROTOTYPE => EPROTOTYPE,
2119+
libc::ENOPROTOOPT => ENOPROTOOPT,
2120+
libc::EPROTONOSUPPORT => EPROTONOSUPPORT,
2121+
libc::ESOCKTNOSUPPORT => ESOCKTNOSUPPORT,
2122+
libc::EOPNOTSUPP => EOPNOTSUPP,
2123+
libc::EPFNOSUPPORT => EPFNOSUPPORT,
2124+
libc::EAFNOSUPPORT => EAFNOSUPPORT,
2125+
libc::EADDRINUSE => EADDRINUSE,
2126+
libc::EADDRNOTAVAIL => EADDRNOTAVAIL,
2127+
libc::ENETDOWN => ENETDOWN,
2128+
libc::ENETUNREACH => ENETUNREACH,
2129+
libc::ENETRESET => ENETRESET,
2130+
libc::ECONNABORTED => ECONNABORTED,
2131+
libc::ECONNRESET => ECONNRESET,
2132+
libc::ENOBUFS => ENOBUFS,
2133+
libc::EISCONN => EISCONN,
2134+
libc::ENOTCONN => ENOTCONN,
2135+
libc::ESHUTDOWN => ESHUTDOWN,
2136+
libc::ETOOMANYREFS => ETOOMANYREFS,
2137+
libc::ETIMEDOUT => ETIMEDOUT,
2138+
libc::ECONNREFUSED => ECONNREFUSED,
2139+
libc::ELOOP => ELOOP,
2140+
libc::ENAMETOOLONG => ENAMETOOLONG,
2141+
libc::EHOSTDOWN => EHOSTDOWN,
2142+
libc::EHOSTUNREACH => EHOSTUNREACH,
2143+
libc::ENOTEMPTY => ENOTEMPTY,
2144+
libc::EUSERS => EUSERS,
2145+
libc::EDQUOT => EDQUOT,
2146+
libc::ESTALE => ESTALE,
2147+
libc::EREMOTE => EREMOTE,
2148+
libc::ENOLCK => ENOLCK,
2149+
libc::ENOSYS => ENOSYS,
2150+
libc::EIDRM => EIDRM,
2151+
libc::ENOMSG => ENOMSG,
2152+
libc::EOVERFLOW => EOVERFLOW,
2153+
libc::EILSEQ => EILSEQ,
2154+
libc::ECANCELED => ECANCELED,
2155+
libc::EBADMSG => EBADMSG,
2156+
libc::ENODATA => ENODATA,
2157+
libc::ENOSR => ENOSR,
2158+
libc::ENOSTR => ENOSTR,
2159+
libc::ETIME => ETIME,
2160+
libc::EMULTIHOP => EMULTIHOP,
2161+
libc::ENOLINK => ENOLINK,
2162+
libc::EPROTO => EPROTO,
2163+
_ => UnknownErrno,
2164+
}
2165+
}
2166+
}

0 commit comments

Comments
 (0)