Skip to content
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

Pass a headers pointer into incoming-response-headers #9

Closed
brendandburns opened this issue Mar 5, 2023 · 4 comments
Closed

Pass a headers pointer into incoming-response-headers #9

brendandburns opened this issue Mar 5, 2023 · 4 comments

Comments

@brendandburns
Copy link
Contributor

For similar reasons to #8 it is challenging to implement returning headers for an incoming response because it returns a fields structure, while it is possible to implement this, I think it makes more sense to leave the memory allocation on the guest side and instead pass a pointer to a headers object into the incoming-response-headers function. (get-headers(incoming-response, ptr, len))

@lukewagner
Copy link
Member

In this case, the returned integer is an index to a fields resource, which avoids eagerly copying all the headers into linear memory at once. I think this is an important ability to maintain, but it is a good question of whether we should perhaps add a new method for when you want to bulk-copy over all the contents of the headers into linear memory at once.

@brendandburns
Copy link
Contributor Author

Yes, but both fields-get and fields-entries require returning string to the caller which means that the host needs to be able to allocate memory in the guest's memory space which isn't obvious how to implement (same as #8).

So bulk is part of it, but managing memory allocation in the guest from the host implementation is the bigger challenge.

@lukewagner
Copy link
Member

lukewagner commented Mar 8, 2023

(Sorry for the slow replies; at a conference this week.) Yes, that's not clear from the signatures (although perhaps the generated headers should include this information in comments). Instead, the protocol for allocation/ownership is specified by the Canonical ABI which says, for every type, how to "lift" (read) and "lower" (write) the type out of and into linear memory. In the case of lists, the main rule is here. To summarize, the memory is cabi_realloced in the guest, then the host writes the elements (which, for list<string> are themselves i32 pairs pointing to cabi_realloced string conents), and finally returns ownership of the list to the import caller.

@brendandburns
Copy link
Contributor Author

I discussed this somewhat more in-depth and it seems that the overall wit approach is going to be to enable someone to provide a buffer, but this mechanism is not currently available. I'm going to close this for now, but leave #8 open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants