Commit Graph

1276 Commits

Author SHA1 Message Date
Crypt Keeper
40341af448 fs: returns EBADF on negative file descriptor (#1391)
This changes file descriptors from uint32 to int32 and the
corresponding file table to reject negative values. This ensures
invalid values aren't mistaken for very large descriptor entries, which
can use a lot of memory as the table implementation isn't designed to
be sparse.

See https://pubs.opengroup.org/onlinepubs/9699919799/functions/dirfd.html#tag_16_90

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-04-21 16:08:35 +02:00
Takeshi Yoneda
010f0a93a2 asm/amd64: optimizes maybeNOPPadding if conds (#1389)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-21 15:11:37 +09:00
Takeshi Yoneda
f3deb47d69 asm/amd64: uses enum for operand types (#1388)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-21 11:30:14 +09:00
Takeshi Yoneda
ae6a43b367 asm/amd64: removes map access in encoding (#1387)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-21 10:50:35 +09:00
Takeshi Yoneda
a9cf51234c asm/amd64: optimizes register3bits via array (#1386)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-21 09:19:04 +09:00
Takeshi Yoneda
b1fec9fb0a asm/amd64: avoids allocations in static const offset resolution (#1384) 2023-04-20 03:56:11 -07:00
Takeshi Yoneda
70c5e03836 compiler(amd64): reuses static consts properly (#1382)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-19 16:18:01 +09:00
Takeshi Yoneda
d33ecd0e3a cache: fixes consistency with CloseOnContextDone and listeners (#1381)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-19 15:00:46 +09:00
Kevin Burns
b8a4e8ff68 Fixes syntax errors in examples (#1380)
Signed-off-by: kevburnsjr <kevburnsjr@gmail.com>
2023-04-19 08:31:42 +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>
v1.0.2
2023-04-18 16:31:34 +02:00
Adrian Cole
ab78591915 Revert "examples(allocation): free memory after unmarshalling a result from the guest (#1368)"
This reverts commit 5aafcc4836.
2023-04-18 13:28:44 +02:00
Crypt Keeper
df0faa5d16 emscripten: adds experimental InstantiateForModule for invoke exports (#1372)
This adds emscripten.InstantiateForModule into the experimental package.
This builds dynamic invoke exports in the same order and only matching
those needed by the importing modules.

Finally, this removes special casing of function type IDs by deferring
resolution of them only in Emscripten.

Fixes #1364

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-04-18 09:13:50 +02:00
Takeshi Yoneda
2a2e07a91f asm/arm64: uses enum for operand types (#1378)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-18 15:20:25 +09:00
Luca Burgazzoli
5aafcc4836 examples(allocation): free memory after unmarshalling a result from the guest (#1368)
Signed-off-by: Luca Burgazzoli <lburgazzoli@gmail.com>
2023-04-18 07:38:10 +02:00
Takeshi Yoneda
6a4bdd31db compiler: fixes false-positive invalid ptr detection in -race (#1376)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-18 08:44:30 +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
cd34767954 Fixes race where HostFunc names are needlessly lazy set (#1375)
A prior change broke race tests as it lazy set HostFunc.Name even when
saved as a field. This sets name in all places we instantiate HostFunc
for use in fields.

Fixes #1373

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-04-18 08:14:05 +09:00
Edoardo Vacchi
b32189e5a9 wasi: fix zig-cc/wasi.c repeat arg (#1371)
While working on #1346 I noticed that `zig cc` built a faulty
`wasi.wasm` that would fail on `ls`.

Only now have I realized that the `ls` subroutine was faulty to
begin with because we did not verify that `argv[3]` existed
before dereferencing. Oh, you, UB!

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-04-17 20:45:25 +02:00
Crypt Keeper
9263bef174 logging: fixes bug where unsampled logger is called from a sampled one (#1369)
We had a logging bug where an unsampled function (such as fd_write to
stdout/stderr) would end up with its logging "after" hook called, if it
was called from a sampled function.

For example, if a wasm function called fd_write with stdout, the before
hook on fd_write would skip, but the after would not, and accidentally
use its caller's parameters. This results in a panic due to incorrect
length.

This fixes the bug by ensuring we mute the logging context if there's
one in progress. It ensures the bug won't pop up again by adding test
data that matches the call pattern (from xpdf-wasm).

Thanks to @jerbob92 for helping isolate this!

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-04-17 17:36:15 +01: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
27b405f17b asm/arm64: removes unneeded 16 bytes alignment (#1367)
signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-17 15:16:40 +09: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
Clifton Kaznocha
00d9d885ff Cleanup aliased modules when the main module is deleted (#1365)
Signed-off-by: Clifton Kaznocha <ckaznocha@users.noreply.github.com>
2023-04-17 09:32:08 +09:00
Clifton Kaznocha
a9ec3b62d3 Shrink the store's nameToModule map (#1285)
Signed-off-by: Clifton Kaznocha <ckaznocha@users.noreply.github.com>
2023-04-17 08:40:58 +09:00
Chris O'Hara
dfa2560cef Fix HostFunctionBuilder docs (#1362)
Signed-off-by: Chris O'Hara <cohara87@gmail.com>
2023-04-13 13:26:14 +09: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
a979e0f643 wasm: removes name node to simplify instantiation path (#1359)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-13 09:26:18 +09:00
Takeshi Yoneda
1bed2238ad ci: uses actions/cache instead of artifacts for integration tests (#1358)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-12 14:23:22 +09:00
Takeshi Yoneda
5464903d8f interpreter: use slice of values on functions, not ptrs (#1357)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-12 11:35:13 +09:00
Takeshi Yoneda
a56b4435c1 Fixes memory capacity with max larger than limit (#1356)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-12 09:23:48 +09:00
Takeshi Yoneda
3aeeb0b01d asm/arm64: avoids using unnecessary map access (#1355)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-11 15:40:33 +09:00
Takeshi Yoneda
c719af9a14 binary: avoids copy in decodeUTF8 (#1354)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-11 14:26:28 +09:00
Takeshi Yoneda
13794d4329 gojs: stop file caching in tests (#1353)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-11 14:15:36 +09:00
Takeshi Yoneda
84ea9efc14 binary: reduces allocation during code section decoding (#1352)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-10 21:48:09 +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
b6d19696da compiler: reuses allocated runtimeValueLocation stacks (#1348)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-10 14:58:47 +09:00
Takeshi Yoneda
f167939c88 wazeroir: avoids allocation with InclusiveRange (#1345)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-07 12:14:39 +09:00
Takeshi Yoneda
24dbf49c79 compiler: avoid alloc with stack pointer ceil and reuse bytes reader (#1344)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-06 16:47:08 +09:00
Takeshi Yoneda
df8586e58b interpreter: reduces allocations in lowerIR (#1343)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-06 15:04:39 +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
Edoardo Vacchi
0dc152d672 wazeroir: migrate vector, table, branch and all other remaining ops to compact repr (#1334)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
Co-authored-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-05 09:38:49 +09:00
Takeshi Yoneda
87942692bf Reuses stack in requireStackValues of func validation (#1341)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-04 10:49:07 +09:00
Takeshi Yoneda
4f6b9f6637 Reuses bytes.Reader and value stack in func validation (#1340)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-04 10:31:15 +09:00
Takeshi Yoneda
18195355d5 Fixes race in TestModuleInstance_CloseModuleOnCanceledOrTimeout (#1339)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-03 16:48:19 +09:00
Takeshi Yoneda
967df4c1ff example: anonymous module in concurrent instantiation (#1338)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-03 15:03:20 +09:00
Takeshi Yoneda
4dbdbc79a2 Defer resource closure on context cancelation to ModuleInstance.FailIfClosed (#1336)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-03 12:42:27 +09:00
Achille
27c7c320b3 add github.com/stealthrocket/wazergo to the list of libraries using wazero (#1337)
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
2023-04-03 12:22:20 +09:00
Takeshi Yoneda
fa3090a022 Allows WithMemoryLimitPages to override the default pages (#1335)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-03 09:30:34 +09:00
Edoardo Vacchi
f3ef84c9b3 wazeroir: Load Ops, Store Ops, Set, Pick, Select, CallIndirect (#1329)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
Co-authored-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-04-01 08:00:27 +09:00
Takeshi Yoneda
ebe48da023 Reuses allocated slices in func validation (#1328)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-31 15:58:15 +09:00