Skip to content

Commit f383473

Browse files
authored
wasi: export stubs for preopened files and directories. (#201)
Resolves #199. Signed-off-by: mathetake <[email protected]>
1 parent e0636f7 commit f383473

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

include/proxy-wasm/exports.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ Word call_foreign_function(Word function_name, Word function_name_size, Word arg
159159

160160
// Runtime environment functions exported from envoy to wasm.
161161

162+
Word wasi_unstable_path_open(Word fd, Word dir_flags, Word path, Word path_len, Word oflags,
163+
int64_t fs_rights_base, int64_t fg_rights_inheriting, Word fd_flags,
164+
Word nwritten_ptr);
165+
Word wasi_unstable_fd_prestat_get(Word fd, Word buf_ptr);
166+
Word wasi_unstable_fd_prestat_dir_name(Word fd, Word path_ptr, Word path_len);
162167
Word wasi_unstable_fd_write(Word fd, Word iovs, Word iovs_len, Word nwritten_ptr);
163168
Word wasi_unstable_fd_read(Word, Word, Word, Word);
164169
Word wasi_unstable_fd_seek(Word, int64_t, Word, Word);
@@ -196,7 +201,7 @@ Word pthread_equal(Word left, Word right);
196201
#define FOR_ALL_WASI_FUNCTIONS(_f) \
197202
_f(fd_write) _f(fd_read) _f(fd_seek) _f(fd_close) _f(fd_fdstat_get) _f(environ_get) \
198203
_f(environ_sizes_get) _f(args_get) _f(args_sizes_get) _f(clock_time_get) _f(random_get) \
199-
_f(proc_exit)
204+
_f(proc_exit) _f(path_open) _f(fd_prestat_get) _f(fd_prestat_dir_name)
200205

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

include/proxy-wasm/wasm_vm.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ using WasmCallback_WWl = Word (*)(Word, int64_t);
110110
using WasmCallback_WWlWW = Word (*)(Word, int64_t, Word, Word);
111111
using WasmCallback_WWm = Word (*)(Word, uint64_t);
112112
using WasmCallback_WWmW = Word (*)(Word, uint64_t, Word);
113+
using WasmCallback_WWWWWWllWW = Word (*)(Word, Word, Word, Word, Word, int64_t, int64_t, Word,
114+
Word);
113115
using WasmCallback_dd = double (*)(double);
114116

115117
#define FOR_ALL_WASM_VM_IMPORTS(_f) \
@@ -127,7 +129,8 @@ using WasmCallback_dd = double (*)(double);
127129
_f(proxy_wasm::WasmCallback_WWlWW) \
128130
_f(proxy_wasm::WasmCallback_WWm) \
129131
_f(proxy_wasm::WasmCallback_WWmW) \
130-
_f(proxy_wasm::WasmCallback_dd)
132+
_f(proxy_wasm::WasmCallback_WWWWWWllWW) \
133+
_f(proxy_wasm::WasmCallback_dd)
131134

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

src/exports.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,25 @@ Word grpc_send(Word token, Word message_ptr, Word message_size, Word end_stream)
666666
return context->grpcSend(token, message.value(), end_stream);
667667
}
668668

669+
// __wasi_errno_t path_open(__wasi_fd_t fd, __wasi_lookupflags_t dirflags, const char *path,
670+
// size_t path_len, __wasi_oflags_t oflags, __wasi_rights_t fs_rights_base, __wasi_rights_t
671+
// fs_rights_inheriting, __wasi_fdflags_t fdflags, __wasi_fd_t *retptr0)
672+
Word wasi_unstable_path_open(Word fd, Word dir_flags, Word path, Word path_len, Word oflags,
673+
int64_t fs_rights_base, int64_t fg_rights_inheriting, Word fd_flags,
674+
Word nwritten_ptr) {
675+
return 44; // __WASI_ERRNO_NOENT
676+
}
677+
678+
// __wasi_errno_t __wasi_fd_prestat_get(__wasi_fd_t fd, __wasi_prestat_t *retptr0)
679+
Word wasi_unstable_fd_prestat_get(Word fd, Word buf_ptr) {
680+
return 8; // __WASI_ERRNO_BADF
681+
}
682+
683+
// __wasi_errno_t __wasi_fd_prestat_dir_name(__wasi_fd_t fd, uint8_t * path, __wasi_size_t path_len)
684+
Word wasi_unstable_fd_prestat_dir_name(Word fd, Word path_ptr, Word path_len) {
685+
return 52; // __WASI_ERRNO_ENOSYS
686+
}
687+
669688
// Implementation of writev-like() syscall that redirects stdout/stderr to Envoy
670689
// logs.
671690
Word writevImpl(Word fd, Word iovs, Word iovs_len, Word *nwritten_ptr) {

0 commit comments

Comments
 (0)