Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<DevBuild Condition="'$(DevBuild)'==''">true</DevBuild>
<WasmtimeVersion Condition="'$(WasmtimeVersion)'==''">35.0.0</WasmtimeVersion>
<WasmtimeVersion Condition="'$(WasmtimeVersion)'==''">44.0.0</WasmtimeVersion>
<WasmtimeDotnetVersion Condition="'$(WasmtimeDotnetVersion)'==''"></WasmtimeDotnetVersion>
<WasmtimePackageVersion Condition="'$(DevBuild)'=='true'">$(WasmtimeVersion)$(WasmtimeDotnetVersion)-dev</WasmtimePackageVersion>
<WasmtimePackageVersion Condition="'$(WasmtimePackageVersion)'==''">$(WasmtimeVersion)$(WasmtimeDotnetVersion)</WasmtimePackageVersion>
Expand Down
8 changes: 4 additions & 4 deletions src/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ private unsafe void InvokeWithoutReturn(Span<ValueRaw> arguments, StoreContext s
// `wasmtime_externref_new` failed).
for (int releaseIndex = 0; releaseIndex < i; releaseIndex++)
{
args[releaseIndex].Release(store);
args[releaseIndex].Dispose();
}

throw;
Expand Down Expand Up @@ -347,15 +347,15 @@ private unsafe void InvokeWithoutReturn(Span<ValueRaw> arguments, StoreContext s
{
for (int i = 0; i < Results.Count; ++i)
{
resultsSpan[i].Release(store);
resultsSpan[i].Dispose();
}
}
}
finally
{
for (int i = 0; i < arguments.Length; ++i)
{
args[i].Release(store);
args[i].Dispose();
}
}
}
Expand Down Expand Up @@ -672,7 +672,7 @@ internal static unsafe IntPtr InvokeUntypedCallback(UntypedCallbackDelegate call
// of already allocated result values.
for (int releaseIndex = 0; releaseIndex < i; releaseIndex++)
{
results[releaseIndex].Release(caller.Store);
results[releaseIndex].Dispose();
}

throw;
Expand Down
10 changes: 5 additions & 5 deletions src/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public Global(Store store, ValueKind kind, object? initialValue, Mutability muta
}
finally
{
value.Release(store);
value.Dispose();
}
}

Expand All @@ -152,7 +152,7 @@ public Global(Store store, ValueKind kind, object? initialValue, Mutability muta
}
finally
{
v.Release(store);
v.Dispose();
}
}

Expand All @@ -176,7 +176,7 @@ public void SetValue(object? value)
}
finally
{
v.Release(store);
v.Dispose();
}
}

Expand Down Expand Up @@ -325,7 +325,7 @@ public T GetValue()
}
finally
{
v.Release(_store);
v.Dispose();
}
}

Expand All @@ -350,7 +350,7 @@ public void SetValue(T value)
}
finally
{
v.Release(_store);
v.Dispose();
}
}

