Skip to content

add all wasi hostcalls used by Go SDK #433

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions include/proxy-wasm/exports.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ Word wasi_unstable_path_open(Word fd, Word dir_flags, Word path, Word path_len,
int64_t fs_rights_base, int64_t fg_rights_inheriting, Word fd_flags,
Word nwritten_ptr);
Word wasi_unstable_fd_prestat_get(Word fd, Word buf_ptr);
Word wasi_unstable_fd_filestat_get(Word fd, Word buf_ptr);
Word wasi_unstable_fd_prestat_dir_name(Word fd, Word path_ptr, Word path_len);
Word wasi_unstable_fd_write(Word fd, Word iovs, Word iovs_len, Word nwritten_ptr);
Word wasi_unstable_fd_read(Word, Word, Word, Word);
Expand All @@ -148,9 +149,35 @@ Word wasi_unstable_sched_yield();
Word wasi_unstable_poll_oneoff(Word in, Word out, Word nsubscriptions, Word nevents);
void wasi_unstable_proc_exit(Word);
Word wasi_unstable_clock_time_get(Word, uint64_t, Word);
Word wasi_unstable_clock_res_get(Word, Word);
Word wasi_unstable_fd_advise(Word, uint64_t, uint64_t, Word);
Word wasi_unstable_fd_allocate(Word, uint64_t, uint64_t);
Word wasi_unstable_fd_datasync(Word);
Word wasi_unstable_fd_fdstat_set_rights(Word, uint64_t, uint64_t);
Word wasi_unstable_fd_filestat_set_size(Word, uint64_t);
Word wasi_unstable_fd_filestat_set_times(Word, uint64_t, uint64_t, Word);
Word wasi_unstable_fd_pread(Word, Word, Word, uint64_t, Word);
Word wasi_unstable_fd_pwrite(Word, Word, Word, uint64_t, Word);
Word wasi_unstable_fd_readdir(Word, Word, Word, uint64_t, Word);
Word wasi_unstable_fd_renumber(Word, Word);
Word wasi_unstable_fd_sync(Word);
Word wasi_unstable_fd_tell(Word, Word);
Word wasi_unstable_path_create_directory(Word, Word, Word);
Word wasi_unstable_path_filestat_set_times(Word, Word, Word, Word, uint64_t, uint64_t, Word);
Word wasi_unstable_path_link(Word, Word, Word, Word, Word, Word);
Word wasi_unstable_path_readlink(Word, Word, Word, Word, Word, Word);
Word wasi_unstable_path_remove_directory(Word, Word, Word);
Word wasi_unstable_path_rename(Word, Word, Word, Word, Word);
Word wasi_unstable_path_symlink(Word, Word, Word, Word);
Word wasi_unstable_path_unlink_file(Word, Word, Word);
Word wasi_unstable_sock_accept(Word, Word, Word);
Word wasi_unstable_sock_recv(Word, Word, Word, Word, Word, Word);
Word wasi_unstable_sock_send(Word, Word, Word, Word, Word);
Word wasi_unstable_sock_shutdown(Word, Word);
Word wasi_unstable_random_get(Word, Word);
Word pthread_equal(Word left, Word right);
void emscripten_notify_memory_growth(Word);
Word wasi_unstable_path_filestat_get(Word fd, Word flags, Word path, Word path_len, Word buf);

// Support for embedders, not exported to Wasm.

Expand All @@ -174,9 +201,15 @@ 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(fd_fdstat_set_flags) \
_f(environ_get) _f(environ_sizes_get) _f(args_get) _f(args_sizes_get) _f(clock_time_get) \
_f(random_get) _f(sched_yield) _f(poll_oneoff) _f(proc_exit) _f(path_open) \
_f(fd_prestat_get) _f(fd_prestat_dir_name)
_f(fd_fdstat_set_rights) _f(environ_get) _f(environ_sizes_get) _f(args_get) _f(args_sizes_get) \
_f(clock_time_get) _f(clock_res_get) _f(fd_advise) _f(fd_allocate) _f(fd_datasync) \
_f(fd_filestat_set_size) _f(fd_filestat_set_times) _f(fd_pread) _f(fd_pwrite) \
_f(fd_readdir) _f(fd_renumber) _f(fd_sync) _f(fd_tell) _f(path_create_directory) \
_f(path_filestat_set_times) _f(path_link) _f(path_readlink) _f(path_remove_directory) \
_f(path_rename) _f(path_symlink) _f(path_unlink_file) _f(sock_accept) \
_f(sock_recv) _f(sock_send) _f(sock_shutdown) _f(random_get) _f(sched_yield) \
_f(poll_oneoff) _f(proc_exit) _f(path_open) _f(fd_prestat_get) \
_f(fd_prestat_dir_name) _f(path_filestat_get) _f(fd_filestat_get)

// 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
4 changes: 3 additions & 1 deletion include/proxy-wasm/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,9 @@ inline void *WasmBase::allocMemory(uint64_t size, uint64_t *address) {
// logging (stdout/stderr)
"wasi_unstable.fd_write", "wasi_snapshot_preview1.fd_write",
// time
"wasi_unstable.clock_time_get", "wasi_snapshot_preview1.clock_time_get"});
"wasi_unstable.clock_time_get", "wasi_snapshot_preview1.clock_time_get",
// go runtime gc sleep
"wasi_unstable.poll_oneoff", "wasi_snapshot_preview1.poll_oneoff"});
Word a = malloc_(vm_context(), size);
wasm_vm_->setRestrictedCallback(false);
if (!a.u64_) {
Expand Down
30 changes: 19 additions & 11 deletions include/proxy-wasm/wasm_vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,31 @@ using WasmCallback_WWmW = Word (*)(Word, uint64_t, Word);
using WasmCallback_WWWWWWllWW = Word (*)(Word, Word, Word, Word, Word, int64_t, int64_t, Word,
Word);
using WasmCallback_dd = double (*)(double);
// Additional callback types for new WASI functions
using WasmCallback_WWWWmm = Word (*)(Word, Word, Word, Word, uint64_t, uint64_t);
using WasmCallback_WWWWmmW = Word (*)(Word, Word, Word, Word, uint64_t, uint64_t, Word);
using WasmCallback_WWmm = Word (*)(Word, uint64_t, uint64_t);
using WasmCallback_WWmmW = Word (*)(Word, uint64_t, uint64_t, Word);
using WasmCallback_WWWWmW = Word (*)(Word, Word, Word, uint64_t, Word);

#define FOR_ALL_WASM_VM_IMPORTS(_f) \
_f(proxy_wasm::WasmCallbackVoid<0>) _f(proxy_wasm::WasmCallbackVoid<1>) \
_f(proxy_wasm::WasmCallbackVoid<2>) _f(proxy_wasm::WasmCallbackVoid<3>) \
_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::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_WWWWmm) \
_f(proxy_wasm::WasmCallback_WWWWmmW) \
_f(proxy_wasm::WasmCallback_WWmm) \
_f(proxy_wasm::WasmCallback_WWmmW) \
_f(proxy_wasm::WasmCallback_WWWWmW) \
_f(proxy_wasm::WasmCallback_dd)

enum class Cloneable {
Expand Down
Loading