Skip to content

Commit 6374b84

Browse files
committed
update to wasi v0.7
1 parent 3772146 commit 6374b84

File tree

5 files changed

+80
-53
lines changed

5 files changed

+80
-53
lines changed

Cargo.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3866,6 +3866,7 @@ dependencies = [
38663866
"rustc_msan",
38673867
"rustc_tsan",
38683868
"unwind",
3869+
"wasi",
38693870
]
38703871

38713872
[[package]]
@@ -4664,6 +4665,17 @@ dependencies = [
46644665
"try-lock",
46654666
]
46664667

4668+
[[package]]
4669+
name = "wasi"
4670+
version = "0.7.0"
4671+
source = "registry+https://github.com/rust-lang/crates.io-index"
4672+
checksum = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d"
4673+
dependencies = [
4674+
"compiler_builtins",
4675+
"rustc-std-workspace-alloc",
4676+
"rustc-std-workspace-core",
4677+
]
4678+
46674679
[[package]]
46684680
name = "winapi"
46694681
version = "0.2.8"

src/libstd/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ compiler_builtins = { version = "0.1.16" }
2424
profiler_builtins = { path = "../libprofiler_builtins", optional = true }
2525
unwind = { path = "../libunwind" }
2626
hashbrown = { version = "0.5.0", features = ['rustc-dep-of-std'] }
27-
wasi = { git = "https://github.com/newpavlov/rust-wasi", branch = "safe_rework", features = ['rustc-dep-of-std', 'alloc'] }
27+
wasi = { version = "0.7.0", features = ['rustc-dep-of-std', 'alloc'] }
2828

2929
[dependencies.backtrace]
3030
version = "0.3.35"

src/libstd/sys/wasi/fd.rs

Lines changed: 56 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,23 @@ impl WasiFd {
5353
}
5454

5555
pub fn datasync(&self) -> io::Result<()> {
56-
wasi::fd_datasync(self.fd).map_err(err2io)
56+
unsafe { wasi::fd_datasync(self.fd).map_err(err2io) }
5757
}
5858

