Remove need for explicit `Config::async_support` knob (#12371)* Refactor component model host function definitionsPush the `async`-ness down one layer.* Remove need for explicit `Config::async
Remove need for explicit `Config::async_support` knob (#12371)* Refactor component model host function definitionsPush the `async`-ness down one layer.* Remove need for explicit `Config::async_support` knobThis commit is an attempt to step towards reconciling "old async" and"new async" in Wasmtime. The old async style is the original asyncsupport in Wasmtime with `call_async`, `func_wrap_async`, etc, where themain property is that the store is "locked" during an async operation.Put another way, a store can only execute at most one async operation ata time. This is in contrast to "new async" support in Wasmtime with thecomponent-model-async (WASIp3) support, where stores can have more thanone async operation in flight at once.This commit does not fully reconcile these differences, but it doesremove one hurdle along the way: `Config::async_support`. Since thebeginning of Wasmtime this configuration knob has existed to explicitlydemarcate a config/engine/store as "this thing requires `async` stuffinternally." This has started to make less and less sense over timewhere the line between sync and async has become more murky with WASIp3where the two worlds comingle. The goal of this commit is to deprecate`Config::async_support` and make the function not actually do anything.In isolation this can't simply be done, however, because there are manyload-bearing aspects of Wasmtime that rely on this `async_support` knob.For example once epochs + yielding are enabled it's required that allWasm is executed on a fiber lest it hit an epoch and not know how toyield. That means that this commit is not a simple removal of`async_support` but instead a refactoring/rearchitecting of how async isused internally within Wasmtime. The high-level ideas within Wasmtimenow are:* A `Store` has a "requires async" boolean stored within it.* All configuration options which end up requiring async, such as yielding with epochs, turn this boolean on.* Creation of host functions which use async (e.g. `func_wrap_{async,concurrent}`) will also turn this option on.* Synchronous API entrypoints into Wasmtime ensure that this boolean is disabled.* Asynchronous APIs are usable at any time.This means that the concept of an async store vs a sync store is nowgone. All stores are equally capable of executing sync/async, and thechange now is that dynamically some stores will require that async isused with certain configuration. Additionally all panicking conditionsaround `async_support` have been converted to errors instead. Allrelevant APIs already returned an error and things are murky enough nowthat it's not necessarily trivial to get this right at the embedderlevel. In the interest of avoiding panics all detected async mismatchesare now first-class `wasmtime::Error` values.The end result of this commit is that `Config::async_support` is adeprecated `#[doc(hidden)]` function that does nothing. While manyinternal changes happened as well as having new tests for all this sortof behavior this is not expected to have a great impact on externalconsumers. In general a deletion of `async_support(true)` is in theoryall that's required. This is intended to make it easier to think aboutasync/sync/etc in the future with WASIp3 and eventually reconcile`func_wrap_async` and `func_wrap_concurrent` for example. That's leftfor future refactorings however.prtest:full* Review comments* Fix CI failures
show more ...
Migrate the `wasmtime` crate to `wasmtime_environ::error::*` (#12231)* Migrate the `wasmtime` crate to `wasmtime_environ::error::*`Instead of `anyhow::Error`.This commit re-exports the `wasmtim
Migrate the `wasmtime` crate to `wasmtime_environ::error::*` (#12231)* Migrate the `wasmtime` crate to `wasmtime_environ::error::*`Instead of `anyhow::Error`.This commit re-exports the `wasmtime_environ::error` as the `wasmtime::error`module, updates the prelude to include these new error-handling types, redirectsour top-level `wasmtime::{Error, Result}` re-exports to re-export`wasmtime::error::{Error, Result}`, and updates various use sites that weredirectly using `anyhow` to use the new `wasmtime` versions.This process also required updating the component macro and wit-bindgen macro touse the new error types instead of `anyhow`.Part of https://github.com/bytecodealliance/wasmtime/issues/12069* Replace wasmtime::error::Thing with wasmtime::Thing where it makes sense* cargo fmt* Move `crate::error::Thing` to `crate::Thing` where it makes sense
Refactor resetting memory on `MemoryImageSlot` drop (#11510)* Refactor resetting memory on `MemoryImageSlot` dropThis commit refactors the behavior of dropping a `MemoryImageSlot` to nolonger ma
Refactor resetting memory on `MemoryImageSlot` drop (#11510)* Refactor resetting memory on `MemoryImageSlot` dropThis commit refactors the behavior of dropping a `MemoryImageSlot` to nolonger map anonymous memory into the slot. This behavior was implementedpreviously because if a `MemoryImageSlot` is dropped then the state ofthe slot is unknown and to prevent any sort of data leakage a reset isperformed.This reset operation, however, is fallible in that it calls `mmap`.Calls to `mmap` can fail due to `ENOMEM`, for example, if the processhas reached its VMA limit. This means that if a process is in a near-OOMcondition then failing to allocate a memory image could panic theprocess due to the `unwrap()` in the destructor of `MemoryImageSlot`.The purpose of this commit is to avoid this `unwrap()` and instead movethe reset behavior to a location where an error can be propagated.This commit removes the clear-on-drop behavior of `MemoryImageSlot`slot. This was already disabled everywhere except the pooling allocator.The pooling allocator now maintains an extra bit of state-per-slot whereinstead of storing `Option<MemoryImageSlot>` it now stores effectivelyone other variant of "unknown". On reuse of an "unknown" slot the memoryis reset back to an anonymous mapping and this is all done in a contextwhere an error can be propagated.Two tests are added in this commit to confirm all of this behavior:* The first test is a new test that passes both before and after this commit which performs a failed allocation of a memory slot. A successful allocation is then made to ensure that the previous image is not present and zero memory is present. This test fails before the commit if the clear-on-drop behavior is removed, and it fails with this commit if the clear-on-reusing-unknown behavior is removed. Effectively this test ensures that the clear-on-unknown-state logic is present.* The second test is a new test that panicked before this commit and passes afterwards. This second test exhausts all VMAs in the current process, or at least most of them, and then tries to allocate some instances with an image. Instance allocation will eventually fail and cause the erroneous path to get executed. This previously unwrapped a `ENOMEM` failure, and now it can be handled gracefully by the embedder.* Skip the new test on QEMU, it fails on CI* Only run test on Linux
Add a configuration knob for `PAGEMAP_SCAN` (#11433)* Add a configuration knob for `PAGEMAP_SCAN`This commit adds `PoolingAlloationConfig::pagemap_scan` and additionallyadds `-Opooling-pagemap-s
Add a configuration knob for `PAGEMAP_SCAN` (#11433)* Add a configuration knob for `PAGEMAP_SCAN`This commit adds `PoolingAlloationConfig::pagemap_scan` and additionallyadds `-Opooling-pagemap-scan` to configure on the CLI. This is the sametri-state configuration option as `MpkEnable` so that enum was renamedto just `Enabled` and repurposed for both options.This then additionally turns the option off-by-default instead of theprevious on-by-default-if-able-to to enable more slowly rolling out thisfeature.* Fix broken test
Add support for the Linux PAGEMAP_SCAN ioctl (#11372)* WIP: use the pagemap_scan ioctl to selectively reset an instance's dirty pages* Less hacky, and supporting tables, too* Bugfixes* WIP: m
Add support for the Linux PAGEMAP_SCAN ioctl (#11372)* WIP: use the pagemap_scan ioctl to selectively reset an instance's dirty pages* Less hacky, and supporting tables, too* Bugfixes* WIP: memcpy instead of pread* Refactor support for pagemap* Don't hold a raw pointer to the original data, plumb through an `Arc` to have a safe reference instead.* Update pagemap bindings to latest version of abstraction written.* Include pagemap-specific tests.* Use a `PageMap` structure created once-per-pool instead of a static-with-a-file.* Refactor to use the "pagemap path" unconditionally which blends in the keep_resident bits.* Improve safety documentationprtest:full* Fix some lints* Skip ioctl tests when it's not supported* Fix a memory leak by moving impls around* Fix no vm build* Review comments* Add more pagemap-specific documentation* Add more docs, refactor implementation slightly* Improve `category_*` docsBasically forward to the Linux kernel source itself.* Fix compile* Make pagemap integration resilient across forks* Fix non-pooling-allocator-build* Fix portability issues of new test* Actually use config on macos---------Co-authored-by: Till Schneidereit <[email protected]>
Update Wasmtime to the 2024 Rust Edition (#10806)* Update Wasmtime to the 2024 Rust EditionNow that our MSRV supports the 2024 edition it's possible to make thisswitch. This commit moves Wasmtim
Update Wasmtime to the 2024 Rust Edition (#10806)* Update Wasmtime to the 2024 Rust EditionNow that our MSRV supports the 2024 edition it's possible to make thisswitch. This commit moves Wasmtime to the 2024 Edition to keepup-to-date with Rust idioms and access many of the edition featuresexclusive to the 2024 edition.prtest:full* Reformat with the 2024 edition
Run CI tests through AddressSanitizer (#10537)This is similar to running tests in Valgrind (which we should perhapsalso do...) but can be useful for catching use-after-free style bugsfaster than
Run CI tests through AddressSanitizer (#10537)This is similar to running tests in Valgrind (which we should perhapsalso do...) but can be useful for catching use-after-free style bugsfaster than when a process crashes. Given the unsafe nature of Wasmtimethis is something we should have probably enabled awhile back butotherwise so long as it doesn't take too long to run on CI seems like aneasy win of a boost-of-confidence.prtest:asan
Add a `wasmtime objdump` subcommand (#10405)This commit adds an `objdump` subcommand to the `wasmtime` CLI. Like allother subcommands this can be disabled for a more minimal build of theCLI as we
Add a `wasmtime objdump` subcommand (#10405)This commit adds an `objdump` subcommand to the `wasmtime` CLI. Like allother subcommands this can be disabled for a more minimal build of theCLI as well. The purpose of this subcommand is to provide aWasmtime-specific spin on the venerable native `objdump` itself. Notablythis brings Wasmtime-specific knowledge for filtering functions, showingWasmtime metadata, etc.This command is intended to look like `objdump` roughly but also hasconfigurable output with various flags and things that can be printed.For now the main Wasmtime additions are showing the address mapsection, stack map section, and trap section of a `*.cwasm` file.This new subcommand replaces the infrastructure of the `disas` testsuite, and now that test suite uses `wasmtime objdump` to generate testexpectations. Additionally the subcommand replaces the Pulley `objdump`example as a more full-featured objdump that also works natively withPulley.The hope is that if we add more binary metadata in the future (such asunwinding tables) that can be relatively easily added here forexploration as well. Otherwise this is mostly just a developerconvenience for Wasmtime developers as well and hopefully doesn't costtoo much in maintenance burden.Closes #10336
Improve support for completely unknown architectures (#10107)* Improve support for completely unknown architecturesThis commit is a step in the direction of trying to make Wasmtime moreportable
Improve support for completely unknown architectures (#10107)* Improve support for completely unknown architecturesThis commit is a step in the direction of trying to make Wasmtime moreportable by default. The goal here is to enable Wasmtime to compile forarchitectures that it has no prior knowledge of. There's a fewmiscellaneous locations through Wasmtime where we needarchitecture-specific intrinsics and such but that's all in service ofCranelift itself. Without Cranelift support none of them are necessary.This commit plumbs a custom `#[cfg]` from Wasmtime's `build.rs` scriptinto the crate about whether there's a supported Cranelift backend. Ifthis isn't available some architecture-specific intrinsics are turnedoff and not included. An example is that `vm::arch` entirely disappearswhich is only in service of `UnwindHost`, which also disappears.Furthermore the `helpers.c` file also entirely disappears as it's notnecessary on unknown architectures.To help keep this working I've added CI to build Wasmtime for`powerpc64le-unknown-linux-gnu`. Wasmtime currently has no support forthis architecture, although if it grows such support in the futurethis'll need to be changed to some other unsupported architecture.* Review feedback* Fix powerpc build* Refactor windows trap handling to look like UnixShuffle some files around to be more amenable to #[cfg]* Move signal-handling tests to wasmtime crateThat way it's got easy access to the #[cfg]'s from the build script* Disable signals support without a host compilerEven if custom signals are enabled, don't compile it in.prtest:full* Fix windows unused imports* Fix unused imports on Windows* Remove untested stubs for arch intrinsicsThese aren't needed any more to compile Pulley* Defer tunables validation to loading modulesInstead of validating at `Engine` config time instead validate at`Module` config time to enable cross-compilation.* Skip `Tunables` auto-configuration if cross-compilingThis commit* Tweak some Tunables based on PulleyEnsures that specific `--target pulleyNN` works most of the time.* Update host_segfault.rs to handle new 32-bit defaultsNo signal handlers are used at all with Pulley so when the async stackoverflows there's no message printed any more.* Disable Tunables::signals_based_traps on miri