~jb55/protoverse

fb5dfd6ff4b5718328dbac95715a146939d44ce0 — William Casarin 2 months ago b6d8c2e
wasi fclose
2 files changed, 14 insertions(+), 1 deletions(-)

M Makefile
M src/wasm.c
M Makefile => Makefile +1 -1
@@ 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 $@"

M src/wasm.c => src/wasm.c +13 -0
@@ 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;