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