You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We expose allocate and deallocate, which return pointers. This is good to allocate memory so we can set arguments. And we can take a pointer as result and load in a string result. However, there are two issues here:
Minor: we don't include length, so require 0 byte terminated C strings, copying one byte at a time. This causes "nice" crashes when we forget to explicitly add this null byte to some rust data.
Major: If the guest (wasm) calls out to the host (via imports - c_read), it is very hard to call back into the guest. We can now use function tables but it is unclear how to get the index in the first place. Ideally, we do not need to call allocate inside the host function.
Solution:
Don't pass a ptr to memory, but ptr to a Slice (offset, len). Both as a return value from alloc, as well as argument to function calls and free. This lets us clearly specify a size and avoid first problem.
Wasm should never expect a callback to be able to allocate memory. It should pass a pre-allocated buffer to the function where it expects it to be written, the function can return the length written. This is much like old-school C style, which works with very similar constraints as we have. This avoids the callback issue, and also the length guarantess the host function will never write data outside of the pre-allocated buffer.
We expose allocate and deallocate, which return pointers. This is good to allocate memory so we can set arguments. And we can take a pointer as result and load in a string result. However, there are two issues here:
allocate
inside the host function.Solution:
This describes the general idea the slice structure, intended for use over rust-ffi
The text was updated successfully, but these errors were encountered: