Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b9b4a5e

Browse files
committedDec 13, 2024··
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 3212034 commit b9b4a5e

File tree

4 files changed

+60
-13
lines changed

4 files changed

+60
-13
lines changed
 

‎include/proxy-wasm/exports.h

+13-2
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

+12-11
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

+33
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,31 @@ 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+
957+
Word secure_getenv(Word /*name*/) { return 0; }
958+
959+
Word getpid() { return 4; }
960+
928961
} // namespace exports
929962
} // namespace proxy_wasm

‎src/wasm.cc

+2
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)
Please sign in to comment.