Skip to content

Commit 00cbc8d

Browse files
committed
wasi: update to wasi 0.11.0
To make use of `sock_accept()`, update the wasi crate to `0.11.0`. Signed-off-by: Harald Hoyer <harald@profian.com>
1 parent 312a799 commit 00cbc8d

File tree

7 files changed

+54
-28
lines changed

7 files changed

+54
-28
lines changed

Cargo.lock

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"
14731473
dependencies = [
14741474
"cfg-if 0.1.10",
14751475
"libc",
1476-
"wasi",
1476+
"wasi 0.9.0+wasi-snapshot-preview1",
14771477
]
14781478

14791479
[[package]]
@@ -1484,7 +1484,7 @@ checksum = "ee8025cf36f917e6a52cce185b7c7177689b838b7ec138364e50cc2277a56cf4"
14841484
dependencies = [
14851485
"cfg-if 0.1.10",
14861486
"libc",
1487-
"wasi",
1487+
"wasi 0.9.0+wasi-snapshot-preview1",
14881488
]
14891489

14901490
[[package]]
@@ -4854,7 +4854,7 @@ dependencies = [
48544854
"rustc-demangle",
48554855
"std_detect",
48564856
"unwind",
4857-
"wasi",
4857+
"wasi 0.11.0+wasi-snapshot-preview1",
48584858
]
48594859

