Skip to content

Commit d6525dd

Browse files
Bas Geertsemajsturtevant
authored andcommitted
Upgrade to 27.0.0
Changes to the C api: Wasi file and directory permissions Shared Memory support Configuration changes from static/dynamic to a single guard region: https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.memory_guard_size All tests passing
1 parent 603ef95 commit d6525dd

File tree

5 files changed

+66
-30
lines changed

5 files changed

+66
-30
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
33
<DevBuild Condition="'$(DevBuild)'==''">false</DevBuild>
4-
<WasmtimeVersion Condition="'$(WasmtimeVersion)'==''">26.0.1</WasmtimeVersion>
4+
<WasmtimeVersion Condition="'$(WasmtimeVersion)'==''">27.0.0</WasmtimeVersion>
55
<WasmtimeDotnetVersion Condition="'$(WasmtimeDotnetVersion)'==''"></WasmtimeDotnetVersion>
66
<WasmtimePackageVersion Condition="'$(DevBuild)'=='true'">
77
$(WasmtimeVersion)$(WasmtimeDotnetVersion)-dev</WasmtimePackageVersion>

src/Config.cs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -303,24 +303,13 @@ public Config WithStaticMemoryMaximumSize(ulong size)
303303
}
304304

305305
/// <summary>
306-
/// Sets the maximum size of the guard region for static WebAssembly linear memories.
306+
/// Sets the size of the guard region used at the end of a linear memory’s address space reservation
307307
/// </summary>
308-
/// <param name="size">The maximum guard region size for static WebAssembly linear memories, in bytes.</param>
308+
/// <param name="size">The size, in bytes, of the guard region used at the end of a linear memory’s address space reservation</param>
309309
/// <returns>Returns the current config.</returns>
310-
public Config WithStaticMemoryGuardSize(ulong size)
310+
public Config WithMemoryGuardSize(ulong size)
311311
{
312-
Native.wasmtime_config_static_memory_guard_size_set(handle, size);
313-
return this;
314-
}
315-
316-
/// <summary>
317-
/// Sets the maximum size of the guard region for dynamic WebAssembly linear memories.
318-
/// </summary>
319-
/// <param name="size">The maximum guard region size for dynamic WebAssembly linear memories, in bytes.</param>
320-
/// <returns>Returns the current config.</returns>
321-
public Config WithDynamicMemoryGuardSize(ulong size)
322-
{
323-
Native.wasmtime_config_dynamic_memory_guard_size_set(handle, size);
312+
Native.wasmtime_config_memory_guard_size_set(handle, size);
324313
return this;
325314
}
326315

@@ -457,10 +446,7 @@ private static class Native
457446
public static extern void wasmtime_config_static_memory_maximum_size_set(Handle config, ulong size);
458447

459448
[DllImport(Engine.LibraryName)]
460-
public static extern void wasmtime_config_static_memory_guard_size_set(Handle config, ulong size);
461-
462-
[DllImport(Engine.LibraryName)]
463-
public static extern void wasmtime_config_dynamic_memory_guard_size_set(Handle config, ulong size);
449+
public static extern void wasmtime_config_memory_guard_size_set(Handle config, ulong size);
464450

465451
[DllImport(Engine.LibraryName)]
466452
public static extern IntPtr wasmtime_config_cache_config_load(Handle config, [MarshalAs(Extensions.LPUTF8Str)] string? path);

