-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Streams are challenging to implement because they return pointers #8
Comments
Counter-example: Host manages buffers allocated from guest memory. When guest calls read, host returns a window into the memory. Example: buffered file reader that has a fixed block of memory, say 64kb, Guest reads chunks until end of block, then on the next read the host can page in another 64kb from the file into the same block. Another use case that I'm looking is when multiple shared memories become implemented. Then the host might return a pointer into a shared memory region to avoid copying. I can also see the use case for the guest calling If I had to choose between the two, I'd favor host managed memory because of its advantages in large data handling. |
I think that having both options is a good idea. If we are going to do it host side, I think we absolutely need to implement a good library to make it easy for host-side implementors to support streams. We also probably need to be super clear with people about the ownership semantics (#7) because if it is host managed then you definitely don't want to be calling However, the other thing that I'm worried about is accidental guest-side DOS attacks or memory leaks via host memory allocations. I guess that because the host is allocating things within the WASM memory this might not be an issue, but it feels an awful lot like the distinction between kernel memory and userspace memory, and it is always harder to detect/prevent memory leaks in kernel space memory. |
Admittedly I'm new to WASM and wasmtime, but I'm struggling to see how the host can allocate memory in the guest without the guest exposing some sort of I can see how you can create a new page of memory, but it's totally unclear how you could pass the right pointer back to the guest (and more importantly, how the guest would know that that block of memory is in use) Pointers to how this is supposed to work would be welcome. |
To do this, we could extend the Canonical ABI with a special case for returned lists (either directly or lightly nested, e.g., in a |
Can we add |
btw, I figured out the |
That's a good question, and maybe I'm misunderstanding your idea, but iiuc the challenge with having a |
I think the most important thing is that if the host runtime is using The distinction is whether the guest or the host is in control of the memory allocation in the guest for the purposes of reading. |
And concretely, |
Ah, while that is similar in spirit to what Preview-1 interfaces did, with Wit and the component model, the callee function doesn't have access to the caller's memory. E.g., due to virtualizability, the callee might be another component instance with a distinct linear memory. Or, on the Web, the callee can be JS glue code which doesn't have access to the caller's linear memory. I do like the optimization of allowing the caller to supply a buffer for returned lists though; it's just something we need to add at the Canonical ABI level. I filed component-model/#175 to track and discuss further. |
Closing this in favor of WebAssembly/component-model#175 |
As I look to implement streams, it seems like it is excessively challenging to return a pointer from the stream
read
function.Typically in stream reading (e.g.
fread
in C orInputStream.read
in Java) the pattern is to pass a buffer into the stream read, rather than have the stream return an array of bytes.I think that we should change streams to take a buffer from the guest to write data into, that will make the ownership semantics clearer (#7) and will also make it easier to implement.
The text was updated successfully, but these errors were encountered: