@@ -36,7 +36,7 @@ use wasmer_runtime_core::vm::Ctx;
36
36
/// the fd value of the virtual root
37
37
pub const VIRTUAL_ROOT_FD : __wasi_fd_t = 3 ;
38
38
/// all the rights enabled
39
- pub const ALL_RIGHTS : __wasi_rights_t = 0x1FFFFFFF ;
39
+ pub const ALL_RIGHTS : __wasi_rights_t = 0x1FFF_FFFF ;
40
40
const STDIN_DEFAULT_RIGHTS : __wasi_rights_t = __WASI_RIGHT_FD_DATASYNC
41
41
| __WASI_RIGHT_FD_READ
42
42
| __WASI_RIGHT_FD_SYNC
@@ -52,7 +52,10 @@ const STDOUT_DEFAULT_RIGHTS: __wasi_rights_t = __WASI_RIGHT_FD_DATASYNC
52
52
const STDERR_DEFAULT_RIGHTS : __wasi_rights_t = STDOUT_DEFAULT_RIGHTS ;
53
53
54
54
/// 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
56
59
pub unsafe fn get_wasi_state ( ctx : & mut Ctx ) -> & mut WasiState {
57
60
& mut * ( ctx. data as * mut WasiState )
58
61
}
@@ -186,7 +189,7 @@ impl WasiFs {
186
189
for dir in preopened_dirs {
187
190
debug ! ( "Attempting to preopen {}" , & dir. to_string_lossy( ) ) ;
188
191
// TODO: think about this
189
- let default_rights = 0x1FFFFFFF ; // all rights
192
+ let default_rights = ALL_RIGHTS ;
190
193
let cur_dir_metadata = dir. metadata ( ) . map_err ( |e| {
191
194
format ! (
192
195
"Could not get metadata for file {:?}: {}" ,
@@ -236,7 +239,7 @@ impl WasiFs {
236
239
for ( alias, real_dir) in mapped_dirs {
237
240
debug ! ( "Attempting to open {:?} at {}" , real_dir, alias) ;
238
241
// TODO: think about this
239
- let default_rights = 0x1FFFFFFF ; // all rights
242
+ let default_rights = ALL_RIGHTS ;
240
243
let cur_dir_metadata = real_dir. metadata ( ) . map_err ( |e| {
241
244
format ! (
242
245
"Could not get metadata for file {:?}: {}" ,
@@ -428,7 +431,7 @@ impl WasiFs {
428
431
429
432
// create virtual root
430
433
let root_inode = {
431
- let all_rights = 0x1FFFFFFF ;
434
+ let all_rights = ALL_RIGHTS ;
432
435
// TODO: make this a list of positive rigths instead of negative ones
433
436
// root gets all right for now
434
437
let root_rights = all_rights
@@ -525,10 +528,15 @@ impl WasiFs {
525
528
next
526
529
}
527
530
528
- /// like create dir all, but it also opens it
531
+ /// This function is like create dir all, but it also opens it.
529
532
/// Function is unsafe because it may break invariants and hasn't been tested.
530
533
/// 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.
532
540
#[ allow( dead_code) ]
533
541
pub unsafe fn open_dir_all (
534
542
& mut self ,
@@ -1161,7 +1169,7 @@ impl WasiFs {
1161
1169
stat. st_ino = self . get_next_inode_index ( ) ;
1162
1170
1163
1171
Ok ( self . inodes . insert ( InodeVal {
1164
- stat : stat ,
1172
+ stat,
1165
1173
is_preopened,
1166
1174
name,
1167
1175
kind,
@@ -1210,10 +1218,14 @@ impl WasiFs {
1210
1218
Ok ( idx)
1211
1219
}
1212
1220
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.
1215
1225
///
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.
1217
1229
pub unsafe fn remove_inode ( & mut self , inode : Inode ) -> Option < InodeVal > {
1218
1230
self . inodes . remove ( inode)
1219
1231
}
0 commit comments