ModuleInstance.Closed is an atomic variable meant to be loaded and
swapped with sync/atomic. Closed, being a 64 bit integer, requires 64
bit alignment. The simplest way we can get alignment is to place these
atomic fields at the top of their struct.
Closed can be moved to a more logical place once support for Go 1.18 is
dropped and its type changed to atomic.Uint64.
Signed-off-by: Tristan Willy <tristan.willy@gmail.com>
This adds a test to verify the wazero binary produced by homebrew.
Notably, this was made to be small enough to copy/paste in hex format.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
This makes clock source configuration more clear about the timestamps
returned. Specifically, that realtime is UTC and the most common
consumers.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
Ensure that stdio device modes are consistent with the given
file descriptors by stat'ing, instead of returning mocks.
* Use `Stat()` on `poll_oneoff()` too, instead of `IsTerminal()`,
thus avoiding a useless syscall.
* Delete leftover type decl `fileModeStat`.
* Remove IsPlatform()
* Propagate error when Stat() fails
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
The last PR over-solved the WASI close problem as it special cased both
"_start", used by WASI, and the start section (wasm level) which isn't
used by WASI. In the latter case, we ended up returning nil for both the
module *and* the error result. We should never do that.. If we coerce
exit error zero to nil, we have to return a non-nil module, even if it
is unusable as otherwise code like `defer mod.Close(ctx)` will panic.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
We currently allow clearing other config with nil, such as FSConfig.
However, we missed a spot as internally we couldn't differentiate
between name never set, or explicitly set to empty. Now, when someone
sets the module name to empty, the name in the binary section is
ignored.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
This fixes a build problem on solaris and illumos. This also closes
issue #1106 because we can't make everything build with CGO (e.g. our
examples won't build unless CGO is available).
Signed-off-by: Adrian Cole <adrian@tetrate.io>
This removes the generally frowned upon practice of dot imports by
shortening the name of internal/wasi_snapshot_preview1 to
internal/wasip1. This leaves the external one alone as it would break
users to change it.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
It seems WASI now forbids root and relative paths on the at file descriptor and returns EPERM otherwise. This enforces the following:
* require EPERM when you escape a directory (../)
* require EPERM if you add a leading slash (absolute path)
* require ENOENT if you add a trailing slash to a file
* require success if you add a trailing slash to a directory
See https://github.com/WebAssembly/wasi-testsuite/pull/67
Signed-off-by: Adrian Cole <adrian@tetrate.io>
WASI are recently suggesting by test that users who provide an
absolute path should fail via EPERM. Not all compilers deal with
pre-opens the same way. Notably, zig is pass-through, so it doesn't
expect to wash leading slashes around this rule.
While the jury is out on if we should break users as wasi-testsuite
wants us to, or not.. Meanwhile, we can stop suggesting use of absolute
paths, as relative ones work ("/" is the implied workdir in WASI).
See #1266
Signed-off-by: Adrian Cole <adrian@tetrate.io>
This forces all syscall functions, notably filesystem, to return numeric
codes as opposed to mapping in two different areas. The result of this
change is better consolidation in call sites of `sysfs.FS`, while
further refactoring is needed to address consolidation of file errors.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
wasi-testsuite changed its mind on pre-open WebAssembly/wasi-testsuite#66
they also now explicitly forbid paths being passed in with a leading slash. Even when the config bug on WebAssembly/wasi-testsuite#67 is finished, this requires discussion if we want to EPERM on that.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
This forces all syscall functions, notably filesystem, to return numeric
codes as opposed to mapping in two different areas. The result of this
change is better consolidation in call sites of `sysfs.FS`, while
further refactoring is needed to address consolidation of file errors.
Signed-off-by: Adrian Cole <adrian@tetrate.io>