Commit Graph

108 Commits

Author SHA1 Message Date
Nuno Cruces
c8ee0baaf8 compiler: test traps report correct line numbers (#1528)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2023-06-20 08:04:02 +10:00
Crypt Keeper
e31856d360 updates external tool versions (#1498)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-06-02 15:53:29 +08:00
Takeshi Yoneda
256b7a4bf9 dwarf: ignores tombstone entries in inlined information (#1488)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-05-22 15:56:33 +10:00
Anuraag Agrawal
714368bcea Remove threads support (#1487)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2023-05-22 12:18:36 +10:00
Anuraag Agrawal
f2c8caaf92 Generically convert to string in hammer recovery (#1479)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2023-05-17 13:51:20 +10:00
Anuraag Agrawal
bc96257575 Implement WebAssembly threads proposal with interpreter (#1460)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2023-05-16 12:22:17 +08:00
Takeshi Yoneda
80452a94c3 Bulk lazy initialization of FunctionDefinitions (#1425)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
Co-authored-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-05-12 08:02:40 +10:00
Achille
78c35acd6e experimental: remove return value of FunctionListener.Before (#1453)
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
Co-authored-by: Crypt Keeper <64215+codefromthecrypt@users.noreply.github.com>
2023-05-11 11:52:10 +08:00
Achille
a105c43629 experimental: remove error parameter from FunctionListener.After (#1452)
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
2023-05-11 06:48:26 +08:00
Thomas Pelletier
ef3d671195 experimental: split program counter and source offset resolution (#1448)
Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>
2023-05-09 13:34:01 -07:00
Achille
daad2fdb66 experimental: add FunctionListener and FunctionListenerFactory implementations (#1444)
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
2023-05-09 17:03:08 +08:00
Thomas Pelletier
ed17e523ba experimental: expose source offset to Listener (#1433)
Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
Co-authored-by: Achille Roussel <achille.roussel@gmail.com>
2023-05-09 08:18:27 +08:00
Takeshi Yoneda
f47b0d3362 Reduces FunctionDefinition usages (#1419)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-05-01 10:37:43 +08:00
Nuno Cruces
77e8d72d67 api: adds CallWithStack to avoid allocations (#1407)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2023-05-01 08:52:40 +09:00
Thomas Pelletier
0bfb4b52eb Give Listener a read-only view of globals (#1404)
* experimental: give listener r/o view of globals

Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>

* experimental: add global support to interpreter

Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>

* exp: replace globals proxy with module interface

Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>

* exp: trim down experimental.InternalModule

Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>

* Replace globals view slice with constantGlobal

Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>

* Fix tests after merge

Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>

* Address PR feedback

Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>

* Rename methods of experimental.Module

Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>

* Run make check

Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>

* Add WazeroOnlyType to constantGlobal

Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>

---------

Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>
2023-04-29 00:07:28 -07:00
Takeshi Yoneda
3c1c76e2a1 debug: includes Go stack trace in the face of Go runtime errors (#1401)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-25 10:45:20 +09:00
Thomas Pelletier
9aca08c5e6 Provide new StackIterator to Before Listener hook (#1363)
Signed-off-by: Thomas Pelletier <thomas@pelletier.codes>
2023-04-18 08:22:58 +09:00
Crypt Keeper
b9e03dc691 Makes host function index insertion order (#1370)
This makes host functions index consistently on insertion order, rather
than lexicographic order. This helps with ABI such as Emscripten, which
need an expected order.

This also constrains the internal code around host functions to only one
export name. More than one was never used. By restricting this, logic is
simpler and smaller.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-04-17 17:18:11 +01:00
Takeshi Yoneda
8ac9a54923 wasm: reduces allocs during import resolution (#1361)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-13 12:35:04 +09:00
Takeshi Yoneda
3cbd881201 binary: makes NameMap and IndirectNameMap slices over values, not ptrs (#1351)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-10 21:27:50 +09:00
Takeshi Yoneda
cc28399052 wazeroir: reuses allocated slices for a module (#1342)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-05 20:26:44 +09:00
Takeshi Yoneda
fa722dd9e3 Implements api.Function directly over engine specific callEngine (#1297)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-28 16:49:35 +09:00
Takeshi Yoneda
0857336746 Removes wasm.FunctionInstance type (#1294)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-28 14:43:44 +09:00
Takeshi Yoneda
cd606bde04 Refactors NewModuleEngine and NewCallEngine (#1291)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-27 09:40:55 +09:00
Takeshi Yoneda
a4226906cf Deletes wasm.CallCtx (#1280)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-24 17:00:43 -07:00
Crypt Keeper
451c792ee8 Avoids returning ExitError on exit code zero, and optimizes for no allocations (#1284)
Fixes #1283

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-24 16:42:30 +01:00
Takeshi Yoneda
cd1110c088 Avoids allocation of exports map per instance (#1275)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-23 16:37:56 +09:00
Takeshi Yoneda
cd05a22df2 Reduces allocations during instantiation (#1267)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-22 18:55:58 +09:00
Takeshi Yoneda
e17a85146a Holds wasm.Code as values on wasm.Module (#1243)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-15 14:45:54 +09:00
Takeshi Yoneda
350e81e632 Holds function types as values, not ptrs in wasm.Module (#1227)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-15 13:45:52 +09:00
Takeshi Yoneda
aba4ede088 Removes usage of host functions with Wasm optocdes (#1241)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-15 13:42:53 +09:00
Takeshi Yoneda
e42987a17a Holds memory/func defs, and validated elements as values in wasm.Module (#1224)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-13 14:52:01 +09:00
Takeshi Yoneda
7466f0e7bd Holds most fields as slice of values, not ptrs in wasm.Module (#1221)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-13 12:50:36 +09:00
Takeshi Yoneda
24e4d5dfa0 Generates typeIDs at compilation time (#1218)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-10 13:46:08 +09:00
Takeshi Yoneda
ad968dc3fe Pass correct api.Module to host functions (#1213)
Fixes #1211

Previously, host functions are getting api.Module for the "originating" module, 
which is the module for api.Function currently invoked, except that the api.Module 
is modified by withMemory with the caller's memory instance, therefore there 
haven't been no problem for most cases. The only issues were the methods 
besides Memory() of api.Module, and this commit fixes them.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-08 15:05:48 +09:00
Edoardo Vacchi
117474c477 refactor binary encoding to its own package (#1187)
move binary encoder to its own package

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-03-03 07:21:22 +08:00
Crypt Keeper
75aa6b2a6e examples: updates to the latest SDKs (#1169)
This updates our examples to the latest SDKs as particularly this can
help reveal issues around fan-out stats.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-02-27 09:05:48 +08:00
Crypt Keeper
4ca0858e57 sysfs: adds FS.Stat and companions in platform (#1140)
This centralizes filestat logic by making our own `Stat_t` similar to
`syscall.Stat_t`. This exposes utilities in the platform package and
adds a new function `FS.Stat` which avoids having to use `fs.File` to
get the same info. Doing so at the FS abstraction allows us to optimize
how it is implemented internally using portable means (e.g.
`os.StatFile`) or OS-specific means where necessary, e.g. in windows.

This also ensures `platform.OpenFile` returns syscall.Errno and
centralizes error checking with a new `require.EqualErrno` test.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-02-21 10:13:37 +08:00
Takeshi Yoneda
b68ee641cc ci: update TinyGo to 0.27 (#1120)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-02-13 17:38:53 +09:00
Takeshi Yoneda
92e0a488b6 Support context Cancelation/Timeout in function executions (#1108)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-02-10 09:39:04 +09:00
Crypt Keeper
f9db80624d zig: bumps to latest (#1080)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-01-30 16:30:52 +02:00
Edoardo Vacchi
599c097603 Add -hostlogging=crypto (#1064)
This allows you to specify multiple logging scopes, both in API and the CLI.

e.g for the CLI.
```bash
$ wazero run --hostlogging=crypto --hostlogging=filesystem --mount=.:/:ro cat.wasm
```

e.g. for Go
```go
loggingCtx := context.WithValue(testCtx, experimental.FunctionListenerFactoryKey{},
	logging.NewHostLoggingListenerFactory(&log, logging.LogScopeCrypto|logging.LogScopeFilesystem))
```

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-01-28 12:51:44 +02:00
Crypt Keeper
105cdcdef7 cli: rewrites compositeFS to syscallfs and adds read-only (:ro) mounts (#1030)
This rewrites compositeFS to syscallfs.FS following wasi-sdk preopen
rules. Notably, this allows use of read-only mounts now.

For example,
```bash
$ GOOS=js GOARCH=wasm bin/go test -c -o template.wasm text/template
$ wazero run -mount=src/text/template:/ -mount=/tmp:/tmp template.wasm -test.v
=== RUN   TestExecute
--- PASS: TestExecute (0.07s)
--snip--
```

This is the first step to native WASI handling of multiple pre-opens.
After this change, it is still the case that there's only one pre-open
FD visible to wasm. A later change will make it possible for WASI to see
multiple pre-opens while `GOOS=js` which doesn't use preopens, remains
on a rootFS.

A future PR may need to add a CLI flag to disable escaping directories,
(e.g. make ../.. EINVAL), similar to `fs.FS` in Go. The simplest way to
allow this is to use a host-side RootFS even in WASI, and wrap that with
a `syscallfs` filename filter.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-01-13 15:50:11 +08:00
Takeshi Yoneda
b63d4e6dcd Deletes namespace API (#1018)
Formerly, we introduced `wazero.Namespace` to help avoid module name or import conflicts while still sharing the runtime's compilation cache. Now that we've introduced `CompilationCache` `wazero.Namespace` is no longer necessary. By removing it, we reduce the conceptual load on end users as well internal complexity. Since most users don't use namespace, the change isn't very impactful.

Users who are only trying to avoid module name conflict can generate a name like below instead of using multiple runtimes:

```go
moduleName := fmt.Sprintf("%d", atomic.AddUint64(&m.instanceCounter, 1))
module, err := runtime.InstantiateModule(ctx, compiled, config.WithName(moduleName))
```

For `HostModuleBuilder` users, we no longer take `Namespace` as the last parameter of `Instantiate` method: 

```diff
 	// log to the console.
 	_, err := r.NewHostModuleBuilder("env").
 		NewFunctionBuilder().WithFunc(logString).Export("log").
-		Instantiate(ctx, r)
+		Instantiate(ctx)
 	if err != nil {
 		log.Panicln(err)
 	}
```


The following is an example diff a use of namespace can use to keep compilation cache while also ensuring their modules don't conflict:

```diff

 func useMultipleRuntimes(ctx context.Context, cache) {
-	r := wazero.NewRuntime(ctx)
+	cache := wazero.NewCompilationCache()
 
 	for i := 0; i < N; i++ {
-		// Create a new namespace to instantiate modules into.
-		ns := r.NewNamespace(ctx) // Note: this is closed when the Runtime is
+		r := wazero.NewRuntimeWithConfig(ctx, wazero.NewRuntimeConfig().WithCompilationCache(cache))
 
 		// Instantiate a new "env" module which exports a stateful function.
 		_, err := r.NewHostModuleBuilder("env").
```

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-01-10 14:11:46 +09: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
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
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
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
126bd9050d Removes context parameter from instruction-scoped operations (#923)
We originally had a `context.Context` for anything that might be
traced, but it turned out to be only useful for lifecycle and host functions.

For instruction-scoped aspects like memory updates, a context parameter is too
fine-grained and also invisible in practice. For example, most users will use
the compiler engine, and its memory, global or table access will never use go's
context.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-14 16:08:07 +09:00
Takeshi Yoneda
7bd1c1600f dwarf: fixes for non-exact matched lines (#916)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-13 13:37:40 +09:00