Skip to content

Commit c78bf3c

Browse files
authored
Merge pull request #784 from marmistrz/path_open_doc
Document the behavior of some rights-related functions.
2 parents ef6e1ca + 919190e commit c78bf3c

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

crates/wasi-common/src/hostcalls_impl/fs.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,8 @@ pub(crate) unsafe fn path_open(
610610
let fd = hostcalls_impl::path_open(resolved, read, write, oflags, fs_flags)?;
611611

612612
let mut fe = FdEntry::from(fd)?;
613-
// We need to manually deny the rights which are not explicitly requested.
614-
// This should not be needed, but currently determine_type_and_access_rights,
615-
// which is used by FdEntry::from, may grant extra rights while inferring it
616-
// from the open mode.
613+
// We need to manually deny the rights which are not explicitly requested
614+
// because FdEntry::from will assign maximal consistent rights.
617615
fe.rights_base &= fs_rights_base;
618616
fe.rights_inheriting &= fs_rights_inheriting;
619617
let guest_fd = wasi_ctx.insert_fd_entry(fe)?;

crates/wasi-common/src/old/snapshot_0/fdentry.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ pub(crate) struct FdEntry {
6161
}
6262

6363
impl FdEntry {
64+
/// Create an FdEntry with *maximal* possible rights from a given `File`.
65+
/// If this is not desired, the rights of the resulting `FdEntry` should
66+
/// be manually restricted.
6467
pub(crate) fn from(file: fs::File) -> Result<Self> {
6568
unsafe { determine_type_and_access_rights(&file) }.map(
6669
|(file_type, rights_base, rights_inheriting)| Self {

crates/wasi-common/src/sys/unix/fdentry_impl.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ pub(crate) fn descriptor_as_oshandle<'lifetime>(
2626
})))
2727
}
2828

29+
/// Returns the set of all possible rights that are both relevant for the file
30+
/// type and consistent with the open mode.
31+
///
2932
/// This function is unsafe because it operates on a raw file descriptor.
3033
pub(crate) unsafe fn determine_type_and_access_rights<Fd: AsRawFd>(
3134
fd: &Fd,
@@ -48,6 +51,8 @@ pub(crate) unsafe fn determine_type_and_access_rights<Fd: AsRawFd>(
4851
Ok((file_type, rights_base, rights_inheriting))
4952
}
5053

54+
/// Returns the set of all possible rights that are relevant for file type.
55+
///
5156
/// This function is unsafe because it operates on a raw file descriptor.
5257
pub(crate) unsafe fn determine_type_rights<Fd: AsRawFd>(
5358
fd: &Fd,

crates/wasi-common/src/sys/windows/fdentry_impl.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ pub(crate) fn descriptor_as_oshandle<'lifetime>(
5454
})))
5555
}
5656

57-
/// This function is unsafe because it operates on a raw file handle.
57+
/// Returns the set of all possible rights that are both relevant for the file
58+
/// type and consistent with the open mode.
59+
///
60+
/// This function is unsafe because it operates on a raw file descriptor.
5861
pub(crate) unsafe fn determine_type_and_access_rights<Handle: AsRawHandle>(
5962
handle: &Handle,
6063
) -> Result<(
@@ -85,7 +88,9 @@ pub(crate) unsafe fn determine_type_and_access_rights<Handle: AsRawHandle>(
8588
Ok((file_type, rights_base, rights_inheriting))
8689
}
8790

88-
/// This function is unsafe because it operates on a raw file handle.
91+
/// Returns the set of all possible rights that are relevant for file type.
92+
///
93+
/// This function is unsafe because it operates on a raw file descriptor.
8994
pub(crate) unsafe fn determine_type_rights<Handle: AsRawHandle>(
9095
handle: &Handle,
9196
) -> Result<(

0 commit comments

Comments
 (0)