Implement WASI C API.
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.
This commit is contained in:
44
crates/misc/dotnet/src/Wasi.cs
Normal file
44
crates/misc/dotnet/src/Wasi.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using Wasmtime.Bindings;
|
||||
using Wasmtime.Imports;
|
||||
|
||||
namespace Wasmtime
|
||||
{
|
||||
public class Wasi
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a default <see cref="Wasi"/> instance.
|
||||
/// </summary>
|
||||
public Wasi(Store store) :
|
||||
this(
|
||||
(store ?? throw new ArgumentNullException(nameof(store))).Handle,
|
||||
Interop.wasi_config_new()
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
internal Wasi(Interop.StoreHandle store, Interop.WasiConfigHandle config)
|
||||
{
|
||||
IntPtr trap;
|
||||
Handle = Interop.wasi_instance_new(store, config, out trap);
|
||||
config.SetHandleAsInvalid();
|
||||
|
||||
if (trap != IntPtr.Zero)
|
||||
{
|
||||
throw TrapException.FromOwnedTrap(trap);
|
||||
}
|
||||
}
|
||||
|
||||
internal WasiBinding Bind(Import import)
|
||||
{
|
||||
var export = Interop.wasi_instance_bind_import(Handle, import.Handle);
|
||||
if (export == IntPtr.Zero)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new WasiBinding(export);
|
||||
}
|
||||
|
||||
internal Interop.WasiInstanceHandle Handle { get; private set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user