Skip to content

Commit 1af87ce

Browse files
committed
feat(go-sdk): add wasi hostcalls used by the Go SDK
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 <[email protected]>
1 parent 63cb9c1 commit 1af87ce

File tree

3 files changed

+50
-12
lines changed

3 files changed

+50
-12
lines changed

include/proxy-wasm/exports.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ Word wasi_unstable_args_sizes_get(Word argc_ptr, Word argv_buf_size_ptr);
146146
void wasi_unstable_proc_exit(Word);
147147
Word wasi_unstable_clock_time_get(Word, uint64_t, Word);
148148
Word wasi_unstable_random_get(Word, Word);
149+
Word wasi_unstable_fd_filestat_get(Word fd, Word statOut);
150+
Word wasi_unstable_fd_readdir(Word fd, Word buf, Word buf_len, int64_t cookie, Word bufused);
151+
Word wasi_unstable_path_filestat_get(Word fd, Word flags, Word path, Word path_len, Word statOut);
152+
Word wasi_unstable_fd_fdstat_set_flags(Word fd, Word flags);
153+
Word wasi_unstable_sched_yield();
154+
Word wasi_unstable_poll_oneoff(Word in, Word out, Word nsubscriptions, Word nevents);
149155
Word pthread_equal(Word left, Word right);
150156
void emscripten_notify_memory_growth(Word);
151157

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

177185
// Helpers to generate a stub to pass to VM, in place of a restricted proxy-wasm capability.
178186
#define _CREATE_PROXY_WASM_STUB(_fn) \

include/proxy-wasm/wasm_vm.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ using WasmCallback_WWl = Word (*)(Word, int64_t);
111111
using WasmCallback_WWlWW = Word (*)(Word, int64_t, Word, Word);
112112
using WasmCallback_WWm = Word (*)(Word, uint64_t);
113113
using WasmCallback_WWmW = Word (*)(Word, uint64_t, Word);
114+
using WasmCallback_WWWWlW = Word (*)(Word, Word, Word, int64_t, Word);
114115
using WasmCallback_WWWWWWllWW = Word (*)(Word, Word, Word, Word, Word, int64_t, int64_t, Word,
115116
Word);
116117
using WasmCallback_dd = double (*)(double);
@@ -121,17 +122,17 @@ using WasmCallback_dd = double (*)(double);
121122
_f(proxy_wasm::WasmCallbackVoid<4>) _f(proxy_wasm::WasmCallbackWord<0>) \
122123
_f(proxy_wasm::WasmCallbackWord<1>) _f(proxy_wasm::WasmCallbackWord<2>) \
123124
_f(proxy_wasm::WasmCallbackWord<3>) _f(proxy_wasm::WasmCallbackWord<4>) \
124-
_f(proxy_wasm::WasmCallbackWord<5>) _f(proxy_wasm::WasmCallbackWord<6>) \
125-
_f(proxy_wasm::WasmCallbackWord<7>) _f(proxy_wasm::WasmCallbackWord<8>) \
126-
_f(proxy_wasm::WasmCallbackWord<9>) \
127-
_f(proxy_wasm::WasmCallbackWord<10>) \
128-
_f(proxy_wasm::WasmCallbackWord<12>) \
129-
_f(proxy_wasm::WasmCallback_WWl) \
130-
_f(proxy_wasm::WasmCallback_WWlWW) \
131-
_f(proxy_wasm::WasmCallback_WWm) \
132-
_f(proxy_wasm::WasmCallback_WWmW) \
133-
_f(proxy_wasm::WasmCallback_WWWWWWllWW) \
134-
_f(proxy_wasm::WasmCallback_dd)
125+
_f(proxy_wasm::WasmCallbackWord<5>) _f(proxy_wasm::WasmCallbackWord<6>) _f( \
126+
proxy_wasm::WasmCallbackWord<7>) _f(proxy_wasm::WasmCallbackWord<8>) \
127+
_f(proxy_wasm::WasmCallbackWord<9>) _f(proxy_wasm::WasmCallbackWord<10>) \
128+
_f(proxy_wasm::WasmCallbackWord<12>) \
129+
_f(proxy_wasm::WasmCallback_WWl) \
130+
_f(proxy_wasm::WasmCallback_WWlWW) \
131+
_f(proxy_wasm::WasmCallback_WWm) \
132+
_f(proxy_wasm::WasmCallback_WWmW) \
133+
_f(proxy_wasm::WasmCallback_WWWWlW) \
134+
_f(proxy_wasm::WasmCallback_WWWWWWllWW) \
135+
_f(proxy_wasm::WasmCallback_dd)
135136

136137
enum class Cloneable {
137138
NotCloneable, // VMs can not be cloned and should be created from scratch.

src/exports.cc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,13 @@ void wasi_unstable_proc_exit(Word /*exit_code*/) {
885885
context->error("wasi_unstable proc_exit");
886886
}
887887

888+
Word wasi_unstable_sched_yield() { return 0; }
889+
890+
Word wasi_unstable_poll_oneoff(Word /*in*/, Word /*out*/, Word /*nsubscriptions*/,
891+
Word /*nevents*/) {
892+
return 0;
893+
}
894+
888895
Word pthread_equal(Word left, Word right) { return static_cast<uint64_t>(left == right); }
889896

890897
void emscripten_notify_memory_growth(Word /*memory_index*/) {}
@@ -925,5 +932,27 @@ Word get_log_level(Word result_level_uint32_ptr) {
925932
return WasmResult::Ok;
926933
}
927934

935+
Word wasi_unstable_fd_fdstat_set_flags(Word /*fd*/, Word /*flags*/) {
936+
// Don't support reading of any files.
937+
return 52; // __WASI_ERRNO_ENOSYS
938+
}
939+
940+
Word wasi_unstable_fd_filestat_get(Word /*fd*/, Word /*statOut*/) {
941+
// Don't support reading of any files.
942+
return 52; // __WASI_ERRNO_ENOSYS
943+
}
944+
945+
Word wasi_unstable_fd_readdir(Word /*fd*/, Word /*buf*/, Word /*buf_len*/, int64_t /*cookie*/,
946+
Word /*bufused*/) {
947+
// Don't support reading of any files.
948+
return 52; // __WASI_ERRNO_ENOSYS
949+
}
950+
951+
Word wasi_unstable_path_filestat_get(Word /*fd*/, Word /*flags*/, Word /*path*/, Word /*path_len*/,
952+
Word /*statOut*/) {
953+
// Don't support reading of any files.
954+
return 52; // __WASI_ERRNO_ENOSYS
955+
}
956+
928957
} // namespace exports
929958
} // namespace proxy_wasm

0 commit comments

Comments
 (0)