protoverse

A metaverse protocol
git clone git://jb55.com/protoverse
Log | Files | Refs | README | LICENSE

commit fb5dfd6ff4b5718328dbac95715a146939d44ce0
parent b6d8c2e2b126b0705f22be27c3f376271fd62840
Author: William Casarin <jb55@jb55.com>
Date:   Fri,  6 Aug 2021 17:22:23 -0700

wasi fclose

Diffstat:
MMakefile | 2+-
Msrc/wasm.c | 13+++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile @@ -46,7 +46,7 @@ wasm/hello-c.wasm: wasm/hello-c.c emcc -g $< -s WASM=1 -o $@ protoverse.wasm: src/protoverse.c $(SRCS) - emcc -g $^ -s WASM=1 -o $@ + emcc -g $^ -s WASM=1 -s ERROR_ON_UNDEFINED_SYMBOLS=0 -o $@ protoverse: src/protoverse.c $(OBJS) @echo "ld $@" diff --git a/src/wasm.c b/src/wasm.c @@ -550,6 +550,7 @@ static INLINE const char *get_function_name(struct module *module, int fn) static int wasi_args_sizes_get(struct wasm_interp *interp); static int wasi_args_get(struct wasm_interp *interp); static int wasi_fd_write(struct wasm_interp *interp); +static int wasi_fd_close(struct wasm_interp *interp); static int wasi_environ_sizes_get(struct wasm_interp *interp); static int wasi_environ_get(struct wasm_interp *interp); @@ -557,6 +558,7 @@ static struct builtin BUILTINS[] = { { .name = "null", .fn = NULL }, // for reasons { .name = "args_get", .fn = wasi_args_get }, { .name = "fd_write", .fn = wasi_fd_write }, + { .name = "fd_close", .fn = wasi_fd_close }, { .name = "environ_sizes_get", .fn = wasi_environ_sizes_get }, { .name = "environ_get", .fn = wasi_environ_get }, { .name = "args_sizes_get", .fn = wasi_args_sizes_get }, @@ -5478,6 +5480,17 @@ static INLINE int load_i32(struct wasm_interp *interp, int addr, int *i) return stack_pop_i32(interp, i); } +static int wasi_fd_close(struct wasm_interp *interp) +{ + struct val *params = NULL; + if (!get_params(interp, &params, 1)) + return interp_error(interp, "param"); + + close(params[0].num.i32); + + return stack_push_i32(interp, 0); +} + static int wasi_fd_write(struct wasm_interp *interp) { struct val *fd, *iovs_ptr, *iovs_len, *written;