Expand Down
14 changes: 11 additions & 3 deletions src/Memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,17 @@ public Memory(Store store, long minimum = 0, long? maximum = null, bool is64Bit
Is64Bit = is64Bit;
IsShared = false;

var typeHandle = Native.wasmtime_memorytype_new((ulong)minimum, maximum is not null, (ulong)(maximum ?? 0), is64Bit, IsShared);
IntPtr typeHandle;
var error = Native.wasmtime_memorytype_new((ulong)minimum, maximum is not null, (ulong)(maximum ?? 0), is64Bit, IsShared, PageSizeLog2, out typeHandle);

if (error != IntPtr.Zero){
throw WasmtimeException.FromOwnedError(error);
}

try
{

var error = Native.wasmtime_memory_new(store.Context.handle, typeHandle, out this.memory);
error = Native.wasmtime_memory_new(store.Context.handle, typeHandle, out this.memory);
GC.KeepAlive(store);

if (error != IntPtr.Zero)
Expand All @@ -62,6 +68,8 @@ public Memory(Store store, long minimum = 0, long? maximum = null, bool is64Bit
Native.wasm_memorytype_delete(typeHandle);
}
}

private const int PageSizeLog2 = 16;

/// <summary>
/// The size, in bytes, of a WebAssembly memory page.
Expand Down Expand Up @@ -602,7 +610,7 @@ internal static class Native
public static extern IntPtr wasmtime_memory_type(IntPtr context, in ExternMemory memory);

[DllImport(Engine.LibraryName)]
public static extern IntPtr wasmtime_memorytype_new(ulong min, [MarshalAs(UnmanagedType.I1)] bool max_present, ulong max, [MarshalAs(UnmanagedType.I1)] bool is_64, [MarshalAs(UnmanagedType.I1)] bool shared);
public static extern IntPtr wasmtime_memorytype_new(ulong min, [MarshalAs(UnmanagedType.I1)] bool max_present, ulong max, [MarshalAs(UnmanagedType.I1)] bool is_64, [MarshalAs(UnmanagedType.I1)] bool shared, byte page_size_log2, out IntPtr ret);

[DllImport(Engine.LibraryName)]
public static extern ulong wasmtime_memorytype_minimum(IntPtr type);
Expand Down
8 changes: 6 additions & 2 deletions src/Store.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ internal StoreContext(IntPtr handle)

internal void GC()
{
Native.wasmtime_context_gc(handle);
var error = Native.wasmtime_context_gc(handle);
if (error != IntPtr.Zero)
{
throw WasmtimeException.FromOwnedError(error);
}
}

internal ulong GetFuel()
Expand Down Expand Up @@ -84,7 +88,7 @@ public void SetEpochDeadline(ulong deadline)
private static class Native
{
[DllImport(Engine.LibraryName)]
public static extern void wasmtime_context_gc(IntPtr handle);
public static extern IntPtr wasmtime_context_gc(IntPtr handle);

[DllImport(Engine.LibraryName)]
public static extern IntPtr wasmtime_context_set_fuel(IntPtr handle, ulong fuel);
Expand Down
8 changes: 4 additions & 4 deletions src/Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public Table(Store store, TableKind kind, object? initialValue, uint initial, ui
}
finally
{
value.Release(store);
value.Dispose();
}
}

Expand Down Expand Up @@ -134,7 +134,7 @@ public Table(Store store, TableKind kind, object? initialValue, uint initial, ui
}
finally
{
v.Release(store);
v.Dispose();
}
}

Expand All @@ -159,7 +159,7 @@ public void SetElement(uint index, object? value)
}
finally
{
v.Release(store);
v.Dispose();
}
}

Expand Down Expand Up @@ -198,7 +198,7 @@ public ulong Grow(uint delta, object? initialValue)
}
finally
{
v.Release(store);
v.Dispose();
}
}

