Commit Graph

865 Commits

Author SHA1 Message Date
Crypt Keeper
859ca2451c Adds checks into the Makefile for 32-bit platforms (#1002)
Developers don't commonly think about 32-bit platforms and in one
instance we broke a release due to this (quickly fixed in pre.7). This
ensures arm and 386, used by dapr and trivy respectively are tested. It
also helps prove these are in use to avoid a later developer removing
support by thinking they aren't.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-01-05 09:02:58 +08:00
Crypt Keeper
b90158cdf5 gojs: backfills reference count tests (#1006)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-01-04 16:20:08 +08:00
Crypt Keeper
f8a33cef8d logging: avoids logging activity to stdio file descriptors (#1007)
This avoids logging activity on stdio file descriptors, in order to help
make troubleshooting easier. Usually, there isn't an issue in these, yet
wasm panics are harder to read if there is also logging of the ..
logging.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-01-04 16:04:40 +08:00
Takeshi Yoneda
3ab7e4b36d Ensures user-defined primitive types are usable in host func signatures (#1005)
Ensure primitive types are usable in host func signatures

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-01-04 15:32:32 +08:00
Crypt Keeper
83e4b66659 Consolidates internal code to syscallfs (#1003)
This consolidates internal code to syscallfs, which removes the fs.FS
specific path rules, except when adapting one to syscallfs. For example,
this allows the underlying filesystem to decide if relative paths are
supported or not, as well any EINVAL related concerns.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-01-04 13:53:53 +08:00
Takeshi Yoneda
846575d0fa interpreter: removes unneeded fields from func instances (#1004)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-01-04 11:50:49 +09:00
Crypt Keeper
65c7d9dd1b gojs: stubs all remaining filesystem calls to ENOSYS (#1001)
This stubs all remaining syscalls for `GOARCH=wasm GOOS=js` to return
ENOSYS, instead of panic'ing. This allows us to see the parameters it
receives.

For example:
```
==> go.syscall/js.valueCall(fs.truncate(path=/tmp/_Go_TestTruncate135754730,length=0))
<== (err=function not implemented,ok=false)
```

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-01-03 15:54:29 +08:00
Takeshi Yoneda
ef3937ffed Simplifies spectest initialization (#1000)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-01-03 13:22:14 +09:00
Crypt Keeper
8c5106b942 Ensures writes aren't allowed when opening for read (#999)
This masks interfaces returned by `fs.File` so that we don't
accidentally allow writes when opened for reading. This also adds
`syscall.NewReadFS` which can enforce read-only access in general, such
as would be ideal for tests that try to read files from the host root
filesystem (e.g. /etc/passwd).

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-01-03 12:17:37 +08:00
Takeshi Yoneda
d29b6b011c cache: fixes deadlock in version mismatch (#998)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-01-03 12:17:12 +09:00
Crypt Keeper
5c2c6a042a site: Adds notes about how GOARCH=js GOOS=wasm tests work (#997)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-01-03 10:03:26 +08:00
Crypt Keeper
4197caa05b Ensures 32-bit platforms build (#996)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
v1.0.0-pre.7
2023-01-02 11:03:23 +09:00
Crypt Keeper
94491fef0b Implements rename in GOOS=js and WASI (#991)
This implements rename, which is the last function needed to pass TinyGo
os package tests:

Signed-off-by: Adrian Cole <adrian@tetrate.io>
v1.0.0-pre.6
2022-12-31 16:37:28 +08:00
Crypt Keeper
e4740efef4 site: updates wasi support table (#993)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-31 16:33:47 +08:00
Crypt Keeper
2fbf83e0b3 wasi: fixes or'd open flags (#990)
Before, we didn't handle multiple flags correctly.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-31 14:03:41 +08:00
Crypt Keeper
c9868d89cb Removes internal dependency on fs.FS (#987)
As noted in slack, we are unlikley to long term use fs.FS internally.
This ensures we attempt to cast to syscallfs.FS for all I/O by panicing
on fs.Open.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-31 13:27:54 +08:00
Takeshi Yoneda
2045f71363 enginetest: fixes panic om memory def (#989)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-31 14:27:04 +09:00
Crypt Keeper
da3aa7a5ad Adds ExportedFunctionDefinitions and ExportedMemoryDefinitions (#986)
This adds ExportedFunctionDefinitions and ExportedMemoryDefinitions to
api.Module so that those who can't access CompileModule can see them.

Fixes #839

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-31 13:11:37 +08:00
Takeshi Yoneda
e7018d19ff compiler: force moduleContext initialization after Go function calls (#988)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-31 14:05:30 +09:00
Crypt Keeper
efc72de1e6 gojs: implements timeout events (#984)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-31 08:26:32 +08:00
Crypt Keeper
67cc6d3779 compilationcache: uses version-specific subdirectory (#982)
This makes the version, arch, os tuple into a subdirectory to help
troubleshooting and cache management in general. The version is left
inside the binary key regardless.

Note: when installing via `go install ./cmd/wazero/...` the version ends
up as `dev`. This helps make that obvious. For example.

```bash
$ wazero version
dev
$ ./build/tinygo test -target wasi -c -o os.wasm os
$ wazero run -cachedir=$HOME/.wazero -mount=.:/ -env=HOME=.  os.wasm -test.v
$ find $HOME/.wazero
/Users/adrian/.wazero
/Users/adrian/.wazero/wazero-dev-amd64-darwin
/Users/adrian/.wazero/wazero-dev-amd64-darwin/1f149f4bf475a33023ce33302780bee29ec08e89bd57cfbdf639c65c6009f1a4
```

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-31 07:01:57 +08:00
Achille
1db5433154 add internal/sys.FileTable (#975)
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
2022-12-31 06:34:25 +08:00
Crypt Keeper
4495979cf0 wasi: fixes open flags (#981)
This fixes and backfills tests for open flags, notably O_CREAT. I
verified this with TinyGo tests, which now proceed when attempting to
create new files.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-30 19:32:18 +08:00
Crypt Keeper
9a4a372642 renames writefs to syscallfs and implements utimes in gojs (#979)
This renames the internal writefs package to syscallfs as it is largely
dependent on syscall signatures. This also implements utimes in gojs.
WASI will be a follow-up change as it requires more infrastructure.
Notably, we also need non-TinyGo tests because TinyGo doesn't yet
support os.Chtimes or corresponding syscalls.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-30 14:18:06 +08:00
Crypt Keeper
6d53a0033a wasi: implements path_(create|remove)_directory path_unlink_file (#976)
This implements path_(create|remove)_directory path_unlink_file in wasi, particularly needed to use TinyGo tests to verify our interpretation of WASI. Use of this requires the experimental `writefs.DirFS`.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-30 07:30:21 +08:00
Crypt Keeper
62be68dfc5 writefs: require ENOTEMPTY (#974)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-29 17:29:47 +08:00
Crypt Keeper
3f578ddac3 fs: splits unlink and rmdir from remove (#973)
This splits unlink and rmdir from remove, as it is not only more precise
in GOOS=js, but it is also needed to implement wasi. I verified this
works by running go unit tests with logging.

```
==> go.syscall/js.valueCall(fs.open(name=/tmp/TestErrIsNotExist1062486353,flags=,perm=----------))
<== (err=<nil>,fd=10)
==> go.syscall/js.valueCall(fs.fstat(fd=10))
<== (err=<nil>,stat={isDir=true,mode=-rwx------,size=96,mtimeMs=1672285985206})
==> go.syscall/js.valueCall(fs.readdir(name=/tmp/TestErrIsNotExist1062486353))
<== (err=<nil>,dirents=&{[001]})
==> go.syscall/js.valueCall(fs.unlink(path=/tmp/TestErrIsNotExist1062486353/001))
<== (err=is a directory,ok=true)
==> go.syscall/js.valueCall(fs.rmdir(path=/tmp/TestErrIsNotExist1062486353/001))
<== (err=<nil>,ok=false)
```

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-29 15:39:45 +08:00
Nuno Cruces
3ab68ed8f8 Fix fdPread: shouldn't move file offset (#967)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2022-12-29 11:56:48 +08:00
Crypt Keeper
07a814a105 Exposes experimental writefs.DirFS, but hides implementation (#972)
The type we use to expose write operations is still evolving. It might
be a single writefs.FS interface, or similar to go where we have an
interface per feature (e.g. writefs.MkdirFS). These choices are all
implementation details for DirFS and won't be settled before the end of
the month version cutoff. Instead, this only exposes the ability to
create a DirFS, not an arbitrary implementation of writefs.FS. This does
so by making `writefs.FS` an internal type.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-29 10:39:04 +08:00
Crypt Keeper
64a4ab3ba5 wasi: unexports errno and re-uses constants for logging (#971)
We originally exported WASI errno as we originally supported invoking
host functions directly (e.g. without a guest). This was an invalid call
pattern, and we removed that. However, we left the errnos exported even
though the caller of a guest won't ever see them. This prevented us from
re-using them cleanly in features such as logging.

This moves all constants including function names and flag enums
internal so that there is less duplication between logging and
implementation of wasi functions. This also helps in reference searches,
as we can analyze uses of a particular function name.

The only constant left exported is the module name, as there's a use
case for that (overriding implementations via FunctionBuilder).

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-29 09:42:10 +08:00
Crypt Keeper
15dc3d7d37 Adds experimental write support and implements on gojs (#970)
This adds writefs.FS, allowing functions to create and delete files.
This begins by implementing them on `GOARCH=js GOOS=wasm`. The current
status is a lot farther than before, even if completing write on WASI is
left for a later PR (possibly by another volunteer).

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-28 19:49:46 +08:00
Crypt Keeper
921df7e7a6 cli: adds -hostlogging=filesystem for diagnosing problems (#966)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-28 11:38:24 +08:00
Crypt Keeper
d874ebbe48 logging: reformats wasi filesystem logs to display paths (#965)
This uses logging infrastructure introduced in #938 to show
paths and certain result parameters. While further tuning is expected,
the main thing this does is show which paths are affected by syscalls.

Signed-off-by: Adrian Cole <adrian@tetrate.io>

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-27 19:11:01 +08:00
Crypt Keeper
9dfe87531e logging: extracts utilities to read parameters and results from memory (#938)
This changes the listener signature to accept context and calling
module, so that all possible parameters and results can be logged. This
also changes the logging listener to make parameters visible when
logging results.

This infrastructure supports some helpful use cases, such as logging
WASI result parameters, such as the prestat path, which is only knowable
after the function has been called. The context parameter supposed
reading results of gojs functions, which are stored host-side in a go
context object.

Future pull requests will complete this as well backfill unit tests.
This is raised independently mainly to keep the PR size down of the
upcoming filesystem logger.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-27 16:08:25 +08:00
Crypt Keeper
5751bd758c gojs: extracts parameter names into a pseudo name section (#963)
`GOARCH=wasm GOOS=js` defines parameter names in go source, and they are
indirectly related to the wasm parameter "sp". This creates a pseudo
name section so that we can access the parameter names. The alternative
would be adding a hack to normal FunctionDefinition, only used for gojs.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-27 14:09:20 +08:00
Crypt Keeper
1ad900d179 gojs: refactors GOOS and GOARCH specific code into their own packages (#959)
This refactors GOOS and GOARCH specific code into their own packages.
This allows logging interceptors to be built without cyclic package
dependencies.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-27 08:45:43 +08:00
Takeshi Yoneda
a1706eb05c asm(arm64): fixes stack pointer add/sub for large consts (#962)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-26 16:26:23 +09:00
Takeshi Yoneda
69688468f8 asm(arm64): adds UDF instruction (#961)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-26 15:58:35 +09:00
Takeshi Yoneda
3d70c85032 asm(arm64): adds support for stack pointer manipulation (#960)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-26 10:07:13 +09:00
Takeshi Yoneda
6b9d119a7b doc: document why it's safe against async preemption (#957)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-23 13:38:55 +09:00
Crypt Keeper
acf32dfa46 Hides internal logging (#956)
This makes it easier to do maintenance by hiding the implementation
details of using a proxy module to test host modules. What happens is we
skip logging of these proxy modules, which makes it easier to see what
log affects a change has.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-23 09:14:16 +08:00
Crypt Keeper
c7da409287 cli: allows use of GOOS=js (#955)
This changes the CLI to detect if GOOS=js is likely in use and switches
accordingly. This makes it eaiser to find bugs and may eventually lead
to go being able to swap out node.js for wazero.

Note: GOOS=js a.k.a. gojs isn't complete, yet, so this helps identify
that as well. For example, similar to WASI there's no suppor for mkdir
yet.

```bash
$ GOOS=js GOARCH=wasm go test -o os.wasm -c os
$ wazero run os.wasm -test.v
```

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-22 12:13:59 +08:00
Crypt Keeper
b02b516807 wasi: allows closing stdio file descriptors (#954)
Allows wasm to close stdio file descriptors

This allows wasm to close stdio file descriptors such as STDOUT(1).
This will not close the underlying host resource as that would break a
lot of folks doing logging to the console.

Fixes #953

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-22 08:01:13 +08:00
Takeshi Yoneda
b9b76de03c internal/gojs: reuse single wazero.Runtime to fix flake in tests (#952)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-21 13:55:43 +08:00
Takeshi Yoneda
7666a2a7f7 Disable comp cache for host modules (#949)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-21 14:08:30 +09:00
Takeshi Yoneda
100725dd1c cli: adds version command (#950)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-21 13:59:10 +09:00
Takeshi Yoneda
2e4f207191 Fixes wasmedge installation (#951)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-21 13:01:04 +09:00
Crypt Keeper
d3c5e8655f Adds benchmarks from lib sodium (#948)
This adds benchmarks from lib sodium, but the results are hard to interpret. We may need to recompile them using zig so that we can export a function instead of using WASI to do it. Right now, we can't really see performance of functions because other runtimes aren't designed to re-instantiate like ours.

This only compares against wasmtime as that's the only runtime besides
ours that is safe to re-instantiate.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-21 09:17:13 +08:00
Crypt Keeper
796fca4689 cli: adds compile command and -cachedir option (#945)
This adds a `compile` command and a `-cachedir` option to expose our
compilation cache to end users. This allows substantial speedup
especially for large wasm.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Co-authored-by: Anuraag Agrawal <anuraaga@gmail.com>
2022-12-20 13:56:29 +08:00
Takeshi Yoneda
d63c747d53 asm,compiler: reduce allocations during compilation (#936)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-20 12:49:47 +09:00