kubkon opened PR #1412 from rc-entry to master:
This commit refactors the use of
Refs andRefMuts inwasi-common.
Now,Entryis stored behind anRcinside theEntryTable. TheEntry
itself on the other hand now stores rights behind aRefCelland the
descriptor asRc<RefCell<..>>combo to enable easy reference tracking
and interior mutability which is required down the line in a couple of
syscalls. In essence, this implies that we no longer have need for
mutable accessor toEntryfromWasiCtx, and so all related methods
go away (get_entry_mut, etc.).While here, I've also simplified handling and aggregating of rights on
theEntryobject. Instead of storing base and inheriting rights as
separate fields, they are now aggregated into one structEntryRights
which features convenient constructors for each possible combination; i.e.,
when only base rights are set, or both base and inheriting are set, or
both are left as empty. Since we do need to be able to mutate those
rights down the line infdstat_set_rightssyscall, this object
is kept behind aRefCell(note noRcsince we don't need to pass it
around anywhere).The descriptor field in
Entryis now kept behindRc<RefCell<..>>combo
since we not only need to mutate it down the line, but we also need to
be able to pass it around (as part of the machinery makingpoll_oneoff
work).I've also removed
as_fileandtry_clonemethods onDescriptorstruct
since they were adding more noise than necessary, and making them work
withRcwas unnecessarily complicated.Finally, I've converted the
get_dir_from_os_handlefunction into a
method attached to theOsHandleitself, calleddir_stream. IMHO,
it makes more sense to have it there directly as a method than as a separate
function.
kubkon requested alexcrichton and sunfishcode for a review on PR #1412.
kubkon requested alexcrichton and sunfishcode for a review on PR #1412.
kubkon updated PR #1412 from rc-entry to master:
This commit refactors the use of
Refs andRefMuts inwasi-common.
Now,Entryis stored behind anRcinside theEntryTable. TheEntry
itself on the other hand now stores rights behind aRefCelland the
descriptor asRc<RefCell<..>>combo to enable easy reference tracking
and interior mutability which is required down the line in a couple of
syscalls. In essence, this implies that we no longer have need for
mutable accessor toEntryfromWasiCtx, and so all related methods
go away (get_entry_mut, etc.).While here, I've also simplified handling and aggregating of rights on
theEntryobject. Instead of storing base and inheriting rights as
separate fields, they are now aggregated into one structEntryRights
which features convenient constructors for each possible combination; i.e.,
when only base rights are set, or both base and inheriting are set, or
both are left as empty. Since we do need to be able to mutate those
rights down the line infdstat_set_rightssyscall, this object
is kept behind aRefCell(note noRcsince we don't need to pass it
around anywhere).The descriptor field in
Entryis now kept behindRc<RefCell<..>>combo
since we not only need to mutate it down the line, but we also need to
be able to pass it around (as part of the machinery makingpoll_oneoff
work).I've also removed
as_fileandtry_clonemethods onDescriptorstruct
since they were adding more noise than necessary, and making them work
withRcwas unnecessarily complicated.Finally, I've converted the
get_dir_from_os_handlefunction into a
method attached to theOsHandleitself, calleddir_stream. IMHO,
it makes more sense to have it there directly as a method than as a separate
function.
alexcrichton submitted PR Review.
alexcrichton submitted PR Review.
alexcrichton created PR Review Comment:
This is a
Copytype I think, so could this perhaps be aCell<types::Fdflags>to entirely elimitate the possibility of panics?
alexcrichton created PR Review Comment:
So to prefix this, I'm not very familiar with what this
Descriptoris and what it's used for. That being said I think it'd be great, if possible, to continue to push theRefCelldeeper here. The purpose of removing the ability to get&mut Entrywas all about making mutable borrows as small as possible to eliminate possibilities of panics, and I think the same might apply here as well. It may even be possible to haveDescriptoronly haveCellfields, but ideally anyRefCellfields would have very small borrows and no methods would have to return aReforRefMut
kubkon updated PR #1412 from rc-entry to master:
This commit refactors the use of
Refs andRefMuts inwasi-common.
Now,Entryis stored behind anRcinside theEntryTable. TheEntry
itself on the other hand now stores rights behind aRefCelland the
descriptor asRc<RefCell<..>>combo to enable easy reference tracking
and interior mutability which is required down the line in a couple of
syscalls. In essence, this implies that we no longer have need for
mutable accessor toEntryfromWasiCtx, and so all related methods
go away (get_entry_mut, etc.).While here, I've also simplified handling and aggregating of rights on
theEntryobject. Instead of storing base and inheriting rights as
separate fields, they are now aggregated into one structEntryRights
which features convenient constructors for each possible combination; i.e.,
when only base rights are set, or both base and inheriting are set, or
both are left as empty. Since we do need to be able to mutate those
rights down the line infdstat_set_rightssyscall, this object
is kept behind aRefCell(note noRcsince we don't need to pass it
around anywhere).The descriptor field in
Entryis now kept behindRc<RefCell<..>>combo
since we not only need to mutate it down the line, but we also need to
be able to pass it around (as part of the machinery makingpoll_oneoff
work).I've also removed
as_fileandtry_clonemethods onDescriptorstruct
since they were adding more noise than necessary, and making them work
withRcwas unnecessarily complicated.Finally, I've converted the
get_dir_from_os_handlefunction into a
method attached to theOsHandleitself, calleddir_stream. IMHO,
it makes more sense to have it there directly as a method than as a separate
function.
kubkon created PR Review Comment:
Yep, thanks!
kubkon submitted PR Review.
kubkon submitted PR Review.
kubkon created PR Review Comment:
I think you're right. Although making it work will require some bigger reorg to
OsHandleespecially on BSD platform. I have an idea for this and will investigate but given that this probably will be a bigger change, I'd prefer to have it as a subsequent PR. In short, if we makeOsHandlea bit closer to the metal by replacingFilewithRawFd, we can makeOsHandleCopywhich would then make it possible to haveDescriptorinside aCell. There's a little bit more work involved with BSD since currentlyOsHandle, in addition toFile, also stores an optionalyanix::Dir(which is non-Copysince it's got a customDropimpl) and it would probably make sense to split the handle into either representing an actual file, or a directory. Then, we wouldn't needOptionnor interior mutability, since we could easily makeyanix::DirCopycalling it something likeyanix::UnsafeDirand specifically mentioning that it is the user's responsibility to close the underlying dir stream withlibc::closedirfn. Does that make sense?
kubkon submitted PR Review.
kubkon created PR Review Comment:
Oh, and the only reason we ever need to mutate the actual
DescriptorinEntryis because on Windows, setting fdstat flags requires reopening the file.
alexcrichton submitted PR Review.
alexcrichton created PR Review Comment:
Ah ok punting this to later seems fine, in any case looks like a great refactoring!
alexcrichton submitted PR Review.
kubkon updated PR #1412 from rc-entry to master:
This commit refactors the use of
Refs andRefMuts inwasi-common.
Now,Entryis stored behind anRcinside theEntryTable. TheEntry
itself on the other hand now stores rights behind aRefCelland the
descriptor asRc<RefCell<..>>combo to enable easy reference tracking
and interior mutability which is required down the line in a couple of
syscalls. In essence, this implies that we no longer have need for
mutable accessor toEntryfromWasiCtx, and so all related methods
go away (get_entry_mut, etc.).While here, I've also simplified handling and aggregating of rights on
theEntryobject. Instead of storing base and inheriting rights as
separate fields, they are now aggregated into one structEntryRights
which features convenient constructors for each possible combination; i.e.,
when only base rights are set, or both base and inheriting are set, or
both are left as empty. Since we do need to be able to mutate those
rights down the line infdstat_set_rightssyscall, this object
is kept behind aRefCell(note noRcsince we don't need to pass it
around anywhere).The descriptor field in
Entryis now kept behindRc<RefCell<..>>combo
since we not only need to mutate it down the line, but we also need to
be able to pass it around (as part of the machinery makingpoll_oneoff
work).I've also removed
as_fileandtry_clonemethods onDescriptorstruct
since they were adding more noise than necessary, and making them work
withRcwas unnecessarily complicated.Finally, I've converted the
get_dir_from_os_handlefunction into a
method attached to theOsHandleitself, calleddir_stream. IMHO,
it makes more sense to have it there directly as a method than as a separate
function.
kubkon merged PR #1412.
Last updated: Dec 06 2025 at 06:05 UTC