Commit Graph

82 Commits

Author SHA1 Message Date
Crypt Keeper
16baeaab47 Adds Readdir to platform.File and removes internal use of fs.FS (#1454)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-11 10:04:34 +08:00
Crypt Keeper
4dd4d54cda Removes platform.Readdirnames (#1451)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-10 14:44:54 +08:00
Crypt Keeper
745f2c9d8a Adds IsNonblock SetNonblock PollRead to platform.File (#1447)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-10 08:43:54 +08:00
Nuno Cruces
6503e82d3c Follow unsafe rules. (#1449)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2023-05-09 15:34:08 +01:00
Crypt Keeper
29c7c7667b Adds IsDir and Seek to platform.File (#1441)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-09 07:47:25 +08:00
Achille
99d45623c0 wasip1: support non-blocking mode on stdio (#1443)
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
2023-05-09 06:45:04 +08:00
Nuno Cruces
2bf8abe1fe Cleanup scattered documentation TODOs. (#1442)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2023-05-08 18:04:02 +01:00
Crypt Keeper
3bf7e342c2 Adds Utimens to platform.File (#1440)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-08 11:14:28 +08:00
Crypt Keeper
76ef347b8c Adds Read and Pread to platform.File (#1439)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-08 07:54:06 +08:00
Crypt Keeper
b5198a46ff Adds AccessMode Write and Pwrite to platform.File (#1438)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-05 13:23:30 +08:00
Crypt Keeper
5380321eea Adds Truncate to platform.File (#1428)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-04 15:07:18 +08:00
Crypt Keeper
6dd0cef551 Splits EACCES from EPERM on Windows (#1430)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-04 14:50:35 +08:00
Crypt Keeper
e5dc733df7 Adds Path to platform.File and refactors tests (#1431)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
Co-authored-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-05-04 07:05:40 +08:00
Adrian Cole
cf5ebf6f6b Use require.ErrnoEquals for more precise failures
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-03 13:54:12 +08:00
Crypt Keeper
c5871c772c Adds Datasync to platform.File (#1427)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-02 14:12:47 +08:00
Crypt Keeper
b79c45b91c Adds Sync to platform.File (#1426)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-02 13:16:50 +08:00
Achille
d5a2d3c7b4 wasip1: fix file open modes used by wasi-libc (#1421)
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>
2023-05-02 09:48:26 +08:00
Crypt Keeper
20017ca5e6 shows implementation impact of UnimplementedFile (#1424)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-02 07:31:17 +08:00
Crypt Keeper
18c793f8e6 Adds platform.File.Chmod (#1423)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-01 19:18:56 +08:00
Crypt Keeper
1047ddee78 Adds platform.File.Chown (#1422)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-01 18:32:13 +08:00
Crypt Keeper
493fe2d410 sysfs: stubs in approach to defining a new file type (#1290)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-01 12:33:40 +08:00
Edoardo Vacchi
34a639b770 wasi: improve select(2) impl on Windows (#1398)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-04-28 08:36:48 +09:00
Edoardo Vacchi
ea336061c2 wasi: introduce platform.Select and use it for poll_oneoff (#1346)
Some checks failed
Release CLI / Pre-release build (push) Has been cancelled
Release CLI / Pre-release test (macos-12) (push) Has been cancelled
Release CLI / Pre-release test (ubuntu-22.04) (push) Has been cancelled
Release CLI / Pre-release test (windows-2022) (push) Has been cancelled
Release CLI / Release (push) Has been cancelled
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>
2023-04-18 16:31:34 +02:00
Takeshi Yoneda
d9e5d6b0d3 Avoids unnecessary allocations during mmap executables (#1366)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-17 14:03:35 +09:00
Takeshi Yoneda
2fc1fa9d79 Stop using pointer of function pointers in sys.Context (#1301)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-29 11:23:38 +09:00
Edoardo Vacchi
d63813a830 fs: stat and cache mode for stdio devices (#1295)
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>
2023-03-28 12:48:24 +02:00
Crypt Keeper
7721f0ab97 build: makes wazero buildable on solaris and illumos (#1274)
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>
2023-03-23 08:09:21 +09:00
Crypt Keeper
a2ddb04fdb wasi: enforce EPERM on malformed paths (#1266)
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>
2023-03-22 14:46:32 +01:00
Crypt Keeper
36bf277534 sysfs: requires all methods to return syscall.Errno (#1264)
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>
2023-03-22 07:47:57 +01:00
Adrian Cole
a43a0f11e4 Revert "sysfs: requires all methods to return syscall.Errno"
This reverts commit 4ea9d1a7b5.
2023-03-21 22:22:36 +08:00
Adrian Cole
4ea9d1a7b5 sysfs: requires all methods to return syscall.Errno
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>
2023-03-21 22:20:28 +08:00
Crypt Keeper
c46a6eb4ae sysfs: return st instead of accepting it (#1261)
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>
2023-03-21 10:57:19 +08:00
Edoardo Vacchi
0a4ebdf159 poll_oneoff: do not wait for input if fd is not a tty (#1251)
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>
2023-03-20 19:17:15 +08:00
Crypt Keeper
8464474e21 gojs: adds support for uid and gid (#1245)
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>
2023-03-16 11:07:27 +08:00
Crypt Keeper
14c409eaf7 cli: changes experimental workdir flag to inherit (#1235)
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>
2023-03-14 10:20:44 +08:00
Crypt Keeper
7e953d7483 gojs: introduces --experimental-workdir CLI arg (#1226)
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>
2023-03-13 15:43:45 +08:00
Crypt Keeper
41ef17c5c2 wasi: implements path_filestat_set_times (#1220)
This implements `path_filestat_set_times` which is the last remaining filesystem function in wasi we formerly stubbed.

Other minor changes:
* this removes all places we import alias path as pathutil, introducing a utility function `joinPath` where that was used to reduce name conflicts.
* this fixes places where we used different variable names for the same parameter between main and test source.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-13 09:46:17 +08:00
Crypt Keeper
4d90a5c364 platform: Allows sysfs to implement utimens natively (#1215)
platform: Allows sysfs to implement utimesns natively

This moves away from `syscall.UtimesNano` as it has intentionally
avoided common features in POSIX, such as handling UTIME_NOW and
UTIME_OMIT. When we eventually expose this API, users will be free to
override `UTIME_NOW` with a fake clock, possibly the same that was
supplied to wazero's `ModuleConfig`.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Co-authored-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-03-09 13:14:09 +08:00
Crypt Keeper
89f918105a platform: adds notes about darwin and CGO (#1212)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-08 09:47:10 +08:00
Edoardo Vacchi
b16f74a86b implement futimens on Darwin and Linux (#1210)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-03-08 08:21:12 +08:00
Crypt Keeper
f5d194c43c wasi: implements platform.UtimesFile for fd_filestat_set_times (#1199)
This implements `platform.UtimesFile` which is similar to futimes.
Before, we were using path-based functionality even though the call site
was for a file descriptor.

Note: right now, there's no obvious code in Go to invoke the `futimens`
syscall. This means non-windows isn't implemented at nanos granularity,
so ends up falling back to the path based option.

Finally, this removes tests for the seldom supported updates with
negative epoch time. There's little impact to this as setting times on
files before 1970 isn't a typical use case.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-07 13:44:46 +08:00
Crypt Keeper
b742c7a8cc gojs: implements chown (#1204)
This finishes the last remaining syscalls in `GOOS=js`. After this is
merged, further bugs are easier to hunt down as we know ENOSYS is not
expected on writeable file systems.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-06 17:43:46 +08:00
Crypt Keeper
a9b3301862 gojs: implements remaining link functions (#1198)
This implements the last remaining link functions using the same logic
as WASI. In doing so, this changes the signature for FS.ReadLink to be
more similar to the rest of the functions. Particularly, it stops
reading the result into a buffer.

After this, the only syscalls left to implement in gojs are chown.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-05 16:11:36 +08:00
Crypt Keeper
e77f24fe31 sysfs: drops os.File special casing for fs.FS to pass wasi-testsuite (#1174)
This adds a wazero adapter which passes wasi-testsuite 100pct on darwin,
linux and windows. While the main change was adding inodes to the wasi
`fd_readdir` dirents, there was a lot of incidental work needed.

Most of the work was troubleshooting in nature, around windows
specifically, but also wrapping of files. This backfills a lot of tests
and reworked how wrapping works, particularly around windows.

To accommodate this, we drop `os.File` special casing except for
`sysfs.DirFS`

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-01 13:28:57 +08:00
Crypt Keeper
3d5b6d609a implements lstat and fixes inode stat on windows go 1.20 (#1168)
gojs: implements lstat

This implements platform.Lstat and uses it in GOOS=js. Notably,
directory listings need to run lstat on their entries to get the correct
inodes back. In GOOS=js, directories are a fan-out of names, then lstat.

This also fixes stat for inodes on directories. We were missing a test
so we didn't know it was broken on windows. The approach used now is
reliable on go 1.20, and we should suggest anyone using windows to
compile with go 1.20.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-02-28 07:20:31 +08:00
Takeshi Yoneda
d955cd7a13 windows: fixes unlinking symlink to dir, rmdir on opened empty dir. (#1172)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-02-27 16:23:54 +09:00
Crypt Keeper
70924aa7a1 Readdir: handles io.EOF (#1166)
This handles EOF even if current and possibly future wasi don't have a
way to propagate an EOF signal. This is mainly to match up with go
semantics and ensure we don't have any error conditions (by adding
tests).

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-02-26 06:47:10 +08:00
Crypt Keeper
1e7660fc4f wasi: shares more cached stat info to reduce impact of inode requirement (#1161)
We formerly cached only the directory type, to avoid re-stat'ing the
same directory many times. Since we are there, we can also cache the
inode, which is strictly required by wasi and costly to fetch. Note:
this only affects the directory: its contents still need a potential
fan-out of stats which will be handled in another change.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-02-25 07:28:45 +08:00
Crypt Keeper
bb002c862f wasi: adds platform.Dirent in preparation of inode fetching (#1154)
wasi_snapshot_preview1 recently requires fd_readdir to return actual
inode values. On zero, wasi-libc will call fdstat to retrieve them.

This introduces our own `platform.Dirent` type and `Readdir` function
which a later change will allow fetching of inodes.

See https://github.com/WebAssembly/wasi-libc/pull/345

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-02-23 18:56:27 +08:00
Crypt Keeper
d5c321e29a adds platform.Readdirnames and uses in gojs (#1149)
This adds `platform.Readdirnames` which is preparation work before doing
something similar for reading the directory. We use this in gojs as it
doesn't actually need dirents, rather just names.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-02-21 15:56:22 +08:00