Stream: general

Topic: Understanding GuestMemory


view this post on Zulip osa1 (Dec 30 2020 at 07:44):

I'm implementing GuestMemory for a memory type in my Wasm interpreter, to be able to use wasi-common. Can I assume that whenever wasi-common writes to the memory it first calls mut_borrow, or does it only do that if for some reason it's going to store a memory region somewhere to be used later, or something like that? Would be good to know in what cases mut_borrow will be called by wasi-common.

view this post on Zulip Pat Hickey (Dec 30 2020 at 23:34):

Hi. Yes that’s the idea behind the runtime borrow checker. It will call the borrow functions at the start of (possible) access and the unborrow functions at the end.

view this post on Zulip Pat Hickey (Dec 30 2020 at 23:36):

The runtime borrow checking is something the wiggle crate abstracts away. Wiggle-generated code will call the is_borrowed methods when copying items out of guest memory (to ensure the copy operation is safe) and the borrow methods get called at creation and drop of the GuestSlice / GuestSliceMut / GuestStr / GuestStrMut structs

view this post on Zulip Pat Hickey (Dec 30 2020 at 23:37):

In general I suggest that you use the wiggle-borrow crates implementation of the borrow checker and wire that into your guest memory impl.

view this post on Zulip Pat Hickey (Dec 30 2020 at 23:38):

It’s probably not the most efficient implementation possible but so far we haven’t found that runtime borrow checking is a performance bottleneck. If you do find ways to improve the wiggle-borrow crate we are happy to accept them

view this post on Zulip Pat Hickey (Dec 30 2020 at 23:40):

Btw, I’m most of the way through a rewrite of wasi-common, it’s in a draft PR. So, expect the way you build a wasi common context to change, and other interfaces to it as well.

view this post on Zulip Pat Hickey (Dec 30 2020 at 23:41):

I’m on vacation this week but sometimes I check zulip. I haven’t been watching GitHub. Will be back next week.

view this post on Zulip osa1 (Dec 31 2020 at 14:37):

Thanks @Pat Hickey for the details . I'm already using wiggle-borrow.


Last updated: Dec 23 2024 at 13:07 UTC