Repository: tetratelabs/wazero
Pull request #222 (2022-02-10 07:00:36)

wasi: backfills constants and TODOs for remaining functions
This also normalizes naming conventions


Patch:
diff --git a/wasi/errno.go b/wasi/errno.go
deleted file mode 100644
index 7f5d1558..00000000
--- a/wasi/errno.go
+++ /dev/null
@@ -1,175 +0,0 @@
-package wasi
-
-import "fmt"
-
-// Errno is a type representing standard WASI error codes and implementing the
-// error interface.
-type Errno uint32
-
-func (err Errno) Error() string {
-	if int(err) < len(errnoToString) {
-		return errnoToString[err]
-	}
-	return fmt.Sprintf("errno(%d)", uint32(err))
-}
-
-// WASI error codes
-const (
-	ESUCCESS        Errno = 0
-	E2BIG           Errno = 1 /* Arg list too long */
-	EACCES          Errno = 2 /* Permission denied */
-	EADDRINUSE      Errno = 3 /* Address already in use */
-	EADDRNOTAVAIL   Errno = 4 /* Cannot assign requested address */
-	EAFNOSUPPORT    Errno = 5 /* Address family not supported by protocol */
-	EAGAIN          Errno = 6 /* Try again */
-	EALREADY        Errno = 7 /* Operation already in progress */
-	EBADF           Errno = 8 /* Bad file number */
-	EBADMSG         Errno = 9
-	EBUSY           Errno = 10
-	ECANCELED       Errno = 11
-	ECHILD          Errno = 12
-	ECONNABORTED    Errno = 13
-	ECONNREFUSED    Errno = 14
-	ECONNRESET      Errno = 15
-	EDEADLK         Errno = 16
-	EDESTADDRREQ    Errno = 17
-	EDOM            Errno = 18
-	EDQUOT          Errno = 19
-	EEXIST          Errno = 20
-	EFAULT          Errno = 21
-	EFBIG           Errno = 22
-	EHOSTUNREACH    Errno = 23
-	EIDRM           Errno = 24
-	EILSEQ          Errno = 25
-	EINPROGRESS     Errno = 26
-	EINTR           Errno = 27
-	EINVAL          Errno = 28 /* Invalid argument */
-	EIO             Errno = 29
-	EISCONN         Errno = 30
-	EISDIR          Errno = 31
-	ELOOP           Errno = 32
-	EMFILE          Errno = 33
-	EMLINK          Errno = 34
-	EMSGSIZE        Errno = 35
-	EMULTIHOP       Errno = 36
-	ENAMETOOLONG    Errno = 37
-	ENETDOWN        Errno = 38
-	ENETRESET       Errno = 39
-	ENETUNREACH     Errno = 40
-	ENFILE          Errno = 41
-	ENOBUFS         Errno = 42
-	ENODEV          Errno = 43
-	ENOENT          Errno = 44
-	ENOEXEC         Errno = 45
-	ENOLCK          Errno = 46
-	ENOLINK         Errno = 47
-	ENOMEM          Errno = 48
-	ENOMSG          Errno = 49
-	ENOPROTOOPT     Errno = 50
-	ENOSPC          Errno = 51
-	ENOSYS          Errno = 52
-	ENOTCONN        Errno = 53
-	ENOTDIR         Errno = 54
-	ENOTEMPTY       Errno = 55
-	ENOTRECOVERABLE Errno = 56
-	ENOTSOCK        Errno = 57
-	ENOTSUP         Errno = 58
-	ENOTTY          Errno = 59
-	ENXIO           Errno = 60
-	EOVERFLOW       Errno = 61
-	EOWNERDEAD      Errno = 62
-	EPERM           Errno = 63
-	EPIPE           Errno = 64
-	EPROTO          Errno = 65
-	EPROTONOSUPPORT Errno = 66
-	EPROTOTYPE      Errno = 67
-	ERANGE          Errno = 68
-	EROFS           Errno = 69
-	ESPIPE          Errno = 70
-	ESRCH           Errno = 71
-	ESTALE          Errno = 72
-	ETIMEDOUT       Errno = 73
-	ETXTBSY         Errno = 74
-	EXDEV           Errno = 75
-	ENOTCAPABLE     Errno = 76
-)
-
-var errnoToString = [...]string{
-	ESUCCESS:        "ESUCCESS",
-	E2BIG:           "E2BIG",
-	EACCES:          "EACCES",
-	EADDRINUSE:      "EADDRINUSE",
-	EADDRNOTAVAIL:   "EADDRNOTAVAIL",
-	EAFNOSUPPORT:    "EAFNOSUPPORT",
-	EAGAIN:          "EAGAIN",
-	EALREADY:        "EALREADY",
-	EBADF:           "EBADF",
-	EBADMSG:         "EBADMSG",
-	EBUSY:           "EBUSY",
-	ECANCELED:       "ECANCELED",
-	ECHILD:          "ECHILD",
-	ECONNABORTED:    "ECONNABORTED",
-	ECONNREFUSED:    "ECONNREFUSED",
-	ECONNRESET:      "ECONNRESET",
-	EDEADLK:         "EDEADLK",
-	EDESTADDRREQ:    "EDESTADDRREQ",
-	EDOM:            "EDOM",
-	EDQUOT:          "EDQUOT",
-	EEXIST:          "EEXIST",
-	EFAULT:          "EFAULT",
-	EFBIG:           "EFBIG",
-	EHOSTUNREACH:    "EHOSTUNREACH",
-	EIDRM:           "EIDRM",
-	EILSEQ:          "EILSEQ",
-	EINPROGRESS:     "EINPROGRESS",
-	EINTR:           "EINTR",
-	EINVAL:          "EINVAL",
-	EIO:             "EIO",
-	EISCONN:         "EISCONN",
-	EISDIR:          "EISDIR",
-	ELOOP:           "ELOOP",
-	EMFILE:          "EMFILE",
-	EMLINK:          "EMLINK",
-	EMSGSIZE:        "EMSGSIZE",
-	EMULTIHOP:       "EMULTIHOP",
-	ENAMETOOLONG:    "ENAMETOOLONG",
-	ENETDOWN:        "ENETDOWN",
-	ENETRESET:       "ENETRESET",
-	ENETUNREACH:     "ENETUNREACH",
-	ENFILE:          "ENFILE",
-	ENOBUFS:         "ENOBUFS",
-	ENODEV:          "ENODEV",
-	ENOENT:          "ENOENT",
-	ENOEXEC:         "ENOEXEC",
-	ENOLCK:          "ENOLCK",
-	ENOLINK:         "ENOLINK",
-	ENOMEM:          "ENOMEM",
-	ENOMSG:          "ENOMSG",
-	ENOPROTOOPT:     "ENOPROTOOPT",
-	ENOSPC:          "ENOSPC",
-	ENOSYS:          "ENOSYS",
-	ENOTCONN:        "ENOTCONN",
-	ENOTDIR:         "ENOTDIR",
-	ENOTEMPTY:       "ENOTEMPTY",
-	ENOTRECOVERABLE: "ENOTRECOVERABLE",
-	ENOTSOCK:        "ENOTSOCK",
-	ENOTSUP:         "ENOTSUP",
-	ENOTTY:          "ENOTTY",
-	ENXIO:           "ENXIO",
-	EOVERFLOW:       "EOVERFLOW",
-	EOWNERDEAD:      "EOWNERDEAD",
-	EPERM:           "EPERM",
-	EPIPE:           "EPIPE",
-	EPROTO:          "EPROTO",
-	EPROTONOSUPPORT: "EPROTONOSUPPORT",
-	EPROTOTYPE:      "EPROTOTYPE",
-	ERANGE:          "ERANGE",
-	EROFS:           "EROFS",
-	ESPIPE:          "ESPIPE",
-	ESRCH:           "ESRCH",
-	ESTALE:          "ESTALE",
-	ETIMEDOUT:       "ETIMEDOUT",
-	ETXTBSY:         "ETXTBSY",
-	EXDEV:           "EXDEV",
-	ENOTCAPABLE:     "ENOTCAPABLE",
-}
diff --git a/wasi/strings.go b/wasi/strings.go
new file mode 100644
index 00000000..bf4a01ce
--- /dev/null
+++ b/wasi/strings.go
@@ -0,0 +1,41 @@
+package wasi
+
+import (
+	"fmt"
+	"unicode/utf8"
+)
+
+// nullTerminatedStrings holds null-terminated strings. It ensures that
+// its length and total buffer size don't exceed the max of uint32.
+// nullTerminatedStrings are convenience struct for args_get and environ_get. (environ_get is not implemented yet)
+//
+// A Null-terminated string is a byte string with a NULL suffix ("\x00").
+// See https://en.wikipedia.org/wiki/Null-terminated_string
+type nullTerminatedStrings struct {
+	// nullTerminatedValues are null-terminated values with a NULL suffix.
+	nullTerminatedValues [][]byte
+	totalBufSize         uint32
+}
+
+// newNullTerminatedStrings creates a nullTerminatedStrings from the given string slice. It returns an error
+// if the length or the total buffer size of the result WASIStringArray exceeds the maxBufSize
+func newNullTerminatedStrings(maxBufSize uint32, args ...string) (*nullTerminatedStrings, error) {
+	if len(args) == 0 {
+		return &nullTerminatedStrings{nullTerminatedValues: [][]byte{}}, nil
+	}
+	var strings [][]byte // don't pre-allocate as this function is size bound
+	totalBufSize := uint32(0)
+	for i, arg := range args {
+		if !utf8.ValidString(arg) {
+			return nil, fmt.Errorf("arg[%d] is not a valid UTF-8 string", i)
+		}
+		argLen := uint64(len(arg)) + 1 // + 1 for "\x00"; uint64 in case this one arg is huge
+		nextSize := uint64(totalBufSize) + argLen
+		if nextSize > uint64(maxBufSize) {
+			return nil, fmt.Errorf("arg[%d] will exceed max buffer size %d", i, maxBufSize)
+		}
+		totalBufSize = uint32(nextSize)
+		strings = append(strings, append([]byte(arg), 0))
+	}
+	return &nullTerminatedStrings{nullTerminatedValues: strings, totalBufSize: totalBufSize}, nil
+}
diff --git a/wasi/types.go b/wasi/types.go
new file mode 100644
index 00000000..6fe666e7
--- /dev/null
+++ b/wasi/types.go
@@ -0,0 +1,366 @@
+package wasi
+
+import "fmt"
+
+// Errno are the error codes returned by WASI functions.
+//
+// Note: Codes are defined even when not relevant to WASI for use in higher-level libraries or alignment with POSIX.
+// See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-errno-enumu16
+// See https://linux.die.net/man/3/errno
+type Errno uint32
+
+// Error returns the POSIX error code name, except ErrnoSuccess, which isn't defined. Ex. Errno2big -> "E2BIG"
+func (err Errno) Error() string {
+	if int(err) < len(errnoToString) {
+		return errnoToString[err]
+	}
+	return fmt.Sprintf("errno(%d)", uint32(err))
+}
+
+// Note: Below prefers POSIX symbol names over WASI ones, even if the docs are from WASI.
+// See https://linux.die.net/man/3/errno
+// See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#variants-1
+const (
+	// ErrnoSuccess No error occurred. System call completed successfully.
+	ErrnoSuccess Errno = iota
+	// Errno2big Argument list too long.
+	Errno2big
+	// ErrnoAcces Permission denied.
+	ErrnoAcces
+	// ErrnoAddrinuse Address in use.
+	ErrnoAddrinuse
+	// ErrnoAddrnotavail Address not available.
+	ErrnoAddrnotavail
+	// ErrnoAfnosupport Address family not supported.
+	ErrnoAfnosupport
+	// ErrnoAgain Resource unavailable, or operation would block.
+	ErrnoAgain
+	// ErrnoAlready Connection already in progress.
+	ErrnoAlready
+	// ErrnoBadf Bad file descriptor.
+	ErrnoBadf
+	// ErrnoBadmsg Bad message.
+	ErrnoBadmsg
+	// ErrnoBusy Device or resource busy.
+	ErrnoBusy
+	// ErrnoCanceled Operation canceled.
+	ErrnoCanceled
+	// ErrnoChild No child processes.
+	ErrnoChild
+	// ErrnoConnaborted Connection aborted.
+	ErrnoConnaborted
+	// ErrnoConnrefused Connection refused.
+	ErrnoConnrefused
+	// ErrnoConnreset Connection reset.
+	ErrnoConnreset
+	// ErrnoDeadlk Resource deadlock would occur.
+	ErrnoDeadlk
+	// ErrnoDestaddrreq Destination address required.
+	ErrnoDestaddrreq
+	// ErrnoDom Mathematics argument out of domain of function.
+	ErrnoDom
+	// ErrnoDquot Reserved.
+	ErrnoDquot
+	// ErrnoExist File exists.
+	ErrnoExist
+	// ErrnoFault Bad address.
+	ErrnoFault
+	// ErrnoFbig File too large.
+	ErrnoFbig
+	// ErrnoHostunreach Host is unreachable.
+	ErrnoHostunreach
+	// ErrnoIdrm Identifier removed.
+	ErrnoIdrm
+	// ErrnoIlseq Illegal byte sequence.
+	ErrnoIlseq
+	// ErrnoInprogress Operation in progress.
+	ErrnoInprogress
+	// ErrnoIntr Interrupted function.
+	ErrnoIntr
+	// ErrnoInval Invalid argument.
+	ErrnoInval
+	// ErrnoIo I/O error.
+	ErrnoIo
+	// ErrnoIsconn Socket is connected.
+	ErrnoIsconn
+	// ErrnoIsdir Is a directory.
+	ErrnoIsdir
+	// ErrnoLoop Too many levels of symbolic links.
+	ErrnoLoop
+	// ErrnoMfile File descriptor value too large.
+	ErrnoMfile
+	// ErrnoMlink Too many links.
+	ErrnoMlink
+	// ErrnoMsgsize Message too large.
+	ErrnoMsgsize
+	// ErrnoMultihop Reserved.
+	ErrnoMultihop
+	// ErrnoNametoolong Filename too long.
+	ErrnoNametoolong
+	// ErrnoNetdown Network is down.
+	ErrnoNetdown
+	// ErrnoNetreset Connection aborted by network.
+	ErrnoNetreset
+	// ErrnoNetunreach Network unreachable.
+	ErrnoNetunreach
+	// ErrnoNfile Too many files open in system.
+	ErrnoNfile
+	// ErrnoNobufs No buffer space available.
+	ErrnoNobufs
+	// ErrnoNodev No such device.
+	ErrnoNodev
+	// ErrnoNoent No such file or directory.
+	ErrnoNoent
+	// ErrnoNoexec Executable file format error.
+	ErrnoNoexec
+	// ErrnoNolck No locks available.
+	ErrnoNolck
+	// ErrnoNolink Reserved.
+	ErrnoNolink
+	// ErrnoNomem Not enough space.
+	ErrnoNomem
+	// ErrnoNomsg No message of the desired type.
+	ErrnoNomsg
+	// ErrnoNoprotoopt No message of the desired type.
+	ErrnoNoprotoopt
+	// ErrnoNospc No space left on device.
+	ErrnoNospc
+	// ErrnoNosys Function not supported.
+	ErrnoNosys
+	// ErrnoNotconn The socket is not connected.
+	ErrnoNotconn
+	// ErrnoNotdir Not a directory or a symbolic link to a directory.
+	ErrnoNotdir
+	// ErrnoNotempty Directory not empty.
+	ErrnoNotempty
+	// ErrnoNotrecoverable State not recoverable.
+	ErrnoNotrecoverable
+	// ErrnoNotsock Not a socket.
+	ErrnoNotsock
+	// ErrnoNotsup Not supported, or operation not supported on socket.
+	ErrnoNotsup
+	// ErrnoNotty Inappropriate I/O control operation.
+	ErrnoNotty
+	// ErrnoNxio No such device or address.
+	ErrnoNxio
+	// ErrnoOverflow Value too large to be stored in data type.
+	ErrnoOverflow
+	// ErrnoOwnerdead Previous owner died.
+	ErrnoOwnerdead
+	// ErrnoPerm Operation not permitted.
+	ErrnoPerm
+	// ErrnoPipe Broken pipe.
+	ErrnoPipe
+	// ErrnoProto Protocol error.
+	ErrnoProto
+	// ErrnoProtonosupport Protocol error.
+	ErrnoProtonosupport
+	// ErrnoPrototype Protocol wrong type for socket.
+	ErrnoPrototype
+	// ErrnoRange Result too large.
+	ErrnoRange
+	// ErrnoRofs Read-only file system.
+	ErrnoRofs
+	// ErrnoSpipe Invalid seek.
+	ErrnoSpipe
+	// ErrnoSrch No such process.
+	ErrnoSrch
+	// ErrnoStale Reserved.
+	ErrnoStale
+	// ErrnoTimedout Connection timed out.
+	ErrnoTimedout
+	// ErrnoTxtbsy Text file busy.
+	ErrnoTxtbsy
+	// ErrnoXdev Cross-device link.
+	ErrnoXdev
+	// ErrnoNotcapable Extension: Capabilities insufficient.
+	ErrnoNotcapable
+)
+
+var errnoToString = [...]string{
+	ErrnoSuccess:        "ESUCCESS",
+	Errno2big:           "E2BIG",
+	ErrnoAcces:          "EACCES",
+	ErrnoAddrinuse:      "EADDRINUSE",
+	ErrnoAddrnotavail:   "EADDRNOTAVAIL",
+	ErrnoAfnosupport:    "EAFNOSUPPORT",
+	ErrnoAgain:          "EAGAIN",
+	ErrnoAlready:        "EALREADY",
+	ErrnoBadf:           "EBADF",
+	ErrnoBadmsg:         "EBADMSG",
+	ErrnoBusy:           "EBUSY",
+	ErrnoCanceled:       "ECANCELED",
+	ErrnoChild:          "ECHILD",
+	ErrnoConnaborted:    "ECONNABORTED",
+	ErrnoConnrefused:    "ECONNREFUSED",
+	ErrnoConnreset:      "ECONNRESET",
+	ErrnoDeadlk:         "EDEADLK",
+	ErrnoDestaddrreq:    "EDESTADDRREQ",
+	ErrnoDom:            "EDOM",
+	ErrnoDquot:          "EDQUOT",
+	ErrnoExist:          "EEXIST",
+	ErrnoFault:          "EFAULT",
+	ErrnoFbig:           "EFBIG",
+	ErrnoHostunreach:    "EHOSTUNREACH",
+	ErrnoIdrm:           "EIDRM",
+	ErrnoIlseq:          "EILSEQ",
+	ErrnoInprogress:     "EINPROGRESS",
+	ErrnoIntr:           "EINTR",
+	ErrnoInval:          "EINVAL",
+	ErrnoIo:             "EIO",
+	ErrnoIsconn:         "EISCONN",
+	ErrnoIsdir:          "EISDIR",
+	ErrnoLoop:           "ELOOP",
+	ErrnoMfile:          "EMFILE",
+	ErrnoMlink:          "EMLINK",
+	ErrnoMsgsize:        "EMSGSIZE",
+	ErrnoMultihop:       "EMULTIHOP",
+	ErrnoNametoolong:    "ENAMETOOLONG",
+	ErrnoNetdown:        "ENETDOWN",
+	ErrnoNetreset:       "ENETRESET",
+	ErrnoNetunreach:     "ENETUNREACH",
+	ErrnoNfile:          "ENFILE",
+	ErrnoNobufs:         "ENOBUFS",
+	ErrnoNodev:          "ENODEV",
+	ErrnoNoent:          "ENOENT",
+	ErrnoNoexec:         "ENOEXEC",
+	ErrnoNolck:          "ENOLCK",
+	ErrnoNolink:         "ENOLINK",
+	ErrnoNomem:          "ENOMEM",
+	ErrnoNomsg:          "ENOMSG",
+	ErrnoNoprotoopt:     "ENOPROTOOPT",
+	ErrnoNospc:          "ENOSPC",
+	ErrnoNosys:          "ENOSYS",
+	ErrnoNotconn:        "ENOTCONN",
+	ErrnoNotdir:         "ENOTDIR",
+	ErrnoNotempty:       "ENOTEMPTY",
+	ErrnoNotrecoverable: "ENOTRECOVERABLE",
+	ErrnoNotsock:        "ENOTSOCK",
+	ErrnoNotsup:         "ENOTSUP",
+	ErrnoNotty:          "ENOTTY",
+	ErrnoNxio:           "ENXIO",
+	ErrnoOverflow:       "EOVERFLOW",
+	ErrnoOwnerdead:      "EOWNERDEAD",
+	ErrnoPerm:           "EPERM",
+	ErrnoPipe:           "EPIPE",
+	ErrnoProto:          "EPROTO",
+	ErrnoProtonosupport: "EPROTONOSUPPORT",
+	ErrnoPrototype:      "EPROTOTYPE",
+	ErrnoRange:          "ERANGE",
+	ErrnoRofs:           "EROFS",
+	ErrnoSpipe:          "ESPIPE",
+	ErrnoSrch:           "ESRCH",
+	ErrnoStale:          "ESTALE",
+	ErrnoTimedout:       "ETIMEDOUT",
+	ErrnoTxtbsy:         "ETXTBSY",
+	ErrnoXdev:           "EXDEV",
+	ErrnoNotcapable:     "ENOTCAPABLE",
+}
+
+const (
+	// FunctionArgsGet reads command-line argument data.
+	//
+	// In WebAssembly 1.0 (MVP) Text format, this signature is:
+	//	(import "wasi_snapshot_preview1" "args_get"
+	//		(func $wasi.args_get (param $argv i32) (param $argv_buf i32) (result (;errno;) i32)))
+	//
+	// See API.ArgsGet
+	// See FunctionArgsSizesGet
+	// See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-args_getargv-pointerpointeru8-argv_buf-pointeru8---errno
+	FunctionArgsGet = "args_get"
+
+	// FunctionArgsSizesGet returns command-line argument data sizes.
+	//
+	// In WebAssembly 1.0 (MVP) Text format, this signature is:
+	//	(import "wasi_snapshot_preview1" "args_sizes_get"
+	//		(func $wasi.args_sizes_get (param $result.argc i32) (param $result.argv_buf_size i32) (result (;errno;) i32)))
+	//
+	// See API.ArgsSizesGet
+	// See FunctionArgsGet
+	// See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-args_sizes_get---errno-size-size
+	FunctionArgsSizesGet = "args_sizes_get"
+
+	// FunctionEnvironGet reads environment variable data.
+	//
+	// In WebAssembly 1.0 (MVP) Text format, this signature is:
+	//	(import "wasi_snapshot_preview1" "environ_get"
+	//		(func $wasi.environ_get (param $environ i32) (param $environ_buf i32) (result (;errno;) i32)))
+	//
+	// See API.EnvironGet
+	// See FunctionEnvironSizesGet
+	// See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-environ_getenviron-pointerpointeru8-environ_buf-pointeru8---errno
+	FunctionEnvironGet = "environ_get"
+
+	// FunctionEnvironSizesGet returns environment variable data sizes.
+	//
+	// In WebAssembly 1.0 (MVP) Text format, this signature is:
+	//	(import "wasi_snapshot_preview1" "environ_sizes_get"
+	//		(func $wasi.environ_sizes_get (param $result.environc i32) (param $result.environBufSize i32) (result (;errno;) i32)))
+	//
+	// See API.EnvironSizesGet
+	// See FunctionEnvironGet
+	// See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-environ_sizes_get---errno-size-size
+	FunctionEnvironSizesGet = "environ_sizes_get"
+
+	// FunctionClockResGet returns the resolution of a clock.
+	//
+	// In WebAssembly 1.0 (MVP) Text format, this signature is:
+	//	(import "wasi_snapshot_preview1" "clock_res_get"
+	//		(func $wasi.clock_res_get (param $id i32) (param $result.resolution i32) (result (;errno;) i32)))
+	//
+	// See API.ClockResGet
+	// See FunctionClockTimeGet
+	// See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-clock_res_getid-clockid---errno-timestamp
+	FunctionClockResGet = "clock_res_get"
+
+	// FunctionClockTimeGet returns the time value of a clock.
+	//
+	// In WebAssembly 1.0 (MVP) Text format, this signature is:
+	//	(import "wasi_snapshot_preview1" "clock_time_get"
+	//		(func $wasi.clock_time_get (param $id i32) (param $precision i64) (param $result.timestamp i32) (result (;errno;) i32)))
+	//
+	// See API.ClockResGet
+	// See FunctionClockResGet
+	// See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-clock_time_getid-clockid-precision-timestamp---errno-timestamp
+	FunctionClockTimeGet = "clock_time_get"
+
+	FunctionFDAdvise             = "fd_advise"
+	FunctionFDAllocate           = "fd_allocate"
+	FunctionFDClose              = "fd_close"
+	FunctionFDDataSync           = "fd_datasync"
+	FunctionFDFDStatGet          = "fd_fdstat_get"
+	FunctionFDFDStatSetFlags     = "fd_fdstat_set_flags"
+	FunctionFDFDStatSetRights    = "fd_fdstat_set_rights"
+	FunctionFDFilestatGet        = "fd_filestat_get"
+	FunctionFDFilestatSetSize    = "fd_filestat_set_size"
+	FunctionFDFilestatSetTimes   = "fd_filestat_set_times"
+	FunctionFDPread              = "fd_pread"
+	FunctionFDPrestatGet         = "fd_prestat_get"
+	FunctionFDPrestatDirName     = "fd_prestat_dir_name"
+	FunctionFDPwrite             = "fd_pwrite"
+	FunctionFDRead               = "fd_read"
+	FunctionFDReaddir            = "fd_readdir"
+	FunctionFDRenumber           = "fd_renumber"
+	FunctionFDSeek               = "fd_seek"
+	FunctionFDSync               = "fd_sync"
+	FunctionFDTell               = "fd_tell"
+	FunctionFDWrite              = "fd_write"
+	FunctionPathCreateDirectory  = "path_create_directory"
+	FunctionPathFilestatGet      = "path_filestat_get"
+	FunctionPathFilestatSetTimes = "path_filestat_set_times"
+	FunctionPathLink             = "path_link"
+	FunctionPathOpen             = "path_open"
+	FunctionPathReadlink         = "path_readlink"
+	FunctionPathRemoveDirectory  = "path_remove_directory"
+	FunctionPathRename           = "path_rename"
+	FunctionPathSymlink          = "path_symlink"
+	FunctionPathUnlinkFile       = "path_unlink_file"
+	FunctionPollOneoff           = "poll_oneoff"
+	FunctionProcExit             = "proc_exit"
+	FunctionProcRaise            = "proc_raise"
+	FunctionSchedYield           = "sched_yield"
+	FunctionRandomGet            = "random_get"
+	FunctionSockRecv             = "sock_recv"
+	FunctionSockSend             = "sock_send"
+	FunctionSockShutdown         = "sock_shutdown"
+)
diff --git a/wasi/wasi.go b/wasi/wasi.go
index 8f52f8a1..1299e7cb 100644
--- a/wasi/wasi.go
+++ b/wasi/wasi.go
@@ -3,7 +3,6 @@ package wasi
 import (
 	"encoding/binary"
 	"errors"
-	"fmt"
 	"io"
 	"io/fs"
 	"math"
@@ -11,64 +10,35 @@ import (
 	"os"
 	"reflect"
 	"time"
-	"unicode/utf8"
 
 	"github.com/tetratelabs/wazero/wasm"
 )
 
-// API is a documentation interface for WASI exported functions in version "wasi_snapshot_preview1"
+// API includes all host functions to export for WASI version "wasi_snapshot_preview1"
+//
+// Note: When translating WASI functions, each result besides Errno is always an uint32 parameter. WebAssembly 1.0 (MVP)
+// can have up to one result, which is already used by Errno. This forces other results to be parameters. A result
+// parameter is a memory offset to write the result to. As memory offsets are uint32, each parameter representing a
+// result is uint32.
 //
 // Note: In WebAssembly 1.0 (MVP), there may be up to one Memory per store, which means the wasm.HostFunctionCallContext
 // Memory is always the wasm.Store Memories index zero: `store.Memories[0].Buffer`
 //
 // See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md
-// See https://www.w3.org/TR/wasm-core-1/#memory-instances%E2%91%A0.
+// See https://wwa.w3.org/TR/wasm-core-1/#memory-instances%E2%91%A0.
 type API interface {
-	// ArgsSizesGet is a WASI function that reads command-line argument data (Args) sizes.
-	//
-	// There are two parameters and an Errno result. Both parameters are offsets in the wasm.HostFunctionCallContext
-	// Memory Buffer to write the corresponding sizes in uint32 little-endian encoding.
-	//
-	// * argc - is the offset to write the argument count to the wasm.MemoryInstance Buffer
-	// * argvBufSize - is the offset to write the null terminated argument length to the wasm.MemoryInstance Buffer
-	//
-	// In WebAssembly 1.0 (MVP) Text format, this signature is:
-	//	(import "wasi_snapshot_preview1" "args_sizes_get"
-	//		(func ($wasi_args_sizes_get (param $argc i32) (param $argv_buf_size i32) (result i32))
-	//
-	// For example, if Args are []string{"a","bc"} and
-	//   ArgsSizesGet parameters argc=1 and argvBufSize=6, we expect `ctx.Memory.Buffer` to contain:
-	//
-	//                    uint32         uint32
-	//                  +--------+     +--------+
-	//                  |        |     |        |
-	//        []byte{?, 2, 0, 0, 0, ?, 5, 0, 0, 0, ?}
-	//           argc --^              ^
-	//         2 args --+              |
-	//                   argvBufSize --|
-	//   len([]byte{'a',0,'b',c',0}) --+
-	//
-	// See ArgsGet
-	// See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#args_sizes_get
-	// See https://en.wikipedia.org/wiki/Null-terminated_string
-	ArgsSizesGet(ctx *wasm.HostFunctionCallContext, argc, argvBufSize uint32) Errno
-
-	// ArgsGet is a WASI function that reads command-line argument data (Args).
+	// ArgsGet is the WASI function that reads command-line argument data (Args).
 	//
 	// There are two parameters and an Errno result. Both parameters are offsets in the wasm.HostFunctionCallContext
 	// Memory Buffer to write offsets. These are encoded uint32 little-endian.
 	//
 	// * argv - is the offset to begin writing argument offsets to the wasm.MemoryInstance
-	//   * ArgsSizesGet argc * 4 bytes are written to this offset
+	//   * ArgsSizesGet result argc * 4 bytes are written to this offset
 	// * argvBuf - is the offset to write the null terminated arguments to the wasm.MemoryInstance
-	//   * ArgsSizesGet argv_buf_size bytes are written to this offset
-	//
-	// In WebAssembly 1.0 (MVP) Text format, this signature is:
-	//	(import "wasi_snapshot_preview1" "args_get"
-	//		(func ($wasi_args_get (param $argv i32) (param $argv_buf i32) (result i32))
+	//   * ArgsSizesGet result argv_buf_size bytes are written to this offset
 	//
 	// For example, if ArgsSizesGet wrote argc=2 and argvBufSize=5 for arguments: "a" and "bc"
-	//   and ArgsGet parameters argv=7 and argvBuf=1, we expect `ctx.Memory.Buffer` to contain:
+	//   and ArgsGet results argv=7 and argvBuf=1, we expect `ctx.Memory.Buffer` to contain:
 	//
 	//               argvBufSize                argc * 4
 	//            +----------------+     +--------------------+
@@ -79,10 +49,85 @@ type API interface {
 	//          offset that begins "a" --+           |
 	//                     offset that begins "bc" --+
 	//
+	// Note: FunctionArgsGet documentation has an example of this signature in the WebAssembly 1.0 (MVP) Text Format.
 	// See ArgsSizesGet
 	// See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#args_get
 	// See https://en.wikipedia.org/wiki/Null-terminated_string
 	ArgsGet(ctx *wasm.HostFunctionCallContext, argv, argvBuf uint32) Errno
+
+	// ArgsSizesGet is a WASI function that reads command-line argument data (Args) sizes.
+	//
+	// There are two parameters and an Errno result. Both parameters are offsets in the wasm.HostFunctionCallContext
+	// Memory Buffer to write the corresponding sizes in uint32 little-endian encoding.
+	//
+	// * argc - is the offset to write the argument count to the wasm.MemoryInstance Buffer
+	// * argvBufSize - is the offset to write the null terminated argument length to the wasm.MemoryInstance Buffer
+	//
+	// For example, if Args are []string{"a","bc"} and
+	//   ArgsSizesGet parameters resultArgc=1 and resultArgvBufSize=6, we expect `ctx.Memory.Buffer` to contain:
+	//
+	//                    uint32         uint32
+	//                  +--------+     +--------+
+	//                  |        |     |        |
+	//        []byte{?, 2, 0, 0, 0, ?, 5, 0, 0, 0, ?}
+	//     resultArgc --^              ^
+	//         2 args --+              |
+	//             resultArgvBufSize --|
+	//   len([]byte{'a',0,'b',c',0}) --+
+	//
+	// Note: FunctionArgsSizesGet documentation has an example of this signature in the WebAssembly 1.0 (MVP) Text Format.
+	// See ArgsGet
+	// See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#args_sizes_get
+	// See https://en.wikipedia.org/wiki/Null-terminated_string
+	ArgsSizesGet(ctx *wasm.HostFunctionCallContext, resultArgc, resultArgvBufSize uint32) Errno
+
+	// TODO: EnvironGet(ctx *wasm.HostFunctionCallContext, environ, environBuf uint32) Errno
+
+	// TODO: EnvironSizesGet(ctx *wasm.HostFunctionCallContext, resulEnvironc, resultEnvironBufSize uint32) Errno
+
+	// TODO: ClockResGet(ctx *wasm.HostFunctionCallContext, id, resultResolution uint32) Errno
+
+	// TODO: ClockTimeGet(ctx *wasm.HostFunctionCallContext, id uint32, precision uint64, resultTimestamp uint32) Errno
+
+	// TODO: FDAdvise
+	// TODO: FDAllocate
+	// TODO: FDClose
+	// TODO: FDDataSync
+	// TODO: FDFDStatGet
+	// TODO: FDFDStatSetFlags
+	// TODO: FDFDStatSetRights
+	// TODO: FDFilestatGet
+	// TODO: FDFilestatSetSize
+	// TODO: FDFilestatSetTimes
+	// TODO: FDPread
+	// TODO: FDPrestatGet
+	// TODO: FDPrestatDirName
+	// TODO: FDPwrite
+	// TODO: FDRead
+	// TODO: FDReaddir
+	// TODO: FDRenumber
+	// TODO: FDSeek
+	// TODO: FDSync
+	// TODO: FDTell
+	// TODO: FDWrite
+	// TODO: PathCreateDirectory
+	// TODO: PathFilestatGet
+	// TODO: PathFilestatSetTimes
+	// TODO: PathLink
+	// TODO: PathOpen
+	// TODO: PathReadlink
+	// TODO: PathRemoveDirectory
+	// TODO: PathRename
+	// TODO: PathSymlink
+	// TODO: PathUnlinkFile
+	// TODO: PollOneoff
+	// TODO: ProcExit
+	// TODO: ProcRaise
+	// TODO: SchedYield
+	// TODO: RandomGet
+	// TODO: SockRecv
+	// TODO: SockSend
+	// TODO: SockShutdown
 }
 
 const (
@@ -99,66 +144,68 @@ type api struct {
 	getTimeNanosFn func() uint64
 }
 
-func (w *api) register(store *wasm.Store) (err error) {
+func (a *api) register(store *wasm.Store) (err error) {
+	// Note: these are ordered per spec for consistency
+	// See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#functions
+	nameToFunction := []struct {
+		funcName string
+		fn       interface{}
+	}{
+		{FunctionArgsGet, a.ArgsGet},
+		{FunctionArgsSizesGet, a.ArgsSizesGet},
+		{FunctionEnvironGet, environ_get},
+		{FunctionEnvironSizesGet, environ_sizes_get},
+		// TODO: FunctionClockResGet
+		{FunctionClockTimeGet, a.clock_time_get},
+		// TODO: FunctionFDAdvise
+		// TODO: FunctionFDAllocate
+		{FunctionFDClose, a.fd_close},
+		// TODO: FunctionFDDataSync
+		{FunctionFDFDStatGet, a.fd_fdstat_get},
+		// TODO: FunctionFDFDStatSetFlags
+		// TODO: FunctionFDFDStatSetRights
+		// TODO: FunctionFDFilestatGet
+		// TODO: FunctionFDFilestatSetSize
+		// TODO: FunctionFDFilestatSetTimes
+		// TODO: FunctionFDPread
+		{FunctionFDPrestatGet, a.fd_prestat_get},
+		{FunctionFDPrestatDirName, a.fd_prestat_dir_name},
+		// TODO: FunctionFDPwrite
+		{FunctionFDRead, a.fd_read},
+		// TODO: FunctionFDReaddir
+		// TODO: FunctionFDRenumber
+		{FunctionFDSeek, a.fd_seek},
+		// TODO: FunctionFDSync
+		// TODO: FunctionFDTell
+		{FunctionFDWrite, a.fd_write},
+		// TODO: FunctionPathCreateDirectory
+		// TODO: FunctionPathFilestatGet
+		// TODO: FunctionPathFilestatSetTimes
+		// TODO: FunctionPathLink
+		{FunctionPathOpen, a.path_open},
+		// TODO: FunctionPathReadlink
+		// TODO: FunctionPathRemoveDirectory
+		// TODO: FunctionPathRename
+		// TODO: FunctionPathSymlink
+		// TODO: FunctionPathUnlinkFile
+		// TODO: FunctionPollOneoff
+		{FunctionProcExit, proc_exit},
+		// TODO: FunctionProcRaise
+		// TODO: FunctionSchedYield
+		// TODO: FunctionRandomGet
+		// TODO: FunctionSockRecv
+		// TODO: FunctionSockSend
+		// TODO: FunctionSockShutdown
+	}
 	for _, wasiName := range []string{
-		wasiUnstableName,
+		wasiUnstableName, // TODO: check if there are any signature incompatibility between stable and preview 1
 		wasiSnapshotPreview1Name,
 	} {
-		err = store.AddHostFunction(wasiName, "proc_exit", reflect.ValueOf(proc_exit))
-		if err != nil {
-			return err
-		}
-		err = store.AddHostFunction(wasiName, "fd_write", reflect.ValueOf(w.fd_write))
-		if err != nil {
-			return err
-		}
-		err = store.AddHostFunction(wasiName, "environ_sizes_get", reflect.ValueOf(environ_sizes_get))
-		if err != nil {
-			return err
-		}
-		err = store.AddHostFunction(wasiName, "environ_get", reflect.ValueOf(environ_get))
-		if err != nil {
-			return err
-		}
-		err = store.AddHostFunction(wasiName, "fd_prestat_get", reflect.ValueOf(w.fd_prestat_get))
-		if err != nil {
-			return err
-		}
-		err = store.AddHostFunction(wasiName, "fd_prestat_dir_name", reflect.ValueOf(w.fd_prestat_dir_name))
-		if err != nil {
-			return err
-		}
-		err = store.AddHostFunction(wasiName, "fd_fdstat_get", reflect.ValueOf(w.fd_fdstat_get))
-		if err != nil {
-			return err
-		}
-		err = store.AddHostFunction(wasiName, "fd_close", reflect.ValueOf(w.fd_close))
-		if err != nil {
-			return err
-		}
-		err = store.AddHostFunction(wasiName, "fd_read", reflect.ValueOf(w.fd_read))
-		if err != nil {
-			return err
-		}
-		err = store.AddHostFunction(wasiName, "fd_seek", reflect.ValueOf(w.fd_seek))
-		if err != nil {
-			return err
-		}
-		err = store.AddHostFunction(wasiName, "path_open", reflect.ValueOf(w.path_open))
-		if err != nil {
-			return err
-		}
-		err = store.AddHostFunction(wasiName, "args_get", reflect.ValueOf(w.ArgsGet))
-		if err != nil {
-			return err
-		}
-		err = store.AddHostFunction(wasiName, "args_sizes_get", reflect.ValueOf(w.ArgsSizesGet))
-		if err != nil {
-			return err
-		}
-		err = store.AddHostFunction(wasiName, "clock_time_get", reflect.ValueOf(w.clock_time_get))
-		if err != nil {
-			return err
+		for _, pair := range nameToFunction {
+			err = store.AddHostFunction(wasiName, pair.funcName, reflect.ValueOf(pair.fn))
+			if err != nil {
+				return err
+			}
 		}
 	}
 	return nil
@@ -173,56 +220,21 @@ type fileEntry struct {
 type Option func(*api)
 
 func Stdin(reader io.Reader) Option {
-	return func(w *api) {
-		w.stdin = reader
+	return func(a *api) {
+		a.stdin = reader
 	}
 }
 
 func Stdout(writer io.Writer) Option {
-	return func(w *api) {
-		w.stdout = writer
+	return func(a *api) {
+		a.stdout = writer
 	}
 }
 
 func Stderr(writer io.Writer) Option {
-	return func(w *api) {
-		w.stderr = writer
-	}
-}
-
-// nullTerminatedStrings holds null-terminated strings. It ensures that
-// its length and total buffer size don't exceed the max of uint32.
-// nullTerminatedStrings are convenience struct for args_get and environ_get. (environ_get is not implemented yet)
-//
-// A Null-terminated string is a byte string with a NULL suffix ("\x00").
-// See https://en.wikipedia.org/wiki/Null-terminated_string
-type nullTerminatedStrings struct {
-	// nullTerminatedValues are null-terminated values with a NULL suffix.
-	nullTerminatedValues [][]byte
-	totalBufSize         uint32
-}
-
-// newNullTerminatedStrings creates a nullTerminatedStrings from the given string slice. It returns an error
-// if the length or the total buffer size of the result WASIStringArray exceeds the maxBufSize
-func newNullTerminatedStrings(maxBufSize uint32, args ...string) (*nullTerminatedStrings, error) {
-	if len(args) == 0 {
-		return &nullTerminatedStrings{nullTerminatedValues: [][]byte{}}, nil
-	}
-	var strings [][]byte // don't pre-allocate as this function is size bound
-	totalBufSize := uint32(0)
-	for i, arg := range args {
-		if !utf8.ValidString(arg) {
-			return nil, fmt.Errorf("arg[%d] is not a valid UTF-8 string", i)
-		}
-		argLen := uint64(len(arg)) + 1 // + 1 for "\x00"; uint64 in case this one arg is huge
-		nextSize := uint64(totalBufSize) + argLen
-		if nextSize > uint64(maxBufSize) {
-			return nil, fmt.Errorf("arg[%d] will exceed max buffer size %d", i, maxBufSize)
-		}
-		totalBufSize = uint32(nextSize)
-		strings = append(strings, append([]byte(arg), 0))
+	return func(a *api) {
+		a.stderr = writer
 	}
-	return &nullTerminatedStrings{nullTerminatedValues: strings, totalBufSize: totalBufSize}, nil
 }
 
 // Args returns an option to give a command-line arguments to the API or errs if the inputs are too large.
@@ -234,14 +246,14 @@ func Args(args ...string) (Option, error) {
 	if err != nil {
 		return nil, err
 	}
-	return func(w *api) {
-		w.args = wasiStrings
+	return func(a *api) {
+		a.args = wasiStrings
 	}, nil
 }
 
 func Preopen(dir string, fileSys FS) Option {
-	return func(w *api) {
-		w.opened[uint32(len(w.opened))+3] = fileEntry{
+	return func(a *api) {
+		a.opened[uint32(len(a.opened))+3] = fileEntry{
 			path:    dir,
 			fileSys: fileSys,
 		}
@@ -280,51 +292,51 @@ func newAPI(opts ...Option) *api {
 	return ret
 }
 
-func (w *api) randUnusedFD() uint32 {
+func (a *api) randUnusedFD() uint32 {
 	fd := uint32(rand.Int31())
 	for {
-		if _, ok := w.opened[fd]; !ok {
+		if _, ok := a.opened[fd]; !ok {
 			return fd
 		}
 		fd = (fd + 1) % (1 << 31)
 	}
 }
 
-func (w *api) fd_prestat_get(ctx *wasm.HostFunctionCallContext, fd uint32, bufPtr uint32) (err Errno) {
-	if _, ok := w.opened[fd]; !ok {
-		return EBADF
+func (a *api) fd_prestat_get(ctx *wasm.HostFunctionCallContext, fd uint32, bufPtr uint32) (err Errno) {
+	if _, ok := a.opened[fd]; !ok {
+		return ErrnoBadf
 	}
-	return ESUCCESS
+	return ErrnoSuccess
 }
 
-func (w *api) fd_prestat_dir_name(ctx *wasm.HostFunctionCallContext, fd uint32, pathPtr uint32, pathLen uint32) (err Errno) {
-	f, ok := w.opened[fd]
+func (a *api) fd_prestat_dir_name(ctx *wasm.HostFunctionCallContext, fd uint32, pathPtr uint32, pathLen uint32) (err Errno) {
+	f, ok := a.opened[fd]
 	if !ok {
-		return EINVAL
+		return ErrnoInval
 	}
 
 	if uint32(len(f.path)) < pathLen {
-		return ENAMETOOLONG
+		return ErrnoNametoolong
 	}
 
 	copy(ctx.Memory.Buffer[pathPtr:], f.path)
-	return ESUCCESS
+	return ErrnoSuccess
 }
 
-func (w *api) fd_fdstat_get(ctx *wasm.HostFunctionCallContext, fd uint32, bufPtr uint32) (err Errno) {
-	if _, ok := w.opened[fd]; !ok {
-		return EBADF
+func (a *api) fd_fdstat_get(ctx *wasm.HostFunctionCallContext, fd uint32, bufPtr uint32) (err Errno) {
+	if _, ok := a.opened[fd]; !ok {
+		return ErrnoBadf
 	}
 	binary.LittleEndian.PutUint64(ctx.Memory.Buffer[bufPtr+16:], R_FD_READ|R_FD_WRITE)
-	return ESUCCESS
+	return ErrnoSuccess
 }
 
-func (w *api) path_open(ctx *wasm.HostFunctionCallContext, fd, dirFlags, pathPtr, pathLen, oFlags uint32,
+func (a *api) path_open(ctx *wasm.HostFunctionCallContext, fd, dirFlags, pathPtr, pathLen, oFlags uint32,
 	fsRightsBase, fsRightsInheriting uint64,
 	fdFlags, fdPtr uint32) (errno Errno) {
-	dir, ok := w.opened[fd]
+	dir, ok := a.opened[fd]
 	if !ok || dir.fileSys == nil {
-		return EINVAL
+		return ErrnoInval
 	}
 
 	path := string(ctx.Memory.Buffer[pathPtr : pathPtr+pathLen])
@@ -332,39 +344,38 @@ func (w *api) path_open(ctx *wasm.HostFunctionCallContext, fd, dirFlags, pathPtr
 	if err != nil {
 		switch {
 		case errors.Is(err, fs.ErrNotExist):
-			return ENOENT
+			return ErrnoNoent
 		default:
-			return EINVAL
+			return ErrnoInval
 		}
 	}
 
-	newFD := w.randUnusedFD()
+	newFD := a.randUnusedFD()
 
-	w.opened[newFD] = fileEntry{
+	a.opened[newFD] = fileEntry{
 		file: f,
 	}
 
 	binary.LittleEndian.PutUint32(ctx.Memory.Buffer[fdPtr:], newFD)
-	return ESUCCESS
+	return ErrnoSuccess
 }
 
-func (w *api) fd_seek(ctx *wasm.HostFunctionCallContext, fd uint32, offset uint64, whence uint32, nwrittenPtr uint32) (err Errno) {
-	// not implemented yet
-	return ENOSYS
+func (a *api) fd_seek(ctx *wasm.HostFunctionCallContext, fd uint32, offset uint64, whence uint32, nwrittenPtr uint32) (err Errno) {
+	return ErrnoNosys // TODO: implement
 }
 
-func (w *api) fd_write(ctx *wasm.HostFunctionCallContext, fd uint32, iovsPtr uint32, iovsLen uint32, nwrittenPtr uint32) (err Errno) {
+func (a *api) fd_write(ctx *wasm.HostFunctionCallContext, fd uint32, iovsPtr uint32, iovsLen uint32, nwrittenPtr uint32) (err Errno) {
 	var writer io.Writer
 
 	switch fd {
 	case 1:
-		writer = w.stdout
+		writer = a.stdout
 	case 2:
-		writer = w.stderr
+		writer = a.stderr
 	default:
-		f, ok := w.opened[fd]
+		f, ok := a.opened[fd]
 		if !ok || f.file == nil {
-			return EBADF
+			return ErrnoBadf
 		}
 		writer = f.file
 	}
@@ -381,19 +392,19 @@ func (w *api) fd_write(ctx *wasm.HostFunctionCallContext, fd uint32, iovsPtr uin
 		nwritten += uint32(n)
 	}
 	binary.LittleEndian.PutUint32(ctx.Memory.Buffer[nwrittenPtr:], nwritten)
-	return ESUCCESS
+	return ErrnoSuccess
 }
 
-func (w *api) fd_read(ctx *wasm.HostFunctionCallContext, fd uint32, iovsPtr uint32, iovsLen uint32, nreadPtr uint32) (err Errno) {
+func (a *api) fd_read(ctx *wasm.HostFunctionCallContext, fd uint32, iovsPtr uint32, iovsLen uint32, nreadPtr uint32) (err Errno) {
 	var reader io.Reader
 
 	switch fd {
 	case 0:
-		reader = w.stdin
+		reader = a.stdin
 	default:
-		f, ok := w.opened[fd]
+		f, ok := a.opened[fd]
 		if !ok || f.file == nil {
-			return EBADF
+			return ErrnoBadf
 		}
 		reader = f.file
 	}
@@ -408,66 +419,65 @@ func (w *api) fd_read(ctx *wasm.HostFunctionCallContext, fd uint32, iovsPtr uint
 		if errors.Is(err, io.EOF) {
 			break
 		} else if err != nil {
-			return EIO
+			return ErrnoIo
 		}
 	}
 	binary.LittleEndian.PutUint32(ctx.Memory.Buffer[nreadPtr:], nread)
-	return ESUCCESS
+	return ErrnoSuccess
 }
 
-func (w *api) fd_close(ctx *wasm.HostFunctionCallContext, fd uint32) (err Errno) {
-	f, ok := w.opened[fd]
+func (a *api) fd_close(ctx *wasm.HostFunctionCallContext, fd uint32) (err Errno) {
+	f, ok := a.opened[fd]
 	if !ok {
-		return EBADF
+		return ErrnoBadf
 	}
 
 	if f.file != nil {
 		f.file.Close()
 	}
 
-	delete(w.opened, fd)
+	delete(a.opened, fd)
 
-	return ESUCCESS
+	return ErrnoSuccess
 }
 
 // ArgsSizesGet implements API.ArgsSizesGet
-func (w *api) ArgsSizesGet(ctx *wasm.HostFunctionCallContext, argc, argvBufSize uint32) Errno {
-	if !ctx.Memory.PutUint32(argc, uint32(len(w.args.nullTerminatedValues))) {
-		return EINVAL
+func (a *api) ArgsSizesGet(ctx *wasm.HostFunctionCallContext, resultArgc, resultArgvBufSize uint32) Errno {
+	if !ctx.Memory.PutUint32(resultArgc, uint32(len(a.args.nullTerminatedValues))) {
+		return ErrnoInval
 	}
-	if !ctx.Memory.PutUint32(argvBufSize, w.args.totalBufSize) {
-		return EINVAL
+	if !ctx.Memory.PutUint32(resultArgvBufSize, a.args.totalBufSize) {
+		return ErrnoInval
 	}
 
-	return ESUCCESS
+	return ErrnoSuccess
 }
 
 // ArgsGet implements API.ArgsGet
-func (w *api) ArgsGet(ctx *wasm.HostFunctionCallContext, argv, argvBuf uint32) Errno {
-	if !ctx.Memory.ValidateAddrRange(argv, uint64(len(w.args.nullTerminatedValues))*4) /*4 is the size of uint32*/ ||
-		!ctx.Memory.ValidateAddrRange(argvBuf, uint64(w.args.totalBufSize)) {
-		return EINVAL
+func (a *api) ArgsGet(ctx *wasm.HostFunctionCallContext, argv, argvBuf uint32) Errno {
+	if !ctx.Memory.ValidateAddrRange(argv, uint64(len(a.args.nullTerminatedValues))*4) /*4 is the size of uint32*/ ||
+		!ctx.Memory.ValidateAddrRange(argvBuf, uint64(a.args.totalBufSize)) {
+		return ErrnoInval
 	}
-	for _, arg := range w.args.nullTerminatedValues {
+	for _, arg := range a.args.nullTerminatedValues {
 		binary.LittleEndian.PutUint32(ctx.Memory.Buffer[argv:], argvBuf)
 		argv += 4 // size of uint32
 		argvBuf += uint32(copy(ctx.Memory.Buffer[argvBuf:], arg))
 	}
 
-	return ESUCCESS
+	return ErrnoSuccess
 }
 
 func proc_exit(*wasm.HostFunctionCallContext, uint32) {
-	// not implemented yet
+	// TODO: implement
 }
 
 func environ_sizes_get(*wasm.HostFunctionCallContext, uint32, uint32) (err Errno) {
-	// not implemented yet
-	return
+	return ErrnoNosys // TODO: implement
 }
 
 func environ_get(*wasm.HostFunctionCallContext, uint32, uint32) (err Errno) {
-	return
+	return ErrnoNosys // TODO: implement
 }
 
 // clock_time_get is a WASI API that returns the time value of a clock. Note: This is similar to clock_gettime in POSIX.
@@ -476,10 +486,10 @@ func environ_get(*wasm.HostFunctionCallContext, uint32, uint32) (err Errno) {
 // * timestampPtr: a pointer to an address of uint64 type. The time value of the clock in nanoseconds is written there.
 //
 // See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-clock_time_getid-clockid-precision-timestamp---errno-timestamp
-func (w *api) clock_time_get(ctx *wasm.HostFunctionCallContext, id uint32, precision uint64, timestampPtr uint32) (err Errno) {
+func (a *api) clock_time_get(ctx *wasm.HostFunctionCallContext, id uint32, precision uint64, timestampPtr uint32) (err Errno) {
 	// TODO: The clock id and precision are currently ignored.
-	if !ctx.Memory.PutUint64(timestampPtr, w.getTimeNanosFn()) {
-		return EINVAL
+	if !ctx.Memory.PutUint64(timestampPtr, a.getTimeNanosFn()) {
+		return ErrnoInval
 	}
-	return ESUCCESS
+	return ErrnoSuccess
 }
diff --git a/wasm/binary/value.go b/wasm/binary/value.go
index a89b8eca..79c675cf 100644
--- a/wasm/binary/value.go
+++ b/wasm/binary/value.go
@@ -26,15 +26,15 @@ func encodeValTypes(vt []wasm.ValueType) []byte {
 	switch uint32(len(vt)) {
 	case 0: // nullary
 		return noValType
-	case 1: // ex $wasi_snapshot_preview1.fd_close or any result
+	case 1: // ex $wasi.fd_close or any result
 		if encoded, ok := encodedValTypes[vt[0]]; ok {
 			return encoded
 		}
-	case 2: // ex $wasi_snapshot_preview1.environ_sizes_get
+	case 2: // ex $wasi.environ_sizes_get
 		return []byte{2, vt[0], vt[1]}
-	case 4: // ex $wasi_snapshot_preview1.fd_write
+	case 4: // ex $wasi.fd_write
 		return []byte{4, vt[0], vt[1], vt[2], vt[3]}
-	case 9: // ex $wasi_snapshot_preview1.fd_write
+	case 9: // ex $wasi.fd_write
 		return []byte{9, vt[0], vt[1], vt[2], vt[3], vt[4], vt[5], vt[6], vt[7], vt[8]}
 	}
 	// Slow path others until someone complains with a valid signature


Test patch:
diff --git a/tests/codec/codec_test.go b/tests/codec/codec_test.go
index b7745807..34a910a2 100644
--- a/tests/codec/codec_test.go
+++ b/tests/codec/codec_test.go
@@ -42,11 +42,11 @@ func newExample() *wasm.Module {
 		},
 		ImportSection: []*wasm.Import{
 			{
-				Module: "wasi_snapshot_preview1", Name: "args_sizes_get",
+				Module: "wasi_snapshot_preview1", Name: wasi.FunctionArgsSizesGet,
 				Kind:     wasm.ImportKindFunc,
 				DescFunc: 0,
 			}, {
-				Module: "wasi_snapshot_preview1", Name: "fd_write",
+				Module: "wasi_snapshot_preview1", Name: wasi.FunctionFDWrite,
 				Kind:     wasm.ImportKindFunc,
 				DescFunc: 2,
 			},
@@ -67,8 +67,8 @@ func newExample() *wasm.Module {
 		NameSection: &wasm.NameSection{
 			ModuleName: "example",
 			FunctionNames: wasm.NameMap{
-				{Index: wasm.Index(0), Name: "runtime.args_sizes_get"},
-				{Index: wasm.Index(1), Name: "runtime.fd_write"},
+				{Index: wasm.Index(0), Name: "wasi.args_sizes_get"},
+				{Index: wasm.Index(1), Name: "wasi.fd_write"},
 				{Index: wasm.Index(2), Name: "call_hello"},
 				{Index: wasm.Index(3), Name: "hello"},
 				{Index: wasm.Index(4), Name: "addInt"},
diff --git a/tests/codec/testdata/example.wat b/tests/codec/testdata/example.wat
index e13e3e8c..f1086e61 100644
--- a/tests/codec/testdata/example.wat
+++ b/tests/codec/testdata/example.wat
@@ -4,9 +4,10 @@
 	(type $i32i32_i32 (func (param $i i32) (param $j i32) (result i32)))
 
     ;; type use by symbolic ID, but no param names
-	(import "wasi_snapshot_preview1" "args_sizes_get" (func $runtime.args_sizes_get (type $i32i32_i32)))
+    (import "wasi_snapshot_preview1" "args_sizes_get" (func $wasi.args_sizes_get (type $i32i32_i32)))
 	;; type use on an import func which adds param names on anonymous type
-	(import "wasi_snapshot_preview1" "fd_write" (func $runtime.fd_write
+	;; TODO correct the param names
+	(import "wasi_snapshot_preview1" "fd_write" (func $wasi.fd_write
 		(param $fd i32) (param $iovs_ptr i32) (param $iovs_len i32) (param $nwritten_ptr i32) (result i32)))
 
     ;; func call referencing a func not defined, yet
diff --git a/wasi/strings_test.go b/wasi/strings_test.go
new file mode 100644
index 00000000..d9eb0d98
--- /dev/null
+++ b/wasi/strings_test.go
@@ -0,0 +1,88 @@
+package wasi
+
+import (
+	_ "embed"
+	"testing"
+
+	"github.com/stretchr/testify/require"
+)
+
+func TestNewNullTerminatedStrings(t *testing.T) {
+	emptyWASIStringArray := &nullTerminatedStrings{nullTerminatedValues: [][]byte{}}
+	tests := []struct {
+		name     string
+		input    []string
+		expected *nullTerminatedStrings
+	}{
+		{
+			name:     "nil",
+			expected: emptyWASIStringArray,
+		},
+		{
+			name:     "none",
+			input:    []string{},
+			expected: emptyWASIStringArray,
+		},
+		{
+			name:  "two",
+			input: []string{"a", "bc"},
+			expected: &nullTerminatedStrings{
+				nullTerminatedValues: [][]byte{
+					{'a', 0},
+					{'b', 'c', 0},
+				},
+				totalBufSize: 5,
+			},
+		},
+		{
+			name:  "two and empty string",
+			input: []string{"a", "", "bc"},
+			expected: &nullTerminatedStrings{
+				nullTerminatedValues: [][]byte{
+					{'a', 0},
+					{0},
+					{'b', 'c', 0},
+				},
+				totalBufSize: 6,
+			},
+		},
+		{
+			name: "utf-8",
+			// "😨", "🤣", and "️🏃‍♀️" have 4, 4, and 13 bytes respectively
+			input: []string{"😨🤣🏃\u200d♀️", "foo", "bar"},
+			expected: &nullTerminatedStrings{
+				nullTerminatedValues: [][]byte{
+					[]byte("😨🤣🏃\u200d♀️\x00"),
+					{'f', 'o', 'o', 0},
+					{'b', 'a', 'r', 0},
+				},
+				totalBufSize: 30,
+			},
+		},
+	}
+
+	for _, tt := range tests {
+		tc := tt
+
+		t.Run(tc.name, func(t *testing.T) {
+			s, err := newNullTerminatedStrings(100, tc.input...)
+			require.NoError(t, err)
+			require.Equal(t, tc.expected, s)
+		})
+	}
+}
+
+func TestNewNullTerminatedStrings_Errors(t *testing.T) {
+	t.Run("invalid utf-8", func(t *testing.T) {
+		_, err := newNullTerminatedStrings(100, "\xff\xfe\xfd", "foo", "bar")
+		require.EqualError(t, err, "arg[0] is not a valid UTF-8 string")
+	})
+	t.Run("arg[0] too large", func(t *testing.T) {
+		_, err := newNullTerminatedStrings(1, "a", "bc")
+		require.EqualError(t, err, "arg[0] will exceed max buffer size 1")
+	})
+	t.Run("empty arg too large due to null terminator", func(t *testing.T) {
+		_, err := newNullTerminatedStrings(2, "a", "", "bc")
+		require.EqualError(t, err, "arg[1] will exceed max buffer size 2")
+	})
+}
diff --git a/wasi/testdata/args.wat b/wasi/testdata/args.wat
index 10a3c633..fcfa914d 100644
--- a/wasi/testdata/args.wat
+++ b/wasi/testdata/args.wat
@@ -7,8 +7,10 @@
 ;; this file is put here for now, because this is a temporary file until the parser supports
 ;; the enough syntax, and this file will be embedded in unit test codes after that.
 (module
-  (import "wasi_snapshot_preview1" "args_sizes_get" (func $wasi_args_sizes_get (param i32 i32) (result i32)))
-  (import "wasi_snapshot_preview1" "args_get"       (func $wasi_args_get (param i32 i32) (result i32)))
+  (import "wasi_snapshot_preview1" "args_sizes_get"
+    (func $wasi.args_sizes_get (param $result.argc i32) (param $result.argv_buf_size i32) (result (;errno;) i32)))
+  (import "wasi_snapshot_preview1" "args_get"
+    (func $wasi.args_get (param $argv i32) (param $argv_buf i32) (result (;errno;) i32)))
   (memory 1)  ;; just an arbitrary size big enough for tests
   (export "memory" (memory 0))
   ;; Define wrapper functions instead of just exporting the imported WASI APIS for now
@@ -18,12 +20,12 @@
   (func $args_sizes_get (param i32 i32) (result i32)
         local.get 0
         local.get 1
-        call $wasi_args_sizes_get
+        call $wasi.args_sizes_get
         )
   (func $args_get (param i32 i32) (result i32)
         local.get 0
         local.get 1
-        call $wasi_args_get
+        call $wasi.args_get
         )
   (export "args_sizes_get" (func $args_sizes_get))
   (export "args_get" (func $args_get))
diff --git a/wasi/testdata/clock.wat b/wasi/testdata/clock.wat
index 2c87a83d..36ac423f 100644
--- a/wasi/testdata/clock.wat
+++ b/wasi/testdata/clock.wat
@@ -7,7 +7,8 @@
 ;; this file is put here for now, because this is a temporary file until the parser supports
 ;; the enough syntax, and this file will be embedded in unit test codes after that.
 (module
-  (import "wasi_snapshot_preview1" "clock_time_get" (func $wasi_clock_time_get (param i32 i64 i32) (result i32)))
+  (import "wasi_snapshot_preview1" "clock_time_get"
+    (func $wasi.clock_time_get (param $id i32) (param $precision i64) (param $result.timestamp i32) (result (;errno;) i32)))
   (memory 1)  ;; just an arbitrary size big enough for tests
   (export "memory" (memory 0))
   ;; Define wrapper functions instead of just exporting the imported WASI APIS for now
@@ -18,7 +19,7 @@
         local.get 0
         local.get 1
         local.get 2
-        call $wasi_clock_time_get
+        call $wasi.clock_time_get
         )
   (export "clock_time_get" (func $clock_time_get))
   )
diff --git a/wasi/wasi_test.go b/wasi/wasi_test.go
index 41cd5834..83b03f19 100644
--- a/wasi/wasi_test.go
+++ b/wasi/wasi_test.go
@@ -15,86 +15,6 @@ import (
 	"github.com/tetratelabs/wazero/wasm/text"
 )
 
-func TestNewNullTerminatedStrings(t *testing.T) {
-	emptyWASIStringArray := &nullTerminatedStrings{nullTerminatedValues: [][]byte{}}
-	tests := []struct {
-		name     string
-		input    []string
-		expected *nullTerminatedStrings
-	}{
-		{
-			name:     "nil",
-			expected: emptyWASIStringArray,
-		},
-		{
-			name:     "none",
-			input:    []string{},
-			expected: emptyWASIStringArray,
-		},
-		{
-			name:  "two",
-			input: []string{"a", "bc"},
-			expected: &nullTerminatedStrings{
-				nullTerminatedValues: [][]byte{
-					{'a', 0},
-					{'b', 'c', 0},
-				},
-				totalBufSize: 5,
-			},
-		},
-		{
-			name:  "two and empty string",
-			input: []string{"a", "", "bc"},
-			expected: &nullTerminatedStrings{
-				nullTerminatedValues: [][]byte{
-					{'a', 0},
-					{0},
-					{'b', 'c', 0},
-				},
-				totalBufSize: 6,
-			},
-		},
-		{
-			name: "utf-8",
-			// "😨", "🤣", and "️🏃‍♀️" have 4, 4, and 13 bytes respectively
-			input: []string{"😨🤣🏃\u200d♀️", "foo", "bar"},
-			expected: &nullTerminatedStrings{
-				nullTerminatedValues: [][]byte{
-					[]byte("😨🤣🏃\u200d♀️\x00"),
-					{'f', 'o', 'o', 0},
-					{'b', 'a', 'r', 0},
-				},
-				totalBufSize: 30,
-			},
-		},
-	}
-
-	for _, tt := range tests {
-		tc := tt
-
-		t.Run(tc.name, func(t *testing.T) {
-			s, err := newNullTerminatedStrings(100, tc.input...)
-			require.NoError(t, err)
-			require.Equal(t, tc.expected, s)
-		})
-	}
-}
-
-func TestNewNullTerminatedStrings_Errors(t *testing.T) {
-	t.Run("invalid utf-8", func(t *testing.T) {
-		_, err := newNullTerminatedStrings(100, "\xff\xfe\xfd", "foo", "bar")
-		require.EqualError(t, err, "arg[0] is not a valid UTF-8 string")
-	})
-	t.Run("arg[0] too large", func(t *testing.T) {
-		_, err := newNullTerminatedStrings(1, "a", "bc")
-		require.EqualError(t, err, "arg[0] will exceed max buffer size 1")
-	})
-	t.Run("empty arg too large due to null terminator", func(t *testing.T) {
-		_, err := newNullTerminatedStrings(2, "a", "", "bc")
-		require.EqualError(t, err, "arg[1] will exceed max buffer size 2")
-	})
-}
-
 func TestNewAPI_Args(t *testing.T) {
 	t.Run("valid", func(t *testing.T) {
 		o, err := Args("a", "bc")
@@ -114,97 +34,134 @@ func TestNewAPI_Args(t *testing.T) {
 	})
 }
 
-func TestApi_ArgsSizesGet(t *testing.T) {
+// argsWat is a wasm module to call args_get and args_sizes_get.
+//go:embed testdata/args.wat
+var argsWat []byte
+
+func TestApi_ArgsGet(t *testing.T) {
 	ctx := context.Background()
 	args, err := Args("a", "bc")
 	require.NoError(t, err)
 
-	argc := uint32(1)        // arbitrary offset
-	argvBufSize := uint32(6) // arbitrary offset
-	maskLength := 11         // number of bytes to write '?' to tell what we've written
+	argv := uint32(7)    // arbitrary offset
+	argvBuf := uint32(1) // arbitrary offset
+	maskLength := 16     // number of bytes to write '?' to tell what we've written
 	expectedMemory := []byte{
-		'?',                // argc is after this
-		0x2, 0x0, 0x0, 0x0, // little endian-encoded arg count
-		'?',                // argvBufSize is after this
-		0x5, 0x0, 0x0, 0x0, // little endian-encoded size of null terminated strings
+		'?',                 // argvBuf is after this
+		'a', 0, 'b', 'c', 0, // null terminated "a", "bc"
+		'?',        // argv is after this
+		1, 0, 0, 0, // little endian-encoded offset of "a"
+		3, 0, 0, 0, // little endian-encoded offset of "bc"
 		'?', // stopped after encoding
 	} // tr
 	store, wasiAPI := instantiateWasmStore(t, argsWat, "test", args)
 
-	t.Run("API.ArgsSizesGet", func(t *testing.T) {
+	t.Run("API.ArgsGet", func(t *testing.T) {
 		maskMemory(store, maskLength)
 
 		// provide a host context we call directly
 		hContext := wasm.NewHostFunctionCallContext(ctx, store.Memories[0])
 
-		// invoke ArgsSizesGet directly and check the memory side-effects!
-		errno := wasiAPI.ArgsSizesGet(hContext, argc, argvBufSize)
-		require.Equal(t, ESUCCESS, errno)
+		// invoke ArgsGet directly and check the memory side-effects!
+		errno := wasiAPI.ArgsGet(hContext, argv, argvBuf)
+		require.Equal(t, ErrnoSuccess, errno)
 		require.Equal(t, expectedMemory, store.Memories[0].Buffer[0:maskLength])
 	})
-	t.Run("args_sizes_get", func(t *testing.T) {
+	t.Run(FunctionArgsGet, func(t *testing.T) {
 		maskMemory(store, maskLength)
 
-		ret, _, err := store.CallFunction(ctx, "test", "args_sizes_get", uint64(argc), uint64(argvBufSize))
+		ret, _, err := store.CallFunction(ctx, "test", FunctionArgsGet, uint64(argv), uint64(argvBuf))
 		require.NoError(t, err)
-		require.Equal(t, ESUCCESS, Errno(ret[0])) // cast because results are always uint64
+		require.Equal(t, ErrnoSuccess, Errno(ret[0])) // cast because results are always uint64
 		require.Equal(t, expectedMemory, store.Memories[0].Buffer[0:maskLength])
 	})
 }
 
-func TestApi_ArgsGet(t *testing.T) {
+func TestArgsGet_Errors(t *testing.T) {
 	ctx := context.Background()
 	args, err := Args("a", "bc")
 	require.NoError(t, err)
+	store, wasiAPI := instantiateWasmStore(t, argsWat, "test", args)
 
-	argv := uint32(7)    // arbitrary offset
-	argvBuf := uint32(1) // arbitrary offset
-	maskLength := 16     // number of bytes to write '?' to tell what we've written
+	memorySize := uint32(len(store.Memories[0].Buffer))
+	validAddress := uint32(0) // arbitrary valid address as arguments to args_get. We chose 0 here.
+
+	tests := []struct {
+		name    string
+		argv    uint32
+		argvBuf uint32
+	}{
+		{
+			name:    "out-of-memory argv",
+			argv:    memorySize,
+			argvBuf: validAddress,
+		},
+		{
+			name:    "out-of-memory argvBuf",
+			argv:    validAddress,
+			argvBuf: memorySize,
+		},
+		{
+			name: "argv exceeds the maximum valid address by 1",
+			// 4*uint32(len(argsArray.nullTerminatedValues)) is the size of the result of the pointers to args, 4 is the size of uint32
+			argv:    memorySize - 4*uint32(len(wasiAPI.(*api).args.nullTerminatedValues)) + 1,
+			argvBuf: validAddress,
+		},
+		{
+			name:    "argvBuf exceeds the maximum valid address by 1",
+			argv:    validAddress,
+			argvBuf: memorySize - wasiAPI.(*api).args.totalBufSize + 1,
+		},
+	}
+
+	for _, tt := range tests {
+		tc := tt
+
+		t.Run(tc.name, func(t *testing.T) {
+			ret, _, err := store.CallFunction(ctx, "test", FunctionArgsGet, uint64(tc.argv), uint64(tc.argvBuf))
+			require.NoError(t, err)
+			require.Equal(t, uint64(ErrnoInval), ret[0]) // ret[0] is returned errno
+		})
+	}
+}
+
+func TestApi_ArgsSizesGet(t *testing.T) {
+	ctx := context.Background()
+	args, err := Args("a", "bc")
+	require.NoError(t, err)
+	resultArgc := uint32(1)        // arbitrary offset
+	resultArgvBufSize := uint32(6) // arbitrary offset
+	maskLength := 11               // number of bytes to write '?' to tell what we've written
 	expectedMemory := []byte{
-		'?',                 // argvBuf is after this
-		'a', 0, 'b', 'c', 0, // null terminated "a", "bc"
-		'?',        // argv is after this
-		1, 0, 0, 0, // little endian-encoded offset of "a"
-		3, 0, 0, 0, // little endian-encoded offset of "bc"
+		'?',                // resultArgc is after this
+		0x2, 0x0, 0x0, 0x0, // little endian-encoded arg count
+		'?',                // resultArgvBufSize is after this
+		0x5, 0x0, 0x0, 0x0, // little endian-encoded size of null terminated strings
 		'?', // stopped after encoding
 	} // tr
 	store, wasiAPI := instantiateWasmStore(t, argsWat, "test", args)
 
-	t.Run("API.ArgsGet", func(t *testing.T) {
+	t.Run("API.ArgsSizesGet", func(t *testing.T) {
 		maskMemory(store, maskLength)
 
 		// provide a host context we call directly
 		hContext := wasm.NewHostFunctionCallContext(ctx, store.Memories[0])
 
-		// invoke ArgsGet directly and check the memory side-effects!
-		errno := wasiAPI.ArgsGet(hContext, argv, argvBuf)
-		require.Equal(t, ESUCCESS, errno)
+		// invoke ArgsSizesGet directly and check the memory side effects!
+		errno := wasiAPI.ArgsSizesGet(hContext, resultArgc, resultArgvBufSize)
+		require.Equal(t, ErrnoSuccess, errno)
 		require.Equal(t, expectedMemory, store.Memories[0].Buffer[0:maskLength])
 	})
-	t.Run("args_get", func(t *testing.T) {
+	t.Run(FunctionArgsSizesGet, func(t *testing.T) {
 		maskMemory(store, maskLength)
 
-		ret, _, err := store.CallFunction(ctx, "test", "args_get", uint64(argv), uint64(argvBuf))
+		ret, _, err := store.CallFunction(ctx, "test", FunctionArgsSizesGet, uint64(resultArgc), uint64(resultArgvBufSize))
 		require.NoError(t, err)
-		require.Equal(t, ESUCCESS, Errno(ret[0])) // cast because results are always uint64
+		require.Equal(t, ErrnoSuccess, Errno(ret[0])) // cast because results are always uint64
 		require.Equal(t, expectedMemory, store.Memories[0].Buffer[0:maskLength])
 	})
 }
 
-// maskMemory overwrites the first memory in the store with '?', so tests can see what's written.
-// As the memory can be very large, this only masks up to the given length.
-//
-// Note: WebAssembly 1.0 (MVP) can have only up to one memory, so which is unambiguous.
-func maskMemory(store *wasm.Store, maskLength int) {
-	for i := 0; i < maskLength; i++ {
-		store.Memories[0].Buffer[i] = '?'
-	}
-}
-
-// argsWat is a wasm module to call args_get and args_sizes_get.
-//go:embed testdata/args.wat
-var argsWat []byte
-
 func TestArgsSizesGet_Errors(t *testing.T) {
 	ctx := context.Background()
 	args, err := Args("a", "bc")
@@ -245,65 +202,22 @@ func TestArgsSizesGet_Errors(t *testing.T) {
 		tc := tt
 
 		t.Run(tc.name, func(t *testing.T) {
-			ret, _, err := store.CallFunction(ctx, "test", "args_sizes_get", uint64(tc.argc), uint64(tc.argvBufSize))
+			ret, _, err := store.CallFunction(ctx, "test", FunctionArgsSizesGet, uint64(tc.argc), uint64(tc.argvBufSize))
 			require.NoError(t, err)
-			require.Equal(t, uint64(EINVAL), ret[0]) // ret[0] is returned errno
+			require.Equal(t, uint64(ErrnoInval), ret[0]) // ret[0] is returned errno
 		})
 	}
 }
 
-func TestArgsGet_Error(t *testing.T) {
-	ctx := context.Background()
-	args, err := Args("a", "bc")
-	require.NoError(t, err)
-	store, wasiAPI := instantiateWasmStore(t, argsWat, "test", args)
-
-	memorySize := uint32(len(store.Memories[0].Buffer))
-	validAddress := uint32(0) // arbitrary valid address as arguments to args_get. We chose 0 here.
-
-	tests := []struct {
-		name    string
-		argv    uint32
-		argvBuf uint32
-	}{
-		{
-			name:    "out-of-memory argv",
-			argv:    memorySize,
-			argvBuf: validAddress,
-		},
-		{
-			name:    "out-of-memory argvBuf",
-			argv:    validAddress,
-			argvBuf: memorySize,
-		},
-		{
-			name: "argv exceeds the maximum valid address by 1",
-			// 4*uint32(len(argsArray.nullTerminatedValues)) is the size of the result of the pointers to args, 4 is the size of uint32
-			argv:    memorySize - 4*uint32(len(wasiAPI.(*api).args.nullTerminatedValues)) + 1,
-			argvBuf: validAddress,
-		},
-		{
-			name:    "argvBuf exceeds the maximum valid address by 1",
-			argv:    validAddress,
-			argvBuf: memorySize - wasiAPI.(*api).args.totalBufSize + 1,
-		},
-	}
-
-	for _, tt := range tests {
-		tc := tt
-
-		t.Run(tc.name, func(t *testing.T) {
-			ret, _, err := store.CallFunction(ctx, "test", "args_get", uint64(tc.argv), uint64(tc.argvBuf))
-			require.NoError(t, err)
-			require.Equal(t, uint64(EINVAL), ret[0]) // ret[0] is returned errno
-		})
-	}
-}
+// TODO TestEnvironGet TestEnvironGet_Errors
+// TODO TestEnvironSizesGet TestEnvironSizesGet_Errors
+// TODO TestClockResGet TestClockResGet_Errors
 
 // clockWat is a wasm module to call clock_time_get.
 //go:embed testdata/clock.wat
 var clockWat []byte
 
+// TODO: rewrite
 func TestClockGetTime(t *testing.T) {
 	ctx := context.Background()
 	store, wasiAPI := instantiateWasmStore(t, clockWat, "test")
@@ -320,42 +234,42 @@ func TestClockGetTime(t *testing.T) {
 			name:         "zero uint64 value",
 			timestampVal: 0,
 			timestampPtr: validAddress,
-			result:       ESUCCESS,
+			result:       ErrnoSuccess,
 		},
 		{
 			name:         "low uint64 value",
 			timestampVal: 12345,
 			timestampPtr: validAddress,
-			result:       ESUCCESS,
+			result:       ErrnoSuccess,
 		},
 		{
 			name:         "high uint64 value - no truncation",
 			timestampVal: math.MaxUint64,
 			timestampPtr: validAddress,
-			result:       ESUCCESS,
+			result:       ErrnoSuccess,
 		},
 		{
 			name:         "with an endian-sensitive uint64 val - no truncation",
 			timestampVal: math.MaxUint64 - 1,
 			timestampPtr: validAddress,
-			result:       ESUCCESS,
+			result:       ErrnoSuccess,
 		},
 		{
 			name:         "timestampPtr exceeds the maximum valid address by 1",
 			timestampVal: math.MaxUint64,
 			timestampPtr: memorySize - 8 + 1,
-			result:       EINVAL,
+			result:       ErrnoInval,
 		},
 	}
 
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			wasiAPI.(*api).getTimeNanosFn = func() uint64 { return tt.timestampVal }
-			ret, _, err := store.CallFunction(ctx, "test", "clock_time_get", uint64(0), uint64(0), uint64(tt.timestampPtr))
+			ret, _, err := store.CallFunction(ctx, "test", FunctionClockTimeGet, uint64(0), uint64(0), uint64(tt.timestampPtr))
 			require.NoError(t, err)
 			errno := Errno(ret[0])
 			require.Equal(t, tt.result, errno) // ret[0] is returned errno
-			if errno == ESUCCESS {
+			if errno == ErrnoSuccess {
 				nanos := binary.LittleEndian.Uint64(store.Memories[0].Buffer)
 				assert.Equal(t, tt.timestampVal, nanos)
 			}
@@ -363,6 +277,46 @@ func TestClockGetTime(t *testing.T) {
 	}
 }
 
+// TODO: TestFDAdvise TestFDAdvise_Errors
+// TODO: TestFDAllocate TestFDAllocate_Errors
+// TODO: TestFDClose TestFDClose_Errors
+// TODO: TestFDDataSync TestFDDataSync_Errors
+// TODO: TestFDFDStatGet TestFDFDStatGet_Errors
+// TODO: TestFDFDStatSetFlags TestFDFDStatSetFlags_Errors
+// TODO: TestFDFDStatSetRights TestFDFDStatSetRights_Errors
+// TODO: TestFDFilestatGet TestFDFilestatGet_Errors
+// TODO: TestFDFilestatSetSize TestFDFilestatSetSize_Errors
+// TODO: TestFDFilestatSetTimes TestFDFilestatSetTimes_Errors
+// TODO: TestFDPread TestFDPread_Errors
+// TODO: TestFDPrestatGet TestFDPrestatGet_Errors
+// TODO: TestFDPrestatDirName TestFDPrestatDirName_Errors
+// TODO: TestFDPwrite TestFDPwrite_Errors
+// TODO: TestFDRead TestFDRead_Errors
+// TODO: TestFDReaddir TestFDReaddir_Errors
+// TODO: TestFDRenumber TestFDRenumber_Errors
+// TODO: TestFDSeek TestFDSeek_Errors
+// TODO: TestFDSync TestFDSync_Errors
+// TODO: TestFDTell TestFDTell_Errors
+// TODO: TestFDWrite TestFDWrite_Errors
+// TODO: TestPathCreateDirectory TestPathCreateDirectory_Errors
+// TODO: TestPathFilestatGet TestPathFilestatGet_Errors
+// TODO: TestPathFilestatSetTimes TestPathFilestatSetTimes_Errors
+// TODO: TestPathLink TestPathLink_Errors
+// TODO: TestPathOpen TestPathOpen_Errors
+// TODO: TestPathReadlink TestPathReadlink_Errors
+// TODO: TestPathRemoveDirectory TestPathRemoveDirectory_Errors
+// TODO: TestPathRename TestPathRename_Errors
+// TODO: TestPathSymlink TestPathSymlink_Errors
+// TODO: TestPathUnlinkFile TestPathUnlinkFile_Errors
+// TODO: TestPollOneoff TestPollOneoff_Errors
+// TODO: TestProcExit TestProcExit_Errors
+// TODO: TestProcRaise TestProcRaise_Errors
+// TODO: TestSchedYield TestSchedYield_Errors
+// TODO: TestRandomGet TestRandomGet_Errors
+// TODO: TestSockRecv TestSockRecv_Errors
+// TODO: TestSockSend TestSockSend_Errors
+// TODO: TestSockShutdown TestSockShutdown_Errors
+
 func instantiateWasmStore(t *testing.T, wat []byte, moduleName string, opts ...Option) (*wasm.Store, API) {
 	mod, err := text.DecodeModule(wat)
 	require.NoError(t, err)
@@ -376,3 +330,13 @@ func instantiateWasmStore(t *testing.T, wat []byte, moduleName string, opts ...O
 
 	return store, wasiAPI
 }
+
+// maskMemory overwrites the first memory in the store with '?', so tests can see what's written.
+// As the memory can be very large, this only masks up to the given length.
+//
+// Note: WebAssembly 1.0 (MVP) can have only up to one memory, so which is unambiguous.
+func maskMemory(store *wasm.Store, maskLength int) {
+	for i := 0; i < maskLength; i++ {
+		store.Memories[0].Buffer[i] = '?'
+	}
+}
diff --git a/wasm/binary/names_test.go b/wasm/binary/names_test.go
index ecb3776e..d148b7cb 100644
--- a/wasm/binary/names_test.go
+++ b/wasm/binary/names_test.go
@@ -52,24 +52,24 @@ func TestEncodeNameSectionData(t *testing.T) {
 		{
 			name: "two function names", // Ex. TinyGo which at one point didn't set a module name
 			//	(module
-			//		(import "wasi_snapshot_preview1" "args_sizes_get" (func $runtime.args_sizes_get (param i32, i32) (result i32)))
-			//		(import "wasi_snapshot_preview1" "fd_write" (func $runtime.fd_write (param i32, i32, i32, i32) (result i32)))
+			//		(import "wasi_snapshot_preview1" "args_sizes_get" (func $wasi.args_sizes_get (param i32, i32) (result i32)))
+			//		(import "wasi_snapshot_preview1" "fd_write" (func $wasi.fd_write (param i32, i32, i32, i32) (result i32)))
 			//	)
 			input: &wasm.NameSection{
 				FunctionNames: wasm.NameMap{
-					{Index: wasm.Index(0), Name: "runtime.args_sizes_get"},
-					{Index: wasm.Index(1), Name: "runtime.fd_write"},
+					{Index: wasm.Index(0), Name: "wasi.args_sizes_get"},
+					{Index: wasm.Index(1), Name: "wasi.fd_write"},
 				},
 			},
 			expected: []byte{
-				subsectionIDFunctionNames, 0x2b, // 43 bytes
+				subsectionIDFunctionNames, 0x25, // 37 bytes
 				0x02, // two function names
 				0x00, // the function index is zero
-				0x16, // the function name runtime.args_sizes_get is 22 bytes long
-				'r', 'u', 'n', 't', 'i', 'm', 'e', '.', 'a', 'r', 'g', 's', '_', 's', 'i', 'z', 'e', 's', '_', 'g', 'e', 't',
+				0x13, // the function name wasi.args_sizes_get is 19 bytes long
+				'w', 'a', 's', 'i', '.', 'a', 'r', 'g', 's', '_', 's', 'i', 'z', 'e', 's', '_', 'g', 'e', 't',
 				0x01, // the function index is one
-				0x10, // the function name runtime.fd_write is 16 bytes long
-				'r', 'u', 'n', 't', 'i', 'm', 'e', '.', 'f', 'd', '_', 'w', 'r', 'i', 't', 'e',
+				0x0d, // the function name wasi.fd_write is 13 bytes long
+				'w', 'a', 's', 'i', '.', 'f', 'd', '_', 'w', 'r', 'i', 't', 'e',
 			},
 		},
 		{
@@ -164,15 +164,15 @@ func TestDecodeNameSection(t *testing.T) {
 			name: "module and function name",
 			input: &wasm.NameSection{
 				ModuleName:    "simple",
-				FunctionNames: wasm.NameMap{{Index: wasm.Index(0), Name: "runtime.hello"}},
+				FunctionNames: wasm.NameMap{{Index: wasm.Index(0), Name: "wasi.hello"}},
 			},
 		},
 		{
 			name: "two function names",
 			input: &wasm.NameSection{
 				FunctionNames: wasm.NameMap{
-					{Index: wasm.Index(0), Name: "runtime.args_sizes_get"},
-					{Index: wasm.Index(1), Name: "runtime.fd_write"},
+					{Index: wasm.Index(0), Name: "wasi.args_sizes_get"},
+					{Index: wasm.Index(1), Name: "wasi.fd_write"},
 				},
 			},
 		},
diff --git a/wasm/text/decoder_test.go b/wasm/text/decoder_test.go
index 26dbb815..01ce4b14 100644
--- a/wasm/text/decoder_test.go
+++ b/wasm/text/decoder_test.go
@@ -6,6 +6,7 @@ import (
 
 	"github.com/stretchr/testify/require"
 
+	"github.com/tetratelabs/wazero/wasi"
 	"github.com/tetratelabs/wazero/wasm"
 )
 
@@ -41,7 +42,7 @@ func TestDecodeModule(t *testing.T) {
 		{
 			name: "type func empty after inlined", // ensures the parser was reset properly
 			input: `(module
-	(import "wasi_snapshot_preview1" "fd_write" (func $runtime.fd_write (param i32 i32 i32 i32) (result i32)))
+	(import "wasi_snapshot_preview1" "fd_write" (func $wasi.fd_write (param i32 i32 i32 i32) (result i32)))
 	(type (func))
 )`,
 			expected: &wasm.Module{
@@ -50,12 +51,12 @@ func TestDecodeModule(t *testing.T) {
 					i32i32i32i32_i32,
 				},
 				ImportSection: []*wasm.Import{{
-					Module: "wasi_snapshot_preview1", Name: "fd_write",
+					Module: "wasi_snapshot_preview1", Name: wasi.FunctionFDWrite,
 					Kind:     wasm.ImportKindFunc,
 					DescFunc: 1,
 				}},
 				NameSection: &wasm.NameSection{
-					FunctionNames: wasm.NameMap{&wasm.NameAssoc{Index: 0, Name: "runtime.fd_write"}},
+					FunctionNames: wasm.NameMap{&wasm.NameAssoc{Index: 0, Name: "wasi.fd_write"}},
 				},
 			},
 		},
@@ -155,34 +156,34 @@ func TestDecodeModule(t *testing.T) {
 		{
 			name: "import func inlined type",
 			input: `(module
-	(import "wasi_snapshot_preview1" "fd_write" (func $runtime.fd_write (param i32) (param i32) (param i32) (param i32) (result i32)))
+	(import "wasi_snapshot_preview1" "fd_write" (func $wasi.fd_write (param i32) (param i32) (param i32) (param i32) (result i32)))
 )`,
 			expected: &wasm.Module{
 				TypeSection: []*wasm.FunctionType{i32i32i32i32_i32},
 				ImportSection: []*wasm.Import{{
-					Module: "wasi_snapshot_preview1", Name: "fd_write",
+					Module: "wasi_snapshot_preview1", Name: wasi.FunctionFDWrite,
 					Kind:     wasm.ImportKindFunc,
 					DescFunc: 0,
 				}},
 				NameSection: &wasm.NameSection{
-					FunctionNames: wasm.NameMap{&wasm.NameAssoc{Index: 0, Name: "runtime.fd_write"}},
+					FunctionNames: wasm.NameMap{&wasm.NameAssoc{Index: 0, Name: "wasi.fd_write"}},
 				},
 			},
 		},
 		{
 			name: "import func inlined type - abbreviated",
 			input: `(module
-	(import "wasi_snapshot_preview1" "fd_write" (func $runtime.fd_write (param i32 i32 i32 i32) (result i32)))
+	(import "wasi_snapshot_preview1" "fd_write" (func $wasi.fd_write (param i32 i32 i32 i32) (result i32)))
 )`,
 			expected: &wasm.Module{
 				TypeSection: []*wasm.FunctionType{i32i32i32i32_i32},
 				ImportSection: []*wasm.Import{{
-					Module: "wasi_snapshot_preview1", Name: "fd_write",
+					Module: "wasi_snapshot_preview1", Name: wasi.FunctionFDWrite,
 					Kind:     wasm.ImportKindFunc,
 					DescFunc: 0,
 				}},
 				NameSection: &wasm.NameSection{
-					FunctionNames: wasm.NameMap{&wasm.NameAssoc{Index: 0, Name: "runtime.fd_write"}},
+					FunctionNames: wasm.NameMap{&wasm.NameAssoc{Index: 0, Name: "wasi.fd_write"}},
 				},
 			},
 		},
@@ -207,34 +208,34 @@ func TestDecodeModule(t *testing.T) {
 			// See https://www.w3.org/TR/wasm-core-1/#abbreviations%E2%91%A0
 			name: "import func inlined type - mixed abbreviated",
 			input: `(module
-	(import "wasi_snapshot_preview1" "fd_write" (func $runtime.fd_write (param i32) (param i32 i32) (param i32) (result i32)))
+	(import "wasi_snapshot_preview1" "fd_write" (func $wasi.fd_write (param i32) (param i32 i32) (param i32) (result i32)))
 )`,
 			expected: &wasm.Module{
 				TypeSection: []*wasm.FunctionType{i32i32i32i32_i32},
 				ImportSection: []*wasm.Import{{
-					Module: "wasi_snapshot_preview1", Name: "fd_write",
+					Module: "wasi_snapshot_preview1", Name: wasi.FunctionFDWrite,
 					Kind:     wasm.ImportKindFunc,
 					DescFunc: 0,
 				}},
 				NameSection: &wasm.NameSection{
-					FunctionNames: wasm.NameMap{&wasm.NameAssoc{Index: 0, Name: "runtime.fd_write"}},
+					FunctionNames: wasm.NameMap{&wasm.NameAssoc{Index: 0, Name: "wasi.fd_write"}},
 				},
 			},
 		},
 		{
 			name: "import func inlined type no result",
 			input: `(module
-	(import "wasi_snapshot_preview1" "proc_exit" (func $runtime.proc_exit (param i32)))
+	(import "wasi_snapshot_preview1" "proc_exit" (func $wasi.proc_exit (param i32)))
 )`,
 			expected: &wasm.Module{
 				TypeSection: []*wasm.FunctionType{i32_v},
 				ImportSection: []*wasm.Import{{
-					Module: "wasi_snapshot_preview1", Name: "proc_exit",
+					Module: "wasi_snapshot_preview1", Name: wasi.FunctionProcExit,
 					Kind:     wasm.ImportKindFunc,
 					DescFunc: 0,
 				}},
 				NameSection: &wasm.NameSection{
-					FunctionNames: wasm.NameMap{&wasm.NameAssoc{Index: 0, Name: "runtime.proc_exit"}},
+					FunctionNames: wasm.NameMap{&wasm.NameAssoc{Index: 0, Name: "wasi.proc_exit"}},
 				},
 			},
 		},
@@ -249,58 +250,58 @@ func TestDecodeModule(t *testing.T) {
 		{
 			name: "import func inlined type different param types",
 			input: `(module
-	(import "wasi_snapshot_preview1" "path_open" (func $runtime.path_open (param i32) (param i32) (param i32) (param i32) (param i32) (param i64) (param i64) (param i32) (param i32) (result i32)))
+	(import "wasi_snapshot_preview1" "path_open" (func $wasi.path_open (param i32) (param i32) (param i32) (param i32) (param i32) (param i64) (param i64) (param i32) (param i32) (result i32)))
 )`,
 			expected: &wasm.Module{
 				TypeSection: []*wasm.FunctionType{i32i32i32i32i32i64i64i32i32_i32},
 				ImportSection: []*wasm.Import{{
-					Module: "wasi_snapshot_preview1", Name: "path_open",
+					Module: "wasi_snapshot_preview1", Name: wasi.FunctionPathOpen,
 					Kind:     wasm.ImportKindFunc,
 					DescFunc: 0,
 				}},
 				NameSection: &wasm.NameSection{
-					FunctionNames: wasm.NameMap{&wasm.NameAssoc{Index: 0, Name: "runtime.path_open"}},
+					FunctionNames: wasm.NameMap{&wasm.NameAssoc{Index: 0, Name: "wasi.path_open"}},
 				},
 			},
 		},
 		{
 			name: "import func inlined type different param types - abbreviated",
 			input: `(module
-	(import "wasi_snapshot_preview1" "path_open" (func $runtime.path_open (param i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i32)))
+	(import "wasi_snapshot_preview1" "path_open" (func $wasi.path_open (param i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i32)))
 )`,
 			expected: &wasm.Module{
 				TypeSection: []*wasm.FunctionType{i32i32i32i32i32i64i64i32i32_i32},
 				ImportSection: []*wasm.Import{{
-					Module: "wasi_snapshot_preview1", Name: "path_open",
+					Module: "wasi_snapshot_preview1", Name: wasi.FunctionPathOpen,
 					Kind:     wasm.ImportKindFunc,
 					DescFunc: 0,
 				}},
 				NameSection: &wasm.NameSection{
-					FunctionNames: wasm.NameMap{&wasm.NameAssoc{Index: 0, Name: "runtime.path_open"}},
+					FunctionNames: wasm.NameMap{&wasm.NameAssoc{Index: 0, Name: "wasi.path_open"}},
 				},
 			},
 		},
 		{
 			name: "multiple import func different inlined type",
 			input: `(module
-			(import "wasi_snapshot_preview1" "args_sizes_get" (func $runtime.args_sizes_get (param i32 i32) (result i32)))
-			(import "wasi_snapshot_preview1" "fd_write" (func $runtime.fd_write (param i32 i32 i32 i32) (result i32)))
+			(import "wasi_snapshot_preview1" "args_sizes_get" (func $wasi.args_sizes_get (param i32 i32) (result i32)))
+			(import "wasi_snapshot_preview1" "fd_write" (func $wasi.fd_write (param i32 i32 i32 i32) (result i32)))
 		)`,
 			expected: &wasm.Module{
 				TypeSection: []*wasm.FunctionType{i32i32_i32, i32i32i32i32_i32},
 				ImportSection: []*wasm.Import{{
-					Module: "wasi_snapshot_preview1", Name: "args_sizes_get",
+					Module: "wasi_snapshot_preview1", Name: wasi.FunctionArgsSizesGet,
 					Kind:     wasm.ImportKindFunc,
 					DescFunc: 0,
 				}, {
-					Module: "wasi_snapshot_preview1", Name: "fd_write",
+					Module: "wasi_snapshot_preview1", Name: wasi.FunctionFDWrite,
 					Kind:     wasm.ImportKindFunc,
 					DescFunc: 1,
 				}},
 				NameSection: &wasm.NameSection{
 					FunctionNames: wasm.NameMap{
-						&wasm.NameAssoc{Index: 0, Name: "runtime.args_sizes_get"},
-						&wasm.NameAssoc{Index: 1, Name: "runtime.fd_write"},
+						&wasm.NameAssoc{Index: 0, Name: "wasi.args_sizes_get"},
+						&wasm.NameAssoc{Index: 1, Name: "wasi.fd_write"},
 					},
 				},
 			},
@@ -311,8 +312,8 @@ func TestDecodeModule(t *testing.T) {
 	(type (func) (; ensures no false match on index 0 ;))
 	(type $i32i32_i32 (func (param i32 i32) (result i32)))
 	(type $i32i32i32i32_i32 (func (param i32 i32 i32 i32) (result i32)))
-	(import "wasi_snapshot_preview1" "args_sizes_get" (func $runtime.args_sizes_get (type $i32i32_i32)))
-	(import "wasi_snapshot_preview1" "fd_write" (func $runtime.fd_write (type $i32i32i32i32_i32)))
+	(import "wasi_snapshot_preview1" "args_sizes_get" (func $wasi.args_sizes_get (type $i32i32_i32)))
+	(import "wasi_snapshot_preview1" "fd_write" (func $wasi.fd_write (type $i32i32i32i32_i32)))
 )`,
 			expected: &wasm.Module{
 				TypeSection: []*wasm.FunctionType{
@@ -322,19 +323,19 @@ func TestDecodeModule(t *testing.T) {
 				},
 				ImportSection: []*wasm.Import{
 					{
-						Module: "wasi_snapshot_preview1", Name: "args_sizes_get",
+						Module: "wasi_snapshot_preview1", Name: wasi.FunctionArgsSizesGet,
 						Kind:     wasm.ImportKindFunc,
 						DescFunc: 1,
 					}, {
-						Module: "wasi_snapshot_preview1", Name: "fd_write",
+						Module: "wasi_snapshot_preview1", Name: wasi.FunctionFDWrite,
 						Kind:     wasm.ImportKindFunc,
 						DescFunc: 2,
 					},
 				},
 				NameSection: &wasm.NameSection{
 					FunctionNames: wasm.NameMap{
-						{Index: 0, Name: "runtime.args_sizes_get"},
-						{Index: 1, Name: "runtime.fd_write"},
+						{Index: 0, Name: "wasi.args_sizes_get"},
+						{Index: 1, Name: "wasi.fd_write"},
 					},
 				},
 			},
@@ -345,26 +346,26 @@ func TestDecodeModule(t *testing.T) {
 			(type (func) (; ensures no false match on index 0 ;))
 			(type (func (param i32 i32) (result i32)))
 			(type (func (param i32 i32 i32 i32) (result i32)))
-			(import "wasi_snapshot_preview1" "args_sizes_get" (func $runtime.args_sizes_get (type 1)))
-			(import "wasi_snapshot_preview1" "fd_write" (func $runtime.fd_write (type 2)))
+			(import "wasi_snapshot_preview1" "args_sizes_get" (func $wasi.args_sizes_get (type 1)))
+			(import "wasi_snapshot_preview1" "fd_write" (func $wasi.fd_write (type 2)))
 		)`,
 			expected: &wasm.Module{
 				TypeSection: []*wasm.FunctionType{v_v, i32i32_i32, i32i32i32i32_i32},
 				ImportSection: []*wasm.Import{
 					{
-						Module: "wasi_snapshot_preview1", Name: "args_sizes_get",
+						Module: "wasi_snapshot_preview1", Name: wasi.FunctionArgsSizesGet,
 						Kind:     wasm.ImportKindFunc,
 						DescFunc: 1,
 					}, {
-						Module: "wasi_snapshot_preview1", Name: "fd_write",
+						Module: "wasi_snapshot_preview1", Name: wasi.FunctionFDWrite,
 						Kind:     wasm.ImportKindFunc,
 						DescFunc: 2,
 					},
 				},
 				NameSection: &wasm.NameSection{
 					FunctionNames: wasm.NameMap{
-						&wasm.NameAssoc{Index: 0, Name: "runtime.args_sizes_get"},
-						&wasm.NameAssoc{Index: 1, Name: "runtime.fd_write"},
+						&wasm.NameAssoc{Index: 0, Name: "wasi.args_sizes_get"},
+						&wasm.NameAssoc{Index: 1, Name: "wasi.fd_write"},
 					},
 				},
 			},
@@ -373,26 +374,26 @@ func TestDecodeModule(t *testing.T) {
 			name: "multiple import func same inlined type",
 			input: `(module
 			(type (func) (; ensures no false match on index 0 ;))
-			(import "wasi_snapshot_preview1" "environ_get" (func $runtime.environ_get (param i32 i32) (result i32)))
-			(import "wasi_snapshot_preview1" "args_sizes_get" (func $runtime.args_sizes_get (param i32 i32) (result i32)))
+			(import "wasi_snapshot_preview1" "environ_get" (func $wasi.environ_get (param i32 i32) (result i32)))
+			(import "wasi_snapshot_preview1" "args_sizes_get" (func $wasi.args_sizes_get (param i32 i32) (result i32)))
 		)`,
 			expected: &wasm.Module{
 				TypeSection: []*wasm.FunctionType{v_v, i32i32_i32},
 				ImportSection: []*wasm.Import{
 					{
-						Module: "wasi_snapshot_preview1", Name: "environ_get",
+						Module: "wasi_snapshot_preview1", Name: wasi.FunctionEnvironGet,
 						Kind:     wasm.ImportKindFunc,
 						DescFunc: 1,
 					}, {
-						Module: "wasi_snapshot_preview1", Name: "args_sizes_get",
+						Module: "wasi_snapshot_preview1", Name: wasi.FunctionArgsSizesGet,
 						Kind:     wasm.ImportKindFunc,
 						DescFunc: 1,
 					},
 				},
 				NameSection: &wasm.NameSection{
 					FunctionNames: wasm.NameMap{
-						&wasm.NameAssoc{Index: 0, Name: "runtime.environ_get"},
-						&wasm.NameAssoc{Index: 1, Name: "runtime.args_sizes_get"},
+						&wasm.NameAssoc{Index: 0, Name: "wasi.environ_get"},
+						&wasm.NameAssoc{Index: 1, Name: "wasi.args_sizes_get"},
 					},
 				},
 			},
@@ -402,26 +403,26 @@ func TestDecodeModule(t *testing.T) {
 			input: `(module
 			(type (func) (; ensures no false match on index 0 ;))
 			(type (func (param i32 i32) (result i32)))
-			(import "wasi_snapshot_preview1" "environ_get" (func $runtime.environ_get (type 1)))
-			(import "wasi_snapshot_preview1" "args_sizes_get" (func $runtime.args_sizes_get (type 1)))
+			(import "wasi_snapshot_preview1" "environ_get" (func $wasi.environ_get (type 1)))
+			(import "wasi_snapshot_preview1" "args_sizes_get" (func $wasi.args_sizes_get (type 1)))
 		)`,
 			expected: &wasm.Module{
 				TypeSection: []*wasm.FunctionType{v_v, i32i32_i32},
 				ImportSection: []*wasm.Import{
 					{
-						Module: "wasi_snapshot_preview1", Name: "environ_get",
+						Module: "wasi_snapshot_preview1", Name: wasi.FunctionEnvironGet,
 						Kind:     wasm.ImportKindFunc,
 						DescFunc: 1,
 					}, {
-						Module: "wasi_snapshot_preview1", Name: "args_sizes_get",
+						Module: "wasi_snapshot_preview1", Name: wasi.FunctionArgsSizesGet,
 						Kind:     wasm.ImportKindFunc,
 						DescFunc: 1,
 					},
 				},
 				NameSection: &wasm.NameSection{
 					FunctionNames: wasm.NameMap{
-						&wasm.NameAssoc{Index: 0, Name: "runtime.environ_get"},
-						&wasm.NameAssoc{Index: 1, Name: "runtime.args_sizes_get"},
+						&wasm.NameAssoc{Index: 0, Name: "wasi.environ_get"},
+						&wasm.NameAssoc{Index: 1, Name: "wasi.args_sizes_get"},
 					},
 				},
 			},
@@ -430,27 +431,27 @@ func TestDecodeModule(t *testing.T) {
 			name: "multiple import func same type index - type after import",
 			input: `(module
 			(type (func) (; ensures no false match on index 0 ;))
-			(import "wasi_snapshot_preview1" "environ_get" (func $runtime.environ_get (type 1)))
-			(import "wasi_snapshot_preview1" "args_sizes_get" (func $runtime.args_sizes_get (type 1)))
+			(import "wasi_snapshot_preview1" "environ_get" (func $wasi.environ_get (type 1)))
+			(import "wasi_snapshot_preview1" "args_sizes_get" (func $wasi.args_sizes_get (type 1)))
 			(type (func (param i32 i32) (result i32)))
 		)`,
 			expected: &wasm.Module{
 				TypeSection: []*wasm.FunctionType{v_v, i32i32_i32},
 				ImportSection: []*wasm.Import{
 					{
-						Module: "wasi_snapshot_preview1", Name: "environ_get",
+						Module: "wasi_snapshot_preview1", Name: wasi.FunctionEnvironGet,
 						Kind:     wasm.ImportKindFunc,
 						DescFunc: 1,
 					}, {
-						Module: "wasi_snapshot_preview1", Name: "args_sizes_get",
+						Module: "wasi_snapshot_preview1", Name: wasi.FunctionArgsSizesGet,
 						Kind:     wasm.ImportKindFunc,
 						DescFunc: 1,
 					},
 				},
 				NameSection: &wasm.NameSection{
 					FunctionNames: wasm.NameMap{
-						&wasm.NameAssoc{Index: 0, Name: "runtime.environ_get"},
-						&wasm.NameAssoc{Index: 1, Name: "runtime.args_sizes_get"},
+						&wasm.NameAssoc{Index: 0, Name: "wasi.environ_get"},
+						&wasm.NameAssoc{Index: 1, Name: "wasi.args_sizes_get"},
 					},
 				},
 			},
@@ -518,8 +519,8 @@ func TestDecodeModule(t *testing.T) {
 			name: "multiple import func with different inlined type",
 			input: `(module
 	(type (func) (; ensures no false match on index 0 ;))
-	(import "wasi_snapshot_preview1" "path_open" (func $runtime.path_open (param i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i32)))
-	(import "wasi_snapshot_preview1" "fd_write" (func $runtime.fd_write (param i32 i32 i32 i32) (result i32)))
+	(import "wasi_snapshot_preview1" "path_open" (func $wasi.path_open (param i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i32)))
+	(import "wasi_snapshot_preview1" "fd_write" (func $wasi.fd_write (param i32 i32 i32 i32) (result i32)))
 )`,
 			expected: &wasm.Module{
 				TypeSection: []*wasm.FunctionType{
@@ -529,19 +530,19 @@ func TestDecodeModule(t *testing.T) {
 				},
 				ImportSection: []*wasm.Import{
 					{
-						Module: "wasi_snapshot_preview1", Name: "path_open",
+						Module: "wasi_snapshot_preview1", Name: wasi.FunctionPathOpen,
 						Kind:     wasm.ImportKindFunc,
 						DescFunc: 1,
 					}, {
-						Module: "wasi_snapshot_preview1", Name: "fd_write",
+						Module: "wasi_snapshot_preview1", Name: wasi.FunctionFDWrite,
 						Kind:     wasm.ImportKindFunc,
 						DescFunc: 2,
 					},
 				},
 				NameSection: &wasm.NameSection{
 					FunctionNames: wasm.NameMap{
-						{Index: 0, Name: "runtime.path_open"},
-						{Index: 1, Name: "runtime.fd_write"},
+						{Index: 0, Name: "wasi.path_open"},
+						{Index: 1, Name: "wasi.fd_write"},
 					},
 				},
 			},
@@ -676,28 +677,28 @@ func TestDecodeModule(t *testing.T) {
 		{
 			name: "func inlined type",
 			input: `(module
-			(func $runtime.fd_write (param i32) (param i32) (param i32) (param i32) (result i32) local.get 0 )
+			(func $wasi.fd_write (param i32) (param i32) (param i32) (param i32) (result i32) local.get 0 )
 		)`,
 			expected: &wasm.Module{
 				TypeSection:     []*wasm.FunctionType{i32i32i32i32_i32},
 				FunctionSection: []wasm.Index{0},
 				CodeSection:     []*wasm.Code{{Body: localGet0End}},
 				NameSection: &wasm.NameSection{
-					FunctionNames: wasm.NameMap{&wasm.NameAssoc{Index: 0, Name: "runtime.fd_write"}},
+					FunctionNames: wasm.NameMap{&wasm.NameAssoc{Index: 0, Name: "wasi.fd_write"}},
 				},
 			},
 		},
 		{
 			name: "func inlined type - abbreviated",
 			input: `(module
-			(func $runtime.fd_write (param i32 i32 i32 i32) (result i32) local.get 0)
+			(func $wasi.fd_write (param i32 i32 i32 i32) (result i32) local.get 0)
 		)`,
 			expected: &wasm.Module{
 				TypeSection:     []*wasm.FunctionType{i32i32i32i32_i32},
 				FunctionSection: []wasm.Index{0},
 				CodeSection:     []*wasm.Code{{Body: localGet0End}},
 				NameSection: &wasm.NameSection{
-					FunctionNames: wasm.NameMap{&wasm.NameAssoc{Index: 0, Name: "runtime.fd_write"}},
+					FunctionNames: wasm.NameMap{&wasm.NameAssoc{Index: 0, Name: "wasi.fd_write"}},
 				},
 			},
 		},
@@ -706,14 +707,14 @@ func TestDecodeModule(t *testing.T) {
 			// See https://www.w3.org/TR/wasm-core-1/#abbreviations%E2%91%A0
 			name: "func inlined type - mixed abbreviated",
 			input: `(module
-			(func $runtime.fd_write (param i32) (param i32 i32) (param i32) (result i32) local.get 0)
+			(func $wasi.fd_write (param i32) (param i32 i32) (param i32) (result i32) local.get 0)
 		)`,
 			expected: &wasm.Module{
 				TypeSection:     []*wasm.FunctionType{i32i32i32i32_i32},
 				FunctionSection: []wasm.Index{0},
 				CodeSection:     []*wasm.Code{{Body: localGet0End}},
 				NameSection: &wasm.NameSection{
-					FunctionNames: wasm.NameMap{&wasm.NameAssoc{Index: 0, Name: "runtime.fd_write"}},
+					FunctionNames: wasm.NameMap{&wasm.NameAssoc{Index: 0, Name: "wasi.fd_write"}},
 				},
 			},
 		},
@@ -914,7 +915,7 @@ func TestDecodeModule(t *testing.T) {
 				TypeSection: []*wasm.FunctionType{v_v, i32i32_i32},
 				ImportSection: []*wasm.Import{
 					{
-						Module: "wasi_snapshot_preview1", Name: "args_get",
+						Module: "wasi_snapshot_preview1", Name: wasi.FunctionArgsGet,
 						Kind:     wasm.ImportKindFunc,
 						DescFunc: 1,
 					},
@@ -941,7 +942,7 @@ func TestDecodeModule(t *testing.T) {
 				TypeSection: []*wasm.FunctionType{v_v, i32i32_i32},
 				ImportSection: []*wasm.Import{
 					{
-						Module: "wasi_snapshot_preview1", Name: "args_get",
+						Module: "wasi_snapshot_preview1", Name: wasi.FunctionArgsGet,
 						Kind:     wasm.ImportKindFunc,
 						DescFunc: 1,
 					},
@@ -968,7 +969,7 @@ func TestDecodeModule(t *testing.T) {
 				TypeSection: []*wasm.FunctionType{v_v, i32i32_i32},
 				ImportSection: []*wasm.Import{
 					{
-						Module: "wasi_snapshot_preview1", Name: "args_get",
+						Module: "wasi_snapshot_preview1", Name: wasi.FunctionArgsGet,
 						Kind:     wasm.ImportKindFunc,
 						DescFunc: 1,
 					},
@@ -995,7 +996,7 @@ func TestDecodeModule(t *testing.T) {
 				TypeSection: []*wasm.FunctionType{v_v, i32i32_i32},
 				ImportSection: []*wasm.Import{
 					{
-						Module: "wasi_snapshot_preview1", Name: "args_get",
+						Module: "wasi_snapshot_preview1", Name: wasi.FunctionArgsGet,
 						Kind:     wasm.ImportKindFunc,
 						DescFunc: 1,
 					},
@@ -1022,7 +1023,7 @@ func TestDecodeModule(t *testing.T) {
 				TypeSection: []*wasm.FunctionType{v_v, i32i32_i32},
 				ImportSection: []*wasm.Import{
 					{
-						Module: "wasi_snapshot_preview1", Name: "args_get",
+						Module: "wasi_snapshot_preview1", Name: wasi.FunctionArgsGet,
 						Kind:     wasm.ImportKindFunc,
 						DescFunc: 1,
 					},