Skip to content

Commit 8c17455

Browse files
bors[bot]Mark McCaskey
and
Mark McCaskey
authored
Merge #1229
1229: Add clippy::missing_safety_doc lint to wasi, misc clean up r=MarkMcCaskey a=MarkMcCaskey Part of #1219 # Review - [ ] Add a short description of the the change to the CHANGELOG.md file Co-authored-by: Mark McCaskey <[email protected]>
2 parents 5bf6be4 + c005f94 commit 8c17455

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

lib/wasi/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
unused_mut,
66
unused_variables,
77
unused_unsafe,
8-
unreachable_patterns
8+
unreachable_patterns,
9+
clippy::missing_safety_doc
910
)]
1011
#![doc(html_favicon_url = "https://wasmer.io/static/icons/favicon.ico")]
1112
#![doc(html_logo_url = "https://avatars3.githubusercontent.com/u/44205449?s=200&v=4")]

lib/wasi/src/state/mod.rs

+23-11
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use wasmer_runtime_core::vm::Ctx;
3636
/// the fd value of the virtual root
3737
pub const VIRTUAL_ROOT_FD: __wasi_fd_t = 3;
3838
/// all the rights enabled
39-
pub const ALL_RIGHTS: __wasi_rights_t = 0x1FFFFFFF;
39+
pub const ALL_RIGHTS: __wasi_rights_t = 0x1FFF_FFFF;
4040
const STDIN_DEFAULT_RIGHTS: __wasi_rights_t = __WASI_RIGHT_FD_DATASYNC
4141
| __WASI_RIGHT_FD_READ
4242
| __WASI_RIGHT_FD_SYNC
@@ -52,7 +52,10 @@ const STDOUT_DEFAULT_RIGHTS: __wasi_rights_t = __WASI_RIGHT_FD_DATASYNC
5252
const STDERR_DEFAULT_RIGHTS: __wasi_rights_t = STDOUT_DEFAULT_RIGHTS;
5353

5454
/// Get WasiState from a Ctx
55-
/// This function is unsafe because it must be called on a WASI Ctx
55+
///
56+
/// # Safety
57+
/// - This function must be called on a `Ctx` that was created with `WasiState`
58+
/// in the data field
5659
pub unsafe fn get_wasi_state(ctx: &mut Ctx) -> &mut WasiState {
5760
&mut *(ctx.data as *mut WasiState)
5861
}
@@ -186,7 +189,7 @@ impl WasiFs {
186189
for dir in preopened_dirs {
187190
debug!("Attempting to preopen {}", &dir.to_string_lossy());
188191
// TODO: think about this
189-
let default_rights = 0x1FFFFFFF; // all rights
192+
let default_rights = ALL_RIGHTS;
190193
let cur_dir_metadata = dir.metadata().map_err(|e| {
191194
format!(
192195
"Could not get metadata for file {:?}: {}",
@@ -236,7 +239,7 @@ impl WasiFs {
236239
for (alias, real_dir) in mapped_dirs {
237240
debug!("Attempting to open {:?} at {}", real_dir, alias);
238241
// TODO: think about this
239-
let default_rights = 0x1FFFFFFF; // all rights
242+
let default_rights = ALL_RIGHTS;
240243
let cur_dir_metadata = real_dir.metadata().map_err(|e| {
241244
format!(
242245
"Could not get metadata for file {:?}: {}",
@@ -428,7 +431,7 @@ impl WasiFs {
428431

429432
// create virtual root
430433
let root_inode = {
431-
let all_rights = 0x1FFFFFFF;
434+
let all_rights = ALL_RIGHTS;
432435
// TODO: make this a list of positive rigths instead of negative ones
433436
// root gets all right for now
434437
let root_rights = all_rights
@@ -525,10 +528,15 @@ impl WasiFs {
525528
next
526529
}
527530

528-
/// like create dir all, but it also opens it
531+
/// This function is like create dir all, but it also opens it.
529532
/// Function is unsafe because it may break invariants and hasn't been tested.
530533
/// This is an experimental function and may be removed
531-
// dead code because this is an API for external use
534+
///
535+
/// # Safety
536+
/// - Virtual directories created with this function must not conflict with
537+
/// the standard operation of the WASI filesystem. This is vague and
538+
/// unlikely in pratice. Join the discussion at https://github.com/wasmerio/wasmer/issues/1219
539+
/// for what the newer, safer WASI FS APIs should look like.
532540
#[allow(dead_code)]
533541
pub unsafe fn open_dir_all(
534542
&mut self,
@@ -1161,7 +1169,7 @@ impl WasiFs {
11611169
stat.st_ino = self.get_next_inode_index();
11621170

11631171
Ok(self.inodes.insert(InodeVal {
1164-
stat: stat,
1172+
stat,
11651173
is_preopened,
11661174
name,
11671175
kind,
@@ -1210,10 +1218,14 @@ impl WasiFs {
12101218
Ok(idx)
12111219
}
12121220

1213-
/// This function is unsafe because it's the caller's responsibility to ensure that
1214-
/// all refences to the given inode have been removed from the filesystem
1221+
/// Low level function to remove an inode, that is it deletes the WASI FS's
1222+
/// knowledge of a file.
1223+
///
1224+
/// This function returns the inode if it existed and was removed.
12151225
///
1216-
/// returns the inode if it existed and was removed
1226+
/// # Safety
1227+
/// - The caller must ensure that all references to the specified inode have
1228+
/// been removed from the filesystem.
12171229
pub unsafe fn remove_inode(&mut self, inode: Inode) -> Option<InodeVal> {
12181230
self.inodes.remove(inode)
12191231
}

lib/wasi/src/state/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ impl<'de> Deserialize<'de> for HostFile {
434434
}
435435
}
436436

437-
const FIELDS: &'static [&'static str] = &["host_path", "flags"];
437+
const FIELDS: &[&str] = &["host_path", "flags"];
438438
deserializer.deserialize_struct("HostFile", FIELDS, HostFileVisitor)
439439
}
440440
}

lib/wasi/src/syscalls/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(non_camel_case_types)]
1+
#![allow(non_camel_case_types, clippy::identity_op)]
22

33
use crate::ptr::{Array, WasmPtr};
44
use byteorder::{ReadBytesExt, WriteBytesExt, LE};

lib/wasi/src/utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ pub enum WasiVersion {
3030
}
3131

3232
/// Namespace for the `Snapshot0` version.
33-
const SNAPSHOT0_NAMESPACE: &'static str = "wasi_unstable";
33+
const SNAPSHOT0_NAMESPACE: &str = "wasi_unstable";
3434

3535
/// Namespace for the `Snapshot1` version.
36-
const SNAPSHOT1_NAMESPACE: &'static str = "wasi_snapshot_preview1";
36+
const SNAPSHOT1_NAMESPACE: &str = "wasi_snapshot_preview1";
3737

3838
/// Detect the version of WASI being used based on the import
3939
/// namespaces.

0 commit comments

Comments
 (0)