diff --git a/Makefile b/Makefile index 6a6011124b..2359011060 100644 --- a/Makefile +++ b/Makefile @@ -5,9 +5,9 @@ space := space += goimports := golang.org/x/tools/cmd/goimports@v0.1.10 -golangci_lint := github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.0 +golangci_lint := github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2 # sync this with netlify.toml! -hugo := github.com/gohugoio/hugo@v0.99.0 +hugo := github.com/gohugoio/hugo@v0.100.0 # Make 3.81 doesn't support '**' globbing: Set explicitly instead of recursion. all_sources := $(wildcard *.go */*.go */*/*.go */*/*/*.go */*/*/*.go */*/*/*/*.go) diff --git a/README.md b/README.md index d8d35f89af..19d40e4f1e 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ bundles an implementation. That way, you don't have to write these functions. For example, here's how you can allow WebAssembly modules to read "/work/home/a.txt" as "/a.txt" or "./a.txt": ```go -_, err := wasi.InstantiateSnapshotPreview1(ctx, r) +_, err := wasi_snapshot_preview1.Instantiate(ctx, r) if err != nil { log.Panicln(err) } diff --git a/assemblyscript/assemblyscript.go b/assemblyscript/assemblyscript.go index 2845c93f77..ca19816d45 100644 --- a/assemblyscript/assemblyscript.go +++ b/assemblyscript/assemblyscript.go @@ -11,7 +11,7 @@ // Relationship to WASI // // A program compiled to use WASI, via "import wasi" in any file, won't import these functions. -// See wasi.InstantiateSnapshotPreview1 +// See wasi_snapshot_preview1.InstantiateSnapshotPreview1 // // See https://www.assemblyscript.org/concepts.html#special-imports package assemblyscript diff --git a/builder.go b/builder.go index d59ca9f1fc..c528d73e08 100644 --- a/builder.go +++ b/builder.go @@ -97,7 +97,7 @@ type ModuleBuilder interface { // // Parameters // - // * name - the name to export. Ex "memory" for wasi.ModuleSnapshotPreview1 + // * name - the name to export. Ex "memory" for wasi_snapshot_preview1.ModuleSnapshotPreview1 // * minPages - the possibly zero initial size in pages (65536 bytes per page). // // For example, the WebAssembly 1.0 Text Format below is the equivalent of this builder method: diff --git a/examples/allocation/tinygo/greet.go b/examples/allocation/tinygo/greet.go index 7e00293a43..9ed29b7cb5 100644 --- a/examples/allocation/tinygo/greet.go +++ b/examples/allocation/tinygo/greet.go @@ -9,7 +9,7 @@ import ( "github.com/tetratelabs/wazero" "github.com/tetratelabs/wazero/api" - "github.com/tetratelabs/wazero/wasi" + "github.com/tetratelabs/wazero/wasi_snapshot_preview1" ) // greetWasm was compiled using `tinygo build -o greet.wasm -scheduler=none --no-debug -target=wasi greet.go` @@ -39,7 +39,7 @@ func main() { // Note: testdata/greet.go doesn't use WASI, but TinyGo needs it to // implement functions such as panic. - if _, err = wasi.InstantiateSnapshotPreview1(ctx, r); err != nil { + if _, err = wasi_snapshot_preview1.Instantiate(ctx, r); err != nil { log.Panicln(err) } diff --git a/examples/wasi/cat.go b/examples/wasi/cat.go index 52fb353581..285559af32 100644 --- a/examples/wasi/cat.go +++ b/examples/wasi/cat.go @@ -9,7 +9,7 @@ import ( "os" "github.com/tetratelabs/wazero" - "github.com/tetratelabs/wazero/wasi" + "github.com/tetratelabs/wazero/wasi_snapshot_preview1" ) // catFS is an embedded filesystem limited to test.txt @@ -42,7 +42,7 @@ func main() { config := wazero.NewModuleConfig().WithStdout(os.Stdout).WithFS(rooted) // Instantiate WASI, which implements system I/O such as console output. - if _, err = wasi.InstantiateSnapshotPreview1(ctx, r); err != nil { + if _, err = wasi_snapshot_preview1.Instantiate(ctx, r); err != nil { log.Panicln(err) } diff --git a/experimental/fs_example_test.go b/experimental/fs_example_test.go index a1c4c33484..c45c168a8e 100644 --- a/experimental/fs_example_test.go +++ b/experimental/fs_example_test.go @@ -8,7 +8,7 @@ import ( "github.com/tetratelabs/wazero" "github.com/tetratelabs/wazero/experimental" - "github.com/tetratelabs/wazero/wasi" + "github.com/tetratelabs/wazero/wasi_snapshot_preview1" ) // This is a basic example of overriding the file system via WithFS. The main goal is to show how it is configured. @@ -18,7 +18,7 @@ func Example_withFS() { r := wazero.NewRuntime() defer r.Close(ctx) // This closes everything this Runtime created. - if _, err := wasi.InstantiateSnapshotPreview1(ctx, r); err != nil { + if _, err := wasi_snapshot_preview1.Instantiate(ctx, r); err != nil { log.Panicln(err) } diff --git a/experimental/listener_example_test.go b/experimental/listener_example_test.go index 7510787019..b6c63597a7 100644 --- a/experimental/listener_example_test.go +++ b/experimental/listener_example_test.go @@ -9,7 +9,7 @@ import ( "github.com/tetratelabs/wazero" "github.com/tetratelabs/wazero/experimental" - "github.com/tetratelabs/wazero/wasi" + "github.com/tetratelabs/wazero/wasi_snapshot_preview1" ) // loggerFactory implements experimental.FunctionListenerFactory to log all function calls to the console. @@ -62,7 +62,7 @@ func Example_listener() { r := wazero.NewRuntimeWithConfig(wazero.NewRuntimeConfigInterpreter()) defer r.Close(ctx) // This closes everything this Runtime created. - if _, err := wasi.InstantiateSnapshotPreview1(ctx, r); err != nil { + if _, err := wasi_snapshot_preview1.Instantiate(ctx, r); err != nil { log.Panicln(err) } diff --git a/experimental/time_example_test.go b/experimental/time_example_test.go index 5802a33fe5..92683c93b1 100644 --- a/experimental/time_example_test.go +++ b/experimental/time_example_test.go @@ -8,7 +8,7 @@ import ( "github.com/tetratelabs/wazero" "github.com/tetratelabs/wazero/experimental" - "github.com/tetratelabs/wazero/wasi" + "github.com/tetratelabs/wazero/wasi_snapshot_preview1" ) const epochNanos = uint64(1640995200000000000) // midnight UTC 2022-01-01 @@ -20,7 +20,7 @@ func Example_withTimeNowUnixNano() { r := wazero.NewRuntime() defer r.Close(ctx) // This closes everything this Runtime created. - if _, err := wasi.InstantiateSnapshotPreview1(ctx, r); err != nil { + if _, err := wasi_snapshot_preview1.Instantiate(ctx, r); err != nil { log.Panicln(err) } diff --git a/internal/integration_test/bench/bench_test.go b/internal/integration_test/bench/bench_test.go index c22400c044..4025956acf 100644 --- a/internal/integration_test/bench/bench_test.go +++ b/internal/integration_test/bench/bench_test.go @@ -10,7 +10,7 @@ import ( "github.com/tetratelabs/wazero" "github.com/tetratelabs/wazero/api" - "github.com/tetratelabs/wazero/wasi" + "github.com/tetratelabs/wazero/wasi_snapshot_preview1" ) // testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors. @@ -190,7 +190,7 @@ func createRuntime(b *testing.B, config wazero.RuntimeConfig) wazero.Runtime { // Note: host_func.go doesn't directly use WASI, but TinyGo needs to be initialized as a WASI Command. // Add WASI to satisfy import tests - _, err = wasi.InstantiateSnapshotPreview1(testCtx, r) + _, err = wasi_snapshot_preview1.Instantiate(testCtx, r) if err != nil { b.Fatal(err) } diff --git a/internal/integration_test/fs/fs_test.go b/internal/integration_test/fs/fs_test.go index bb414c64f4..3f74d7c0a6 100644 --- a/internal/integration_test/fs/fs_test.go +++ b/internal/integration_test/fs/fs_test.go @@ -13,7 +13,7 @@ import ( "github.com/tetratelabs/wazero" "github.com/tetratelabs/wazero/api" "github.com/tetratelabs/wazero/internal/testing/require" - "github.com/tetratelabs/wazero/wasi" + "github.com/tetratelabs/wazero/wasi_snapshot_preview1" ) var testCtx = context.Background() @@ -21,7 +21,7 @@ var testCtx = context.Background() //go:embed testdata/animals.txt var animals []byte -// wasiFs is an implementation of fs.Fs calling into wasi. Not thread-safe because we use +// wasiFs is an implementation of fs.Fs calling into wasiWASI. Not thread-safe because we use // fixed Memory offsets for transferring data with wasm. type wasiFs struct { t *testing.T @@ -57,7 +57,7 @@ func (fs *wasiFs) Open(name string) (fs.File, error) { uint64(fd), uint64(dirflags), uint64(pathPtr), uint64(pathLen), uint64(oflags), fsRightsBase, fsRightsInheriting, uint64(fdflags), uint64(resultOpenedFd)) require.NoError(fs.t, err) - require.Equal(fs.t, uint64(wasi.ErrnoSuccess), res[0]) + require.Equal(fs.t, uint64(wasi_snapshot_preview1.ErrnoSuccess), res[0]) resFd, ok := fs.memory.ReadUint32Le(testCtx, resultOpenedFd) require.True(fs.t, ok) @@ -65,8 +65,8 @@ func (fs *wasiFs) Open(name string) (fs.File, error) { return &wasiFile{fd: resFd, fs: fs}, nil } -// wasiFile implements io.Reader and io.Seeker using wasi functions. It does not -// implement io.ReaderAt because there is no wasi function for directly reading +// wasiFile implements io.Reader and io.Seeker using wasiWASI functions. It does not +// implement io.ReaderAt because there is no wasiWASI function for directly reading // from an offset. type wasiFile struct { fd uint32 @@ -98,7 +98,7 @@ func (f *wasiFile) Read(bytes []byte) (int, error) { res, err := f.fs.fdRead.Call(testCtx, uint64(f.fd), uint64(iovsOff), uint64(iovsCount), uint64(resultSizeOff)) require.NoError(f.fs.t, err) - require.NotEqual(f.fs.t, uint64(wasi.ErrnoFault), res[0]) + require.NotEqual(f.fs.t, uint64(wasi_snapshot_preview1.ErrnoFault), res[0]) numRead, ok := f.fs.memory.ReadUint32Le(testCtx, resultSizeOff) require.True(f.fs.t, ok) @@ -107,7 +107,7 @@ func (f *wasiFile) Read(bytes []byte) (int, error) { if len(bytes) == 0 { return 0, nil } - if wasi.Errno(res[0]) == wasi.ErrnoSuccess { + if wasi_snapshot_preview1.Errno(res[0]) == wasi_snapshot_preview1.ErrnoSuccess { return 0, io.EOF } else { return 0, fmt.Errorf("could not read from file") @@ -123,7 +123,7 @@ func (f *wasiFile) Read(bytes []byte) (int, error) { func (f *wasiFile) Close() error { res, err := f.fs.fdClose.Call(testCtx, uint64(f.fd)) require.NoError(f.fs.t, err) - require.NotEqual(f.fs.t, uint64(wasi.ErrnoFault), res[0]) + require.NotEqual(f.fs.t, uint64(wasi_snapshot_preview1.ErrnoFault), res[0]) return nil } @@ -133,7 +133,7 @@ func (f *wasiFile) Seek(offset int64, whence int) (int64, error) { res, err := f.fs.fdSeek.Call(testCtx, uint64(f.fd), uint64(offset), uint64(whence), uint64(resultNewoffsetOff)) require.NoError(f.fs.t, err) - require.NotEqual(f.fs.t, uint64(wasi.ErrnoFault), res[0]) + require.NotEqual(f.fs.t, uint64(wasi_snapshot_preview1.ErrnoFault), res[0]) newOffset, ok := f.fs.memory.ReadUint32Le(testCtx, resultNewoffsetOff) require.True(f.fs.t, ok) @@ -145,7 +145,7 @@ func TestReader(t *testing.T) { r := wazero.NewRuntime() defer r.Close(testCtx) - _, err := wasi.InstantiateSnapshotPreview1(testCtx, r) + _, err := wasi_snapshot_preview1.Instantiate(testCtx, r) require.NoError(t, err) realFs := fstest.MapFS{"animals.txt": &fstest.MapFile{Data: animals}} diff --git a/internal/integration_test/vs/codec_test.go b/internal/integration_test/vs/codec_test.go index 338ec059e6..8ce4ad2500 100644 --- a/internal/integration_test/vs/codec_test.go +++ b/internal/integration_test/vs/codec_test.go @@ -9,7 +9,7 @@ import ( "github.com/tetratelabs/wazero/internal/wasm" "github.com/tetratelabs/wazero/internal/wasm/binary" "github.com/tetratelabs/wazero/internal/wasm/text" - "github.com/tetratelabs/wazero/wasi" + "github.com/tetratelabs/wazero/wasi_snapshot_preview1" ) func TestExampleUpToDate(t *testing.T) { @@ -29,7 +29,7 @@ func TestExampleUpToDate(t *testing.T) { r := wazero.NewRuntimeWithConfig(wazero.NewRuntimeConfig().WithWasmCore2()) // Add WASI to satisfy import tests - wm, err := wasi.InstantiateSnapshotPreview1(testCtx, r) + wm, err := wasi_snapshot_preview1.Instantiate(testCtx, r) require.NoError(t, err) defer wm.Close(testCtx) diff --git a/internal/integration_test/vs/runtime.go b/internal/integration_test/vs/runtime.go index 63643207db..4214db4694 100644 --- a/internal/integration_test/vs/runtime.go +++ b/internal/integration_test/vs/runtime.go @@ -6,7 +6,7 @@ import ( "github.com/tetratelabs/wazero" "github.com/tetratelabs/wazero/api" - "github.com/tetratelabs/wazero/wasi" + "github.com/tetratelabs/wazero/wasi_snapshot_preview1" ) type RuntimeConfig struct { @@ -96,7 +96,7 @@ func (r *wazeroRuntime) Instantiate(ctx context.Context, cfg *RuntimeConfig) (mo // Instantiate WASI, if configured. if cfg.NeedsWASI { - if m.wasi, err = wasi.InstantiateSnapshotPreview1(ctx, r.runtime); err != nil { + if m.wasi, err = wasi_snapshot_preview1.Instantiate(ctx, r.runtime); err != nil { return } } diff --git a/internal/sys/fs.go b/internal/sys/fs.go index 4e72f2cd19..6c55334368 100644 --- a/internal/sys/fs.go +++ b/internal/sys/fs.go @@ -14,8 +14,6 @@ import ( type FSKey struct{} // FileEntry maps a path to an open file in a file system. -// -// Note: This does not introduce cycles because the types here are in the package "wasi" not "internalwasi". type FileEntry struct { Path string FS fs.FS diff --git a/namespace.go b/namespace.go index 365acfb436..8691875a7b 100644 --- a/namespace.go +++ b/namespace.go @@ -35,7 +35,7 @@ type Namespace interface { // defer n.CloseWithExitCode(ctx, 2) // This closes all modules in this Namespace. // // Everything below here can be closed, but will anyway due to above. - // _, _ = wasi.InstantiateSnapshotPreview1(ctx, n) + // _, _ = wasi_snapshot_preview1.InstantiateSnapshotPreview1(ctx, n) // mod, _ := n.InstantiateModuleFromCode(ctx, source) // // See Closer diff --git a/netlify.toml b/netlify.toml index cf2386d93c..75076233db 100644 --- a/netlify.toml +++ b/netlify.toml @@ -3,7 +3,7 @@ publish = "public" [build.environment] - HUGO_VERSION = "0.99.0" + HUGO_VERSION = "0.100.0" [context.production] command = "git submodule update --init && hugo --gc --minify" diff --git a/runtime.go b/runtime.go index e6f689c24b..9c39450649 100644 --- a/runtime.go +++ b/runtime.go @@ -111,7 +111,7 @@ type Runtime interface { // defer r.CloseWithExitCode(ctx, 2) // This closes everything this Runtime created. // // // Everything below here can be closed, but will anyway due to above. - // _, _ = wasi.InstantiateSnapshotPreview1(ctx, r) + // _, _ = wasi_snapshot_preview1.InstantiateSnapshotPreview1(ctx, r) // mod, _ := r.InstantiateModuleFromCode(ctx, source) CloseWithExitCode(ctx context.Context, exitCode uint32) error diff --git a/wasi/errno.go b/wasi_snapshot_preview1/errno.go similarity index 99% rename from wasi/errno.go rename to wasi_snapshot_preview1/errno.go index 5dd21b547d..c31d4e1f76 100644 --- a/wasi/errno.go +++ b/wasi_snapshot_preview1/errno.go @@ -1,4 +1,4 @@ -package wasi +package wasi_snapshot_preview1 import ( "fmt" diff --git a/wasi/example_test.go b/wasi_snapshot_preview1/example_test.go similarity index 96% rename from wasi/example_test.go rename to wasi_snapshot_preview1/example_test.go index 4aa8421ac6..1560b4e890 100644 --- a/wasi/example_test.go +++ b/wasi_snapshot_preview1/example_test.go @@ -1,4 +1,4 @@ -package wasi +package wasi_snapshot_preview1 import ( "context" @@ -21,7 +21,7 @@ func Example() { r := wazero.NewRuntime() // Instantiate WASI, which implements system I/O such as console output. - wm, err := InstantiateSnapshotPreview1(ctx, r) + wm, err := Instantiate(ctx, r) if err != nil { log.Panicln(err) } diff --git a/wasi/testdata/wasi_arg.wasm b/wasi_snapshot_preview1/testdata/wasi_arg.wasm similarity index 100% rename from wasi/testdata/wasi_arg.wasm rename to wasi_snapshot_preview1/testdata/wasi_arg.wasm diff --git a/wasi/testdata/wasi_arg.wat b/wasi_snapshot_preview1/testdata/wasi_arg.wat similarity index 100% rename from wasi/testdata/wasi_arg.wat rename to wasi_snapshot_preview1/testdata/wasi_arg.wat diff --git a/wasi/usage_test.go b/wasi_snapshot_preview1/usage_test.go similarity index 94% rename from wasi/usage_test.go rename to wasi_snapshot_preview1/usage_test.go index 2ce54b0577..f86a1c89ad 100644 --- a/wasi/usage_test.go +++ b/wasi_snapshot_preview1/usage_test.go @@ -1,4 +1,4 @@ -package wasi +package wasi_snapshot_preview1 import ( "bytes" @@ -20,7 +20,7 @@ func TestInstantiateModule(t *testing.T) { // Configure WASI to write stdout to a buffer, so that we can verify it later. sys := wazero.NewModuleConfig().WithStdout(stdout) - wm, err := InstantiateSnapshotPreview1(testCtx, r) + wm, err := Instantiate(testCtx, r) require.NoError(t, err) defer wm.Close(testCtx) diff --git a/wasi/wasi.go b/wasi_snapshot_preview1/wasi.go similarity index 85% rename from wasi/wasi.go rename to wasi_snapshot_preview1/wasi.go index d7668960bd..4590801668 100644 --- a/wasi/wasi.go +++ b/wasi_snapshot_preview1/wasi.go @@ -1,18 +1,18 @@ -// Package wasi contains Go-defined functions to access system calls, such as opening a file, similar to Go's x/sys -// package. These are accessible from WebAssembly-defined functions via importing ModuleSnapshotPreview1. +// Package wasi_snapshot_preview1 contains Go-defined functions to access system calls, such as opening a file, similar +// to Go's x/sys package. These are accessible from WebAssembly-defined functions via importing ModuleName. // All WASI functions return a single Errno result, which is ErrnoSuccess on success. // -// Ex. If your source (%.wasm binary) includes an import "wasi_snapshot_preview1", call InstantiateSnapshotPreview1 +// Ex. If your source (%.wasm binary) includes an import "wasi_snapshot_preview1", call Instantiate // prior to instantiating it. Otherwise, it will error due to missing imports. // ctx := context.Background() // r := wazero.NewRuntime() // defer r.Close(ctx) // This closes everything this Runtime created. // -// _, _ = wasi.InstantiateSnapshotPreview1(ctx, r) +// _, _ = wasi_snapshot_preview1.Instantiate(ctx, r) // mod, _ := r.InstantiateModuleFromCode(ctx, source) // // See https://github.com/WebAssembly/WASI -package wasi +package wasi_snapshot_preview1 import ( "context" @@ -29,54 +29,54 @@ import ( "github.com/tetratelabs/wazero/internal/wasm" ) -// ModuleSnapshotPreview1 is the module name WASI functions are exported into. +// ModuleName is the module name WASI functions are exported into. // // See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md -const ModuleSnapshotPreview1 = "wasi_snapshot_preview1" +const ModuleName = "wasi_snapshot_preview1" -// InstantiateSnapshotPreview1 instantiates the ModuleSnapshotPreview1 module into the runtime default namespace. +// Instantiate instantiates the ModuleName module into the runtime default namespace. // // Notes // // * Closing the wazero.Runtime has the same effect as closing the result. -// * To instantiate into another wazero.Namespace, use NewSnapshotPreview1Builder instead. -func InstantiateSnapshotPreview1(ctx context.Context, r wazero.Runtime) (api.Closer, error) { - return NewSnapshotPreview1Builder(r).Instantiate(ctx, r) +// * To instantiate into another wazero.Namespace, use NewBuilder instead. +func Instantiate(ctx context.Context, r wazero.Runtime) (api.Closer, error) { + return NewBuilder(r).Instantiate(ctx, r) } -// SnapshotPreview1Builder configures the ModuleSnapshotPreview1 module for later use via Compile or Instantiate. -type SnapshotPreview1Builder interface { +// Builder configures the ModuleName module for later use via Compile or Instantiate. +type Builder interface { - // Compile compiles the ModuleSnapshotPreview1 module that can instantiated in any namespace (wazero.Namespace). + // Compile compiles the ModuleName module that can instantiated in any namespace (wazero.Namespace). // // Note: This has the same effect as the same function name on wazero.ModuleBuilder. Compile(context.Context, wazero.CompileConfig) (wazero.CompiledModule, error) - // Instantiate instantiates the ModuleSnapshotPreview1 module into the provided namespace. + // Instantiate instantiates the ModuleName module into the provided namespace. // // Note: This has the same effect as the same function name on wazero.ModuleBuilder. Instantiate(context.Context, wazero.Namespace) (api.Closer, error) } -// NewSnapshotPreview1Builder returns a new SnapshotPreview1Builder. -func NewSnapshotPreview1Builder(r wazero.Runtime) SnapshotPreview1Builder { - return &snapshotPreview1Builder{r} +// NewBuilder returns a new Builder. +func NewBuilder(r wazero.Runtime) Builder { + return &builder{r} } -type snapshotPreview1Builder struct{ r wazero.Runtime } +type builder struct{ r wazero.Runtime } -// moduleBuilder returns a new wazero.ModuleBuilder for ModuleSnapshotPreview1 -func (b *snapshotPreview1Builder) moduleBuilder() wazero.ModuleBuilder { - return b.r.NewModuleBuilder(ModuleSnapshotPreview1).ExportFunctions(snapshotPreview1Functions()) +// moduleBuilder returns a new wazero.ModuleBuilder for ModuleName +func (b *builder) moduleBuilder() wazero.ModuleBuilder { + return b.r.NewModuleBuilder(ModuleName).ExportFunctions(wasiFunctions()) } -// Compile implements SnapshotPreview1Builder.Compile -func (b *snapshotPreview1Builder) Compile(ctx context.Context, config wazero.CompileConfig) (wazero.CompiledModule, error) { +// Compile implements Builder.Compile +func (b *builder) Compile(ctx context.Context, config wazero.CompileConfig) (wazero.CompiledModule, error) { return b.moduleBuilder().Compile(ctx, config) } -// Instantiate implements SnapshotPreview1Builder.Instantiate -func (b *snapshotPreview1Builder) Instantiate(ctx context.Context, ns wazero.Namespace) (api.Closer, error) { +// Instantiate implements Builder.Instantiate +func (b *builder) Instantiate(ctx context.Context, ns wazero.Namespace) (api.Closer, error) { return b.moduleBuilder().Instantiate(ctx, ns) } @@ -392,7 +392,7 @@ const ( // importProcExit is the WebAssembly 1.0 (20191205) Text format import of functionProcExit. // // See importProcExit - // See snapshotPreview1.ProcExit + // See wasi.ProcExit // See functionProcExit // See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#proc_exit importProcExit = `(import "wasi_snapshot_preview1" "proc_exit" @@ -447,7 +447,7 @@ const ( (func $wasi.sock_shutdown (param $fd i32) (param $how i32) (result (;errno;) i32)))` ) -// snapshotPreview1 includes all host functions to export for WASI version "wasi_snapshot_preview1". +// wasi includes all host functions to export for WASI version "wasi_snapshot_preview1". // // ## Translation notes // ### String @@ -458,14 +458,14 @@ const ( // `iovec_array` is encoded as two uin32le values (i32): offset and count. // // ### Result -// Each result besides wasi.Errno is always an uint32 parameter. WebAssembly 1.0 (20191205) can have up to one result, -// which is already used by wasi.Errno. This forces other results to be parameters. A result parameter is a memory +// Each result besides wasi_snapshot_preview1.Errno is always an uint32 parameter. WebAssembly 1.0 (20191205) can have up to one result, +// which is already used by wasi_snapshot_preview1.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. // // ### Errno // The WASI specification is sometimes ambiguous resulting in some runtimes interpreting the same function ways. -// wasi.Errno mappings are not defined in WASI, yet, so these mappings are best efforts by maintainers. When in doubt -// about portability, first look at internal/wasi/RATIONALE.md and if needed an issue on +// wasi_snapshot_preview1.Errno mappings are not defined in WASI, yet, so these mappings are best efforts by maintainers. When in doubt +// about portability, first look at /RATIONALE.md and if needed an issue on // https://github.com/WebAssembly/WASI/issues // // ## Memory @@ -475,12 +475,12 @@ const ( // See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md // See https://github.com/WebAssembly/WASI/issues/215 // See https://wwa.w3.org/TR/2019/REC-wasm-core-1-20191205/#memory-instances%E2%91%A0. -type snapshotPreview1 struct{} +type wasi struct{} -// snapshotPreview1Functions returns all go functions that implement snapshotPreview1. -// These should be exported in the module named ModuleSnapshotPreview1. -func snapshotPreview1Functions() map[string]interface{} { - a := &snapshotPreview1{} +// wasiFunctions returns all go functions that implement wasi. +// These should be exported in the module named ModuleName. +func wasiFunctions() map[string]interface{} { + a := &wasi{} // Note: these are ordered per spec for consistency even if the resulting map can't guarantee that. // See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#functions return map[string]interface{}{ @@ -558,7 +558,7 @@ func snapshotPreview1Functions() map[string]interface{} { // 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 -func (a *snapshotPreview1) ArgsGet(ctx context.Context, m api.Module, argv, argvBuf uint32) Errno { +func (a *wasi) ArgsGet(ctx context.Context, m api.Module, argv, argvBuf uint32) Errno { sys := sysCtx(m) return writeOffsetsAndNullTerminatedValues(ctx, m.Memory(), sys.Args(), argv, argvBuf) } @@ -589,7 +589,7 @@ func (a *snapshotPreview1) ArgsGet(ctx context.Context, m api.Module, argv, argv // 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 -func (a *snapshotPreview1) ArgsSizesGet(ctx context.Context, m api.Module, resultArgc, resultArgvBufSize uint32) Errno { +func (a *wasi) ArgsSizesGet(ctx context.Context, m api.Module, resultArgc, resultArgvBufSize uint32) Errno { sys := sysCtx(m) mem := m.Memory() @@ -628,7 +628,7 @@ func (a *snapshotPreview1) ArgsSizesGet(ctx context.Context, m api.Module, resul // See EnvironSizesGet // See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#environ_get // See https://en.wikipedia.org/wiki/Null-terminated_string -func (a *snapshotPreview1) EnvironGet(ctx context.Context, m api.Module, environ uint32, environBuf uint32) Errno { +func (a *wasi) EnvironGet(ctx context.Context, m api.Module, environ uint32, environBuf uint32) Errno { sys := sysCtx(m) return writeOffsetsAndNullTerminatedValues(ctx, m.Memory(), sys.Environ(), environ, environBuf) } @@ -636,7 +636,7 @@ func (a *snapshotPreview1) EnvironGet(ctx context.Context, m api.Module, environ // EnvironSizesGet is the WASI function named functionEnvironSizesGet that reads environment variable // (WithEnviron) sizes. // -// There are two result parameters: these are offsets in the wasi.Module Memory to write +// There are two result parameters: these are offsets in the wasiapi.Module Memory to write // corresponding sizes in uint32 little-endian encoding. If either are invalid due to memory constraints, this // returns ErrnoFault. // @@ -660,7 +660,7 @@ func (a *snapshotPreview1) EnvironGet(ctx context.Context, m api.Module, environ // See EnvironGet // See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#environ_sizes_get // See https://en.wikipedia.org/wiki/Null-terminated_string -func (a *snapshotPreview1) EnvironSizesGet(ctx context.Context, m api.Module, resultEnvironc uint32, resultEnvironBufSize uint32) Errno { +func (a *wasi) EnvironSizesGet(ctx context.Context, m api.Module, resultEnvironc uint32, resultEnvironBufSize uint32) Errno { sys := sysCtx(m) mem := m.Memory() @@ -692,7 +692,7 @@ func (a *snapshotPreview1) EnvironSizesGet(ctx context.Context, m api.Module, re // Note: This is similar to `clock_getres` in POSIX. // See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-clock_res_getid-clockid---errno-timestamp // See https://linux.die.net/man/3/clock_getres -func (a *snapshotPreview1) ClockResGet(ctx context.Context, m api.Module, id uint32, resultResolution uint32) Errno { +func (a *wasi) ClockResGet(ctx context.Context, m api.Module, id uint32, resultResolution uint32) Errno { // We choose arbitrary resolutions here because there's no perfect alternative. For example, according to the // source in time.go, windows monotonic resolution can be 15ms. This chooses arbitrarily 1us for wall time and // 1ns for monotonic. See RATIONALE.md for more context. @@ -735,7 +735,7 @@ func (a *snapshotPreview1) ClockResGet(ctx context.Context, m api.Module, id uin // Note: This is similar to `clock_gettime` in POSIX. // See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-clock_time_getid-clockid-precision-timestamp---errno-timestamp // See https://linux.die.net/man/3/clock_gettime -func (a *snapshotPreview1) ClockTimeGet(ctx context.Context, m api.Module, id uint32, precision uint64, resultTimestamp uint32) Errno { +func (a *wasi) ClockTimeGet(ctx context.Context, m api.Module, id uint32, precision uint64, resultTimestamp uint32) Errno { // TODO: precision is currently ignored. var val uint64 switch id { @@ -765,12 +765,12 @@ func (a *snapshotPreview1) ClockTimeGet(ctx context.Context, m api.Module, id ui } // FdAdvise is the WASI function named functionFdAdvise and is stubbed for GrainLang per #271 -func (a *snapshotPreview1) FdAdvise(ctx context.Context, m api.Module, fd uint32, offset, len uint64, resultAdvice uint32) Errno { +func (a *wasi) FdAdvise(ctx context.Context, m api.Module, fd uint32, offset, len uint64, resultAdvice uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } // FdAllocate is the WASI function named functionFdAllocate and is stubbed for GrainLang per #271 -func (a *snapshotPreview1) FdAllocate(ctx context.Context, m api.Module, fd uint32, offset, len uint64) Errno { +func (a *wasi) FdAllocate(ctx context.Context, m api.Module, fd uint32, offset, len uint64) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } @@ -782,7 +782,7 @@ func (a *snapshotPreview1) FdAllocate(ctx context.Context, m api.Module, fd uint // Note: This is similar to `close` in POSIX. // See https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#fd_close // See https://linux.die.net/man/3/close -func (a *snapshotPreview1) FdClose(ctx context.Context, m api.Module, fd uint32) Errno { +func (a *wasi) FdClose(ctx context.Context, m api.Module, fd uint32) Errno { _, fsc := sysFSCtx(ctx, m) if ok, err := fsc.CloseFile(fd); err != nil { @@ -795,7 +795,7 @@ func (a *snapshotPreview1) FdClose(ctx context.Context, m api.Module, fd uint32) } // FdDatasync is the WASI function named functionFdDatasync and is stubbed for GrainLang per #271 -func (a *snapshotPreview1) FdDatasync(ctx context.Context, m api.Module, fd uint32) Errno { +func (a *wasi) FdDatasync(ctx context.Context, m api.Module, fd uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } @@ -804,9 +804,9 @@ func (a *snapshotPreview1) FdDatasync(ctx context.Context, m api.Module, fd uint // * fd - the file descriptor to get the fdstat attributes data // * resultFdstat - the offset to write the result fdstat data // -// The wasi.Errno returned is wasi.ErrnoSuccess except the following error conditions: -// * wasi.ErrnoBadf - if `fd` is invalid -// * wasi.ErrnoFault - if `resultFdstat` contains an invalid offset due to the memory constraint +// The wasi_snapshot_preview1.Errno returned is wasi_snapshot_preview1.ErrnoSuccess except the following error conditions: +// * wasi_snapshot_preview1.ErrnoBadf - if `fd` is invalid +// * wasi_snapshot_preview1.ErrnoFault - if `resultFdstat` contains an invalid offset due to the memory constraint // // fdstat byte layout is 24-byte size, which as the following elements in order // * fs_filetype 1 byte, to indicate the file type @@ -831,7 +831,7 @@ func (a *snapshotPreview1) FdDatasync(ctx context.Context, m api.Module, fd uint // See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#fdstat // See https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#fd_fdstat_get // See https://linux.die.net/man/3/fsync -func (a *snapshotPreview1) FdFdstatGet(ctx context.Context, m api.Module, fd uint32, resultStat uint32) Errno { +func (a *wasi) FdFdstatGet(ctx context.Context, m api.Module, fd uint32, resultStat uint32) Errno { _, fsc := sysFSCtx(ctx, m) if _, ok := fsc.OpenedFile(fd); !ok { @@ -845,9 +845,9 @@ func (a *snapshotPreview1) FdFdstatGet(ctx context.Context, m api.Module, fd uin // * fd - the file descriptor to get the prestat // * resultPrestat - the offset to write the result prestat data // -// The wasi.Errno returned is wasi.ErrnoSuccess except the following error conditions: -// * wasi.ErrnoBadf - if `fd` is invalid or the `fd` is not a pre-opened directory. -// * wasi.ErrnoFault - if `resultPrestat` is an invalid offset due to the memory constraint +// The wasi_snapshot_preview1.Errno returned is wasi_snapshot_preview1.ErrnoSuccess except the following error conditions: +// * wasi_snapshot_preview1.ErrnoBadf - if `fd` is invalid or the `fd` is not a pre-opened directory. +// * wasi_snapshot_preview1.ErrnoFault - if `resultPrestat` is an invalid offset due to the memory constraint // // prestat byte layout is 8 bytes, beginning with an 8-bit tag and 3 pad bytes. The only valid tag is `prestat_dir`, // which is tag zero. This simplifies the byte layout to 4 empty bytes followed by the uint32le encoded path length. @@ -867,7 +867,7 @@ func (a *snapshotPreview1) FdFdstatGet(ctx context.Context, m api.Module, fd uin // See FdPrestatDirName // See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#prestat // See https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#fd_prestat_get -func (a *snapshotPreview1) FdPrestatGet(ctx context.Context, m api.Module, fd uint32, resultPrestat uint32) Errno { +func (a *wasi) FdPrestatGet(ctx context.Context, m api.Module, fd uint32, resultPrestat uint32) Errno { _, fsc := sysFSCtx(ctx, m) entry, ok := fsc.OpenedFile(fd) @@ -888,33 +888,33 @@ func (a *snapshotPreview1) FdPrestatGet(ctx context.Context, m api.Module, fd ui } // FdFdstatSetFlags is the WASI function named functionFdFdstatSetFlags and is stubbed for GrainLang per #271 -func (a *snapshotPreview1) FdFdstatSetFlags(ctx context.Context, m api.Module, fd uint32, flags uint32) Errno { +func (a *wasi) FdFdstatSetFlags(ctx context.Context, m api.Module, fd uint32, flags uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } -// FdFdstatSetRights implements snapshotPreview1.FdFdstatSetRights +// FdFdstatSetRights implements wasi.FdFdstatSetRights // Note: This will never be implemented per https://github.com/WebAssembly/WASI/issues/469#issuecomment-1045251844 -func (a *snapshotPreview1) FdFdstatSetRights(ctx context.Context, m api.Module, fd uint32, fsRightsBase, fsRightsInheriting uint64) Errno { +func (a *wasi) FdFdstatSetRights(ctx context.Context, m api.Module, fd uint32, fsRightsBase, fsRightsInheriting uint64) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } // FdFilestatGet is the WASI function named functionFdFilestatGet -func (a *snapshotPreview1) FdFilestatGet(ctx context.Context, m api.Module, fd uint32, resultBuf uint32) Errno { +func (a *wasi) FdFilestatGet(ctx context.Context, m api.Module, fd uint32, resultBuf uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } // FdFilestatSetSize is the WASI function named functionFdFilestatSetSize -func (a *snapshotPreview1) FdFilestatSetSize(ctx context.Context, m api.Module, fd uint32, size uint64) Errno { +func (a *wasi) FdFilestatSetSize(ctx context.Context, m api.Module, fd uint32, size uint64) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } // FdFilestatSetTimes is the WASI function named functionFdFilestatSetTimes -func (a *snapshotPreview1) FdFilestatSetTimes(ctx context.Context, m api.Module, fd uint32, atim, mtim uint64, fstFlags uint32) Errno { +func (a *wasi) FdFilestatSetTimes(ctx context.Context, m api.Module, fd uint32, atim, mtim uint64, fstFlags uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } // FdPread is the WASI function named functionFdPread -func (a *snapshotPreview1) FdPread(ctx context.Context, m api.Module, fd, iovs, iovsCount uint32, offset uint64, resultNread uint32) Errno { +func (a *wasi) FdPread(ctx context.Context, m api.Module, fd, iovs, iovsCount uint32, offset uint64, resultNread uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } @@ -925,10 +925,10 @@ func (a *snapshotPreview1) FdPread(ctx context.Context, m api.Module, fd, iovs, // * pathLen - the count of bytes to write to `path` // * This should match the uint32le FdPrestatGet writes to offset `resultPrestat`+4 // -// The wasi.Errno returned is wasi.ErrnoSuccess except the following error conditions: -// * wasi.ErrnoBadf - if `fd` is invalid -// * wasi.ErrnoFault - if `path` is an invalid offset due to the memory constraint -// * wasi.ErrnoNametoolong - if `pathLen` is longer than the actual length of the result path +// The wasi_snapshot_preview1.Errno returned is wasi_snapshot_preview1.ErrnoSuccess except the following error conditions: +// * wasi_snapshot_preview1.ErrnoBadf - if `fd` is invalid +// * wasi_snapshot_preview1.ErrnoFault - if `path` is an invalid offset due to the memory constraint +// * wasi_snapshot_preview1.ErrnoNametoolong - if `pathLen` is longer than the actual length of the result path // // For example, the directory name corresponding with `fd` was "/tmp" and // parameters path=1 pathLen=4 (correct), this function will write the below to `m.Memory`: @@ -942,7 +942,7 @@ func (a *snapshotPreview1) FdPread(ctx context.Context, m api.Module, fd, iovs, // Note: importFdPrestatDirName shows this signature in the WebAssembly 1.0 (20191205) Text Format. // See FdPrestatGet // See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#fd_prestat_dir_name -func (a *snapshotPreview1) FdPrestatDirName(ctx context.Context, m api.Module, fd uint32, pathPtr uint32, pathLen uint32) Errno { +func (a *wasi) FdPrestatDirName(ctx context.Context, m api.Module, fd uint32, pathPtr uint32, pathLen uint32) Errno { _, fsc := sysFSCtx(ctx, m) f, ok := fsc.OpenedFile(fd) @@ -950,7 +950,7 @@ func (a *snapshotPreview1) FdPrestatDirName(ctx context.Context, m api.Module, f return ErrnoBadf } - // Some runtimes may have another semantics. See internal/wasi/RATIONALE.md + // Some runtimes may have another semantics. See /RATIONALE.md if uint32(len(f.Path)) < pathLen { return ErrnoNametoolong } @@ -963,7 +963,7 @@ func (a *snapshotPreview1) FdPrestatDirName(ctx context.Context, m api.Module, f } // FdPwrite is the WASI function named functionFdPwrite -func (a *snapshotPreview1) FdPwrite(ctx context.Context, m api.Module, fd, iovs, iovsCount uint32, offset uint64, resultNwritten uint32) Errno { +func (a *wasi) FdPwrite(ctx context.Context, m api.Module, fd, iovs, iovsCount uint32, offset uint64, resultNwritten uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } @@ -975,10 +975,10 @@ func (a *snapshotPreview1) FdPwrite(ctx context.Context, m api.Module, fd, iovs, // * iovsCount - the count of memory offset, size pairs to read sequentially starting at iovs. // * resultSize - the offset in `m.Memory` to write the number of bytes read // -// The wasi.Errno returned is wasi.ErrnoSuccess except the following error conditions: -// * wasi.ErrnoBadf - if `fd` is invalid -// * wasi.ErrnoFault - if `iovs` or `resultSize` contain an invalid offset due to the memory constraint -// * wasi.ErrnoIo - if an IO related error happens during the operation +// The wasi_snapshot_preview1.Errno returned is wasi_snapshot_preview1.ErrnoSuccess except the following error conditions: +// * wasi_snapshot_preview1.ErrnoBadf - if `fd` is invalid +// * wasi_snapshot_preview1.ErrnoFault - if `iovs` or `resultSize` contain an invalid offset due to the memory constraint +// * wasi_snapshot_preview1.ErrnoIo - if an IO related error happens during the operation // // For example, this function needs to first read `iovs` to determine where to write contents. If // parameters iovs=1 iovsCount=2, this function reads two offset/length pairs from `m.Memory`: @@ -1010,7 +1010,7 @@ func (a *snapshotPreview1) FdPwrite(ctx context.Context, m api.Module, fd, iovs, // See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#fd_read // See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#iovec // See https://linux.die.net/man/3/readv -func (a *snapshotPreview1) FdRead(ctx context.Context, m api.Module, fd, iovs, iovsCount, resultSize uint32) Errno { +func (a *wasi) FdRead(ctx context.Context, m api.Module, fd, iovs, iovsCount, resultSize uint32) Errno { sys, fsc := sysFSCtx(ctx, m) var reader io.Reader @@ -1053,12 +1053,12 @@ func (a *snapshotPreview1) FdRead(ctx context.Context, m api.Module, fd, iovs, i } // FdReaddir is the WASI function named functionFdReaddir -func (a *snapshotPreview1) FdReaddir(ctx context.Context, m api.Module, fd, buf, bufLen uint32, cookie uint64, resultBufused uint32) Errno { +func (a *wasi) FdReaddir(ctx context.Context, m api.Module, fd, buf, bufLen uint32, cookie uint64, resultBufused uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } // FdRenumber is the WASI function named functionFdRenumber -func (a *snapshotPreview1) FdRenumber(ctx context.Context, m api.Module, fd, to uint32) Errno { +func (a *wasi) FdRenumber(ctx context.Context, m api.Module, fd, to uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } @@ -1072,11 +1072,11 @@ func (a *snapshotPreview1) FdRenumber(ctx context.Context, m api.Module, fd, to // * If io.SeekEnd, new offset == file size of `fd` + `offset`. // * resultNewoffset: the offset in `m.Memory` to write the new offset to, relative to start of the file // -// The wasi.Errno returned is wasi.ErrnoSuccess except the following error conditions: -// * wasi.ErrnoBadf - if `fd` is invalid -// * wasi.ErrnoFault - if `resultNewoffset` is an invalid offset in `m.Memory` due to the memory constraint -// * wasi.ErrnoInval - if `whence` is an invalid value -// * wasi.ErrnoIo - if other error happens during the operation of the underying file system +// The wasi_snapshot_preview1.Errno returned is wasi_snapshot_preview1.ErrnoSuccess except the following error conditions: +// * wasi_snapshot_preview1.ErrnoBadf - if `fd` is invalid +// * wasi_snapshot_preview1.ErrnoFault - if `resultNewoffset` is an invalid offset in `m.Memory` due to the memory constraint +// * wasi_snapshot_preview1.ErrnoInval - if `whence` is an invalid value +// * wasi_snapshot_preview1.ErrnoIo - if other error happens during the operation of the underying file system // // For example, if fd 3 is a file with offset 0, and // parameters fd=3, offset=4, whence=0 (=io.SeekStart), resultNewOffset=1, @@ -1093,7 +1093,7 @@ func (a *snapshotPreview1) FdRenumber(ctx context.Context, m api.Module, fd, to // Note: This is similar to `lseek` in POSIX. // See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#fd_seek // See https://linux.die.net/man/3/lseek -func (a *snapshotPreview1) FdSeek(ctx context.Context, m api.Module, fd uint32, offset uint64, whence uint32, resultNewoffset uint32) Errno { +func (a *wasi) FdSeek(ctx context.Context, m api.Module, fd uint32, offset uint64, whence uint32, resultNewoffset uint32) Errno { _, fsc := sysFSCtx(ctx, m) var seeker io.Seeker @@ -1121,12 +1121,12 @@ func (a *snapshotPreview1) FdSeek(ctx context.Context, m api.Module, fd uint32, } // FdSync is the WASI function named functionFdSync -func (a *snapshotPreview1) FdSync(ctx context.Context, m api.Module, fd uint32) Errno { +func (a *wasi) FdSync(ctx context.Context, m api.Module, fd uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } // FdTell is the WASI function named functionFdTell -func (a *snapshotPreview1) FdTell(ctx context.Context, m api.Module, fd, resultOffset uint32) Errno { +func (a *wasi) FdTell(ctx context.Context, m api.Module, fd, resultOffset uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } @@ -1138,10 +1138,10 @@ func (a *snapshotPreview1) FdTell(ctx context.Context, m api.Module, fd, resultO // * iovsCount - the count of memory offset, size pairs to read sequentially starting at iovs. // * resultSize - the offset in `m.Memory` to write the number of bytes written // -// The wasi.Errno returned is wasi.ErrnoSuccess except the following error conditions: -// * wasi.ErrnoBadf - if `fd` is invalid -// * wasi.ErrnoFault - if `iovs` or `resultSize` contain an invalid offset due to the memory constraint -// * wasi.ErrnoIo - if an IO related error happens during the operation +// The wasi_snapshot_preview1.Errno returned is wasi_snapshot_preview1.ErrnoSuccess except the following error conditions: +// * wasi_snapshot_preview1.ErrnoBadf - if `fd` is invalid +// * wasi_snapshot_preview1.ErrnoFault - if `iovs` or `resultSize` contain an invalid offset due to the memory constraint +// * wasi_snapshot_preview1.ErrnoIo - if an IO related error happens during the operation // // For example, this function needs to first read `iovs` to determine what to write to `fd`. If // parameters iovs=1 iovsCount=2, this function reads two offset/length pairs from `m.Memory`: @@ -1179,7 +1179,7 @@ func (a *snapshotPreview1) FdTell(ctx context.Context, m api.Module, fd, resultO // See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#ciovec // See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#fd_write // See https://linux.die.net/man/3/writev -func (a *snapshotPreview1) FdWrite(ctx context.Context, m api.Module, fd, iovs, iovsCount, resultSize uint32) Errno { +func (a *wasi) FdWrite(ctx context.Context, m api.Module, fd, iovs, iovsCount, resultSize uint32) Errno { sys, fsc := sysFSCtx(ctx, m) var writer io.Writer @@ -1227,22 +1227,22 @@ func (a *snapshotPreview1) FdWrite(ctx context.Context, m api.Module, fd, iovs, } // PathCreateDirectory is the WASI function named functionPathCreateDirectory -func (a *snapshotPreview1) PathCreateDirectory(ctx context.Context, m api.Module, fd, path, pathLen uint32) Errno { +func (a *wasi) PathCreateDirectory(ctx context.Context, m api.Module, fd, path, pathLen uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } // PathFilestatGet is the WASI function named functionPathFilestatGet -func (a *snapshotPreview1) PathFilestatGet(ctx context.Context, m api.Module, fd, flags, path, pathLen, resultBuf uint32) Errno { +func (a *wasi) PathFilestatGet(ctx context.Context, m api.Module, fd, flags, path, pathLen, resultBuf uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } // PathFilestatSetTimes is the WASI function named functionPathFilestatSetTimes -func (a *snapshotPreview1) PathFilestatSetTimes(ctx context.Context, m api.Module, fd, flags, path, pathLen uint32, atim, mtime uint64, fstFlags uint32) Errno { +func (a *wasi) PathFilestatSetTimes(ctx context.Context, m api.Module, fd, flags, path, pathLen uint32, atim, mtime uint64, fstFlags uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } // PathLink is the WASI function named functionPathLink -func (a *snapshotPreview1) PathLink(ctx context.Context, m api.Module, oldFd, oldFlags, oldPath, oldPathLen, newFd, newPath, newPathLen uint32) Errno { +func (a *wasi) PathLink(ctx context.Context, m api.Module, oldFd, oldFlags, oldPath, oldPathLen, newFd, newPath, newPathLen uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } @@ -1259,13 +1259,13 @@ func (a *snapshotPreview1) PathLink(ctx context.Context, m api.Module, oldFd, ol // * resultOpenedFd - the offset in `m.Memory` to write the newly created file descriptor to. // * The result FD value is guaranteed to be less than 2**31 // -// The wasi.Errno returned is wasi.ErrnoSuccess except the following error conditions: -// * wasi.ErrnoBadf - if `fd` is invalid -// * wasi.ErrnoFault - if `resultOpenedFd` contains an invalid offset due to the memory constraint -// * wasi.ErrnoNoent - if `path` does not exist. -// * wasi.ErrnoExist - if `path` exists, while `oFlags` requires that it must not. -// * wasi.ErrnoNotdir - if `path` is not a directory, while `oFlags` requires that it must be. -// * wasi.ErrnoIo - if other error happens during the operation of the underying file system. +// The wasi_snapshot_preview1.Errno returned is wasi_snapshot_preview1.ErrnoSuccess except the following error conditions: +// * wasi_snapshot_preview1.ErrnoBadf - if `fd` is invalid +// * wasi_snapshot_preview1.ErrnoFault - if `resultOpenedFd` contains an invalid offset due to the memory constraint +// * wasi_snapshot_preview1.ErrnoNoent - if `path` does not exist. +// * wasi_snapshot_preview1.ErrnoExist - if `path` exists, while `oFlags` requires that it must not. +// * wasi_snapshot_preview1.ErrnoNotdir - if `path` is not a directory, while `oFlags` requires that it must be. +// * wasi_snapshot_preview1.ErrnoIo - if other error happens during the operation of the underying file system. // // For example, this function needs to first read `path` to determine the file to open. // If parameters `path` = 1, `pathLen` = 6, and the path is "wazero", PathOpen reads the path from `m.Memory`: @@ -1291,7 +1291,7 @@ func (a *snapshotPreview1) PathLink(ctx context.Context, m api.Module, oldFd, ol // Note: Rights will never be implemented per https://github.com/WebAssembly/WASI/issues/469#issuecomment-1045251844 // See https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#path_open // See https://linux.die.net/man/3/openat -func (a *snapshotPreview1) PathOpen(ctx context.Context, m api.Module, fd, dirflags, pathPtr, pathLen, oflags uint32, fsRightsBase, +func (a *wasi) PathOpen(ctx context.Context, m api.Module, fd, dirflags, pathPtr, pathLen, oflags uint32, fsRightsBase, fsRightsInheriting uint64, fdflags, resultOpenedFd uint32) (errno Errno) { _, fsc := sysFSCtx(ctx, m) @@ -1324,32 +1324,32 @@ func (a *snapshotPreview1) PathOpen(ctx context.Context, m api.Module, fd, dirfl } // PathReadlink is the WASI function named functionPathReadlink -func (a *snapshotPreview1) PathReadlink(ctx context.Context, m api.Module, fd, path, pathLen, buf, bufLen, resultBufused uint32) Errno { +func (a *wasi) PathReadlink(ctx context.Context, m api.Module, fd, path, pathLen, buf, bufLen, resultBufused uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } // PathRemoveDirectory is the WASI function named functionPathRemoveDirectory -func (a *snapshotPreview1) PathRemoveDirectory(ctx context.Context, m api.Module, fd, path, pathLen uint32) Errno { +func (a *wasi) PathRemoveDirectory(ctx context.Context, m api.Module, fd, path, pathLen uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } // PathRename is the WASI function named functionPathRename -func (a *snapshotPreview1) PathRename(ctx context.Context, m api.Module, fd, oldPath, oldPathLen, newFd, newPath, newPathLen uint32) Errno { +func (a *wasi) PathRename(ctx context.Context, m api.Module, fd, oldPath, oldPathLen, newFd, newPath, newPathLen uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } // PathSymlink is the WASI function named functionPathSymlink -func (a *snapshotPreview1) PathSymlink(ctx context.Context, m api.Module, oldPath, oldPathLen, fd, newPath, newPathLen uint32) Errno { +func (a *wasi) PathSymlink(ctx context.Context, m api.Module, oldPath, oldPathLen, fd, newPath, newPathLen uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } // PathUnlinkFile is the WASI function named functionPathUnlinkFile -func (a *snapshotPreview1) PathUnlinkFile(ctx context.Context, m api.Module, fd, path, pathLen uint32) Errno { +func (a *wasi) PathUnlinkFile(ctx context.Context, m api.Module, fd, path, pathLen uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } // PollOneoff is the WASI function named functionPollOneoff -func (a *snapshotPreview1) PollOneoff(ctx context.Context, m api.Module, in, out, nsubscriptions, resultNevents uint32) Errno { +func (a *wasi) PollOneoff(ctx context.Context, m api.Module, in, out, nsubscriptions, resultNevents uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } @@ -1362,17 +1362,17 @@ func (a *snapshotPreview1) PollOneoff(ctx context.Context, m api.Module, in, out // // Note: importProcExit shows this signature in the WebAssembly 1.0 (20191205) Text Format. // See https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#proc_exit -func (a *snapshotPreview1) ProcExit(ctx context.Context, m api.Module, exitCode uint32) { +func (a *wasi) ProcExit(ctx context.Context, m api.Module, exitCode uint32) { _ = m.CloseWithExitCode(ctx, exitCode) } // ProcRaise is the WASI function named functionProcRaise -func (a *snapshotPreview1) ProcRaise(ctx context.Context, m api.Module, sig uint32) Errno { +func (a *wasi) ProcRaise(ctx context.Context, m api.Module, sig uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } // SchedYield is the WASI function named functionSchedYield -func (a *snapshotPreview1) SchedYield(m api.Module) Errno { +func (a *wasi) SchedYield(m api.Module) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } @@ -1391,7 +1391,7 @@ func (a *snapshotPreview1) SchedYield(m api.Module) Errno { // // Note: importRandomGet shows this signature in the WebAssembly 1.0 (20191205) Text Format. // See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-random_getbuf-pointeru8-bufLen-size---errno -func (a *snapshotPreview1) RandomGet(ctx context.Context, m api.Module, buf uint32, bufLen uint32) (errno Errno) { +func (a *wasi) RandomGet(ctx context.Context, m api.Module, buf uint32, bufLen uint32) (errno Errno) { randomBytes := make([]byte, bufLen) sys := sysCtx(m) n, err := sys.RandSource().Read(randomBytes) @@ -1408,17 +1408,17 @@ func (a *snapshotPreview1) RandomGet(ctx context.Context, m api.Module, buf uint } // SockRecv is the WASI function named functionSockRecv -func (a *snapshotPreview1) SockRecv(ctx context.Context, m api.Module, fd, riData, riDataCount, riFlags, resultRoDataLen, resultRoFlags uint32) Errno { +func (a *wasi) SockRecv(ctx context.Context, m api.Module, fd, riData, riDataCount, riFlags, resultRoDataLen, resultRoFlags uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } // SockSend is the WASI function named functionSockSend -func (a *snapshotPreview1) SockSend(ctx context.Context, m api.Module, fd, siData, siDataCount, siFlags, resultSoDataLen uint32) Errno { +func (a *wasi) SockSend(ctx context.Context, m api.Module, fd, siData, siDataCount, siFlags, resultSoDataLen uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } // SockShutdown is the WASI function named functionSockShutdown -func (a *snapshotPreview1) SockShutdown(ctx context.Context, m api.Module, fd, how uint32) Errno { +func (a *wasi) SockShutdown(ctx context.Context, m api.Module, fd, how uint32) Errno { return ErrnoNosys // stubbed for GrainLang per #271 } @@ -1478,7 +1478,7 @@ func openFileEntry(rootFS fs.FS, pathName string) (*sys.FileEntry, Errno) { } } - // TODO: verify if oflags is a directory and fail with wasi.ErrnoNotdir if not + // TODO: verify if oflags is a directory and fail with ErrnoNotdir if not // See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-oflags-flagsu16 return &sys.FileEntry{Path: pathName, FS: rootFS, File: f}, ErrnoSuccess diff --git a/wasi/wasi_bench_test.go b/wasi_snapshot_preview1/wasi_bench_test.go similarity index 93% rename from wasi/wasi_bench_test.go rename to wasi_snapshot_preview1/wasi_bench_test.go index 4879df4584..9e2e545c07 100644 --- a/wasi/wasi_bench_test.go +++ b/wasi_snapshot_preview1/wasi_bench_test.go @@ -1,4 +1,4 @@ -package wasi +package wasi_snapshot_preview1 import ( "testing" @@ -25,7 +25,7 @@ func Test_EnvironGet(t *testing.T) { require.NoError(t, err) m := newModule(make([]byte, 20), sys) - environGet := (&snapshotPreview1{}).EnvironGet + environGet := (&wasi{}).EnvironGet require.Equal(t, ErrnoSuccess, environGet(testCtx, m, 11, 1)) require.Equal(t, m.Memory(), testMem) @@ -47,7 +47,7 @@ func Benchmark_EnvironGet(b *testing.B) { 0, }, sys) - environGet := (&snapshotPreview1{}).EnvironGet + environGet := (&wasi{}).EnvironGet b.Run("EnvironGet", func(b *testing.B) { for i := 0; i < b.N; i++ { if environGet(testCtx, m, 0, 4) != ErrnoSuccess { diff --git a/wasi/wasi_test.go b/wasi_snapshot_preview1/wasi_test.go similarity index 96% rename from wasi/wasi_test.go rename to wasi_snapshot_preview1/wasi_test.go index ae68bd7845..525445986a 100644 --- a/wasi/wasi_test.go +++ b/wasi_snapshot_preview1/wasi_test.go @@ -1,4 +1,4 @@ -package wasi +package wasi_snapshot_preview1 import ( "bytes" @@ -34,7 +34,7 @@ const ( // testCtx ensures the fake clock is used for WASI functions. var testCtx = experimental.WithTimeNowUnixNano(context.Background(), func() uint64 { return epochNanos }) -var a = &snapshotPreview1{} +var a = &wasi{} func TestSnapshotPreview1_ArgsGet(t *testing.T) { sysCtx, err := newSysContext([]string{"a", "bc"}, nil, nil) @@ -54,7 +54,7 @@ func TestSnapshotPreview1_ArgsGet(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionArgsGet, importArgsGet, sysCtx) defer mod.Close(testCtx) - t.Run("snapshotPreview1.ArgsGet", func(t *testing.T) { + t.Run("wasi.ArgsGet", func(t *testing.T) { maskMemory(t, testCtx, mod, len(expectedMemory)) // Invoke ArgsGet directly and check the memory side effects. @@ -147,7 +147,7 @@ func TestSnapshotPreview1_ArgsSizesGet(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionArgsSizesGet, importArgsSizesGet, sysCtx) defer mod.Close(testCtx) - t.Run("snapshotPreview1.ArgsSizesGet", func(t *testing.T) { + t.Run("wasi.ArgsSizesGet", func(t *testing.T) { maskMemory(t, testCtx, mod, len(expectedMemory)) // Invoke ArgsSizesGet directly and check the memory side effects. @@ -239,7 +239,7 @@ func TestSnapshotPreview1_EnvironGet(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionEnvironGet, importEnvironGet, sysCtx) defer mod.Close(testCtx) - t.Run("snapshotPreview1.EnvironGet", func(t *testing.T) { + t.Run("wasi.EnvironGet", func(t *testing.T) { maskMemory(t, testCtx, mod, len(expectedMemory)) // Invoke EnvironGet directly and check the memory side effects. @@ -331,7 +331,7 @@ func TestSnapshotPreview1_EnvironSizesGet(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionEnvironSizesGet, importEnvironSizesGet, sysCtx) defer mod.Close(testCtx) - t.Run("snapshotPreview1.EnvironSizesGet", func(t *testing.T) { + t.Run("wasi.EnvironSizesGet", func(t *testing.T) { maskMemory(t, testCtx, mod, len(expectedMemory)) // Invoke EnvironSizesGet directly and check the memory side effects. @@ -430,7 +430,7 @@ func TestSnapshotPreview1_ClockResGet(t *testing.T) { invocation func(clockID uint64) Errno }{ { - name: "snapshotPreview1.ClockResGet", + name: "wasi.ClockResGet", clockID: 0, expectedMemory: expectedMemoryMicro, invocation: func(clockID uint64) Errno { @@ -438,7 +438,7 @@ func TestSnapshotPreview1_ClockResGet(t *testing.T) { }, }, { - name: "snapshotPreview1.ClockResGet", + name: "wasi.ClockResGet", clockID: 1, expectedMemory: expectedMemoryNano, invocation: func(clockID uint64) Errno { @@ -534,7 +534,7 @@ func TestSnapshotPreview1_ClockTimeGet_Realtime(t *testing.T) { invocation func() Errno }{ { - name: "snapshotPreview1.ClockTimeGet", + name: "wasi.ClockTimeGet", invocation: func() Errno { // invoke ClockTimeGet directly and check the memory side effects! return a.ClockTimeGet(testCtx, mod, 0 /* REALTIME */, 0 /* TODO: precision */, resultTimestamp) @@ -577,7 +577,7 @@ func TestSnapshotPreview1_ClockTimeGet_Monotonic(t *testing.T) { invocation func() Errno }{ { - name: "snapshotPreview1.ClockTimeGet", + name: "wasi.ClockTimeGet", invocation: func() Errno { return a.ClockTimeGet(testCtx, mod, 1 /* MONOTONIC */, 0 /* TODO: precision */, resultTimestamp) }, @@ -689,7 +689,7 @@ func TestSnapshotPreview1_FdAdvise(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionFdAdvise, importFdAdvise, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.FdAdvise", func(t *testing.T) { + t.Run("wasi.FdAdvise", func(t *testing.T) { errno := a.FdAdvise(testCtx, mod, 0, 0, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -707,7 +707,7 @@ func TestSnapshotPreview1_FdAllocate(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionFdAllocate, importFdAllocate, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.FdAllocate", func(t *testing.T) { + t.Run("wasi.FdAllocate", func(t *testing.T) { errno := a.FdAllocate(testCtx, mod, 0, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -724,7 +724,7 @@ func TestSnapshotPreview1_FdClose(t *testing.T) { fdToClose := uint32(3) // arbitrary fd fdToKeep := uint32(4) // another arbitrary fd - setupFD := func() (api.Module, api.Function, *snapshotPreview1) { + setupFD := func() (api.Module, api.Function, *wasi) { // fd_close needs to close an open file descriptor. Open two files so that we can tell which is closed. path1, path2 := "a", "b" testFs := fstest.MapFS{path1: {Data: make([]byte, 0)}, path2: {Data: make([]byte, 0)}} @@ -754,7 +754,7 @@ func TestSnapshotPreview1_FdClose(t *testing.T) { require.True(t, ok) } - t.Run("snapshotPreview1.FdClose", func(t *testing.T) { + t.Run("wasi.FdClose", func(t *testing.T) { mod, _, api := setupFD() defer mod.Close(testCtx) @@ -788,7 +788,7 @@ func TestSnapshotPreview1_FdDatasync(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionFdDatasync, importFdDatasync, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.FdDatasync", func(t *testing.T) { + t.Run("wasi.FdDatasync", func(t *testing.T) { errno := a.FdDatasync(testCtx, mod, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -812,7 +812,7 @@ func TestSnapshotPreview1_FdFdstatSetFlags(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionFdFdstatSetFlags, importFdFdstatSetFlags, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.FdFdstatSetFlags", func(t *testing.T) { + t.Run("wasi.FdFdstatSetFlags", func(t *testing.T) { errno := a.FdFdstatSetFlags(testCtx, mod, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -830,7 +830,7 @@ func TestSnapshotPreview1_FdFdstatSetRights(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionFdFdstatSetRights, importFdFdstatSetRights, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.FdFdstatSetRights", func(t *testing.T) { + t.Run("wasi.FdFdstatSetRights", func(t *testing.T) { errno := a.FdFdstatSetRights(testCtx, mod, 0, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -848,7 +848,7 @@ func TestSnapshotPreview1_FdFilestatGet(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionFdFilestatGet, importFdFilestatGet, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.FdFilestatGet", func(t *testing.T) { + t.Run("wasi.FdFilestatGet", func(t *testing.T) { errno := a.FdFilestatGet(testCtx, mod, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -866,7 +866,7 @@ func TestSnapshotPreview1_FdFilestatSetSize(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionFdFilestatSetSize, importFdFilestatSetSize, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.FdFilestatSetSize", func(t *testing.T) { + t.Run("wasi.FdFilestatSetSize", func(t *testing.T) { errno := a.FdFilestatSetSize(testCtx, mod, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -884,7 +884,7 @@ func TestSnapshotPreview1_FdFilestatSetTimes(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionFdFilestatSetTimes, importFdFilestatSetTimes, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.FdFilestatSetTimes", func(t *testing.T) { + t.Run("wasi.FdFilestatSetTimes", func(t *testing.T) { errno := a.FdFilestatSetTimes(testCtx, mod, 0, 0, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -902,7 +902,7 @@ func TestSnapshotPreview1_FdPread(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionFdPread, importFdPread, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.FdPread", func(t *testing.T) { + t.Run("wasi.FdPread", func(t *testing.T) { errno := a.FdPread(testCtx, mod, 0, 0, 0, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -935,7 +935,7 @@ func TestSnapshotPreview1_FdPrestatGet(t *testing.T) { '?', } - t.Run("snapshotPreview1.FdPrestatGet", func(t *testing.T) { + t.Run("wasi.FdPrestatGet", func(t *testing.T) { maskMemory(t, testCtx, mod, len(expectedMemory)) errno := a.FdPrestatGet(testCtx, mod, fd, resultPrestat) @@ -1020,7 +1020,7 @@ func TestSnapshotPreview1_FdPrestatDirName(t *testing.T) { '?', '?', '?', } - t.Run("snapshotPreview1.FdPrestatDirName", func(t *testing.T) { + t.Run("wasi.FdPrestatDirName", func(t *testing.T) { maskMemory(t, testCtx, mod, len(expectedMemory)) errno := a.FdPrestatDirName(testCtx, mod, fd, path, pathLen) @@ -1092,7 +1092,7 @@ func TestSnapshotPreview1_FdPrestatDirName_Errors(t *testing.T) { pathLen: pathLen, expectedErrno: ErrnoBadf, }, - // TODO: non pre-opened file == wasi.ErrnoBadf + // TODO: non pre-opened file == ErrnoBadf } for _, tt := range tests { @@ -1110,7 +1110,7 @@ func TestSnapshotPreview1_FdPwrite(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionFdPwrite, importFdPwrite, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.FdPwrite", func(t *testing.T) { + t.Run("wasi.FdPwrite", func(t *testing.T) { errno := a.FdPwrite(testCtx, mod, 0, 0, 0, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -1152,7 +1152,7 @@ func TestSnapshotPreview1_FdRead(t *testing.T) { name string fdRead func(api.Module, api.Function) fdReadFn }{ - {"snapshotPreview1.FdRead", func(_ api.Module, _ api.Function) fdReadFn { + {"wasi.FdRead", func(_ api.Module, _ api.Function) fdReadFn { return a.FdRead }}, {functionFdRead, func(mod api.Module, fn api.Function) fdReadFn { @@ -1289,7 +1289,7 @@ func TestSnapshotPreview1_FdReaddir(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionFdReaddir, importFdReaddir, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.FdReaddir", func(t *testing.T) { + t.Run("wasi.FdReaddir", func(t *testing.T) { errno := a.FdReaddir(testCtx, mod, 0, 0, 0, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -1307,7 +1307,7 @@ func TestSnapshotPreview1_FdRenumber(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionFdRenumber, importFdRenumber, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.FdRenumber", func(t *testing.T) { + t.Run("wasi.FdRenumber", func(t *testing.T) { errno := a.FdRenumber(testCtx, mod, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -1341,7 +1341,7 @@ func TestSnapshotPreview1_FdSeek(t *testing.T) { name string fdSeek func() fdSeekFn }{ - {"snapshotPreview1.FdSeek", func() fdSeekFn { + {"wasi.FdSeek", func() fdSeekFn { return a.FdSeek }}, {functionFdSeek, func() fdSeekFn { @@ -1484,7 +1484,7 @@ func TestSnapshotPreview1_FdSync(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionFdSync, importFdSync, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.FdSync", func(t *testing.T) { + t.Run("wasi.FdSync", func(t *testing.T) { errno := a.FdSync(testCtx, mod, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -1502,7 +1502,7 @@ func TestSnapshotPreview1_FdTell(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionFdTell, importFdTell, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.FdTell", func(t *testing.T) { + t.Run("wasi.FdTell", func(t *testing.T) { errno := a.FdTell(testCtx, mod, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -1544,7 +1544,7 @@ func TestSnapshotPreview1_FdWrite(t *testing.T) { name string fdWrite func(api.Module, api.Function) fdWriteFn }{ - {"snapshotPreview1.FdWrite", func(_ api.Module, _ api.Function) fdWriteFn { + {"wasi.FdWrite", func(_ api.Module, _ api.Function) fdWriteFn { return a.FdWrite }}, {functionFdWrite, func(mod api.Module, fn api.Function) fdWriteFn { @@ -1675,7 +1675,7 @@ func TestSnapshotPreview1_PathCreateDirectory(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionPathCreateDirectory, importPathCreateDirectory, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.PathCreateDirectory", func(t *testing.T) { + t.Run("wasi.PathCreateDirectory", func(t *testing.T) { errno := a.PathCreateDirectory(testCtx, mod, 0, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -1693,7 +1693,7 @@ func TestSnapshotPreview1_PathFilestatGet(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionPathFilestatGet, importPathFilestatGet, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.PathFilestatGet", func(t *testing.T) { + t.Run("wasi.PathFilestatGet", func(t *testing.T) { errno := a.PathFilestatGet(testCtx, mod, 0, 0, 0, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -1711,7 +1711,7 @@ func TestSnapshotPreview1_PathFilestatSetTimes(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionPathFilestatSetTimes, importPathFilestatSetTimes, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.PathFilestatSetTimes", func(t *testing.T) { + t.Run("wasi.PathFilestatSetTimes", func(t *testing.T) { errno := a.PathFilestatSetTimes(testCtx, mod, 0, 0, 0, 0, 0, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -1729,7 +1729,7 @@ func TestSnapshotPreview1_PathLink(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionPathLink, importPathLink, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.PathLink", func(t *testing.T) { + t.Run("wasi.PathLink", func(t *testing.T) { errno := a.PathLink(testCtx, mod, 0, 0, 0, 0, 0, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -1805,7 +1805,7 @@ func TestSnapshotPreview1_PathOpen(t *testing.T) { require.Equal(t, pathName, f.Path) } - t.Run("snapshotPreview1.PathOpen", func(t *testing.T) { + t.Run("wasi.PathOpen", func(t *testing.T) { workdirFD := uint32(3) // arbitrary fd after 0, 1, and 2, that are stdin/out/err pathName := "wazero" @@ -1827,7 +1827,7 @@ func TestSnapshotPreview1_PathOpen(t *testing.T) { verify(testCtx, errno, mod, pathName, expectedMemory, expectedFD) }) - t.Run("snapshotPreview1.PathOpen.WithFS", func(t *testing.T) { + t.Run("wasi.PathOpen.WithFS", func(t *testing.T) { workdirFD := uint32(100) // dummy fd as it is not used pathName := "wazero" @@ -1923,7 +1923,7 @@ func TestSnapshotPreview1_PathReadlink(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionPathReadlink, importPathReadlink, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.PathLink", func(t *testing.T) { + t.Run("wasi.PathLink", func(t *testing.T) { errno := a.PathReadlink(testCtx, mod, 0, 0, 0, 0, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -1941,7 +1941,7 @@ func TestSnapshotPreview1_PathRemoveDirectory(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionPathRemoveDirectory, importPathRemoveDirectory, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.PathRemoveDirectory", func(t *testing.T) { + t.Run("wasi.PathRemoveDirectory", func(t *testing.T) { errno := a.PathRemoveDirectory(testCtx, mod, 0, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -1959,7 +1959,7 @@ func TestSnapshotPreview1_PathRename(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionPathRename, importPathRename, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.PathRename", func(t *testing.T) { + t.Run("wasi.PathRename", func(t *testing.T) { errno := a.PathRename(testCtx, mod, 0, 0, 0, 0, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -1977,7 +1977,7 @@ func TestSnapshotPreview1_PathSymlink(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionPathSymlink, importPathSymlink, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.PathSymlink", func(t *testing.T) { + t.Run("wasi.PathSymlink", func(t *testing.T) { errno := a.PathSymlink(testCtx, mod, 0, 0, 0, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -1995,7 +1995,7 @@ func TestSnapshotPreview1_PathUnlinkFile(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionPathUnlinkFile, importPathUnlinkFile, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.PathUnlinkFile", func(t *testing.T) { + t.Run("wasi.PathUnlinkFile", func(t *testing.T) { errno := a.PathUnlinkFile(testCtx, mod, 0, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -2013,7 +2013,7 @@ func TestSnapshotPreview1_PollOneoff(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionPollOneoff, importPollOneoff, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.PollOneoff", func(t *testing.T) { + t.Run("wasi.PollOneoff", func(t *testing.T) { errno := a.PollOneoff(testCtx, mod, 0, 0, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -2062,7 +2062,7 @@ func TestSnapshotPreview1_ProcRaise(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionProcRaise, importProcRaise, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.ProcRaise", func(t *testing.T) { + t.Run("wasi.ProcRaise", func(t *testing.T) { errno := a.ProcRaise(testCtx, mod, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -2080,7 +2080,7 @@ func TestSnapshotPreview1_SchedYield(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionSchedYield, importSchedYield, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.SchedYield", func(t *testing.T) { + t.Run("wasi.SchedYield", func(t *testing.T) { errno := a.SchedYield(mod) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -2103,7 +2103,7 @@ func TestSnapshotPreview1_RandomGet(t *testing.T) { length := uint32(5) // arbitrary length, offset := uint32(1) // offset, - t.Run("snapshotPreview1.RandomGet", func(t *testing.T) { + t.Run("wasi.RandomGet", func(t *testing.T) { source := rand.New(rand.NewSource(seed)) sysCtx, err := wasm.NewSysContext(math.MaxUint32, nil, nil, new(bytes.Buffer), nil, nil, source, nil) require.NoError(t, err) @@ -2218,7 +2218,7 @@ func TestSnapshotPreview1_SockRecv(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionSockRecv, importSockRecv, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.SockRecv", func(t *testing.T) { + t.Run("wasi.SockRecv", func(t *testing.T) { errno := a.SockRecv(testCtx, mod, 0, 0, 0, 0, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -2236,7 +2236,7 @@ func TestSnapshotPreview1_SockSend(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionSockSend, importSockSend, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.SockSend", func(t *testing.T) { + t.Run("wasi.SockSend", func(t *testing.T) { errno := a.SockSend(testCtx, mod, 0, 0, 0, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -2254,7 +2254,7 @@ func TestSnapshotPreview1_SockShutdown(t *testing.T) { mod, fn := instantiateModule(testCtx, t, functionSockShutdown, importSockShutdown, nil) defer mod.Close(testCtx) - t.Run("snapshotPreview1.SockShutdown", func(t *testing.T) { + t.Run("wasi.SockShutdown", func(t *testing.T) { errno := a.SockShutdown(testCtx, mod, 0, 0) require.Equal(t, ErrnoNosys, errno, ErrnoName(errno)) }) @@ -2279,7 +2279,7 @@ func maskMemory(t *testing.T, ctx context.Context, mod api.Module, size int) { func instantiateModule(ctx context.Context, t *testing.T, wasifunction, wasiimport string, sysCtx *wasm.SysContext) (api.Module, api.Function) { r := wazero.NewRuntimeWithConfig(wazero.NewRuntimeConfigInterpreter()) - _, err := InstantiateSnapshotPreview1(testCtx, r) + _, err := Instantiate(testCtx, r) require.NoError(t, err) compiled, err := r.CompileModule(ctx, []byte(fmt.Sprintf(`(module