Previously, `first_non_empty_{c}io_vec` always returned `Ok(None)` for buffers
residing in shared memories since they cannot, in general, safely be represented
as slices. That caused e.g. `wasi-libc` to spin forever when trying to write to
stdout using `fd_write` since it always got `Ok(0)` and never made progress.
This commit changes the return type of both functions to use `GuestPtr` instead
of `GuestSlice{Mut}`, allowing safe access to shared guest memory.
Big thanks to Alex Crichton for narrowing this down and suggesting the fix.
Fixes#7745
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
The file copy added for shared libraries is not needed and unused, it's not done for static builds and everywhere refers to WASMTIME_BUILD_PRODUCT or the original file in cargo's output.
* winch: Add memory instructions
This commit adds support for the following memory instructions to winch:
* `data.drop`
* `memory.init`
* `memory.fill`
* `memory.copy`
* `memory.size`
* `memory.grow`
In general the implementation is similar to what other instructions via
builtins are hanlded (e.g. table instructions), which involve stack
manipulation prior to emitting a builtin function call, with the
exception of `memory.size`, which involves loading the current length
from the `VMContext`
* Emit right shift instead of division to obtain the memory size in pages
* Update several dependencies to windows-sys 0.52.
Update cap-std, rustix, io-extras, errno, fd-lock, fs-set-times, and
winx to versions which use windows-sys 0.52.
I started out hoping that everything could be updated to
windows-sys 0.52, however tokio and mio have not yet updated to
windows-sys 0.52 due to supporting an older MSRV.
* Link the C++ examples with CoreFoundation.
This is needed due to the iana-time-zone support.
prtest:full
* Fix compilation on non-Apple platfoms.
* Fix compilation on Apple platforms.
When the top 32 bits of the value are zero and the upper_halfword of the lower
32 bits is u16::MAX, load_constant64_full will emit a single `movn` instruction.
In that case, add_range_fact only adds lower_halfword as the fact range, which
misses the upper halfword value. We should add the hole 32-bit value as the
fact range.
Co-authored-by: Feilong Jiang <jiangfeilong@huawei>
* Cranelift: use more `iconst_[su]` in opts, notably re-enabling some i128 cases
`iconst_u` and `iconst_s` support `$I128`, so we can now enable these even though they had to be excluded before to avoid generating `iconst.i128` that doesn't exist.
* Update for PR feedback
* Restore SO_REUSEADDR.
This inadvertently removed in 8ca8056945 when switching from `bind_existing_tcp_listener` to `rustix::net::bind`
* Remove AddressInUse workarounds by generating a random port.
* fmt
* Ignore unused_variables warning
* Prevent spurious test failures by trying again a few times on EADDRINUSE
* Fix grammar in .wit documentation
* windows-sys 0.52
Not locally tested due to C dependencies which I don't have the tooling for.
The intent is to use GH's CI.
* MEMORYMAPPEDVIEW_HANDLE -> MEMORY_MAPPED_VIEW_ADDRESS
* .Value instead of cast
* fmt
* Remove cast to MEMORY_MAPPED_VIEW_ADDRESS with struct creation
* Cast ptr from *mut u8 from *mut void
* Remove CI changes which were supposed to be on a distinct branch
* Update binutils when the target is x86_64-pc-windows-gnu
* Escape paths in CI
* Update .github/workflows/main.yml
Co-authored-by: Chris Denton <christophersdenton@gmail.com>
* Correct type from p2sh to pwsh
* Use | to correct YAML parsing error
* Fix msys2's installation of MinGW
* Finally fix msys2 handling
---------
Co-authored-by: Chris Denton <christophersdenton@gmail.com>
* wasi-nn: add test programs
This change adds new test programs for wasi-nn in a way fits in with the
existing WASI test infrastructure. The code is not new, though: this
reuses the wasi-nn `examples`, which are currently used by the
`run-wasi-nn-example.sh` CI script. Eventually the examples will be
removed in favor of these tests.
Because wasi-nn's component model support is still in flight, this
change also skips the generation of components for `nn_`-prefixed tests.
* wasi-nn: add `testing` module
This testing-only module has code (i.e., `check_test!`) to check whether
OpenVINO and some test artifacts are available. The test artifacts are
downloaded and cached if not present, expecting `curl` to be present on
the command line (as discussed in the previous version of this, #6895).
* wasi-nn: run `nn_*` test programs as integration tests
Following the pattern of other WASI crates, this change adds the
necessary infrastructure to run the `nn_*` files in
`crates/test-programs` (built by `test-program-artifacts`). These tests
are only run when two sets of conditions are true:
- statically: we only run these tests where we expect OpenVINO to be
easy to install and run (e.g., the `cfg_attr` parts)
- dynamically: we also only run these tests when the OpenVINO libraries
can be located and the model artifacts can be downloaded
* ci: install OpenVINO for running wasi-nn tests
prtest:full
* vet: certify the `wasi-nn` crate
* ci: remove wasi-nn test script
* Add API to WasiCtx for adding dynamic SocketAddr checks
The user can now specify a closure which gets run any time a connection
to an external address is attempted. If the closure returns true, the
address is allowed, but if it returns false, the underlying pool is then
checked. In otherwords, false does not imply denied, but rather, check
the underlyin pool.
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
* Get rid of Pool in favor of just a closure
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
* Add a SocketAddrUse arg to the SocketAddrCheck
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
---------
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
* Use the compilation cache for components as well
Co-authored-by: Pat Hickey <pat@moreproductive.org>
* Wrap artifacts in `Some`
---------
Co-authored-by: Pat Hickey <pat@moreproductive.org>
* Demote `simm32` and `uimm8` to lowering ISLE only
There seems to be nothing in opt ISLE that actually wanted them, just something that's more consistently done with using a 64-bit type to read from an Imm64.
And `simm32` feels like it's probably wrong to me -- `simm32` can't actually match `-1_i32` -- but I'm not confident enough in my analysis to actually change it.
* Cranelift: Add iconst shorthand to simplify ISLE opts
* Do a manually un-currying to avoid duplicating loading the `InstructionData`
* rustfmt is my nemesis
* PCC: Fix several aarch64 check_constant failures
This patch fixes several aarch64 check_constant failures:
1. `check_subsume` for `AluRRImmLogic` failed due to the mismatch of fact width
isle rule for `orr_imm` always generates fact with bit_width 64 regardless of
immediate type. So when Type is I32, `check_subsume` will be failed.
2. `MovN` generates incorrect fact range value when `first_is_inverted` is true
`running_value` should be calculated as !(((!imm16) & 0xffff) << shift) or
!(u64::from(imm.bits) << shift)
Added two test cases in cranelift/filetests/filetests/pcc/succeed/const.clif.
Additional fix for `get_fact_or_default`:
`trace!` treats `reg` as VirtualReg and it will panic when "reg" is RealReg and
`trace-log` feature is enabled.
* simplify get_fact_or_default
Co-authored-by: Nick Fitzgerald <fitzgen@gmail.com>
* fix missing comma
---------
Co-authored-by: Nick Fitzgerald <fitzgen@gmail.com>
* add `adapter_{open|close}_badfd` exports to Preview 1 adapter
This is to be used by `wasi-libc` to reserve file descriptors for its own use
(e.g. for sockets), ensuring that any attempt to pass them directly to Preview 1
functions will consistently return an error.
See https://github.com/WebAssembly/wasi-libc/issues/447 for further details.
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
* add `preview2_adapter_badfd` test
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
---------
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
The test simply tries looking up example.com and ensuring it fails with
`PermanentResolverFailure`. Additionally, `PermanentResolverFailure` is
removed as one of the allowed errors in the normal ip name lookup test
as those allowed errors should only be transient lookup errors and
`PermanentResolverFailure` is very much not a transient error.
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
* Ensure remote_address is allowed when creating UDP stream
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
* Check addr validity after UDP state check and wrap pool in Arc
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
* Check provided addr in outgoing stream
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
* Add test for turning off udp
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
* Model pool on UDP types as optional to catch bad state bugs
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
---------
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
* rename to ResourceTable, docs, and export
* wasi: use the table from wasmtime::component
* wasi-http: use wasmtime::component's resource table now
* rename file (somehow got lost)
* wasmtime-cli: fixes for resourcetable
* fix wasi-http tests
* more test fixes
* error messages
* fix warning
* cli: fix min build
prtest:full
* Add options to WasiCtx for toggling TCP and UDP on and off
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
* Address PR feedback
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
* Add test for turning off tcp
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
---------
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>