Stream: git-wasmtime

Topic: wasmtime / Issue #1230 WasmTime.Net: Access to Handle in ...


view this post on Zulip Wasmtime GitHub notifications bot (Mar 05 2020 at 08:56):

christophwille opened Issue #1230:

I originally built https://github.com/christophwille/csharp-opa-wasm/ using WasmerSharp. Today I started my initial run on porting it to WasmTime, however, I ran into a snag:

https://github.com/christophwille/csharp-opa-wasm/blob/master/WasmTimeTest/Program.cs#L19

All my imports are satisfied by name, however, the env.memory import bombs, exception details in the source code via comment, but basically the wasm expects two pages of memory minimum.

The WasmerSharp equivalent is here https://github.com/christophwille/csharp-opa-wasm/blob/master/src/Opa.Wasm/OpaPolicy.cs#L14. My guess is that I'd actually need the handle here which is internal for Memory, or: I am using the entirely wrong class because I am translating from a different API by similarity...

view this post on Zulip Wasmtime GitHub notifications bot (Mar 05 2020 at 08:57):

christophwille edited Issue #1230:

I originally built https://github.com/christophwille/csharp-opa-wasm/ using WasmerSharp. Today I started my initial run on porting it to WasmTime, however, I ran into a snag with the import for env.memory:

https://github.com/christophwille/csharp-opa-wasm/blob/master/WasmTimeTest/Program.cs#L19

All my imports are satisfied by name, however, the env.memory import bombs, exception details in the source code via comment, but basically the wasm expects two pages of memory minimum.

The WasmerSharp equivalent is here https://github.com/christophwille/csharp-opa-wasm/blob/master/src/Opa.Wasm/OpaPolicy.cs#L14. My guess is that I'd actually need the handle here which is internal for Memory, or: I am using the entirely wrong class because I am translating from a different API by similarity...

view this post on Zulip Wasmtime GitHub notifications bot (Mar 05 2020 at 09:36):

tschneidereit commented on Issue #1230:

CC @peterhuene

view this post on Zulip Wasmtime GitHub notifications bot (Mar 05 2020 at 18:54):

christophwille commented on Issue #1230:

ok, I traced the min exception to here:

https://github.com/bytecodealliance/wasmtime/blob/master/crates/misc/dotnet/src/Bindings/MemoryBinding.cs#L57

and yes, the wat shows (import "env" "memory" (memory $env.memory 2)) with a minimum of 2. This fixes the exception I reported. Just for clarification: providing more min memory than min requested is really a problem?

view this post on Zulip Wasmtime GitHub notifications bot (Mar 05 2020 at 19:03):

peterhuene commented on Issue #1230:

Hi @christophwille. I think these restrictions in the .NET API should be relaxed so that the host doesn't have to specify exactly the same values.

By the way, the constructor to Memory expresses the minimum and maximums in page sizes, so this should do it:

EnvMemory = new Memory(2); // min page size = 2

view this post on Zulip Wasmtime GitHub notifications bot (Mar 05 2020 at 19:03):

peterhuene edited a comment on Issue #1230:

Hi @christophwille. I think these restrictions in the .NET API should be relaxed so that the host doesn't have to specify exactly the same values.

By the way, the constructor to Memory expresses the minimum and maximums in page sizes, so this should do it:

EnvMemory = new Memory(2); // min page size = 2

view this post on Zulip Wasmtime GitHub notifications bot (Mar 05 2020 at 19:04):

peterhuene assigned Issue #1230:

I originally built https://github.com/christophwille/csharp-opa-wasm/ using WasmerSharp. Today I started my initial run on porting it to WasmTime, however, I ran into a snag with the import for env.memory:

https://github.com/christophwille/csharp-opa-wasm/blob/master/WasmTimeTest/Program.cs#L19

All my imports are satisfied by name, however, the env.memory import bombs, exception details in the source code via comment, but basically the wasm expects two pages of memory minimum.

The WasmerSharp equivalent is here https://github.com/christophwille/csharp-opa-wasm/blob/master/src/Opa.Wasm/OpaPolicy.cs#L14. My guess is that I'd actually need the handle here which is internal for Memory, or: I am using the entirely wrong class because I am translating from a different API by similarity...

view this post on Zulip Wasmtime GitHub notifications bot (Mar 05 2020 at 19:05):