48604860
[[package]]
@@ -5612,6 +5612,12 @@ name = "wasi"
56125612
version = "0.9.0+wasi-snapshot-preview1"
56135613
source = "registry+https://github.com/rust-lang/crates.io-index"
56145614
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
5615+
5616+
[[package]]
5617+
name = "wasi"
5618+
version = "0.11.0+wasi-snapshot-preview1"
5619+
source = "registry+https://github.com/rust-lang/crates.io-index"
5620+
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
56155621
dependencies = [
56165622
"compiler_builtins",
56175623
"rustc-std-workspace-alloc",

library/std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fortanix-sgx-abi = { version = "0.3.2", features = ['rustc-dep-of-std'] }
4545
hermit-abi = { version = "0.1.19", features = ['rustc-dep-of-std'] }
4646

4747
[target.wasm32-wasi.dependencies]
48-
wasi = { version = "0.9.0", features = ['rustc-dep-of-std'], default-features = false }
48+
wasi = { version = "0.11.0", features = ['rustc-dep-of-std'], default-features = false }
4949

5050
[features]
5151
backtrace = [

library/std/src/os/wasi/fs.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,21 @@ impl FileExt for fs::File {
250250
}
251251

252252
fn advise(&self, offset: u64, len: u64, advice: u8) -> io::Result<()> {
253+
let advice = match advice {
254+
a if a == wasi::ADVICE_NORMAL.raw() => wasi::ADVICE_NORMAL,
255+
a if a == wasi::ADVICE_SEQUENTIAL.raw() => wasi::ADVICE_SEQUENTIAL,
256+
a if a == wasi::ADVICE_RANDOM.raw() => wasi::ADVICE_RANDOM,
257+
a if a == wasi::ADVICE_WILLNEED.raw() => wasi::ADVICE_WILLNEED,
258+
a if a == wasi::ADVICE_DONTNEED.raw() => wasi::ADVICE_DONTNEED,
259+
a if a == wasi::ADVICE_NOREUSE.raw() => wasi::ADVICE_NOREUSE,
260+
_ => {
261+
return Err(io::Error::new_const(
262+
io::ErrorKind::InvalidInput,
263+
&"invalid parameter 'advice'",
264+
));
265+
}
266+
};
267+
253268
self.as_inner().as_inner().advise(offset, len, advice)
254269
}
255270

library/std/src/sys/wasi/mod.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,26 @@ pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind {
6161
if errno > u16::MAX as i32 || errno < 0 {
6262
return Uncategorized;
6363
}
64-
match errno as u16 {
65-
wasi::ERRNO_CONNREFUSED => ConnectionRefused,
66-
wasi::ERRNO_CONNRESET => ConnectionReset,
67-
wasi::ERRNO_PERM | wasi::ERRNO_ACCES => PermissionDenied,
68-
wasi::ERRNO_PIPE => BrokenPipe,
69-
wasi::ERRNO_NOTCONN => NotConnected,
70-
wasi::ERRNO_CONNABORTED => ConnectionAborted,
71-
wasi::ERRNO_ADDRNOTAVAIL => AddrNotAvailable,
72-
wasi::ERRNO_ADDRINUSE => AddrInUse,
73-
wasi::ERRNO_NOENT => NotFound,
74-
wasi::ERRNO_INTR => Interrupted,
75-
wasi::ERRNO_INVAL => InvalidInput,
76-
wasi::ERRNO_TIMEDOUT => TimedOut,
77-
wasi::ERRNO_EXIST => AlreadyExists,
78-
wasi::ERRNO_AGAIN => WouldBlock,
79-
wasi::ERRNO_NOSYS => Unsupported,
80-
wasi::ERRNO_NOMEM => OutOfMemory,
64+
65+
match errno {
66+
e if e == wasi::ERRNO_CONNREFUSED.raw().into() => ConnectionRefused,
67+
e if e == wasi::ERRNO_CONNRESET.raw().into() => ConnectionReset,
68+
e if e == wasi::ERRNO_PERM.raw().into() || e == wasi::ERRNO_ACCES.raw().into() => {
69+
PermissionDenied
70+
}
71+
e if e == wasi::ERRNO_PIPE.raw().into() => BrokenPipe,
72+
e if e == wasi::ERRNO_NOTCONN.raw().into() => NotConnected,
73+
e if e == wasi::ERRNO_CONNABORTED.raw().into() => ConnectionAborted,
74+
e if e == wasi::ERRNO_ADDRNOTAVAIL.raw().into() => AddrNotAvailable,
75+
e if e == wasi::ERRNO_ADDRINUSE.raw().into() => AddrInUse,
76+
e if e == wasi::ERRNO_NOENT.raw().into() => NotFound,
77+
e if e == wasi::ERRNO_INTR.raw().into() => Interrupted,
78+
e if e == wasi::ERRNO_INVAL.raw().into() => InvalidInput,
79+
e if e == wasi::ERRNO_TIMEDOUT.raw().into() => TimedOut,
80+
e if e == wasi::ERRNO_EXIST.raw().into() => AlreadyExists,
81+
e if e == wasi::ERRNO_AGAIN.raw().into() => WouldBlock,
82+
e if e == wasi::ERRNO_NOSYS.raw().into() => Unsupported,
83+
e if e == wasi::ERRNO_NOMEM.raw().into() => OutOfMemory,
8184
_ => Uncategorized,
8285
}
8386
}
@@ -96,6 +99,6 @@ pub fn hashmap_random_keys() -> (u64, u64) {
9699
return ret;
97100
}
98101

99-
fn err2io(err: wasi::Error) -> std_io::Error {
100-
std_io::Error::from_raw_os_error(err.raw_error().into())
102+
fn err2io(err: wasi::Errno) -> std_io::Error {
103+
std_io::Error::from_raw_os_error(err.raw().into())
101104
}

library/std/src/sys/wasi/stdio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl io::Write for Stderr {
104104
pub const STDIN_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
105105

106106
pub fn is_ebadf(err: &io::Error) -> bool {
107-
err.raw_os_error() == Some(wasi::ERRNO_BADF.into())
107+
err.raw_os_error() == Some(wasi::ERRNO_BADF.raw().into())
108108
}
109109

110110
pub fn panic_output() -> Option<impl io::Write> {

library/std/src/sys/wasi/thread.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ impl Thread {
4141

4242
let in_ = wasi::Subscription {
4343
userdata: USERDATA,
44-
r#type: wasi::EVENTTYPE_CLOCK,
45-
u: wasi::SubscriptionU { clock },
44+
u: wasi::SubscriptionU { tag: 0, u: wasi::SubscriptionUU { clock } },
4645
};
4746
unsafe {
4847
let mut event: wasi::Event = mem::zeroed();
@@ -51,7 +50,10 @@ impl Thread {
5150
(
5251
Ok(1),
5352
wasi::Event {
54-
userdata: USERDATA, error: 0, r#type: wasi::EVENTTYPE_CLOCK, ..
53+
userdata: USERDATA,
54+
error: wasi::ERRNO_SUCCESS,
55+
type_: wasi::EVENTTYPE_CLOCK,
56+
..
5557
},
5658
) => {}
5759
_ => panic!("thread::sleep(): unexpected result of poll_oneoff"),

library/std/src/sys/wasi/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct SystemTime(Duration);
1010

1111
pub const UNIX_EPOCH: SystemTime = SystemTime(Duration::from_secs(0));
1212

13-
fn current_time(clock: u32) -> Duration {
13+
fn current_time(clock: wasi::Clockid) -> Duration {
1414
let ts = unsafe {
1515
wasi::clock_time_get(
1616
clock, 1, // precision... seems ignored though?

0 commit comments

Comments
 (0)