5959
pub fn pread(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> {
60-
wasi::fd_pread(self.fd, iovec(bufs), offset).map_err(err2io)
60+
unsafe { wasi::fd_pread(self.fd, iovec(bufs), offset).map_err(err2io) }
6161
}
6262

6363
pub fn pwrite(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> {
64-
wasi::fd_pwrite(self.fd, ciovec(bufs), offset).map_err(err2io)
64+
unsafe { wasi::fd_pwrite(self.fd, ciovec(bufs), offset).map_err(err2io) }
6565
}
6666

6767
pub fn read(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
68-
wasi::fd_read(self.fd, iovec(bufs)).map_err(err2io)
68+
unsafe { wasi::fd_read(self.fd, iovec(bufs)).map_err(err2io) }
6969
}
7070

7171
pub fn write(&self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
72-
wasi::fd_write(self.fd, ciovec(bufs)).map_err(err2io)
72+
unsafe { wasi::fd_write(self.fd, ciovec(bufs)).map_err(err2io) }
7373
}
7474

7575
pub fn seek(&self, pos: SeekFrom) -> io::Result<u64> {
@@ -78,37 +78,37 @@ impl WasiFd {
7878
SeekFrom::End(pos) => (wasi::WHENCE_END, pos),
7979
SeekFrom::Current(pos) => (wasi::WHENCE_CUR, pos),
8080
};
81-
wasi::fd_seek(self.fd, offset, whence).map_err(err2io)
81+
unsafe { wasi::fd_seek(self.fd, offset, whence).map_err(err2io) }
8282
}
8383

8484
pub fn tell(&self) -> io::Result<u64> {
85-
wasi::fd_tell(self.fd).map_err(err2io)
85+
unsafe { wasi::fd_tell(self.fd).map_err(err2io) }
8686
}
8787

8888
// FIXME: __wasi_fd_fdstat_get
8989

9090
pub fn set_flags(&self, flags: wasi::FdFlags) -> io::Result<()> {
91-
wasi::fd_fdstat_set_flags(self.fd, flags).map_err(err2io)
91+
unsafe { wasi::fd_fdstat_set_flags(self.fd, flags).map_err(err2io) }
9292
}
9393

9494
pub fn set_rights(&self, base: wasi::Rights, inheriting: wasi::Rights) -> io::Result<()> {
95-
wasi::fd_fdstat_set_rights(self.fd, base, inheriting).map_err(err2io)
95+
unsafe { wasi::fd_fdstat_set_rights(self.fd, base, inheriting).map_err(err2io) }
9696
}
9797

9898
pub fn sync(&self) -> io::Result<()> {
99-
wasi::fd_sync(self.fd).map_err(err2io)
99+
unsafe { wasi::fd_sync(self.fd).map_err(err2io) }
100100
}
101101

102102
pub fn advise(&self, offset: u64, len: u64, advice: wasi::Advice) -> io::Result<()> {
103-
wasi::fd_advise(self.fd, offset, len, advice).map_err(err2io)
103+
unsafe { wasi::fd_advise(self.fd, offset, len, advice).map_err(err2io) }
104104
}
105105

106106
pub fn allocate(&self, offset: u64, len: u64) -> io::Result<()> {
107-
wasi::fd_allocate(self.fd, offset, len).map_err(err2io)
107+
unsafe { wasi::fd_allocate(self.fd, offset, len).map_err(err2io) }
108108
}
109109

110110
pub fn create_directory(&self, path: &[u8]) -> io::Result<()> {
111-
wasi::path_create_directory(self.fd, path).map_err(err2io)
111+
unsafe { wasi::path_create_directory(self.fd, path).map_err(err2io) }
112112
}
113113

114114
pub fn link(
@@ -118,8 +118,10 @@ impl WasiFd {
118118
new_fd: &WasiFd,
119119
new_path: &[u8],
120120
) -> io::Result<()> {
121-
wasi::path_link(self.fd, old_flags, old_path, new_fd.fd, new_path)
122-
.map_err(err2io)
121+
unsafe {
122+
wasi::path_link(self.fd, old_flags, old_path, new_fd.fd, new_path)
123+
.map_err(err2io)
124+
}
123125
}
124126

125127
pub fn open(
@@ -131,32 +133,35 @@ impl WasiFd {
131133
fs_rights_inheriting: wasi::Rights,
132134
fs_flags: wasi::FdFlags,
133135
) -> io::Result<WasiFd> {
134-
wasi::path_open(
135-
self.fd,
136-
dirflags,
137-
path,
138-
oflags,
139-
fs_rights_base,
140-
fs_rights_inheriting,
141-
fs_flags,
142-
).map(|fd| unsafe { WasiFd::from_raw(fd) }).map_err(err2io)
136+
unsafe {
137+
wasi::path_open(
138+
self.fd,
139+
dirflags,
140+
path,
141+
oflags,
142+
fs_rights_base,
143+
fs_rights_inheriting,
144+
fs_flags,
145+
).map(|fd| WasiFd::from_raw(fd)).map_err(err2io)
146+
}
143147
}
144148

145149
pub fn readdir(&self, buf: &mut [u8], cookie: wasi::DirCookie) -> io::Result<usize> {
146-
wasi::fd_readdir(self.fd, buf, cookie).map_err(err2io)
150+
unsafe { wasi::fd_readdir(self.fd, buf, cookie).map_err(err2io) }
147151
}
148152

149153
pub fn readlink(&self, path: &[u8], buf: &mut [u8]) -> io::Result<usize> {
150-
wasi::path_readlink(self.fd, path, buf).map_err(err2io)
154+
unsafe { wasi::path_readlink(self.fd, path, buf).map_err(err2io) }
151155
}
152156

153157
pub fn rename(&self, old_path: &[u8], new_fd: &WasiFd, new_path: &[u8]) -> io::Result<()> {
154-
wasi::path_rename(self.fd, old_path, new_fd.fd, new_path)
155-
.map_err(err2io)
158+
unsafe {
159+
wasi::path_rename(self.fd, old_path, new_fd.fd, new_path).map_err(err2io)
160+
}
156161
}
157162

158163
pub fn filestat_get(&self) -> io::Result<wasi::FileStat> {
159-
wasi::fd_filestat_get(self.fd).map_err(err2io)
164+
unsafe { wasi::fd_filestat_get(self.fd).map_err(err2io) }
160165
}
161166

162167
pub fn filestat_set_times(
@@ -165,20 +170,21 @@ impl WasiFd {
165170
mtim: wasi::Timestamp,
166171
fstflags: wasi::FstFlags,
167172
) -> io::Result<()> {
168-
wasi::fd_filestat_set_times(self.fd, atim, mtim, fstflags)
169-
.map_err(err2io)
173+
unsafe {
174+
wasi::fd_filestat_set_times(self.fd, atim, mtim, fstflags).map_err(err2io)
175+
}
170176
}
171177

172178
pub fn filestat_set_size(&self, size: u64) -> io::Result<()> {
173-
wasi::fd_filestat_set_size(self.fd, size).map_err(err2io)
179+
unsafe { wasi::fd_filestat_set_size(self.fd, size).map_err(err2io) }
174180
}
175181

176182
pub fn path_filestat_get(
177183
&self,
178184
flags: wasi::LookupFlags,
179185
path: &[u8],
180186
) -> io::Result<wasi::FileStat> {
181-
wasi::path_filestat_get(self.fd, flags, path).map_err(err2io)
187+
unsafe { wasi::path_filestat_get(self.fd, flags, path).map_err(err2io) }
182188
}
183189

184190
pub fn path_filestat_set_times(
@@ -189,38 +195,40 @@ impl WasiFd {
189195
mtim: wasi::Timestamp,
190196
fstflags: wasi::FstFlags,
191197
) -> io::Result<()> {
192-
wasi::path_filestat_set_times(
193-
self.fd,
194-
flags,
195-
path,
196-
atim,
197-
mtim,
198-
fstflags,
199-
).map_err(err2io)
198+
unsafe {
199+
wasi::path_filestat_set_times(
200+
self.fd,
201+
flags,
202+
path,
203+
atim,
204+
mtim,
205+
fstflags,
206+
).map_err(err2io)
207+
}
200208
}
201209

202210
pub fn symlink(&self, old_path: &[u8], new_path: &[u8]) -> io::Result<()> {
203-
wasi::path_symlink(old_path, self.fd, new_path).map_err(err2io)
211+
unsafe { wasi::path_symlink(old_path, self.fd, new_path).map_err(err2io) }
204212
}
205213

206214
pub fn unlink_file(&self, path: &[u8]) -> io::Result<()> {
207-
wasi::path_unlink_file(self.fd, path).map_err(err2io)
215+
unsafe { wasi::path_unlink_file(self.fd, path).map_err(err2io) }
208216
}
209217

210218
pub fn remove_directory(&self, path: &[u8]) -> io::Result<()> {
211-
wasi::path_remove_directory(self.fd, path).map_err(err2io)
219+
unsafe { wasi::path_remove_directory(self.fd, path).map_err(err2io) }
212220
}
213221

214222
pub fn sock_recv(
215223
&self,
216224
ri_data: &mut [IoSliceMut<'_>],
217225
ri_flags: wasi::RiFlags,
218226
) -> io::Result<(usize, wasi::RoFlags)> {
219-
wasi::sock_recv(self.fd, iovec(ri_data), ri_flags).map_err(err2io)
227+
unsafe { wasi::sock_recv(self.fd, iovec(ri_data), ri_flags).map_err(err2io) }
220228
}
221229

222230
pub fn sock_send(&self, si_data: &[IoSlice<'_>], si_flags: wasi::SiFlags) -> io::Result<usize> {
223-
wasi::sock_send(self.fd, ciovec(si_data), si_flags).map_err(err2io)
231+
unsafe { wasi::sock_send(self.fd, ciovec(si_data), si_flags).map_err(err2io) }
224232
}
225233

226234
pub fn sock_shutdown(&self, how: Shutdown) -> io::Result<()> {
@@ -229,14 +237,14 @@ impl WasiFd {
229237
Shutdown::Write => wasi::SHUT_WR,
230238
Shutdown::Both => wasi::SHUT_WR | wasi::SHUT_RD,
231239
};
232-
wasi::sock_shutdown(self.fd, how).map_err(err2io)
240+
unsafe { wasi::sock_shutdown(self.fd, how).map_err(err2io) }
233241
}
234242
}
235243

236244
impl Drop for WasiFd {
237245
fn drop(&mut self) {
238246
// FIXME: can we handle the return code here even though we can't on
239247
// unix?
240-
let _ = wasi::fd_close(self.fd);
248+
let _ = unsafe { wasi::fd_close(self.fd) };
241249
}
242250
}

src/libstd/sys/wasi/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,17 @@ pub fn unsupported_err() -> std_io::Error {
6969

7070
pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind {
7171
use std_io::ErrorKind::*;
72-
match errno as libc::c_int {
72+
if errno > u16::max_value() as i32 || errno < 0 {
73+
return Other;
74+
}
75+
let code = match wasi::Error::new(errno as u16) {
76+
Some(code) => code,
77+
None => return Other,
78+
};
79+
match code {
7380
wasi::ECONNREFUSED => ConnectionRefused,
7481
wasi::ECONNRESET => ConnectionReset,
75-
wasi::EPERM | libc::EACCES => PermissionDenied,
82+
wasi::EPERM | wasi::EACCES => PermissionDenied,
7683
wasi::EPIPE => BrokenPipe,
7784
wasi::ENOTCONN => NotConnected,
7885
wasi::ECONNABORTED => ConnectionAborted,
@@ -84,7 +91,7 @@ pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind {
8491
wasi::ETIMEDOUT => TimedOut,
8592
wasi::EEXIST => AlreadyExists,
8693
wasi::EAGAIN => WouldBlock,
87-
_ => ErrorKind::Other,
94+
_ => Other,
8895
}
8996
}
9097

src/libstd/sys/wasi/thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Thread {
4747
u: wasi::raw::__wasi_subscription_u { clock: clock },
4848
}];
4949
let mut out: [wasi::Event; 1] = [unsafe { mem::zeroed() }];
50-
let n = wasi::poll_oneoff(&in_, &mut out).unwrap();
50+
let n = unsafe { wasi::poll_oneoff(&in_, &mut out).unwrap() };
5151
let wasi::Event { userdata, error, type_, .. } = out[0];
5252
match (n, userdata, error) {
5353
(1, CLOCK_ID, 0) if type_ == wasi::EVENTTYPE_CLOCK => {}

0 commit comments

Comments
 (0)