This extends wazero's interpretation of rights in wasi_snapshot_preview1.path_open to allow programs to open files in either read-only, write-only, or read-write mode.
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
Co-authored-by: Crypt Keeper <64215+codefromthecrypt@users.noreply.github.com>
The PR introduces the `platform.Select()` API, wrapping `select(2)` on POSIX and emulated in some cases on Windows. RATIONALE.md contains a full explanation of the approach followed in `poll_oneoff` to handle Stdin and the other types of file descriptors, and the clock subscriptions.
It also introduces an abstraction (`StdioFilePoller`) to allow the simulation of different scenarios (waiting for input, input ready, timeout expired, etc.) when unit-testing interactive input.
This closes#1317.
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
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>
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>
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>
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>
This changes the experimental flag introduced yesterday to
`-experimental-workdir-inherit=true`, to reduce edge cases needed to
produce the same behavior as go's wasm test runner.
After this, we have the same failure count, though the latter is likely
related to my machine:
```bash
$ wasm=$PWD/os.wasm; (cd $(go env GOROOT)/src/os; wazero run -mount=/:/ --experimental-workdir-inherit=true $wasm)
--- FAIL: TestMkdirAllAtSlash (0.00s)
path_test.go:111: MkdirAll "/_go_os_test/dir": mkdir /_go_os_test: I/O error, I/O error
--- FAIL: TestOpenFileLimit (0.01s)
rlimit_test.go:31: open rlimit.go: I/O error
FAIL
```
See https://github.com/golang/go/blob/master/misc/wasm/wasm_exec_node.js#L24
Signed-off-by: Adrian Cole <adrian@tetrate.io>
When compiled to `GOOS=js`, wasm does not maintain the working
directory: it is defined by the host. While not explicitly documented,
`os.TestDirFSRootDir` in Go suggests the working directory must be valid
to pass (literally the directory holding the file).
This adds an experimental CLI flag that gives the initial working
directory. This is experimental because while GOOS=js uses this, current
WASI compilers will not, as they maintain working directory in code
managed by wasi-libc, or as a convention (e.g. in Zig).
It is not yet known if wasi-cli will maintain working directory
externally or not.
Signed-off-by: Adrian Cole <adrian@tetrate.io>