wasm3 / wasm3-rs

Rust wrapper for Wasm3, the fastest WebAssembly interpreter
MIT License
155 stars 43 forks source link

implement Runtime::resize_memory() #15

Closed bacongobbler closed 4 years ago

bacongobbler commented 4 years ago

This function will resize the number of allocated pages to num_pages. A unit test has been provided to demonstrate how to resize the runtime.

closes #13

Signed-off-by: Matthew Fisher matt.fisher@microsoft.com

Veykril commented 4 years ago

The reason as to why you aren't seeing the error string in the panic is that I only implemented Display to dereference the CString. A panic on the other hand only shows a values debug formatting, the error message you are getting is "runtime ran out of memory".

I just pushed a fix so it displays properly.

Veykril commented 4 years ago

And it seems the reason as to why this errors is that if no modules are loaded the maxPages var is set to 0, so reallocating at that point will always error as this limit is only set once modules are loaded.

bacongobbler commented 4 years ago

I just pushed a fix so it displays properly.

I don't see the fix in master. Where would your fix be?

Thank you for helping me with this!

It's interesting that maxPages would be set to 0 without any modules loaded, especially since Runtime::new() asks for the requested number of pages. You'd think the runtime could be set up before loading a module into the runtime. In either case, thank you for finding that. I'll fiddle around with the test and load a bogus module into the runtime then call resize_memory.

Veykril commented 4 years ago

I don't see the fix in master. Where would your fix be?

Turns out I tried pushing without rebasing first so it failed but I didn't notice that. 40d7a02aa1b578fbbfc4e134f5dac30ccdc34217 manually implements Debug now.

It's interesting that maxPages would be set to 0 without any modules loaded, especially since Runtime::new() asks for the requested number of pages.

That's actually not quite right, the number you supply to the runtime is the stack size in bytes, not the number of memory pages.

Veykril commented 4 years ago

For the test case there is a test in the module.rs file that has the raw bytes of fibonacci wasm module(at least i think it was a fibonacci thing), you could copy that to load as a random module.

bacongobbler commented 4 years ago

All right that oughta do it! Let me know if you'd like me to add further tests elsewhere.