//1// "No-FS" implementation for WasmFS. This file implements just enough of the2// syscall API to support printf. In particular, enough for a program that3// only does some file writes, but no open() or such. Then those writes must be4// to the standard streams, and we can implement very simple printing for them5// as opposed to linking in all of WasmFS.6//7// This uses weak linking, and as such it depends on all the normal syscalls8// being implemented in a single file, which is the case (syscalls.cpp). That9// way, if that single other file is included then all these methods get10// overridden. (Otherwise, if we had multiple files, we could end up with a mix11// of this file's functions and others.)12//1314#include <emscripten.h>15#include <wasi/api.h>1617#include "wasmfs_internal.h"1819#define WEAK __attribute__((weak))2021// Import the outside (JS or VM) fd_write under a different name. We must22// implement __wasi_fd_write in this file so that all the normal WasmFS code is23// not included - that is the point of no-fs mode - since if we don't implement24// it here then the normal WasmFS code for that function will be linked in. But25// in the cases where this file is linked in, we just want to direct all calls26// to the outside fd_write.27__attribute__((import_module("wasi_snapshot_preview1"),28import_name("fd_write"))) __wasi_errno_t29imported__wasi_fd_write(__wasi_fd_t fd,30const __wasi_ciovec_t* iovs,31size_t iovs_len,32__wasi_size_t* nwritten);3334WEAK35__wasi_errno_t __wasi_fd_write(__wasi_fd_t fd,36const __wasi_ciovec_t* iovs,37size_t iovs_len,38__wasi_size_t* nwritten) {39return imported__wasi_fd_write(fd, iovs, iovs_len, nwritten);40}4142WEAK43__wasi_errno_t __wasi_fd_close(__wasi_fd_t fd) {44// The only possible file descriptors are the standard streams, and there is45// nothing special to do to close them.46return __WASI_ERRNO_SUCCESS;47}4849WEAK50__wasi_errno_t __wasi_fd_fdstat_get(__wasi_fd_t fd, __wasi_fdstat_t* stat) {51// This operation is not supported (but it does appear in system libraries52// even in hello world, even if it isn't actually called, so we do need to53// implement this stub here).54return __WASI_ERRNO_NOSYS;55}565758