Expand Down
145 changes: 127 additions & 18 deletions src/TrapException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,53 +37,162 @@ public enum TrapCode
Unreachable = 9,
/// <summary>The trap was the result of interrupting execution.</summary>
Interrupt = 10,
/// <summary>
/// The trap was the result of executing a function that was `canon lift`'d, then `canonlower`'d, then called.
/// </summary>
/// <remarks>
/// When the component model feature is enabled this trap represents a function that was `canon lift`'d,
/// then `canonlower`'d, then called. This combination of creation of a function in the component model
/// generates a function that always traps and, when called, produces this flavor of trap.
/// </remarks>
AlwaysTrapAdapter = 11,
/// <summary>The trap was the result of running out of the configured fuel amount.</summary>
OutOfFuel = 12,
OutOfFuel = 11,
/// <summary>
/// The trap was the result of atomic wait operations on non-shared memory.
/// </summary>
AtomicWaitNonSharedMemory = 13,
AtomicWaitNonSharedMemory = 12,
/// <summary>
/// The trap was the result of a call to a null reference.
/// </summary>
NullReference = 14,
NullReference = 13,
/// <summary>
/// The trap was the result of an attempt to access beyond the bounds of an array.
/// </summary>
ArrayOutOfBounds = 15,
ArrayOutOfBounds = 14,
/// <summary>
/// The trap was the result of an allocation that was too large to succeed.
/// </summary>
AllocationTooLarge = 16,
AllocationTooLarge = 15,
/// <summary>
/// The trap was the result of an attempt to cast a reference to a type that it is not an instance of.
/// </summary>
CastFailure = 17,
CastFailure = 16,
/// <summary>
/// The trap was the result of a component calling another component that would have violated the reentrance rules.
/// </summary>
CannotEnterComponent = 18,
CannotEnterComponent = 17,
/// <summary>
/// The trap was the result of an async-lifted export failing to return a valid async result.
/// </summary>
/// <remarks>
/// An async-lifted export failed to produce a result by calling `task.return` before returning `STATUS_DONE`
/// and/or after all host tasks completed.
/// </remarks>
NoAsyncResult = 19,
NoAsyncResult = 18,
/// <summary>
/// The trap was the result of suspending to a tag for which there is no active handler.
/// </summary>
UnhandledTag = 19,
/// <summary>
/// The trap was the result of an attempt to resume a continuation twice.
/// </summary>
ContinuationAlreadyConsumed = 20,
/// <summary>
/// The trap was the result of a Pulley opcode executed at runtime when the opcode was disabled at compile time.
/// </summary>
DisabledOpCode = 20
DisabledOpCode = 21,
/// <summary>
/// The trap was the result of an async event loop deadlocking; i.e. it cannot make further
/// progress given that all host tasks have completed and any/all host-owned stream/future
/// handles have been dropped.
/// </summary>
AsyncDeadlock = 22,
/// <summary>
/// When the `component-model` feature is enabled this trap was the result of a scenario
/// where a component instance tried to call an import or intrinsic when it wasn't allowed
/// to, e.g. from a post-return function.
/// </summary>
CannotLeaveComponent = 23,
/// <summary>
/// The trap was the result of a synchronous task attempted to make a potentially blocking
/// call prior to returning.
/// </summary>
CannotBlockSyncTask = 24,
/// <summary>
/// The trap was the result of a component trying to lift a `char` with an invalid bit pattern.
/// </summary>
InvalidChar = 25,
/// <summary>
/// The trap was the result of a debug assertion generated for a fused adapter regarding the
/// expected completion of a string encoding operation.
/// </summary>
DebugAssertStringEncodingFinished = 26,
/// <summary>
/// The trap was the result of a debug assertion generated for a fused adapter regarding a
/// string encoding operation.
/// </summary>
DebugAssertEqualCodeUnits = 27,
/// <summary>
/// The trap was the result of a debug assertion generated for a fused adapter regarding the
/// alignment of a pointer.
/// </summary>
DebugAssertPointerAligned = 28,
/// <summary>
/// The trap was the result of a debug assertion generated for a fused adapter regarding the
/// upper bits of a 64-bit value.
/// </summary>
DebugAssertUpperBitsUnset = 29,
/// <summary>
/// The trap was the result of a component trying to lift or lower a string past the end of its memory.
/// </summary>
StringOutOfBounds = 30,
/// <summary>
/// The trap was the result of a component tryping to lift or lower a list past the end of its memory.
/// </summary>
ListOutOfBounds = 31,
/// <summary>
/// The trap was the result of a component using an invalid discriminant when lowering a variant value.
/// </summary>
InvalidDiscriminant = 32,
/// <summary>
/// The trap was the result of a component passing an unaligned pointer when lifting or
/// lowering a value.
/// </summary>
UnalignedPointer = 33,
/// <summary>
/// The trap was the result of <c>task.cancel</c> being invoked in an invalid way.
/// </summary>
TaskCancelNotCancelled = 34,
/// <summary>
/// The trap was the result of <c>task.cancel</c> or <c>task.return</c> being called too many times
/// </summary>
TaskCancelOrReturnTwice = 35,
/// <summary>
/// The trap was the result of <c>subtask.cancel</c> being invoked after it already finished.
/// </summary>
SubtaskCancelAfterTerminal = 36,
/// <summary>
/// The trap was the result of <c>task.return</c> being invoked with an invalid type.
/// </summary>
TaskReturnInvalid = 37,
/// <summary>
/// The trap was the result of <c>waitable-set.drop</c> being invoked on a waitable set with waiters.
/// </summary>
WaitableSetDropHasWaiters = 38,
/// <summary>
/// The trap was the result of <c>subtask.drop</c> being invoked on a subtask that hasn't resolved yet.
/// </summary>
SubtaskDropNotResolved = 39,
/// <summary>
/// The trap was the result of <c>thread.new-indirect</c> being invoked with a function that
/// has an invalid type.
/// </summary>
ThreadNewIndirectInvalidType = 40,
/// <summary>
/// The trap was the result of <c>thread.new-indirect</c> being invoked with an
/// uninitialized function reference.
/// </summary>
ThreadNewIndirectUninitialized = 41,
/// <summary>
/// The trap was the result of backpressure-related intrinsics overflowing the built-in counter.
/// </summary>
BackpressureOverflow = 42,
/// <summary>
/// The trap was the result of an invalid code being returned from the callback of an
/// async-lifted function.
/// </summary>
UnsupportedCallbackCode = 43,
/// <summary>
/// The trap was the result of trying to resume a thread which is not suspended.
/// </summary>
CannotResumeThread = 44,
/// <summary>
/// The trap was the result of a read/write being issued on a future/stream while there is a
/// pending operation already.
/// </summary>
ConcurrentFutureStreamOp = 45,
}

/// <summary>
Expand Down
Loading
Loading