diff --git a/Directory.Build.props b/Directory.Build.props index 65eb7e5b..a0c461ff 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -6,4 +6,7 @@ $(WasmtimeVersion)$(WasmtimeDotnetVersion)-dev $(WasmtimeVersion)$(WasmtimeDotnetVersion) - \ No newline at end of file + + $(DefineConstants);WASMTIME_DEV + + diff --git a/README.md b/README.md index e0828d04..071fdc87 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,18 @@ $ dotnet build Wasmtime.sln This will download the latest development snapshot of Wasmtime for your platform. +By default, local builds set `DevBuild=true`, which uses the dev C API artifacts +(`wasmtime-dev-*`) and enables a `WASMTIME_DEV` build define to match the dev +ABI (value/trap layouts). To build against the stable Wasmtime release instead, +override the flag: + +``` +$ dotnet build Wasmtime.sln -p:DevBuild=false +``` + +If you switch between `DevBuild=true` and `DevBuild=false`, you may need to +delete `src/obj` to force the correct C API download. + ### Testing Use `dotnet` to run the unit tests: diff --git a/src/Caller.cs b/src/Caller.cs index 35cddc1f..b09f717c 100644 --- a/src/Caller.cs +++ b/src/Caller.cs @@ -168,11 +168,11 @@ public ulong Fuel internal static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern unsafe bool wasmtime_caller_export_get(IntPtr caller, byte* name, UIntPtr len, out Extern item); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_caller_context(IntPtr caller); } diff --git a/src/Config.cs b/src/Config.cs index 76adc3a6..0b5c4c86 100644 --- a/src/Config.cs +++ b/src/Config.cs @@ -382,76 +382,76 @@ protected override bool ReleaseHandle() private static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasm_config_new(); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasm_config_delete(IntPtr config); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_config_debug_info_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_config_epoch_interruption_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_config_consume_fuel_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_config_max_wasm_stack_set(Handle config, nuint size); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_config_wasm_threads_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_config_wasm_reference_types_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_config_wasm_simd_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_config_wasm_relaxed_simd_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_config_wasm_relaxed_simd_deterministic_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_config_wasm_bulk_memory_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_config_wasm_multi_value_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_config_wasm_multi_memory_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_config_wasm_memory64_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_config_strategy_set(Handle config, byte strategy); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_config_cranelift_debug_verifier_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_config_cranelift_nan_canonicalization_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_config_cranelift_opt_level_set(Handle config, byte level); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_config_profiler_set(Handle config, byte strategy); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_config_memory_reservation_set(Handle config, ulong size); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_config_memory_guard_size_set(Handle config, ulong size); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_config_cache_config_load(Handle config, [MarshalAs(Extensions.LPUTF8Str)] string? path); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_config_macos_use_mach_ports(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable); } diff --git a/src/Engine.cs b/src/Engine.cs index cb3705b4..71496c58 100644 --- a/src/Engine.cs +++ b/src/Engine.cs @@ -79,19 +79,19 @@ protected override bool ReleaseHandle() private static class Native { - [DllImport(LibraryName)] + [DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasm_engine_new(); - [DllImport(LibraryName)] + [DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasm_engine_new_with_config(Config.Handle config); - [DllImport(LibraryName)] + [DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasm_engine_delete(IntPtr engine); - [DllImport(LibraryName)] + [DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_engine_increment_epoch(Handle engine); - [DllImport(LibraryName)] + [DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool wasmtime_engine_is_pulley(Handle engine); } diff --git a/src/Export.cs b/src/Export.cs index 6501dcb0..75f8f50a 100644 --- a/src/Export.cs +++ b/src/Export.cs @@ -56,14 +56,14 @@ public Export[] ToExportArray() internal static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasm_exporttype_vec_delete(in ExportTypeArray vec); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern byte wasm_externtype_kind(IntPtr valueType); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasm_exporttype_type(IntPtr exportType); } } @@ -102,7 +102,7 @@ public override string ToString() private static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static unsafe extern ByteArray* wasm_exporttype_name(IntPtr type); } } @@ -139,7 +139,7 @@ internal FunctionExport(IntPtr exportType, IntPtr externType) : base(exportType) internal static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasm_externtype_as_functype_const(IntPtr type); } } @@ -174,7 +174,7 @@ internal GlobalExport(IntPtr exportType, IntPtr externType) : base(exportType) internal static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasm_externtype_as_globaltype_const(IntPtr type); } } @@ -222,7 +222,7 @@ internal MemoryExport(IntPtr exportType, IntPtr externType) : base(exportType) private static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasm_externtype_as_memorytype_const(IntPtr type); } } @@ -267,7 +267,7 @@ internal TableExport(IntPtr exportType, IntPtr externType) : base(exportType) internal static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasm_externtype_as_tabletype_const(IntPtr type); } } diff --git a/src/Externs.cs b/src/Externs.cs index 08b14076..f4bde2ba 100644 --- a/src/Externs.cs +++ b/src/Externs.cs @@ -111,7 +111,7 @@ public void Dispose() private static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_extern_delete(in Extern self); } } diff --git a/src/Function.cs b/src/Function.cs index 947bd986..75d2811b 100644 --- a/src/Function.cs +++ b/src/Function.cs @@ -730,47 +730,50 @@ internal static unsafe IntPtr HandleCallbackException(Exception ex) internal static class Native { + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void Finalizer(IntPtr data); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public unsafe delegate IntPtr WasmtimeFuncCallback(IntPtr env, IntPtr caller, Value* args, nuint nargs, Value* results, nuint nresults); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public unsafe delegate IntPtr WasmtimeFuncUncheckedCallback(IntPtr env, IntPtr caller, ValueRaw* args_and_results, nuint num_args_and_results); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_func_new(IntPtr context, IntPtr type, WasmtimeFuncCallback callback, IntPtr env, Finalizer? finalizer, out ExternFunc func); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_func_new_unchecked(IntPtr context, IntPtr type, WasmtimeFuncUncheckedCallback callback, IntPtr env, Finalizer? finalizer, out ExternFunc func); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static unsafe extern IntPtr wasmtime_func_call(IntPtr context, in ExternFunc func, Value* args, nuint nargs, Value* results, nuint nresults, out IntPtr trap); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static unsafe extern IntPtr wasmtime_func_call_unchecked(IntPtr context, in ExternFunc func, ValueRaw* args_and_results, nuint args_and_results_len, out IntPtr trap); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_func_type(IntPtr context, in ExternFunc func); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static unsafe extern void wasmtime_func_from_raw(IntPtr context, IntPtr raw, out ExternFunc func); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static unsafe extern IntPtr wasmtime_func_to_raw(IntPtr context, in ExternFunc func); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasm_functype_new(in ValueTypeArray parameters, in ValueTypeArray results); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern unsafe ValueTypeArray* wasm_functype_params(IntPtr type); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern unsafe ValueTypeArray* wasm_functype_results(IntPtr type); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasm_functype_delete(IntPtr functype); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static unsafe extern IntPtr wasmtime_trap_new(byte* bytes, nuint len); } diff --git a/src/Global.cs b/src/Global.cs index 2eb37407..67936864 100644 --- a/src/Global.cs +++ b/src/Global.cs @@ -251,28 +251,28 @@ protected override bool ReleaseHandle() internal static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_global_new(IntPtr context, TypeHandle type, in Value val, out ExternGlobal global); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_global_get(IntPtr context, in ExternGlobal global, out Value val); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_global_set(IntPtr context, in ExternGlobal global, in Value val); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_global_type(IntPtr context, in ExternGlobal global); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasm_globaltype_new(IntPtr valueType, Mutability mutability); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasm_globaltype_content(IntPtr type); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern byte wasm_globaltype_mutability(IntPtr type); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasm_globaltype_delete(IntPtr type); } diff --git a/src/Import.cs b/src/Import.cs index e1b20d0d..96960ed6 100644 --- a/src/Import.cs +++ b/src/Import.cs @@ -68,10 +68,10 @@ public Import[] ToImportArray() private static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasm_importtype_vec_delete(in ImportTypeArray vec); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasm_importtype_type(IntPtr importType); } } @@ -124,10 +124,10 @@ public override string ToString() private static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static unsafe extern ByteArray* wasm_importtype_module(IntPtr type); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static unsafe extern ByteArray* wasm_importtype_name(IntPtr type); } } @@ -235,7 +235,7 @@ internal MemoryImport(IntPtr importType, IntPtr externType) : base(importType) private static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasm_externtype_as_memorytype_const(IntPtr type); } } diff --git a/src/Instance.cs b/src/Instance.cs index 84631b40..0988e276 100644 --- a/src/Instance.cs +++ b/src/Instance.cs @@ -713,14 +713,14 @@ internal Instance(Store store, ExternInstance instance) private static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern unsafe IntPtr wasmtime_instance_new(IntPtr context, Module.Handle module, Extern* imports, UIntPtr nimports, out ExternInstance instance, out IntPtr trap); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern unsafe bool wasmtime_instance_export_get(IntPtr context, in ExternInstance instance, byte* name, UIntPtr len, out Extern ext); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern unsafe bool wasmtime_instance_export_nth(IntPtr context, in ExternInstance instance, UIntPtr index, out byte* name, out UIntPtr len, out Extern ext); } diff --git a/src/Linker.cs b/src/Linker.cs index 6556cdb3..d8f6b771 100644 --- a/src/Linker.cs +++ b/src/Linker.cs @@ -500,40 +500,40 @@ protected override bool ReleaseHandle() internal static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_linker_new(Engine.Handle engine); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_linker_delete(IntPtr linker); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_linker_allow_shadowing(Handle linker, [MarshalAs(UnmanagedType.I1)] bool allow); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static unsafe extern IntPtr wasmtime_linker_define(Handle linker, IntPtr context, byte* module, nuint moduleLen, byte* name, nuint nameLen, in Extern item); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_linker_define_wasi(Handle linker); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static unsafe extern IntPtr wasmtime_linker_define_instance(Handle linker, IntPtr context, byte* name, nuint len, in ExternInstance instance); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static unsafe extern IntPtr wasmtime_linker_define_func(Handle linker, byte* module, nuint moduleLen, byte* name, nuint nameLen, IntPtr type, Function.Native.WasmtimeFuncCallback callback, IntPtr data, Function.Native.Finalizer? finalizer); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static unsafe extern IntPtr wasmtime_linker_define_func_unchecked(Handle linker, byte* module, nuint moduleLen, byte* name, nuint nameLen, IntPtr type, Function.Native.WasmtimeFuncUncheckedCallback callback, IntPtr data, Function.Native.Finalizer? finalizer); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_linker_instantiate(Handle linker, IntPtr context, Module.Handle module, out ExternInstance instance, out IntPtr trap); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static unsafe extern IntPtr wasmtime_linker_module(Handle linker, IntPtr context, byte* name, nuint len, Module.Handle module); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static unsafe extern IntPtr wasmtime_linker_get_default(Handle linker, IntPtr context, byte* name, nuint len, out ExternFunc func); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static unsafe extern bool wasmtime_linker_get(Handle linker, IntPtr context, byte* module, nuint moduleLen, byte* name, nuint nameLen, out Extern func); } diff --git a/src/Memory.cs b/src/Memory.cs index 45189440..f66ad57e 100644 --- a/src/Memory.cs +++ b/src/Memory.cs @@ -45,11 +45,26 @@ 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); + var error = Native.wasmtime_memorytype_new( + (ulong)minimum, + maximum is not null, + (ulong)(maximum ?? 0), + is64Bit, + IsShared, + Native.DefaultMemoryPageSizeLog2, + out var typeHandle + ); + if (error != IntPtr.Zero) + { + throw WasmtimeException.FromOwnedError(error); + } + if (typeHandle == IntPtr.Zero) + { + throw new InvalidOperationException("Failed to create a WebAssembly memory type."); + } 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) @@ -59,7 +74,10 @@ public Memory(Store store, long minimum = 0, long? maximum = null, bool is64Bit } finally { - Native.wasm_memorytype_delete(typeHandle); + if (typeHandle != IntPtr.Zero) + { + Native.wasm_memorytype_delete(typeHandle); + } } } @@ -583,39 +601,48 @@ internal Memory(Store store, ExternMemory memory) internal static class Native { - [DllImport(Engine.LibraryName)] + public const byte DefaultMemoryPageSizeLog2 = 16; + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_memory_new(IntPtr context, IntPtr typeHandle, out ExternMemory memory); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static unsafe extern byte* wasmtime_memory_data(IntPtr context, in ExternMemory memory); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern nuint wasmtime_memory_data_size(IntPtr context, in ExternMemory memory); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern ulong wasmtime_memory_size(IntPtr context, in ExternMemory memory); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_memory_grow(IntPtr context, in ExternMemory memory, ulong delta, out ulong prev); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] 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); - - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] + 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, CallingConvention = CallingConvention.Cdecl)] public static extern ulong wasmtime_memorytype_minimum(IntPtr type); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool wasmtime_memorytype_maximum(IntPtr type, out ulong max); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool wasmtime_memorytype_is64(IntPtr type); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasm_memorytype_delete(IntPtr handle); } diff --git a/src/Module.cs b/src/Module.cs index 421558e7..5240daa7 100644 --- a/src/Module.cs +++ b/src/Module.cs @@ -20,7 +20,7 @@ public void Dispose() private static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasm_byte_vec_delete(in ByteArray vec); } } @@ -413,31 +413,31 @@ protected override bool ReleaseHandle() internal static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static unsafe extern IntPtr wasmtime_module_new(Engine.Handle engine, byte* bytes, UIntPtr size, out IntPtr handle); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_module_delete(IntPtr module); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_module_imports(IntPtr module, out ImportTypeArray imports); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_module_exports(IntPtr module, out ExportTypeArray exports); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static unsafe extern IntPtr wasmtime_wat2wasm(byte* text, nuint len, out ByteArray bytes); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern unsafe IntPtr wasmtime_module_validate(Engine.Handle engine, byte* bytes, UIntPtr size); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_module_serialize(Handle module, out ByteArray bytes); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern unsafe IntPtr wasmtime_module_deserialize(Engine.Handle engine, byte* bytes, UIntPtr size, out IntPtr handle); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_module_deserialize_file(Engine.Handle engine, [MarshalAs(Extensions.LPUTF8Str)] string path, out IntPtr handle); } diff --git a/src/Store.cs b/src/Store.cs index d53295ab..d1b4b06f 100644 --- a/src/Store.cs +++ b/src/Store.cs @@ -83,22 +83,22 @@ public void SetEpochDeadline(ulong deadline) private static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_context_gc(IntPtr handle); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_context_set_fuel(IntPtr handle, ulong fuel); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_context_get_fuel(IntPtr handle, out ulong fuel); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_context_set_wasi(IntPtr handle, IntPtr config); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_context_set_epoch_deadline(IntPtr handle, ulong ticksBeyondCurrent); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_context_get_data(IntPtr handle); } @@ -318,18 +318,19 @@ protected override bool ReleaseHandle() private static class Native { + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void Finalizer(IntPtr data); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_store_new(Engine.Handle engine, IntPtr data, Finalizer? finalizer); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_store_context(Handle store); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_store_delete(IntPtr store); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_store_limiter(Handle store, long memory_size, long table_elements, long instances, long tables, long memories); } diff --git a/src/Table.cs b/src/Table.cs index 34fb1139..2aa2fe25 100644 --- a/src/Table.cs +++ b/src/Table.cs @@ -256,35 +256,35 @@ internal struct Limits public uint max; } - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_table_new(IntPtr context, TypeHandle type, in Value val, out ExternTable table); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool wasmtime_table_get(IntPtr context, in ExternTable table, ulong index, out Value val); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_table_set(IntPtr context, in ExternTable table, ulong index, in Value val); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern ulong wasmtime_table_size(IntPtr context, in ExternTable table); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_table_grow(IntPtr context, in ExternTable table, ulong delta, in Value value, out ulong prev); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_table_type(IntPtr context, in ExternTable table); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasm_tabletype_new(IntPtr valueType, in Limits limits); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasm_tabletype_element(IntPtr type); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static unsafe extern Limits* wasm_tabletype_limits(IntPtr type); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasm_tabletype_delete(IntPtr handle); } diff --git a/src/TrapException.cs b/src/TrapException.cs index a158dd0d..94551618 100644 --- a/src/TrapException.cs +++ b/src/TrapException.cs @@ -37,8 +37,112 @@ public enum TrapCode Unreachable = 9, /// The trap was the result of interrupting execution. Interrupt = 10, +#if WASMTIME_DEV + /// The trap was the result of running out of the configured fuel amount. + OutOfFuel = 11, + /// + /// The trap was the result of atomic wait operations on non-shared memory. + /// + AtomicWaitNonSharedMemory = 12, + /// + /// The trap was the result of a call to a null reference. + /// + NullReference = 13, + /// + /// The trap was the result of an attempt to access beyond the bounds of an array. + /// + ArrayOutOfBounds = 14, + /// + /// The trap was the result of an allocation that was too large to succeed. + /// + AllocationTooLarge = 15, + /// + /// The trap was the result of an attempt to cast a reference to a type that it is not an instance of. + /// + CastFailure = 16, + /// + /// The trap was the result of a component calling another component that would have violated the reentrance rules. + /// + CannotEnterComponent = 17, + /// + /// The trap was the result of an async-lifted export failing to return a valid async result. + /// + /// + /// An async-lifted export failed to produce a result by calling `task.return` before returning `STATUS_DONE` + /// and/or after all host tasks completed. + /// + NoAsyncResult = 18, + /// + /// The trap was the result of suspending to a tag for which there is no active handler. + /// + UnhandledTag = 19, + /// + /// The trap was the result of an attempt to resume a continuation twice. + /// + ContinuationAlreadyConsumed = 20, + /// + /// The trap was the result of a Pulley opcode executed at runtime when the opcode was disabled at compile time. + /// + DisabledOpCode = 21, + /// + /// The trap was the result of an async event loop deadlock. + /// + /// + /// The async event loop cannot make further progress given that all host tasks have completed + /// and any/all host-owned stream/future handles have been dropped. + /// + AsyncDeadlock = 22, + /// + /// The trap was the result of a component instance trying to call an import or intrinsic when not allowed. + /// + /// + /// When the component-model feature is enabled this trap represents 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. + /// + CannotLeaveComponent = 23, + /// + /// The trap was the result of a synchronous task attempting to make a potentially blocking call prior to returning. + /// + CannotBlockSyncTask = 24, + /// + /// The trap was the result of a component trying to lift a char with an invalid bit pattern. + /// + InvalidChar = 25, + /// + /// Debug assertion generated for a fused adapter regarding the expected completion of a string encoding operation. + /// + DebugAssertStringEncodingFinished = 26, + /// + /// Debug assertion generated for a fused adapter regarding a string encoding operation. + /// + DebugAssertEqualCodeUnits = 27, + /// + /// Debug assertion generated for a fused adapter regarding the alignment of a pointer. + /// + DebugAssertPointerAligned = 28, + /// + /// Debug assertion generated for a fused adapter regarding the upper bits of a 64-bit value. + /// + DebugAssertUpperBitsUnset = 29, + /// + /// The trap was the result of a component trying to lift or lower a string past the end of its memory. + /// + StringOutOfBounds = 30, + /// + /// The trap was the result of a component trying to lift or lower a list past the end of its memory. + /// + ListOutOfBounds = 31, + /// + /// The trap was the result of a component using an invalid discriminant when lowering a variant value. + /// + InvalidDiscriminant = 32, + /// + /// The trap was the result of a component passing an unaligned pointer when lifting or lowering a value. + /// + UnalignedPointer = 33 +#else /// - /// The trap was the result of executing a function that was `canon lift`'d, then `canonlower`'d, then called. + /// The trap was the result of executing a function that was `canon lift`'d, then `canonlower`'d, then called. /// /// /// When the component model feature is enabled this trap represents a function that was `canon lift`'d, @@ -84,6 +188,7 @@ public enum TrapCode /// The trap was the result of a Pulley opcode executed at runtime when the opcode was disabled at compile time. /// DisabledOpCode = 20 +#endif } /// @@ -134,16 +239,16 @@ unsafe internal TrapFrame(IntPtr frame) private static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern nuint wasm_frame_func_offset(IntPtr frame); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern nuint wasm_frame_module_offset(IntPtr frame); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern unsafe ByteArray* wasmtime_frame_func_name(IntPtr frame); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern unsafe ByteArray* wasmtime_frame_module_name(IntPtr frame); } } @@ -339,19 +444,19 @@ public void Dispose() } } - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasm_trap_message(IntPtr trap, out ByteArray message); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasm_trap_trace(IntPtr trap, out FrameArray frames); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasm_trap_delete(IntPtr trap); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasm_frame_vec_delete(in FrameArray vec); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] internal static extern bool wasmtime_trap_code(IntPtr trap, out byte exitCode); } diff --git a/src/Value.cs b/src/Value.cs index eff55005..db75e3b3 100644 --- a/src/Value.cs +++ b/src/Value.cs @@ -142,10 +142,10 @@ public static ValueKind ToKind(IntPtr type) private static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasm_valtype_new(byte kind); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern byte wasm_valtype_kind(IntPtr valueType); } @@ -188,10 +188,10 @@ public void Dispose() private static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasm_valtype_vec_delete(in ValueTypeArray vec); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasm_valtype_vec_new_uninitialized(out ValueTypeArray vec, UIntPtr len); } } @@ -212,9 +212,27 @@ private static class Native /// . /// /// +#if WASMTIME_DEV + [StructLayout(LayoutKind.Explicit, Size = 32)] + internal struct Value + { + static Value() + { + // Ensure the struct size matches the expected wasmtime_val_t size. + System.Diagnostics.Debug.Assert(Marshal.SizeOf(typeof(Value)) == 32, + $"Value struct size mismatch: expected 32, got {Marshal.SizeOf(typeof(Value))}"); + } +#else [StructLayout(LayoutKind.Sequential)] internal struct Value { + static Value() + { + // Ensure the struct size matches the expected wasmtime_val_t size. + System.Diagnostics.Debug.Assert(Marshal.SizeOf(typeof(Value)) == 24, + $"Value struct size mismatch: expected 24, got {Marshal.SizeOf(typeof(Value))}"); + } +#endif public void Release(Store store) { Native.wasmtime_val_unroot(store.Context.handle, this); @@ -467,32 +485,40 @@ ref value.of.externref public static class Native { + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void Finalizer(IntPtr data); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_val_unroot(IntPtr context, in Value val); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool wasmtime_externref_new(IntPtr context, IntPtr data, Finalizer? finalizer, ref ExternRef @out); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasmtime_externref_data(IntPtr context, in ExternRef externref); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_externref_unroot(IntPtr context, in ExternRef externref); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_externref_from_raw(IntPtr context, uint raw, out ExternRef @out); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern uint wasmtime_externref_to_raw(IntPtr context, in ExternRef externref); } public static readonly Native.Finalizer Finalizer = (p) => GCHandle.FromIntPtr(p).Free(); +#if WASMTIME_DEV + [FieldOffset(0)] + private ValueKind kind; + [FieldOffset(8)] + private ValueUnion of; +#else private ValueKind kind; private ValueUnion of; +#endif } [StructLayout(LayoutKind.Explicit)] @@ -523,9 +549,40 @@ internal unsafe struct ValueUnion public V128 v128; } +#if WASMTIME_DEV + [StructLayout(LayoutKind.Sequential)] + internal struct AnyRef + { + static AnyRef() => System.Diagnostics.Debug.Assert(Marshal.SizeOf(typeof(AnyRef)) == 24); + + public ulong store; + + private uint __private1; + + private uint __private2; + + private IntPtr __private3; + } + + [StructLayout(LayoutKind.Sequential)] + internal struct ExternRef + { + static ExternRef() => System.Diagnostics.Debug.Assert(Marshal.SizeOf(typeof(ExternRef)) == 24); + + public ulong store; + + private uint __private1; + + private uint __private2; + + private IntPtr __private3; + } +#else [StructLayout(LayoutKind.Sequential)] internal struct AnyRef { + static AnyRef() => System.Diagnostics.Debug.Assert(Marshal.SizeOf(typeof(AnyRef)) == 16); + public ulong store; private uint __private1; @@ -536,10 +593,13 @@ internal struct AnyRef [StructLayout(LayoutKind.Sequential)] internal struct ExternRef { + static ExternRef() => System.Diagnostics.Debug.Assert(Marshal.SizeOf(typeof(ExternRef)) == 16); + public ulong store; private uint __private1; private uint __private2; } +#endif } diff --git a/src/WasiConfiguration.cs b/src/WasiConfiguration.cs index 1f397f00..580e5959 100644 --- a/src/WasiConfiguration.cs +++ b/src/WasiConfiguration.cs @@ -487,17 +487,17 @@ protected override bool ReleaseHandle() private static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr wasi_config_new(); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasi_config_delete(IntPtr config); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public unsafe static extern bool wasi_config_set_argv(Handle config, nuint argc, byte** argv); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern unsafe bool wasi_config_set_env( Handle config, @@ -506,40 +506,40 @@ public static extern unsafe bool wasi_config_set_env( byte*[] values ); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasi_config_inherit_env(Handle config); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool wasi_config_set_stdin_file( Handle config, [MarshalAs(Extensions.LPUTF8Str)] string path ); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasi_config_inherit_stdin(Handle config); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool wasi_config_set_stdout_file( Handle config, [MarshalAs(Extensions.LPUTF8Str)] string path ); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasi_config_inherit_stdout(Handle config); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool wasi_config_set_stderr_file( Handle config, [MarshalAs(Extensions.LPUTF8Str)] string path ); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasi_config_inherit_stderr(Handle config); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool wasi_config_preopen_dir( Handle config, diff --git a/src/WasmtimeException.cs b/src/WasmtimeException.cs index 88298034..0018dff2 100644 --- a/src/WasmtimeException.cs +++ b/src/WasmtimeException.cs @@ -82,16 +82,16 @@ internal static WasmtimeException FromOwnedError(IntPtr error) internal static class Native { - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_error_message(IntPtr error, out ByteArray message); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_error_wasm_trace(IntPtr error, out TrapException.Native.FrameArray frames); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern void wasmtime_error_delete(IntPtr error); - [DllImport(Engine.LibraryName)] + [DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool wasmtime_error_exit_status(IntPtr error, out int exitStatus); }