Skip to content

Commit 1a87926

Browse files
committed
Auto merge of #2460 - LegNeato:sysconf, r=RalfJung
Add additional raw error mappings for the nightly `io_error_more` feature Some crates are using nightly and failing when mapping these errors, for example <https://miri.saethlin.dev/?crate=remove_dir_all&version=0.7.0>: ``` error: unsupported operation: io error NotADirectory cannot be translated into a raw os error --> /root/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/sys/unix/fs.rs:1203:19 ```
2 parents 730a799 + e1e1f42 commit 1a87926

File tree

1 file changed

+45
-20
lines changed

1 file changed

+45
-20
lines changed

src/helpers.rs

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,51 @@ use crate::*;
2323

2424
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
2525

26-
const UNIX_IO_ERROR_TABLE: &[(std::io::ErrorKind, &str)] = {
26+
// This mapping should match `decode_error_kind` in
27+
// <https://github.com/rust-lang/rust/blob/master/library/std/src/sys/unix/mod.rs>.
28+
const UNIX_IO_ERROR_TABLE: &[(&str, std::io::ErrorKind)] = {
2729
use std::io::ErrorKind::*;
2830
&[
29-
(ConnectionRefused, "ECONNREFUSED"),
30-
(ConnectionReset, "ECONNRESET"),
31-
(PermissionDenied, "EPERM"),
32-
(BrokenPipe, "EPIPE"),
33-
(NotConnected, "ENOTCONN"),
34-
(ConnectionAborted, "ECONNABORTED"),
35-
(AddrNotAvailable, "EADDRNOTAVAIL"),
36-
(AddrInUse, "EADDRINUSE"),
37-
(NotFound, "ENOENT"),
38-
(Interrupted, "EINTR"),
39-
(InvalidInput, "EINVAL"),
40-
(InvalidFilename, "ENAMETOOLONG"),
41-
(TimedOut, "ETIMEDOUT"),
42-
(AlreadyExists, "EEXIST"),
43-
(WouldBlock, "EWOULDBLOCK"),
44-
(DirectoryNotEmpty, "ENOTEMPTY"),
45-
(FilesystemLoop, "ELOOP"),
31+
("E2BIG", ArgumentListTooLong),
32+
("EADDRINUSE", AddrInUse),
33+
("EADDRNOTAVAIL", AddrNotAvailable),
34+
("EBUSY", ResourceBusy),
35+
("ECONNABORTED", ConnectionAborted),
36+
("ECONNREFUSED", ConnectionRefused),
37+
("ECONNRESET", ConnectionReset),
38+
("EDEADLK", Deadlock),
39+
("EDQUOT", FilesystemQuotaExceeded),
40+
("EEXIST", AlreadyExists),
41+
("EFBIG", FileTooLarge),
42+
("EHOSTUNREACH", HostUnreachable),
43+
("EINTR", Interrupted),
44+
("EINVAL", InvalidInput),
45+
("EISDIR", IsADirectory),
46+
("ELOOP", FilesystemLoop),
47+
("ENOENT", NotFound),
48+
("ENOMEM", OutOfMemory),
49+
("ENOSPC", StorageFull),
50+
("ENOSYS", Unsupported),
51+
("EMLINK", TooManyLinks),
52+
("ENAMETOOLONG", InvalidFilename),
53+
("ENETDOWN", NetworkDown),
54+
("ENETUNREACH", NetworkUnreachable),
55+
("ENOTCONN", NotConnected),
56+
("ENOTDIR", NotADirectory),
57+
("ENOTEMPTY", DirectoryNotEmpty),
58+
("EPIPE", BrokenPipe),
59+
("EROFS", ReadOnlyFilesystem),
60+
("ESPIPE", NotSeekable),
61+
("ESTALE", StaleNetworkFileHandle),
62+
("ETIMEDOUT", TimedOut),
63+
("ETXTBSY", ExecutableFileBusy),
64+
("EXDEV", CrossesDevices),
65+
// The following have two valid options. We have both for the forwards mapping; only the
66+
// first one will be used for the backwards mapping.
67+
("EPERM", PermissionDenied),
68+
("EACCES", PermissionDenied),
69+
("EWOULDBLOCK", WouldBlock),
70+
("EAGAIN", WouldBlock),
4671
]
4772
};
4873

@@ -554,7 +579,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
554579
let this = self.eval_context_ref();
555580
let target = &this.tcx.sess.target;
556581
if target.families.iter().any(|f| f == "unix") {
557-
for &(kind, name) in UNIX_IO_ERROR_TABLE {
582+
for &(name, kind) in UNIX_IO_ERROR_TABLE {
558583
if err_kind == kind {
559584
return this.eval_libc(name);
560585
}
@@ -592,7 +617,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
592617
let target = &this.tcx.sess.target;
593618
if target.families.iter().any(|f| f == "unix") {
594619
let errnum = errnum.to_i32()?;
595-
for &(kind, name) in UNIX_IO_ERROR_TABLE {
620+
for &(name, kind) in UNIX_IO_ERROR_TABLE {
596621
if errnum == this.eval_libc_i32(name)? {
597622
return Ok(kind);
598623
}

0 commit comments

Comments
 (0)