Skip to content

Commit

Permalink
feat(go-sdk): add wasi hostcalls used by the Go SDK
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
leonm1 committed Dec 13, 2024
1 parent 63cb9c1 commit 1af87ce
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
10 changes: 9 additions & 1 deletion include/proxy-wasm/exports.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ Word wasi_unstable_args_sizes_get(Word argc_ptr, Word argv_buf_size_ptr);
void wasi_unstable_proc_exit(Word);
Word wasi_unstable_clock_time_get(Word, uint64_t, Word);
Word wasi_unstable_random_get(Word, Word);
Word wasi_unstable_fd_filestat_get(Word fd, Word statOut);
Word wasi_unstable_fd_readdir(Word fd, Word buf, Word buf_len, int64_t cookie, Word bufused);
Word wasi_unstable_path_filestat_get(Word fd, Word flags, Word path, Word path_len, Word statOut);
Word wasi_unstable_fd_fdstat_set_flags(Word fd, Word flags);
Word wasi_unstable_sched_yield();
Word wasi_unstable_poll_oneoff(Word in, Word out, Word nsubscriptions, Word nevents);
Word pthread_equal(Word left, Word right);
void emscripten_notify_memory_growth(Word);

Expand All @@ -172,7 +178,9 @@ void emscripten_notify_memory_growth(Word);
#define FOR_ALL_WASI_FUNCTIONS(_f) \
_f(fd_write) _f(fd_read) _f(fd_seek) _f(fd_close) _f(fd_fdstat_get) _f(environ_get) \
_f(environ_sizes_get) _f(args_get) _f(args_sizes_get) _f(clock_time_get) _f(random_get) \
_f(proc_exit) _f(path_open) _f(fd_prestat_get) _f(fd_prestat_dir_name)
_f(proc_exit) _f(path_open) _f(fd_prestat_get) _f(fd_prestat_dir_name) \
_f(fd_filestat_get) _f(fd_readdir) _f(path_filestat_get) _f(fd_fdstat_set_flags) \
_f(sched_yield) _f(poll_oneoff)

// Helpers to generate a stub to pass to VM, in place of a restricted proxy-wasm capability.
#define _CREATE_PROXY_WASM_STUB(_fn) \
Expand Down
23 changes: 12 additions & 11 deletions include/proxy-wasm/wasm_vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ using WasmCallback_WWl = Word (*)(Word, int64_t);
using WasmCallback_WWlWW = Word (*)(Word, int64_t, Word, Word);
using WasmCallback_WWm = Word (*)(Word, uint64_t);
using WasmCallback_WWmW = Word (*)(Word, uint64_t, Word);
using WasmCallback_WWWWlW = Word (*)(Word, Word, Word, int64_t, Word);
using WasmCallback_WWWWWWllWW = Word (*)(Word, Word, Word, Word, Word, int64_t, int64_t, Word,
Word);
using WasmCallback_dd = double (*)(double);
Expand All @@ -121,17 +122,17 @@ using WasmCallback_dd = double (*)(double);
_f(proxy_wasm::WasmCallbackVoid<4>) _f(proxy_wasm::WasmCallbackWord<0>) \
_f(proxy_wasm::WasmCallbackWord<1>) _f(proxy_wasm::WasmCallbackWord<2>) \
_f(proxy_wasm::WasmCallbackWord<3>) _f(proxy_wasm::WasmCallbackWord<4>) \
_f(proxy_wasm::WasmCallbackWord<5>) _f(proxy_wasm::WasmCallbackWord<6>) \
_f(proxy_wasm::WasmCallbackWord<7>) _f(proxy_wasm::WasmCallbackWord<8>) \
_f(proxy_wasm::WasmCallbackWord<9>) \
_f(proxy_wasm::WasmCallbackWord<10>) \
_f(proxy_wasm::WasmCallbackWord<12>) \
_f(proxy_wasm::WasmCallback_WWl) \
_f(proxy_wasm::WasmCallback_WWlWW) \
_f(proxy_wasm::WasmCallback_WWm) \
_f(proxy_wasm::WasmCallback_WWmW) \
_f(proxy_wasm::WasmCallback_WWWWWWllWW) \
_f(proxy_wasm::WasmCallback_dd)
_f(proxy_wasm::WasmCallbackWord<5>) _f(proxy_wasm::WasmCallbackWord<6>) _f( \
proxy_wasm::WasmCallbackWord<7>) _f(proxy_wasm::WasmCallbackWord<8>) \
_f(proxy_wasm::WasmCallbackWord<9>) _f(proxy_wasm::WasmCallbackWord<10>) \
_f(proxy_wasm::WasmCallbackWord<12>) \
_f(proxy_wasm::WasmCallback_WWl) \
_f(proxy_wasm::WasmCallback_WWlWW) \
_f(proxy_wasm::WasmCallback_WWm) \
_f(proxy_wasm::WasmCallback_WWmW) \
_f(proxy_wasm::WasmCallback_WWWWlW) \
_f(proxy_wasm::WasmCallback_WWWWWWllWW) \
_f(proxy_wasm::WasmCallback_dd)

enum class Cloneable {
NotCloneable, // VMs can not be cloned and should be created from scratch.
Expand Down
29 changes: 29 additions & 0 deletions src/exports.cc
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,13 @@ void wasi_unstable_proc_exit(Word /*exit_code*/) {
context->error("wasi_unstable proc_exit");
}

Word wasi_unstable_sched_yield() { return 0; }

Word wasi_unstable_poll_oneoff(Word /*in*/, Word /*out*/, Word /*nsubscriptions*/,
Word /*nevents*/) {
return 0;
}

Word pthread_equal(Word left, Word right) { return static_cast<uint64_t>(left == right); }

void emscripten_notify_memory_growth(Word /*memory_index*/) {}
Expand Down Expand Up @@ -925,5 +932,27 @@ Word get_log_level(Word result_level_uint32_ptr) {
return WasmResult::Ok;
}

Word wasi_unstable_fd_fdstat_set_flags(Word /*fd*/, Word /*flags*/) {
// Don't support reading of any files.
return 52; // __WASI_ERRNO_ENOSYS
}

Word wasi_unstable_fd_filestat_get(Word /*fd*/, Word /*statOut*/) {
// Don't support reading of any files.
return 52; // __WASI_ERRNO_ENOSYS
}

Word wasi_unstable_fd_readdir(Word /*fd*/, Word /*buf*/, Word /*buf_len*/, int64_t /*cookie*/,
Word /*bufused*/) {
// Don't support reading of any files.
return 52; // __WASI_ERRNO_ENOSYS
}

Word wasi_unstable_path_filestat_get(Word /*fd*/, Word /*flags*/, Word /*path*/, Word /*path_len*/,
Word /*statOut*/) {
// Don't support reading of any files.
return 52; // __WASI_ERRNO_ENOSYS
}

} // namespace exports
} // namespace proxy_wasm

0 comments on commit 1af87ce

Please sign in to comment.