Commit Graph

612 Commits

Author SHA1 Message Date
Tristan Willy
f3516a656f wasm: move ModuleInstance.Closed to the top (#1321)
ModuleInstance.Closed is an atomic variable meant to be loaded and
swapped with sync/atomic. Closed, being a 64 bit integer, requires 64
bit alignment. The simplest way we can get alignment is to place these
atomic fields at the top of their struct.

Closed can be moved to a more logical place once support for Go 1.18 is
dropped and its type changed to atomic.Uint64.

Signed-off-by: Tristan Willy <tristan.willy@gmail.com>
2023-03-31 08:13:44 +09:00
Edoardo Vacchi
8887799da7 wazeroir: move unary byte ops to UnionOperator (#1320)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-03-31 08:07:12 +09:00
Edoardo Vacchi
c5d37877bd wazeroir: migrate unary operations to UnionOperation (#1318)
* refactor: OperationCall, OperationGlobalGet, OperationGlobalSet

* refactor: Constant Operations

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>

---------
2023-03-30 12:57:45 +02:00
Takeshi Yoneda
448c990ab6 asm/amd64: avoids allocations on forward jump resolution (#1315)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-30 17:46:09 +09:00
Edoardo Vacchi
37135067b6 wazeroir: rm nullary Operations, move interpreterOp to UnionOperation (#1310)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-03-30 16:57:41 +09:00
Crypt Keeper
035c0ffaf4 wasi: adds preopen test for use in homebrew (#1309)
This adds a test to verify the wazero binary produced by homebrew.
Notably, this was made to be small enough to copy/paste in hex format.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-30 13:06:51 +08:00
Takeshi Yoneda
76815dbd75 asm/amd64: avoids map allocation per node (#1307)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-29 16:27:54 +09:00
Takeshi Yoneda
15e393c7e9 asm: reuse StaticConstPool (#1304)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-29 13:30:16 +09:00
Takeshi Yoneda
0f7b691555 bench: do not call _start in concurrent instantiation (#1302)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-29 12:21:05 +09:00
Takeshi Yoneda
376292fe53 asm: reuses the slice on SetBranchTargetOnNextNodes (#1303)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-29 12:20:50 +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
54ba876002 interpreter: add u1, u2 int64 to interpreterOp (#1298)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-03-29 08:26:29 +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
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
9a87d2628b Removes validatedActiveElementSegment (#1292)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-28 08:19:40 +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
d0fc0c6232 Import function type check at validation phrase (#1281)
Import function type check at compilation

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-24 09:10:18 +01:00
Crypt Keeper
244c5c5792 ensures we don't open a file to close it (#1279)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-24 08:20:06 +09:00
Achille
4eba21372c Support registering multiple instances of anonymous modules (#1259)
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
Signed-off-by: Clifton Kaznocha <ckaznocha@users.noreply.github.com>
Co-authored-by: Clifton Kaznocha <ckaznocha@users.noreply.github.com>
2023-03-23 18:27:19 +01:00
Takeshi Yoneda
d8f356e644 Removes unused GoFunc types (#1276)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-23 16:48:14 +09: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
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
b600ed98a2 renames internal wasi package to wasip1 and removes dot imports (#1273)
This removes the generally frowned upon practice of dot imports by
shortening the name of internal/wasi_snapshot_preview1 to
internal/wasip1. This leaves the external one alone as it would break
users to change it.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-23 08:08:27 +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
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
c20073d228 Removes unnecessary .Index field of FunctionInstance (#1270)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-22 18:55:35 +09:00
Takeshi Yoneda
8c0e30b5f3 Removes unnecessary uint64 allocation on callContext (#1271)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-22 18:55:25 +09:00
Takeshi Yoneda
f8eb6a8535 Removes unused function types on encoder/decoder (#1269)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-22 08:42:55 +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
Crypt Keeper
046af4356e wasi: removes constraint around closing a pre-open, and temporarily skips interesting_paths (#1265)
wasi-testsuite changed its mind on pre-open WebAssembly/wasi-testsuite#66

they also now explicitly forbid paths being passed in with a leading slash. Even when the config bug on WebAssembly/wasi-testsuite#67 is finished, this requires discussion if we want to EPERM on that.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-21 23:43:59 +08: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
Takeshi Yoneda
7dd270e9c9 Removes redundant exit code check (#1260)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-20 19:31:23 +09:00
Takeshi Yoneda
fe8784996c Avoides allocation with constExpr execution (#1257)
Previously executConstExpr is called various places, and therefore it was necessary to return interface{}
and that resulted in allocation per call.
This commit avoids the allocation by adding executConstExprI32 which is used by data segment manipulation,
and repurposes executConstExpr solely to global instance initialization.

As a result, this completely removes the allocation around const expr execution, and hence the perf improvement
in the instantiation phrase. The improvement diff is proportionate to the number of data segments and globals.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-20 12:56:25 +09:00
Takeshi Yoneda
f0f5457577 sys/fs: removes redundant cachedStat allocation (#1255)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-20 10:12:07 +09:00
Achille
6471ac7dd7 path_filestat_get: interpret LOOKUP_SYMLINK_FOLLOW (#1252)
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
2023-03-18 08:23:44 +08:00
Crypt Keeper
03ab5a97ad Removes partially completed fstest (#1247)
Before, we didn't have a suite of tests for our filesystem used by ABI,
now we do (`sysfs`). Moreover, we are testing stdlibs and wasi-testsuite
on commit. We don't need this fstest anymore.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-17 09:34:39 +09:00
Takeshi Yoneda
8ab1615b53 Forbids empty name module imports (#1244)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Co-authored-by: Crypt Keeper <64215+codefromthecrypt@users.noreply.github.com>
2023-03-16 12:22:37 +09: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
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
f24a3f49a4 gojs: refactors out gojs.Config type (#1240)
In order to support more configuration, we should stop using context as
it is getting gnarly.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-15 12:27:47 +08:00
Crypt Keeper
8a92cd3841 returns EBADF when attempting to write to STDIN (#1237)
Found this problem while troubleshooting #1232

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-14 12:30:09 +08:00
Crypt Keeper
8c04ad4448 sysfs: maps syscall.EROFS (#1236)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-14 10:47:32 +08:00