Skip to content

Commit 034cca6

Browse files
committed
Add Redox support for most of the modules
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
1 parent 5e463aa commit 034cca6

File tree

12 files changed

+464
-61
lines changed

12 files changed

+464
-61
lines changed

src/dir.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ use {Error, NixPath, Result};
22
use errno::Errno;
33
use fcntl::{self, OFlag};
44
use libc;
5-
use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
5+
use std::os::unix::io::{IntoRawFd, RawFd};
6+
#[cfg(not(target_os = "redox"))]
7+
use std::os::unix::io::AsRawFd;
68
use std::{ffi, ptr};
79
use sys;
810

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

82+
#[cfg(not(target_os = "redox"))]
8083
impl AsRawFd for Dir {
8184
fn as_raw_fd(&self) -> RawFd {
8285
unsafe { libc::dirfd(self.0.as_ptr()) }
@@ -149,6 +152,7 @@ impl Entry {
149152
target_os = "l4re",
150153
target_os = "linux",
151154
target_os = "macos",
155+
target_os = "redox",
152156
target_os = "solaris"))]
153157
pub fn ino(&self) -> u64 {
154158
self.0.d_ino as u64
@@ -163,6 +167,7 @@ impl Entry {
163167
target_os = "l4re",
164168
target_os = "linux",
165169
target_os = "macos",
170+
target_os = "redox",
166171
target_os = "solaris")))]
167172
pub fn ino(&self) -> u64 {
168173
self.0.d_fileno as u64

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
}
@@ -336,7 +336,8 @@ fn desc(errno: Errno) -> &'static str {
336336
#[cfg(any(target_os = "linux", target_os = "android"))]
337337
EUSERS => "Too many users",
338338

339-
#[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))]
339+
#[cfg(any(target_os = "linux", target_os = "android",
340+
target_os = "netbsd", target_os = "redox"))]
340341
EOPNOTSUPP => "Operation not supported on transport endpoint",
341342

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

400-
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
401+
#[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "redox"))]
401402
EMULTIHOP => "Multihop attempted",
402403

403-
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
404+
#[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "redox"))]
404405
ENOLINK => "Link has been severed",
405406

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

417418
#[cfg(any(target_os = "macos", target_os = "freebsd",
418419
target_os = "dragonfly", target_os = "ios",
419-
target_os = "openbsd", target_os = "netbsd"))]
420+
target_os = "openbsd", target_os = "netbsd",
421+
target_os = "redox"))]
420422
EOVERFLOW => "Value too large to be stored in data type",
421423

422424
#[cfg(any(target_os = "macos", target_os = "freebsd",
423425
target_os = "dragonfly", target_os = "ios",
424-
target_os = "netbsd"))]
426+
target_os = "netbsd", target_os = "redox"))]
425427
EILSEQ => "Illegal byte sequence",
426428

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

432434
#[cfg(any(target_os = "macos", target_os = "freebsd",
433435
target_os = "dragonfly", target_os = "ios",
434-
target_os = "openbsd", target_os = "netbsd"))]
436+
target_os = "openbsd", target_os = "netbsd",
437+
target_os = "redox"))]
435438
EBADMSG => "Bad message",
436439

437440
#[cfg(any(target_os = "macos", target_os = "freebsd",
438441
target_os = "dragonfly", target_os = "ios",
439-
target_os = "openbsd", target_os = "netbsd"))]
442+
target_os = "openbsd", target_os = "netbsd",
443+
target_os = "redox"))]
440444
EPROTO => "Protocol error",
441445

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

460464
#[cfg(any(target_os = "macos", target_os = "freebsd",
461465
target_os = "dragonfly", target_os = "ios",
462-
target_os = "openbsd", target_os = "netbsd"))]
466+
target_os = "openbsd", target_os = "netbsd",
467+
target_os = "redox"))]
463468
EUSERS => "Too many users",
464469

465470
#[cfg(any(target_os = "macos", target_os = "freebsd",
466471
target_os = "dragonfly", target_os = "ios",
467-
target_os = "openbsd", target_os = "netbsd"))]
472+
target_os = "openbsd", target_os = "netbsd",
473+
target_os = "redox"))]
468474
EDQUOT => "Disc quota exceeded",
469475

470476
#[cfg(any(target_os = "macos", target_os = "freebsd",
471477
target_os = "dragonfly", target_os = "ios",
472-
target_os = "openbsd", target_os = "netbsd"))]
478+
target_os = "openbsd", target_os = "netbsd",
479+
target_os = "redox"))]
473480
ESTALE => "Stale NFS file handle",
474481

475482
#[cfg(any(target_os = "macos", target_os = "freebsd",
476483
target_os = "dragonfly", target_os = "ios",
477-
target_os = "openbsd", target_os = "netbsd"))]
484+
target_os = "openbsd", target_os = "netbsd",
485+
target_os = "redox"))]
478486
EREMOTE => "Too many levels of remote in path",
479487

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

515523
#[cfg(any(target_os = "macos", target_os = "freebsd",
516524
target_os = "dragonfly", target_os = "ios",
517-
target_os = "openbsd", target_os = "netbsd"))]
525+
target_os = "openbsd", target_os = "netbsd",
526+
target_os = "redox"))]
518527
ECANCELED => "Operation canceled",
519528

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

541-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "netbsd"))]
550+
#[cfg(any(target_os = "macos", target_os = "ios",
551+
target_os = "netbsd", target_os = "redox"))]
542552
ENODATA => "No message available on STREAM",
543553

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

547-
#[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"))]
548559
ENOSR => "No STREAM resources",
549560

550-
#[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"))]
551563
ENOSTR => "Not a STREAM",
552564

553-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "netbsd"))]
565+
#[cfg(any(target_os = "macos", target_os = "ios",
566+
target_os = "netbsd", target_os = "redox"))]
554567
ETIME => "STREAM ioctl timeout",
555568

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

0 commit comments

Comments
 (0)