Commit Graph

96 Commits

Author SHA1 Message Date
Edoardo Vacchi
76dce033d3 Upgrade floor Go version to 1.19 everywhere. (#1622) 2023-08-10 06:09:16 +09:00
Edoardo Vacchi
023a38349a sysfs: implements PollRead with poll instead of select (#1596)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-07-28 10:49:17 +02:00
Edoardo Vacchi
1e0c73d569 wasi: nonblocking I/O for sockets and pipes on Windows (#1579)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-07-19 07:30:06 +08:00
Crypt Keeper
2f8dd23097 adds experimental sys.Errno to begin decoupling from the syscall package (#1582)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-07-17 08:13:29 +08:00
Crypt Keeper
15fa5c4de5 Changes build to test go 1.21rc2 (#1571)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-07-10 13:39:37 +08:00
Anuraag Agrawal
86cf46d021 Fix drift in comment in mmap_other (#1572) 2023-07-10 13:22:59 +08:00
Takeshi Yoneda
9aa8f4e0ae platform: removes unnecessary code (#1492)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-05-29 09:09:24 +10:00
Achille
1b35900911 linux: support using huge pages (#1475)
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
2023-05-17 11:14:31 -07:00
Crypt Keeper
34324031cb extracts FS interfaces into fsapi package and consolidates impls (#1477)
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-17 07:19:54 +03:00
Crypt Keeper
41c4ed5acf Removes out-of-date TODOs in platform.File (#1474)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-16 16:00:11 +08:00
Edoardo Vacchi
cb06b7b779 platform: fix minor linting issue (#1471)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
Signed-off-by: Adrian Cole <adrian@tetrate.io>
Co-authored-by: Adrian Cole <adrian@tetrate.io>
2023-05-16 12:06:29 +08:00
Crypt Keeper
11b346ed75 Removes AccessMode from platform.File (#1472)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-16 11:32:50 +08:00
Achille
d3efad1fc4 compiler: remove intermediary copy of compiled functions code (#1466)
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
Co-authored-by: Crypt Keeper <64215+codefromthecrypt@users.noreply.github.com>
2023-05-14 23:22:16 -07:00
Crypt Keeper
2ad2921eed Separates fs.File from os.File implementations of platform.File (#1455)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-05-15 13:42:20 +08:00
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