File io.cpp
-
namespace wasm
SYSCALL NUMBERING
Have a look in the sysroot at include/bits/syscall.h to determine the system call numbering.
Functions
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "fd_prestat_get", I32, wasi_fd_prestat_get, I32 fd, I32 prestatPtr)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "fd_prestat_dir_name", I32, wasi_fd_prestat_dir_name, I32 fd, I32 resPathPtr, I32 resPathLen)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "path_open", I32, wasi_path_open, I32 rootFd, I32 lookupFlags, I32 path, I32 pathLen, U32 openFlags, U64 rightsBase, U64 rightsInheriting, I32 fdFlags, I32 resFdPtr)
-
int doWasiDup(I32 fd)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "dup", I32, dup, I32 fd)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "__wasi_fd_dup", I32, __wasi_fd_dup, I32 fd, I32 resFdPtr)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "fd_readdir", I32, wasi_fd_readdir, I32 fd, I32 buf, I32 bufLen, U64 startCookie, I32 resSizePtr)
This works a little like the normal Linux readdir, in that it will be called repeatedly to get the full listing of a directory.
The function should fill the read buffer until it’s reached the final “page” of results, at which point the returned size will be smaller than the read buffer.
-
I32 s__getdents64(I32 fd, I32 wasmDirentBuf, I32 wasmDirentBufLen)
This function is tricky to implement as it’s iterating through an unknown number of files in the directory. We will be running two loops, one to fill up the given buffer, and a nested loop to iterate through the native directory listing.
We try to be conservative but will throw an exception if things aren’t right. A bug here can be hard to find.
The musl implementation of readdir seems to require returning (-1 * errno) on error, not -1 as the man pages suggest.
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "fd_close", I32, wasi_fd_close, I32 fd)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "fd_write", I32, wasi_fd_write, I32 fd, I32 iovecsPtr, I32 iovecCount, I32 resBytesWrittenPtr)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "fd_read", I32, wasi_fd_read, I32 fd, I32 iovecsPtr, I32 iovecCount, I32 resBytesRead)
-
I32 s__mkdir(I32 pathPtr, I32 mode)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "path_create_directory", I32, wasi_path_create_directory, I32 fd, I32 path, I32 pathLen)
-
I32 s__rename(I32 srcPtr, I32 destPtr)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "path_rename", I32, wasi_path_rename, I32 fd, I32 oldPath, I32 oldPathLen, I32 newFd, I32 newPath, I32 newPathLen)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "path_unlink_file", I32, wasi_path_unlink_file, I32 rootFd, I32 pathPtr, I32 pathLen)
-
I32 s__unlink(I32 pathPtr)
-
I32 s__access(I32 pathPtr, I32 mode)
-
I32 s__fstat64(I32 fd, I32 statBufPtr)
-
I32 s__lstat64(I32 pathPtr, I32 statBufPtr)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "fd_fdstat_get", I32, wasi_fd_fdstat_get, I32 fd, I32 statPtr)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "fd_fdstat_set_rights", I32, wasi_fd_fdstat_set_rights, I32 a, I64 b, I64 c)
-
I32 doFileStat(int fd, const std::string &relativePath, I32 statPtr)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "fd_filestat_get", I32, wasi_fd_filestat_get, I32 fd, I32 statPtr)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "path_filestat_get", I32, wasi_path_filestat_get, I32 fd, I32 lookupFlags, I32 path, I32 pathLen, I32 statPtr)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "path_filestat_set_times", I32, wasi_path_filestat_set_times, I32 fd, I32 lookupFlags, I32 path, I32 pathLen, I64 accessTimeStamp, I64 modTimeStamp, I32 fstFlags)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "fd_tell", I32, wasi_fd_tell, I32 fd, I32 resOffsetPtr)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "fd_seek", I32, wasi_fd_seek, I32 fd, I64 offset, I32 whence, I32 newOffsetPtr)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "fd_advise", I32, wasi_fd_advise, I32 fd, I64 offset, I64 len, I32 advice)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "ioctl", I32, ioctl, I32 a, I32 b, I32 c)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "puts", I32, puts, I32 strPtr)
Note here that we assume puts is called on a null-terminated string
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "putc", I32, putc, I32 c, I32 streamPtr)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "vfprintf", I32, vfprintf, I32 fd, U32 formatPtr, I32 argList)
fprintf can provide some useful debugging info so we can just spit it to stdout
-
I32 s__readlink(I32 pathPtr, I32 bufPtr, I32 bufLen)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "path_readlink", I32, wasi_path_readlink, I32 rootFd, I32 pathPtr, I32 pathLen, I32 buffPtr, I32 buffLen, I32 resBytesUsed)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "fd_fdstat_set_flags", I32, wasi_fd_fdstat_set_flags, I32 fd, I32 fdFlags)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "bzero", void, bzero, I32 wasmPtr, I32 len)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "explicit_bzero", void, explicit_bzero, I32 wasmPtr, I32 len)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "__small_sprintf", I32, __small_sprintf, I32 a, I32 b, I32 c)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "fd_renumber", I32, wasi_fd_renumber, I32 fdOld, I32 fdNew)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "tmpfile", I32, tmpfile)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "umask", I32, umask, I32 a)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "msync", I32, msync, I32 a, I32 b, I32 c)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "tempnam", I32, tempnam, I32 a, I32 b)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "memfd_create", I32, memfd_create, I32 a, I32 b)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "setgroups", I32, setgroups, I32 a, I32 b)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "fchdir", I32, s__fchdir, I32 a)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "chmod", I32, s__chmod, I32 a, I32 b)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "fd_datasync", I32, wasi_fd_datasync, I32 a)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "fd_pwrite", I32, wasi_fd_pwrite, I32 a, I32 b, I32 c, I64 d, I32 e)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "fd_pread", I32, wasi_fd_pread, I32 a, I32 b, I32 c, I64 d, I32 e)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "fd_filestat_set_size", I32, wasi_fd_filestat_set_size, I32 a, I64 b)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "fd_sync", I32, wasi_fd_sync, I32 a)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "fd_allocate", I32, wasi_fd_allocate, I32 a, I64 b, I64 c)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "fd_filestat_set_times", I32, fd_filestat_set_times, I32 a, I64 b, I64 c, I32 d)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "path_link", I32, wasi_path_link, I32 a, I32 b, I32 c, I32 d, I32 e, I32 f, I32 g)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "path_symlink", I32, wasi_path_symlink, I32 a, I32 b, I32 c, I32 d, I32 e)
- WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "path_remove_directory", I32, wasi_path_remove_directory, I32 a, I32 b, I32 c)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "lockf", I32, lockf, I32 a, I32 b, I64 c)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "strncat", I32, strncat, I32 a, I32 b, I32 c)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "realpath", I32, realpath, I32 a, U32 b)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "dirfd", I32, dirfd, I32 a)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "poll", I32, poll, I32 a, I32 b, I32 c)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "sendfile", I32, sendfile, I32 out_fd, I32 in_fd, I32 offset, I32 count)
- WAVM_DEFINE_INTRINSIC_FUNCTION (env, "fiprintf", I32, wasi_fiprintf, I32 a, I32 b, I32 c)
-
void ioLink()