|
14 | 14 | //! compiling for wasm. That way it's a compile time error for something that's
|
15 | 15 | //! guaranteed to be a runtime error!
|
16 | 16 |
|
17 |
| -use crate::io as std_io; |
18 |
| -use crate::mem; |
19 |
| - |
20 | 17 | #[path = "../unix/alloc.rs"]
|
21 | 18 | pub mod alloc;
|
22 | 19 | pub mod args;
|
@@ -57,123 +54,12 @@ cfg_if::cfg_if! {
|
57 | 54 | mod common;
|
58 | 55 | pub use common::*;
|
59 | 56 |
|
60 |
| -#[inline] |
61 |
| -pub fn is_interrupted(errno: i32) -> bool { |
62 |
| - errno == wasi::ERRNO_INTR.raw().into() |
63 |
| -} |
64 |
| - |
65 |
| -pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind { |
66 |
| - use std_io::ErrorKind; |
67 |
| - |
68 |
| - let Ok(errno) = u16::try_from(errno) else { |
69 |
| - return ErrorKind::Uncategorized; |
70 |
| - }; |
71 |
| - |
72 |
| - macro_rules! match_errno { |
73 |
| - ($($($errno:ident)|+ => $errkind:ident),*, _ => $wildcard:ident $(,)?) => { |
74 |
| - match errno { |
75 |
| - $(e if $(e == ::wasi::$errno.raw())||+ => ErrorKind::$errkind),*, |
76 |
| - _ => ErrorKind::$wildcard, |
77 |
| - } |
78 |
| - }; |
79 |
| - } |
80 |
| - |
81 |
| - match_errno! { |
82 |
| - ERRNO_2BIG => ArgumentListTooLong, |
83 |
| - ERRNO_ACCES => PermissionDenied, |
84 |
| - ERRNO_ADDRINUSE => AddrInUse, |
85 |
| - ERRNO_ADDRNOTAVAIL => AddrNotAvailable, |
86 |
| - ERRNO_AFNOSUPPORT => Unsupported, |
87 |
| - ERRNO_AGAIN => WouldBlock, |
88 |
| - // ALREADY => "connection already in progress", |
89 |
| - // BADF => "bad file descriptor", |
90 |
| - // BADMSG => "bad message", |
91 |
| - ERRNO_BUSY => ResourceBusy, |
92 |
| - // CANCELED => "operation canceled", |
93 |
| - // CHILD => "no child processes", |
94 |
| - ERRNO_CONNABORTED => ConnectionAborted, |
95 |
| - ERRNO_CONNREFUSED => ConnectionRefused, |
96 |
| - ERRNO_CONNRESET => ConnectionReset, |
97 |
| - ERRNO_DEADLK => Deadlock, |
98 |
| - // DESTADDRREQ => "destination address required", |
99 |
| - ERRNO_DOM => InvalidInput, |
100 |
| - // DQUOT => /* reserved */, |
101 |
| - ERRNO_EXIST => AlreadyExists, |
102 |
| - // FAULT => "bad address", |
103 |
| - ERRNO_FBIG => FileTooLarge, |
104 |
| - ERRNO_HOSTUNREACH => HostUnreachable, |
105 |
| - // IDRM => "identifier removed", |
106 |
| - // ILSEQ => "illegal byte sequence", |
107 |
| - // INPROGRESS => "operation in progress", |
108 |
| - ERRNO_INTR => Interrupted, |
109 |
| - ERRNO_INVAL => InvalidInput, |
110 |
| - ERRNO_IO => Uncategorized, |
111 |
| - // ISCONN => "socket is connected", |
112 |
| - ERRNO_ISDIR => IsADirectory, |
113 |
| - ERRNO_LOOP => FilesystemLoop, |
114 |
| - // MFILE => "file descriptor value too large", |
115 |
| - ERRNO_MLINK => TooManyLinks, |
116 |
| - // MSGSIZE => "message too large", |
117 |
| - // MULTIHOP => /* reserved */, |
118 |
| - ERRNO_NAMETOOLONG => InvalidFilename, |
119 |
| - ERRNO_NETDOWN => NetworkDown, |
120 |
| - // NETRESET => "connection aborted by network", |
121 |
| - ERRNO_NETUNREACH => NetworkUnreachable, |
122 |
| - // NFILE => "too many files open in system", |
123 |
| - // NOBUFS => "no buffer space available", |
124 |
| - ERRNO_NODEV => NotFound, |
125 |
| - ERRNO_NOENT => NotFound, |
126 |
| - // NOEXEC => "executable file format error", |
127 |
| - // NOLCK => "no locks available", |
128 |
| - // NOLINK => /* reserved */, |
129 |
| - ERRNO_NOMEM => OutOfMemory, |
130 |
| - // NOMSG => "no message of the desired type", |
131 |
| - // NOPROTOOPT => "protocol not available", |
132 |
| - ERRNO_NOSPC => StorageFull, |
133 |
| - ERRNO_NOSYS => Unsupported, |
134 |
| - ERRNO_NOTCONN => NotConnected, |
135 |
| - ERRNO_NOTDIR => NotADirectory, |
136 |
| - ERRNO_NOTEMPTY => DirectoryNotEmpty, |
137 |
| - // NOTRECOVERABLE => "state not recoverable", |
138 |
| - // NOTSOCK => "not a socket", |
139 |
| - ERRNO_NOTSUP => Unsupported, |
140 |
| - // NOTTY => "inappropriate I/O control operation", |
141 |
| - ERRNO_NXIO => NotFound, |
142 |
| - // OVERFLOW => "value too large to be stored in data type", |
143 |
| - // OWNERDEAD => "previous owner died", |
144 |
| - ERRNO_PERM => PermissionDenied, |
145 |
| - ERRNO_PIPE => BrokenPipe, |
146 |
| - // PROTO => "protocol error", |
147 |
| - ERRNO_PROTONOSUPPORT => Unsupported, |
148 |
| - // PROTOTYPE => "protocol wrong type for socket", |
149 |
| - // RANGE => "result too large", |
150 |
| - ERRNO_ROFS => ReadOnlyFilesystem, |
151 |
| - ERRNO_SPIPE => NotSeekable, |
152 |
| - ERRNO_SRCH => NotFound, |
153 |
| - // STALE => /* reserved */, |
154 |
| - ERRNO_TIMEDOUT => TimedOut, |
155 |
| - ERRNO_TXTBSY => ResourceBusy, |
156 |
| - ERRNO_XDEV => CrossesDevices, |
157 |
| - ERRNO_NOTCAPABLE => PermissionDenied, |
158 |
| - _ => Uncategorized, |
159 |
| - } |
160 |
| -} |
161 |
| - |
162 |
| -pub fn abort_internal() -> ! { |
163 |
| - unsafe { libc::abort() } |
164 |
| -} |
165 |
| - |
166 |
| -pub fn hashmap_random_keys() -> (u64, u64) { |
167 |
| - let mut ret = (0u64, 0u64); |
168 |
| - unsafe { |
169 |
| - let base = core::ptr::addr_of_mut!(ret) as *mut u8; |
170 |
| - let len = mem::size_of_val(&ret); |
171 |
| - wasi::random_get(base, len).expect("random_get failure"); |
172 |
| - } |
173 |
| - return ret; |
174 |
| -} |
175 |
| - |
176 |
| -#[inline] |
177 |
| -fn err2io(err: wasi::Errno) -> std_io::Error { |
178 |
| - std_io::Error::from_raw_os_error(err.raw().into()) |
179 |
| -} |
| 57 | +mod helpers; |
| 58 | +// These exports are listed individually to work around Rust's glob import |
| 59 | +// conflict rules. If we glob export `helpers` and `common` together, then |
| 60 | +// the compiler complains about conflicts. |
| 61 | +pub use helpers::abort_internal; |
| 62 | +pub use helpers::decode_error_kind; |
| 63 | +use helpers::err2io; |
| 64 | +pub use helpers::hashmap_random_keys; |
| 65 | +pub use helpers::is_interrupted; |
0 commit comments