src/Memory.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public class Memory : IExternal
1717
/// <param name="minimum">The minimum number of WebAssembly pages.</param>
1818
/// <param name="maximum">The maximum number of WebAssembly pages, or <c>null</c> to not specify a maximum.</param>
1919
/// <param name="is64Bit"><c>true</c> when memory type represents a 64-bit memory, <c>false</c> when it represents a 32-bit memory.</param>
20-
public Memory(Store store, long minimum = 0, long? maximum = null, bool is64Bit = false)
20+
/// <param name="isShared"><c>true</c> when memory is shared, <c>false</c> when it is not shared.</param>
21+
public Memory(Store store, long minimum = 0, long? maximum = null, bool is64Bit = false, bool isShared = false)
2122
{
2223
if (store is null)
2324
{
@@ -43,8 +44,9 @@ public Memory(Store store, long minimum = 0, long? maximum = null, bool is64Bit
4344
Minimum = minimum;
4445
Maximum = maximum;
4546
Is64Bit = is64Bit;
47+
IsShared = isShared;
4648

47-
var typeHandle = Native.wasmtime_memorytype_new((ulong)minimum, maximum is not null, (ulong)(maximum ?? 0), is64Bit);
49+
var typeHandle = Native.wasmtime_memorytype_new((ulong)minimum, maximum is not null, (ulong)(maximum ?? 0), is64Bit, isShared);
4850
try
4951
{
5052

@@ -61,7 +63,7 @@ public Memory(Store store, long minimum = 0, long? maximum = null, bool is64Bit
6163
Native.wasm_memorytype_delete(typeHandle);
6264
}
6365
}
64-
66+
6567
/// <summary>
6668
/// The size, in bytes, of a WebAssembly memory page.
6769
/// </summary>
@@ -85,6 +87,12 @@ public Memory(Store store, long minimum = 0, long? maximum = null, bool is64Bit
8587
/// <value><c>true</c> if this type of memory represents a 64-bit memory, <c>false</c> otherwise.</value>
8688
public bool Is64Bit { get; }
8789

90+
/// <summary>
91+
/// Gets a value that indicates whether this memory is shared.
92+
/// </summary>
93+
/// <value><c>true</c> if this memory is shared, <c>false</c> otherwise.</value>
94+
public bool IsShared { get; }
95+
8896
/// <summary>
8997
/// Gets the current size of the memory, in WebAssembly page units.
9098
/// </summary>
@@ -595,7 +603,7 @@ internal static class Native
595603
public static extern IntPtr wasmtime_memory_type(IntPtr context, in ExternMemory memory);
596604

597605
[DllImport(Engine.LibraryName)]
598-
public static extern IntPtr wasmtime_memorytype_new(ulong min, [MarshalAs(UnmanagedType.I1)] bool max_present, ulong max, [MarshalAs(UnmanagedType.I1)] bool is_64);
606+
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);
599607

600608
[DllImport(Engine.LibraryName)]
601609
public static extern ulong wasmtime_memorytype_minimum(IntPtr type);

src/WasiConfiguration.cs

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,40 @@
77

88
namespace Wasmtime
99
{
10+
/// <summary>
11+
/// The permissions granted for a directory when preopening it.
12+
/// </summary>
13+
[Flags]
14+
public enum WasiDirectoryPermissions
15+
{
16+
/// <summary>
17+
/// This directory can be read, for example its entries can be iterated.
18+
/// </summary>
19+
Read = 1,
20+
21+
/// <summary>
22+
/// This directory can be written to, for example new files can be created within it.
23+
/// </summary>
24+
Write = 2
25+
}
26+
27+
/// <summary>
28+
/// The permissions granted for files when preopening a directory.
29+
/// </summary>
30+
[Flags]
31+
public enum WasiFilePermissions
32+
{
33+
/// <summary>
34+
/// Files can be read.
35+
/// </summary>
36+
Read = 1,
37+
38+
/// <summary>
39+
/// Files can be written to.
40+
/// </summary>
41+
Write = 2
42+
}
43+
1044
/// <summary>
1145
/// Represents a WASI configuration.
1246
/// </summary>
@@ -249,13 +283,19 @@ public WasiConfiguration WithInheritedStandardError()
249283
return this;
250284
}
251285

286+
287+
252288
/// <summary>
253289
/// Adds a preopen directory to the configuration.
254290
/// </summary>
255291
/// <param name="path">The path to the directory to add.</param>
256292
/// <param name="guestPath">The path the guest will use to open the directory.</param>
293+
/// <param name="directoryPermissions">The permissions that wasm will have to operate on <paramref name="guestPath"/>. This can be used, for example, to provide readonly access to a directory.</param>
294+
/// <param name="filePermissions">The permissions that wasm will have for any file in this directory.</param>
257295
/// <returns>Returns the current configuration.</returns>
258-
public WasiConfiguration WithPreopenedDirectory(string path, string guestPath)
296+
public WasiConfiguration WithPreopenedDirectory(
297+
string path, string guestPath,
298+
WasiDirectoryPermissions directoryPermissions, WasiFilePermissions filePermissions)
259299
{
260300
if (string.IsNullOrEmpty(path))
261301
{
@@ -266,7 +306,7 @@ public WasiConfiguration WithPreopenedDirectory(string path, string guestPath)
266306
throw new ArgumentException("The guest path cannot be null or empty.", nameof(guestPath));
267307
}
268308

269-
_preopenDirs.Add((path, guestPath));
309+
_preopenDirs.Add((path, guestPath, directoryPermissions, filePermissions));
270310
return this;
271311
}
272312

@@ -404,7 +444,7 @@ private void SetPreopenDirectories(Handle config)
404444
{
405445
foreach (var dir in _preopenDirs)
406446
{
407-
if (!Native.wasi_config_preopen_dir(config, dir.Path, dir.GuestPath))
447+
if (!Native.wasi_config_preopen_dir(config, dir.Path, dir.GuestPath, (nuint)dir.directoryPermissions, (nuint)dir.filePermissions))
408448
{
409449
throw new InvalidOperationException($"Failed to preopen directory '{dir.Path}'.");
410450
}
@@ -504,7 +544,9 @@ public static extern bool wasi_config_set_stderr_file(
504544
public static extern bool wasi_config_preopen_dir(
505545
Handle config,
506546
[MarshalAs(Extensions.LPUTF8Str)] string path,
507-
[MarshalAs(Extensions.LPUTF8Str)] string guestPath
547+
[MarshalAs(Extensions.LPUTF8Str)] string guestPath,
548+
nuint dirPerms,
549+
nuint filePerms
508550
);
509551
}
510552

@@ -513,7 +555,7 @@ public static extern bool wasi_config_preopen_dir(
513555
private string? _standardInputPath;
514556
private string? _standardOutputPath;
515557
private string? _standardErrorPath;
516-
private readonly List<(string Path, string GuestPath)> _preopenDirs = new List<(string, string)>();
558+
private readonly List<(string Path, string GuestPath, WasiDirectoryPermissions directoryPermissions, WasiFilePermissions filePermissions)> _preopenDirs = new List<(string, string, WasiDirectoryPermissions, WasiFilePermissions)>();
517559
private bool _inheritArgs = false;
518560
private bool _inheritEnv = false;
519561
private bool _inheritStandardInput = false;

tests/WasiTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public void ItSetsPreopenDirectories(string path)
287287
using var file = new TempFile();
288288

289289
var config = new WasiConfiguration()
290-
.WithPreopenedDirectory(Path.GetDirectoryName(file.Path), "/foo");
290+
.WithPreopenedDirectory(Path.GetDirectoryName(file.Path), "/foo", WasiDirectoryPermissions.Read | WasiDirectoryPermissions.Write, WasiFilePermissions.Read | WasiFilePermissions.Write);
291291

292292
using var engine = new Engine();
293293
using var module = Module.FromTextFile(engine, Path.Combine("Modules", path));

0 commit comments

Comments
 (0)