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>
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>
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>
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>
This returns stat as a value instead of a pointer param. This is both
more efficient and faster. It is also more efficient than returning a
pointer to a stat.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
This is sort-of a hack/approximation, but it works.
Rationale: poll_oneoff is expected to return immediately if there
isn't any input ready.
When the fd is `stdin`, the input either is there
or it is not; i.e. if you are expecting interactive input,
then you probably want to do a blocking read(), otherwise
poll would immediately return with an answer: there is no data.
If indeed there is data, then it means you are not doing
interactive input, but piping it into your stdin.
Thus, platform.isTerminal(fd) gives you the right answer.
However, fd=0,1,2 is not a valid value on Windows, so
we fix the implementation for that platform, and there we go.
I assume this to be a temporary fix, before we do implement
poll_oneoff properly, but for now it is good enough.
As a test, I updated the test for poll so that
the result type is consistent with the state of os.Stdin
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
Previously executConstExpr is called various places, and therefore it was necessary to return interface{}
and that resulted in allocation per call.
This commit avoids the allocation by adding executConstExprI32 which is used by data segment manipulation,
and repurposes executConstExpr solely to global instance initialization.
As a result, this completely removes the allocation around const expr execution, and hence the perf improvement
in the instantiation phrase. The improvement diff is proportionate to the number of data segments and globals.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Before, we didn't have a suite of tests for our filesystem used by ABI,
now we do (`sysfs`). Moreover, we are testing stdlibs and wasi-testsuite
on commit. We don't need this fstest anymore.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
This adds `gojs.WithOSUser` which passes through current user IDs so
that GOOS=js compiled wasm can read them. This also adds support for
reading back the uid and gid on files. In summary, this passes
`os.TestChown` except on windows where it will not work due to lack of
support.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
In order to support more configuration, we should stop using context as
it is getting gnarly.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Signed-off-by: Adrian Cole <adrian@tetrate.io>