-
Notifications
You must be signed in to change notification settings - Fork 266
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
Adds host function interfaces #246
Conversation
This adds two interfaces with only one implementation each, used to decouple end-user code from internals. * api.HostFunctionCallContext - allows access to go Context and Memory * api.Memory - read/write standard types and arbitrary data This currently ports existing code to use the interfaces. It is true that over time we can use structs instead of interfaces internally to save a pointer reference in WASI call sites. However, I'm choosing not to do this right now, as it is more important to see the interfaces work. We should defer optimizing towards structs until after we repackage implementations under the "internal" directory. Fixes #204 Signed-off-by: Adrian Cole <adrian@tetrate.io>
// There are two result parameters: these are offsets in the wasm.HostFunctionCallContext Memory Buffer to write | ||
// corresponding sizes in uint32 little-endian encoding. | ||
// There are two result parameters: these are offsets in the api.HostFunctionCallContext Memory to write | ||
// corresponding sizes in uint32 little-endian encoding. If either are invalid due to memory constraints, this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi @r8d8, this is the sort of comment I'm adding about errno choices. you can make one similarly, and if we need to change later we can update
If either are invalid due to memory constraints, this returns ErrnoFault.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I would add is naming -- maybe putting on top level of repo and use as wazero.HostFunctionCallContext, etc.. together with other future user APIs
|
||
// hasLen returns true if Len is sufficient for sizeInBytes at the given offset. | ||
func (m *MemoryInstance) hasLen(offset uint32, sizeInBytes uint32) bool { | ||
return uint64(offset+sizeInBytes) <= uint64(m.Len()) // uint64 prevents overflow on add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice for overflow prevention
api/host.go
Outdated
@@ -0,0 +1,69 @@ | |||
// Package api only includes constants and interfaces. This ensures no package cycles in implementation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I see nvm the comment ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
incidentally I think we can temporarily put this in the "wasm" package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to wasm package for now as I think even with top-level entry points in the wazero package we'll still be able to keep packages for things like constants if we choose to. I'll show what I mean post-merge in #238
Co-authored-by: Takeshi Yoneda <takeshi@tetrate.io>
Signed-off-by: Adrian Cole <adrian@tetrate.io>
This adds two interfaces with only one implementation each, used to
decouple end-user code from internals.
This currently ports existing code to use the interfaces. It is true
that over time we can use structs instead of interfaces internally to
save a pointer reference in WASI call sites. However, I'm choosing not
to do this right now, as it is more important to see the interfaces
work. We should defer optimizing towards structs until after we
repackage implementations under the "internal" directory.
Fixes #204