Change wasm_module_new to use Module::from_binary.
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.
This commit is contained in:
@@ -180,6 +180,21 @@ namespace Wasmtime
|
||||
}
|
||||
}
|
||||
|
||||
internal class WasmConfigHandle : SafeHandle
|
||||
{
|
||||
public WasmConfigHandle() : base(IntPtr.Zero, true)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool IsInvalid => handle == IntPtr.Zero;
|
||||
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
Interop.wasm_config_delete(handle);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
internal class WasiConfigHandle : SafeHandle
|
||||
{
|
||||
public WasiConfigHandle() : base(IntPtr.Zero, true)
|
||||
@@ -277,6 +292,20 @@ namespace Wasmtime
|
||||
WASM_FUNCREF,
|
||||
}
|
||||
|
||||
internal enum wasmtime_strategy_t : byte
|
||||
{
|
||||
WASMTIME_STRATEGY_AUTO,
|
||||
WASMTIME_STRATEGY_CRANELIFT,
|
||||
WASMTIME_STRATEGY_LIGHTBEAM
|
||||
}
|
||||
|
||||
internal enum wasmtime_opt_level_t : byte
|
||||
{
|
||||
WASMTIME_OPT_LEVEL_NONE,
|
||||
WASMTIME_OPT_LEVEL_SPEED,
|
||||
WASMTIME_OPT_LEVEL_SPEED_AND_SIZE
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
internal struct wasm_val_union_t
|
||||
{
|
||||
@@ -514,6 +543,9 @@ namespace Wasmtime
|
||||
[DllImport(LibraryName)]
|
||||
public static extern EngineHandle wasm_engine_new();
|
||||
|
||||
[DllImport(LibraryName)]
|
||||
public static extern EngineHandle wasm_engine_new_with_config(WasmConfigHandle config);
|
||||
|
||||
[DllImport(LibraryName)]
|
||||
public static extern void wasm_engine_delete(IntPtr engine);
|
||||
|
||||
@@ -828,6 +860,14 @@ namespace Wasmtime
|
||||
[DllImport(LibraryName)]
|
||||
public static extern bool wasm_memory_grow(MemoryHandle memory, uint delta);
|
||||
|
||||
// Wasm config
|
||||
|
||||
[DllImport(LibraryName)]
|
||||
public static extern WasmConfigHandle wasm_config_new();
|
||||
|
||||
[DllImport(LibraryName)]
|
||||
public static extern void wasm_config_delete(IntPtr config);
|
||||
|
||||
// WASI config
|
||||
|
||||
[DllImport(LibraryName)]
|
||||
@@ -900,5 +940,34 @@ namespace Wasmtime
|
||||
|
||||
[DllImport(LibraryName)]
|
||||
public static extern IntPtr wasi_instance_bind_import(WasiInstanceHandle instance, IntPtr importType);
|
||||
}
|
||||
|
||||
// Wasmtime config
|
||||
|
||||
[DllImport(LibraryName)]
|
||||
public static extern void wasmtime_config_debug_info_set(WasmConfigHandle config, [MarshalAs(UnmanagedType.I1)] bool enable);
|
||||
|
||||
[DllImport(LibraryName)]
|
||||
public static extern void wasmtime_config_wasm_threads_set(WasmConfigHandle config, [MarshalAs(UnmanagedType.I1)] bool enable);
|
||||
|
||||
[DllImport(LibraryName)]
|
||||
public static extern void wasmtime_config_wasm_reference_types_set(WasmConfigHandle config, [MarshalAs(UnmanagedType.I1)] bool enable);
|
||||
|
||||
[DllImport(LibraryName)]
|
||||
public static extern IntPtr wasmtime_config_wasm_simd_set(WasmConfigHandle config, [MarshalAs(UnmanagedType.I1)] bool enable);
|
||||
|
||||
[DllImport(LibraryName)]
|
||||
public static extern void wasmtime_config_wasm_bulk_memory_set(WasmConfigHandle config, [MarshalAs(UnmanagedType.I1)] bool enable);
|
||||
|
||||
[DllImport(LibraryName)]
|
||||
public static extern void wasmtime_config_wasm_multi_value_set(WasmConfigHandle config, [MarshalAs(UnmanagedType.I1)] bool enable);
|
||||
|
||||
[DllImport(LibraryName)]
|
||||
public static extern void wasmtime_config_strategy_set(WasmConfigHandle config, wasmtime_strategy_t strategy);
|
||||
|
||||
[DllImport(LibraryName)]
|
||||
public static extern void wasmtime_config_cranelift_debug_verifier_set(WasmConfigHandle config, bool enable);
|
||||
|
||||
[DllImport(LibraryName)]
|
||||
public static extern void wasmtime_config_cranelift_opt_level_set(WasmConfigHandle config, wasmtime_opt_level_t level);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user