ueno opened PR #1855 from wip/dueno/null
to master
:
If stdio is not inherited nor associated with a file,
WasiCtxBuilder
tries to open "/dev/null" ("NUL" on Windows) and attach stdio to it. While most platforms today support those device files, it would be
good to avoid unnecessary access to the host device if possible. This patch instead uses a virtual Handle that emulates the "NUL" device.This is particularly needed when using wasmtime in a restricted environment, such as inside TEE (see https://github.com/enarx/enarx/issues/559 for the context).
<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
ueno updated PR #1855 from wip/dueno/null
to master
:
If stdio is not inherited nor associated with a file,
WasiCtxBuilder
tries to open "/dev/null" ("NUL" on Windows) and attach stdio to it. While most platforms today support those device files, it would be
good to avoid unnecessary access to the host device if possible. This patch instead uses a virtual Handle that emulates the "NUL" device.This is particularly needed when using wasmtime in a restricted environment, such as inside TEE (see https://github.com/enarx/enarx/issues/559 for the context).
<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
kubkon submitted PR Review.
kubkon submitted PR Review.
kubkon created PR Review Comment:
let cast_iovlen: types::Size = iov.len().try_into()?;
I think this should bubble up with an error rather than panic, and same below. Oh, and FWIW this should be convertible to
crate::wasi::Error
without remapping the error types, etc.
kubkon created PR Review Comment:
So the reason we've had a
PendingEntry::Thunk
here was because (if my memory serves me well)OsOther::from_null
was fallible and hence it was convenient to save a function returningResult
rather than dealing with unwraps, etc., inWasiCtxBuilder::new
which is non-fallible. Since I don't see any reason forNullDevice::null_device
to be fallible (it always succeeds since it's a virtual device, am I right?), perhaps we could make the fnnull_device
non-fallible, or better yet, have a more meaningful method such asNullDevice::new
as it's constructor, and here, usePendingEntry::Handle
instead ofPendingEntry::Thunk
?
kubkon created PR Review Comment:
.fold(Some(0u32), |len, iov| len.and_then(|x| x.checked_add(iov)))?;
ueno updated PR #1855 from wip/dueno/null
to master
:
If stdio is not inherited nor associated with a file,
WasiCtxBuilder
tries to open "/dev/null" ("NUL" on Windows) and attach stdio to it. While most platforms today support those device files, it would be
good to avoid unnecessary access to the host device if possible. This patch instead uses a virtual Handle that emulates the "NUL" device.This is particularly needed when using wasmtime in a restricted environment, such as inside TEE (see https://github.com/enarx/enarx/issues/559 for the context).
<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
ueno submitted PR Review.
ueno created PR Review Comment:
Thank you for the suggestion! I've rewritten that part along these lines.
ueno submitted PR Review.
ueno created PR Review Comment:
This and the below seem to be a bit tricky (to a Rust newbie :-), as the error is inside closure. I tried to rewrite this part with
try_fold
, though it required some manual remapping.
kubkon submitted PR Review.
kubkon created PR Review Comment:
Ahh, I missed the fact this was within a
map
closure. FWIW, in situations like this one, I prefer to use a standardfor
loop and use?
without the need to remap or carry over the result until the collect/fold step:let mut total_len = 0; for iov in iovs { let len: types::Size = iov.len().try_into()?; total_len = total_len.checked_add(len).ok_or(Errno::Overflow)?; } Ok(total_len)
kubkon edited PR Review Comment.
kubkon submitted PR Review.
ueno updated PR #1855 from wip/dueno/null
to master
:
If stdio is not inherited nor associated with a file,
WasiCtxBuilder
tries to open "/dev/null" ("NUL" on Windows) and attach stdio to it. While most platforms today support those device files, it would be
good to avoid unnecessary access to the host device if possible. This patch instead uses a virtual Handle that emulates the "NUL" device.This is particularly needed when using wasmtime in a restricted environment, such as inside TEE (see https://github.com/enarx/enarx/issues/559 for the context).
<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
ueno submitted PR Review.
ueno created PR Review Comment:
Indeed, that is much cleaner, thanks!
pchickey merged PR #1855.
Last updated: Nov 22 2024 at 16:03 UTC