Skip to content

Commit 3289872

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.
1 parent 3212034 commit 3289872

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

include/proxy-wasm/exports.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ Word grpc_stream(Word service_ptr, Word service_size, Word service_name_ptr, Wor
118118
Word grpc_cancel(Word token);
119119
Word grpc_close(Word token);
120120
Word grpc_send(Word token, Word message_ptr, Word message_size, Word end_stream);
121+
Word secure_getenv(Word name);
122+
Word getpid();
121123

122124
Word set_tick_period_milliseconds(Word tick_period_milliseconds);
123125
Word get_current_time_nanoseconds(Word result_uint64_ptr);
@@ -146,6 +148,12 @@ Word wasi_unstable_args_sizes_get(Word argc_ptr, Word argv_buf_size_ptr);
146148
void wasi_unstable_proc_exit(Word);
147149
Word wasi_unstable_clock_time_get(Word, uint64_t, Word);
148150
Word wasi_unstable_random_get(Word, Word);
151+
Word wasi_unstable_fd_filestat_get(Word fd, Word statOut);
152+
Word wasi_unstable_fd_readdir(Word fd, Word buf, Word buf_len, int64_t cookie, Word bufused);
153+
Word wasi_unstable_path_filestat_get(Word fd, Word flags, Word path, Word path_len, Word statOut);
154+
Word wasi_unstable_fd_fdstat_set_flags(Word fd, Word flags);
155+
Word wasi_unstable_sched_yield();
156+
Word wasi_unstable_poll_oneoff(Word in, Word out, Word nsubscriptions, Word nevents);
149157
Word pthread_equal(Word left, Word right);
150158
void emscripten_notify_memory_growth(Word);
151159

@@ -163,7 +171,8 @@ void emscripten_notify_memory_growth(Word);
163171
_f(get_current_time_nanoseconds) _f(define_metric) \
164172
_f(increment_metric) _f(record_metric) _f(get_metric) \
165173
_f(set_effective_context) _f(done) \
166-
_f(call_foreign_function)
174+
_f(call_foreign_function) _f(getpid) \
175+
_f(secure_getenv)
167176

168177
#define FOR_ALL_HOST_FUNCTIONS_ABI_SPECIFIC(_f) \
169178
_f(get_configuration) _f(continue_request) _f(continue_response) _f(clear_route_cache) \
@@ -172,7 +181,9 @@ void emscripten_notify_memory_growth(Word);
172181
#define FOR_ALL_WASI_FUNCTIONS(_f) \
173182
_f(fd_write) _f(fd_read) _f(fd_seek) _f(fd_close) _f(fd_fdstat_get) _f(environ_get) \
174183
_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)
184+
_f(proc_exit) _f(path_open) _f(fd_prestat_get) _f(fd_prestat_dir_name) \
185+
_f(fd_filestat_get) _f(fd_readdir) _f(path_filestat_get) _f(fd_fdstat_set_flags) \
186+
_f(sched_yield) _f(poll_oneoff)
176187

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

include/proxy-wasm/wasm_vm.h

Lines changed: 4 additions & 2 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);
@@ -130,8 +131,9 @@ using WasmCallback_dd = double (*)(double);
130131
_f(proxy_wasm::WasmCallback_WWlWW) \
131132
_f(proxy_wasm::WasmCallback_WWm) \
132133
_f(proxy_wasm::WasmCallback_WWmW) \
133-
_f(proxy_wasm::WasmCallback_WWWWWWllWW) \
134-
_f(proxy_wasm::WasmCallback_dd)
134+
_f(proxy_wasm::WasmCallback_WWWWlW) \
135+
_f(proxy_wasm::WasmCallback_WWWWWWllWW)\
136+
_f(proxy_wasm::WasmCallback_dd)
135137

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

src/exports.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,10 @@ 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, Word nevents) { return 0; }
891+
888892
Word pthread_equal(Word left, Word right) { return static_cast<uint64_t>(left == right); }
889893

890894
void emscripten_notify_memory_growth(Word /*memory_index*/) {}
@@ -925,5 +929,29 @@ Word get_log_level(Word result_level_uint32_ptr) {
925929
return WasmResult::Ok;
926930
}
927931

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

src/wasm.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ void WasmBase::registerCallbacks() {
109109
"env", #_fn, &exports::_fn, \
110110
&ConvertFunctionWordToUint32<decltype(exports::_fn), \
111111
exports::_fn>::convertFunctionWordToUint32)
112+
_REGISTER(secure_getenv);
113+
_REGISTER(getpid);
112114
_REGISTER(pthread_equal);
113115
_REGISTER(emscripten_notify_memory_growth);
114116
#undef _REGISTER

0 commit comments

Comments
 (0)