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

feat(go-sdk): add wasi hostcalls used by the Go SDK #427

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

leonm1
Copy link
Contributor

@leonm1 leonm1 commented Dec 13, 2024

The full Go sdk imports hostcalls not currently exported to the wasm module, making the wasm module fail on instantiation. Per discussion with the Go core maintainers, these functions do not need to be implemented, but they must be present.

@leonm1 leonm1 force-pushed the feat/go-sdk branch 4 times, most recently from b9b4a5e to 1af87ce Compare December 13, 2024 19:48
src/exports.cc Outdated Show resolved Hide resolved
include/proxy-wasm/exports.h Outdated Show resolved Hide resolved
src/exports.cc Outdated Show resolved Hide resolved
src/exports.cc Outdated Show resolved Hide resolved
Copy link
Member

@PiotrSikora PiotrSikora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

Two high-level comments:

  1. It would be good to understand why Go SDK wants to import (and use?) those hostcalls. For filesystem calls - does it try to access some files on startup, and why it doesn't use preopen hostcalls? For yield and polling - does it actually work without making progress or are non-trivial plugins going to deadlock?
  2. Since we're exposing those hostcalls globally, how does it affect other the SDKs? If you try to open files in Rust or C++ files, will they gracefully return user errors (i.e. file not found or similar) or crash due to a missing code path for ENOSYS?

src/exports.cc Outdated Show resolved Hide resolved
src/exports.cc Outdated Show resolved Hide resolved
src/exports.cc Outdated Show resolved Hide resolved
@leonm1
Copy link
Contributor Author

leonm1 commented Dec 18, 2024

  1. It would be good to understand why Go SDK wants to import (and use?) those hostcalls. For filesystem calls - does it try to access some files on startup, and why it doesn't use preopen hostcalls?

Answered elsewhere as well, but I was mistaken about some of the filesystem syscalls. This PR now represents the full minimal set of added hostcalls for a helloworld go plugin to initialize.

For yield and polling - does it actually work without making progress or are non-trivial plugins going to deadlock?

Yield should be fine due to the linked behavior. For polling, I do wonder about that — technically we could support some of the subscription types, but I'm not sure how much value they add in a single-threaded environment anyway, since we only support FDs 1 and 2, which never get "closed" and wouldn't "block" from the wasm modules perspective.

  1. Since we're exposing those hostcalls globally, how does it affect other the SDKs? If you try to open files in Rust or C++ files, will they gracefully return user errors (i.e. file not found or similar) or crash due to a missing code path for ENOSYS?

I tested the CPP host with all of service extensions' cpp and rust plugins. Since these are added hostcalls, they should not affect currently-working wasm modules. I attempted to add explicit calls to each of sched_yield, poll, and fdstat_set_flags (which corresponds to posix's fcntl), and confirmed each translated the libc call to the corresponding wasi hostcall and none complained about the ENOSYS (or ESUCCESS, in sched_yield's case).

src/wasm.cc Outdated Show resolved Hide resolved
@PiotrSikora
Copy link
Member

Since these are added hostcalls, they should not affect currently-working wasm modules.

Right, this won't break any of the existing plugins. My point was mostly that with those changes (well, the earlier version of this PR) plugins that attempt to open files would load successfully, but could break at runtime.

src/wasm.cc Outdated Show resolved Hide resolved
Copy link
Member

@PiotrSikora PiotrSikora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

The full Go sdk imports hostcalls not currently exported to the wasm
module, making the wasm module fail on instantiation. Per discussion
with the Go core maintainers, these functions do not need to be
implemented, but they must be present.

Signed-off-by: Matt Leon <mattleon@google.com>
Copy link
Contributor

@martijneken martijneken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Copy link
Contributor

@mpwarres mpwarres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@martijneken martijneken merged commit c4d7bb0 into proxy-wasm:main Dec 19, 2024
30 checks passed
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

Successfully merging this pull request may close these issues.

4 participants