peterhuene commented on Issue #1230:

It also appears that the doc comment for the Memory constructor is missing param text too.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 05 2020 at 19:05):

peterhuene edited a comment on Issue #1230:

Hi @christophwille. I think these restrictions in the .NET API should be relaxed so that the host doesn't have to specify exactly the same values.

By the way, the constructor to Memory expresses the minimum and maximums in page units, so this should do it:

EnvMemory = new Memory(2); // min page size = 2

view this post on Zulip Wasmtime GitHub notifications bot (Mar 05 2020 at 19:21):

christophwille commented on Issue #1230:

Yes, thanks, the min page I figured out by reading the source code of WasmTime.Net.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 05 2020 at 20:01):

christophwille commented on Issue #1230:

I completed porting to WasmTime, please see https://github.com/christophwille/csharp-opa-wasm/tree/master/WasmTimeTest. It is much more readable thanks to DynamicObject (never cared to nicely hide the necessary magic in WasmerSharp). I think I'll port the NuGet that I create over to WasmTime too.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 05 2020 at 22:37):

peterhuene commented on Issue #1230:

@christophwille that's awesome!

If there are other improvements you'd like to see regarding the Wasmtime .NET API, we're definitely open to suggestions and contributions!

view this post on Zulip Wasmtime GitHub notifications bot (Mar 06 2020 at 06:26):

christophwille commented on Issue #1230:

After that little memory snag, the only minor issue was the null-terminated strings; however, I already had the code for WasmerSharp, so this translated nicely to Memory.Span. I don't know how common those null-terminated strings are, but maybe having a ReadNullTerminatedString baked into Memory might be useful (but only if OPA isn't the only one out there doing it this way).

view this post on Zulip Wasmtime GitHub notifications bot (Mar 09 2020 at 17:22):

peterhuene commented on Issue #1230:

ExternMemory.ReadNullTerminatedString was added after 0.12.0 as well and would be included in the next release.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 09 2020 at 17:23):

peterhuene edited a comment on Issue #1230:

ExternMemory.ReadNullTerminatedString was added after 0.12.0 (I think? I'd have to check) as well and would be included in the next release.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 06 2020 at 23:52):

peterhuene commented on Issue #1230:

This should now be fixed in 0.15.0 since it uses the new internal Wasmtime linker rather than implementing linker in the C# API. For future issues, we've created a new repro at https://github.com/bytecodealliance/wasmtime-dotnet.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 06 2020 at 23:52):

peterhuene closed Issue #1230 (assigned to peterhuene):

I originally built https://github.com/christophwille/csharp-opa-wasm/ using WasmerSharp. Today I started my initial run on porting it to WasmTime, however, I ran into a snag with the import for env.memory:

https://github.com/christophwille/csharp-opa-wasm/blob/master/WasmTimeTest/Program.cs#L19

All my imports are satisfied by name, however, the env.memory import bombs, exception details in the source code via comment, but basically the wasm expects two pages of memory minimum.

The WasmerSharp equivalent is here https://github.com/christophwille/csharp-opa-wasm/blob/master/src/Opa.Wasm/OpaPolicy.cs#L14. My guess is that I'd actually need the handle here which is internal for Memory, or: I am using the entirely wrong class because I am translating from a different API by similarity...

view this post on Zulip Wasmtime GitHub notifications bot (Apr 07 2020 at 00:03):

peterhuene transferred Issue #1230 (assigned to peterhuene):

I originally built https://github.com/christophwille/csharp-opa-wasm/ using WasmerSharp. Today I started my initial run on porting it to WasmTime, however, I ran into a snag with the import for env.memory:

https://github.com/christophwille/csharp-opa-wasm/blob/master/WasmTimeTest/Program.cs#L19

All my imports are satisfied by name, however, the env.memory import bombs, exception details in the source code via comment, but basically the wasm expects two pages of memory minimum.

The WasmerSharp equivalent is here https://github.com/christophwille/csharp-opa-wasm/blob/master/src/Opa.Wasm/OpaPolicy.cs#L14. My guess is that I'd actually need the handle here which is internal for Memory, or: I am using the entirely wrong class because I am translating from a different API by similarity...


Last updated: Nov 22 2024 at 17:03 UTC