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...
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...
tschneidereit commented on Issue #1230:
CC @peterhuene
christophwille commented on Issue #1230:
ok, I traced the min exception to here:
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?
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
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
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...
peterhuene commented on Issue #1230:
It also appears that the doc comment for the
Memory
constructor is missingparam
text too.
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
christophwille commented on Issue #1230:
Yes, thanks, the min page I figured out by reading the source code of WasmTime.Net.
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.
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!
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).
peterhuene commented on Issue #1230:
ExternMemory.ReadNullTerminatedString
was added after 0.12.0 as well and would be included in the next release.
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.
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.
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...
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: Dec 23 2024 at 12:05 UTC