Merge current Wasmtime files with history into repo.#2
Merged
peterhuene merged 30 commits intobytecodealliance:masterfrom Apr 6, 2020
peterhuene:add-initial-files
Merged
Merge current Wasmtime files with history into repo.#2peterhuene merged 30 commits intobytecodealliance:masterfrom peterhuene:add-initial-files
peterhuene merged 30 commits intobytecodealliance:masterfrom
peterhuene:add-initial-files
Conversation
This moves the Wasmtime for .NET implementation to the Wasmtime repo. Wasmtime for .NET is a binding of the Wasmtime API for use in .NET.
For Windows release builds, the `wasm_valtype_kind` C API return value is being returned as a single byte. The .NET interop signature for this function was expecting an integer-sized return, resulting in three extra bytes being used on Windows. The fix is to limit the corresponding C# enum to a byte representation, which will properly mask the return value from `wasm_valtype_kind`. CI has also been updated to test both debug and release configurations (previously it was only testing debug, hence why this was missed). Also fixed a cast bug in the `declare_vec!` macro in the C API when the element types were pointers to values. The `as_slice` implementation was incorrectly casting away a level of pointer indirection, resulting in corrupted data when accessing the slice's elements.
The Validate function already checks that the field type is Memory.
It appears there are two trailing null bytes at the end of the string. This does not seem right. But it might be a good idea generally to remove any null bytes that get into error messages.
* Move the C API to a separate crate This commit moves the C API from `crates/api/src/wasm.rs` to `crates/capi/src/lib.rs` to be located in a separate crate. There's a number of reasons for this: * When a Rust program depends on the `wasmtime` crate, there's no need to compile in the C API. * This should improve compile times of the `wasmtime` crate since it's not producing artifacts which aren't always used. * The development of the C API can be guaranteed to only use the public API of the `wasmtime` crate itself. Some CI pieces are tweaked and this overall shouldn't have much impact on users, it's intended that it's a cleanup/speedup for developers! * Disable rustdoc/tests for capi * Review feedback * Add back in accidentally deleted comment * More renamings * Try to fix dotnet build
This commit implements an initial WASI C API that can be used to instantiate and configure a WASI instance from C. This also implements a `WasiBuilder` for the C# API enabling .NET hosts to bind to Wasmtime's WASI implementation.
Close the file descriptors before attempting to reopen the files.
Remove unnecessary loop when marshaling lists of strings as pointers to UTF-8 bytes.
This commit renames `wasi_config_set_std[in|out|err]` to `wasi_config_set_std[in|out|err]_file` so we can reserve the former for when the C API supports a stream abstraction.
This commit changes the C API function `wasm_module_new` to use the Rust API `Module::from_binary` which performs verification of the module, as per the C API spec. This also introduces a `EngineBuilder` type to the C# API that can be used to construct an `Engine` with the various Wasmtime configuration options. This is required to get the C# tests passing since they use reference types and multi-value. Fixes #859.
Change `wasm_module_new` to use `Module::from_binary`.
* Add a wasmtime-specific `wasmtime_wat2wasm` C API This commit implements a wasmtime-specific C API for converting the text format to the binary format. An upstream spec issue exists for adding this to the C API, but in the meantime we can experiment with our own version of this API and use it in the C# extension, for example! Closes #1000 * Reorder arguments * Use wasm_byte_vec_t for input `*.wat` * Mark wat input as const * Return an error message and use `fixed` * Actually include the error message * Use `fixed` in `Module.cs` as well
* Add a .gitattributes file specifying LF-style line endings. This is similar to [Rust's .gitattributes file] though simplified. Most of our source and documentation files already used LF-style line endings, including *.cs files, so this makes things more consistent. [Rust's .gitattributes file]: https://github.com/rust-lang/rust/blob/master/.gitattributes * Remove UTF-8 BOMs in *.cs files. Most of our *.cs files don't have UTF-8 BOMs, so this makes things more consistent.
This commit adds support for snapshot0 in the WASI C API. A name parameter was added to `wasi_instance_new` to accept which WASI module is being instantiated. Additionally, the C# API now supports constructing a WASI instance based on the WASI module name. Fixes #1221.
This commit reimplements the C# API in terms of a Wasmtime linker. It removes the custom binding implementation that was based on reflection in favor of the linker's implementation. This should make the C# API a little closer to the Rust API. The `Engine` and `Store` types have been hidden behind the `Host` type which is responsible for hosting WebAssembly module instances. Documentation and tests have been updated.
Co-authored-by: Håvar Nøvik <havar.novik@esmartsystems.com>
* 'master' of wasmtime: (28 commits) Fix typo in Memory.Maximum doc string. (#1432) Add Wasmtime C API function to control linker shadowing. Fix typo in exception message. Fix typo in method call. Reimplement the C# API. Support WASI snapshot0 in the C API. Add a .gitattributes file to specify eol=LF (#1370) Add a wasmtime-specific `wasmtime_wat2wasm` C API (#1206) Be explicit when marshalling bool. Change `wasm_module_new` to use `Module::from_binary`. Bump .NET NuGet package version to 0.12.0 Rename `wasi_config_set_std[in|out|err]`. Favor using non-braced using statement. Loop the array of strings only once. Ensure marshaled UTF-8 string arrays are null terminated. Fix unit tests on Windows. Add WASI unit tests for the C# API. Implement WASI C API. Move the C API to a separate crate (#818) Add tests calling function imports. ...
Member
Author
|
I'll add the changes from the other PR on top of this PR. |
5 tasks
kitsunoff
added a commit
to kitsunoff/wasmtime-dotnet
that referenced
this pull request
May 3, 2026
…e slots Releases the immediate panic seen in CI on this PR (\`unknown wasmtime_valkind_t: 226\`), which was the predicted manifestation of followups bytecodealliance#1/bytecodealliance#2: ComponentValue.ownsHeap squats on Rust's \`#[repr(C, u8)]\` enum padding, and Rust does not zero those bytes when it copies an enum value into our slot. In Release builds the leftover stack bytes were often 0xE2/0xCD/etc., so ComponentValue.Free() saw \`ownsHeap != 0\` and tried to Marshal.FreeHGlobal a wasmtime-allocated pointer — heap corruption that surfaced in adjacent core wasm tests as a bogus valkind read. This is a minimal, targeted fix rather than the full ownership refactor (which is still tracked in docs/component-model-followups.md): every place where wasmtime writes a 32-byte ComponentValue slot we now zero byte 1 (the byte ComponentValue uses for ownsHeap) before letting managed code touch it. Two sites: - ComponentFunction.Call — after wasmtime_component_func_call returns, walk the results span and clear byte 1 of each slot before post_return / before the caller lifts. - ComponentLinkerInstance.HostCallback.TrampolineImpl — when wasmtime passes args into the host trampoline they came through the same Rust-enum-copy path; clear byte 1 of every arg before exposing the ReadOnlySpan to the user delegate. After the reset, Free() on a wasmtime-filled slot is a no-op (the right behaviour: wasmtime owns those allocations, post_return / store disposal release them). Free() on a managed-allocated value still works because the From* factories explicitly write ownsHeap = 1 after the \`new ComponentValue { kind = ... }\` zeros the rest of the struct. Local Release-mode test count goes from 39 passing (before, with process crash) to 168 passing + 2 skipped (after). The remaining "test run aborted" message comes from a teardown-phase crash that is not flagged against any specific test — likely a finalizer running after the run is done. Tracking that separately. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: ZverGuy <maximbel2003@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.