* wasmtime: add EngineWeak which has ::upgrade, created by Engine::weak
Engine is, internally, just an Arc<EngineInner>, so this is trivial to implement -
EngineWeak is a Weak<EngineInner>.
This behavior is desirable because `Engine::increment_epoch` typically
happens in a worker thread, which in turn requires additional machinery
to discard the `Engine` once it is no longer needed. If instead the
worker thread holds an `EngineWeak`, it can stop ticking when all
consumers of the `Engine` have dropped it. This has been documented as a
suggestion in `increment_epoch`.
For an example of additional machinery which is simplified by this change, see 25edee0700/lib/src/execute.rs (L108-L116))
Co-authored-by: John Van Enk <vanenkj@gmail.com>
* add a test
---------
Co-authored-by: John Van Enk <vanenkj@gmail.com>
* mpk: allow configuring MPK from the command line
This allows the following usage:
```console
$ wasmtime --pooling-allocator=y --memory-protection-keys=y ...
```
* mpk: add CLI test for failure
* review: move `bail!` outside the pooling allocator block
* fix: use absolute dependency path
This mirrors how traits for the host are all called `Host` and it avoids
name clashes with types that share the name of the interface they are in.
I've also added some simple debugging of macro-generated code to get
better error messages.
Closes#7775
* fix: allow dynamic owned resources to be used as borrowed parameters
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
* tests: add `can_use_own_for_borrow` test
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
---------
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
* mpk: also force MPK during benchmarking
This change takes advantage of the `WASMTIME_TEST_FORCE_MPK` environment
variable to force its use in the `call.rs` benchmarks. I see differences
in several cases when running:
```console
$ taskset --cpu-list 0-15 cargo bench -- async
$ WASMTIME_TEST_FORCE_MPK=1 taskset --cpu-list 0-15 cargo bench -- async
```
To properly isolate the MPK effects, this adds a `sync-pool` option
(`IsAsync::NoPooling`).
* mpk: disable PKRU read unless logging is turned on
After noticing some minor effects with this PKRU read, I chose to avoid
it unless logging is enabled. A perfectly valid alternative would be to
remove the logging altogether, but I have found this very helpful when
trying to troubleshoot MPK issues.
* mpk: inline PKRU functions
To avoid any unnecessary call overhead, we hint to the compiler that
`pkru::read` and `pkru::write` should be inlined.
* Add stack overflow tests
* Add stack overflow tests for indirect calls
* Check for stack overflow on function entry
* Ignore the call tests on windows, as stack overflows trap
* Bless the winch filetests
* Omit instruction offsets in winch disassembly when possible
Only emit instruction offsets at basic block boundaries, or for all
instructions after a return. The reason behind the latter, is that many
of the instructions after a return are traps, and will be common jump
targets.
* Update winch tests
* Configure full offset output in the `disasm` function
* wasi: pull in contents of wasi-sockets, wasi-http, and wasi-cli 0.2.0-rc-2024-01-16
* command-extended and test worlds: use rc-2024-01-16
* sockets implementation: v6only is now mandatory
* adapter: cli imports and exports are from rc-2024-01-16 now
* eliminate ipv6-only methods and tests
* a v6_client.blocking_connect(net, v4_listener) will always fail
with INVAL right away.
* eliminate the paths where a v6 client is allowed to connect to v4.
* eliminate the udp_dual_stack_conversation from udp_sample_application
* component-basic: update wasi:cli version
* wasi-http: sync wit directory
* wasi-http: fix import version
* code review from dave
* test both ipv4 address on v6 socket, and ipv6-mapped-ipv4 on v6 socket, both fail
* Move `jit` crate to `environ`
Move the platform agnostic parts of the crate `wasmtime-jit` to
`wasmtime-environ`. This is the first part of the refactoring discussed
here: https://github.com/bytecodealliance/wasmtime/issues/7652 and a
follow up will move the remaining parts of `wasmtime-jit` so that the
crate can be deleted.
* Move `jit` crate to `wasmtime`
Move the remaining parts of `wasmtime-jit` to the `wasmtime` crate and
remove `wasmtime-jit`. This is part of the refactoring discussed in
https://github.com/bytecodealliance/wasmtime/issues/7652.
* undo toml formatting
* Trigger pipeline: prtest:full
* Remove `jit` directory
* move `ProfilingAgent` out of `profiling` feature
* add links to ELF_NAME_DATA
LLVM passes the tag in rax and the u128 val in rdx/rcx. Before this
change Cranelift would pass the first half of the value in rdx and the
second half using an implicit return value pointer.
* Add a small test checking that pollables can be used many times
* Tests where two commands have their stdin/stdout piped together
* Pipe together wasmtime subprocesses instead of managing the buffer
* Update the wasm-tools family of crates
Brings in support for validating gc instructions, but they're all left
disabled for now.
* Update fuzz test case generation
* More test fixes, remove stray files
* More test fixes
* Rebase
* winch: Multi-Value Part 2: Blocks
This commit adds support for the Multi-Value proposal for blocks.
In general, this change, introduces multiple building blocks to enable
supporting arbitrary params and results in blocks:
* `BlockType`: Introduce a block type, to categorize the type of each
block, this makes it easier to categorize blocks per type and also
makes it possible to defer the calculation of the `ABIResults` until
they are actually needed rather than calculating everyghing upfront
even though they might not be needed (when in an unreachable state).
* Push/pop operations are now frame aware. Given that each
`ControlStackFrame` contains all the information needed regarding
params and results, this change moves the the implementation of the
push and pop operations to the `ControlStackFrame` struct.
* `StackState`: this struct holds the entry and exit invariants of each
block; these invariants are pre-computed when entering the block and
used throughout the code generation, to handle params, results and
assert the respective invariants.
In terms of the mechanics of the implementation: when entering each
block, if there are results on the stack, the expected stack pointer
offsets will be calculated via the `StackState`, and the `target_offset`
will be used to create the block's `RetArea`. Note that when entering
the block and calculating the `StackState` no space is actually reserved
for the results, any space increase in the stack is deffered until the
results are popped from the value stack via
`ControlStackFrame::pop_abi_results`.
The trickiest bit of the implementation is handling constant values that
need to be placed on the right location on the machine stack. Given that
constants are generally not spilled, this means that in order to keep
the machine and value stack in sync (spilled-values-wise), values must
be shuffled to ensure that constants are placed in the expected location results wise.
See the comment in `ControlStackFrame::adjust_stack_results` for more
details.
* Review fixes
Try not passing `-y -u` to `pacman` to avoid full system updates.
Currently full system updates might update the `msys2-runtime` package
before actually updating the package we requested, meaning that this
might not actually update anything given an update. This is what's
currently happening on CI which is breaking due to an update of gcc not
actually updating gcc. I'm mostly reading the invocation in
rust-lang/rust CI and seeing that it doesn't pass `-y -u` and hopeing
that by copying that here things might work.
prtest:full
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