Gunnar Beutner
36e36507d5
Everywhere: Prefer using {:#x} over 0x{:x}
...
We have a dedicated format specifier which adds the "0x" prefix, so
let's use that instead of adding it manually.
2021-07-22 08:57:01 +02:00
Ali Mohammad Pur
52a2518a69
LibWasm: Remove a useless use of ScopeGuard
...
There are no multiple exit paths in that function, so we can just put
the ending logic right at the end of the function instead.
2021-07-17 01:13:39 +04:30
Ali Mohammad Pur
65cd5526cb
LibWasm+Everywhere: Make the instruction count limit configurable
...
...and enable it for LibWeb and test-wasm.
Note that `wasm` will not be limited by this.
2021-07-17 01:13:39 +04:30
Ali Mohammad Pur
70b94f58b2
LibWasm: Inline some very hot functions
...
These are mostly pretty small functions too, and they were about ~10%
of runtime.
2021-07-17 01:13:39 +04:30
Ali Mohammad Pur
23b48f8fe1
Revert "LibWasm: Some more performance stuff ( #8812 )"
...
This reverts commit 35394dbfaa
.
I pushed the wrong button again, hopefully this will be the last of
such incidents.
2021-07-17 01:11:28 +04:30
Ali Mohammad Pur
35394dbfaa
LibWasm: Some more performance stuff ( #8812 )
...
* wasm: Don't try to print the function results if it traps
* LibWasm: Inline some very hot functions
These are mostly pretty small functions too, and they were about ~10%
of runtime.
* LibWasm+Everywhere: Make the instruction count limit configurable
...and enable it for LibWeb and test-wasm.
Note that `wasm` will not be limited by this.
* LibWasm: Remove a useless use of ScopeGuard
There are no multiple exit paths in that function, so we can just put
the ending logic right at the end of the function instead.
2021-07-17 01:04:37 +04:30
Andrew Kaster
2af591267c
LibWasm: Adjust signed integer operations to avoid UB
...
Perform signed integer shifts, addition, subtraction, and rotations
using their corresponding unsigned type. Additionally, mod the right
hand side of shifts and rotations by the bit width of the integer per
the spec. This seems strange, but the spec is clear on the desired
wrapping behavior of arithmetic operations.
2021-07-12 18:42:45 +04:30
Ali Mohammad Pur
d74eca78aa
LibWasm: Skip initializing active empty data sections
2021-07-12 18:42:45 +04:30
Ali Mohammad Pur
65355c388b
LibWasm: Use AK::StackInfo to track stack size
...
This way, we can make sure that it doesn't overflow when ASAN is
enabled.
2021-07-12 18:42:45 +04:30
Ali Mohammad Pur
06ffc0c4db
LibWasm: Don't create useless temporary strings for trap reasons
...
These strings are only used when execution traps, so there's no reason
to create actual strings until that happens; instead switch to using
StringViews.
2021-07-06 17:55:00 +04:30
Ali Mohammad Pur
2fc0040ceb
LibWasm: Tweak the implementation-defined limits a bit
2021-07-06 17:55:00 +04:30
Ali Mohammad Pur
5636f8143d
LibWasm: Allow overflow in normal 64-bit arithmetic instructions
2021-07-06 17:55:00 +04:30
Ali Mohammad Pur
c4d4c657d0
LibWasm: Limit module memory to 65536 pages
...
The spec mentions this, and anything past that can't be correctly
addressed by the 32-bit indices anyhow.
2021-07-06 17:55:00 +04:30
Ali Mohammad Pur
03fe50d5e7
LibWasm: Fix data section initialization bounds checking
2021-07-06 17:55:00 +04:30
Ali Mohammad Pur
d2212a1f51
LibWasm: Jump to the default label in br_table with negative values
...
Also adds a forgotten Wasm::Printer implementation for printing table
branch arguments.
2021-07-06 17:55:00 +04:30
Ali Mohammad Pur
0b08392e54
LibWasm: Use the number of bytes when comparing memory limits
...
...instead of comparing page count with byte count.
2021-07-06 17:55:00 +04:30
Ali Mohammad Pur
4bdb0ad132
LibWasm: Guard stack accesses with checks
...
If the stack is empty, let's just trap.
2021-07-06 17:55:00 +04:30
Idan Horowitz
301c1a3a58
Everywhere: Fix incorrect usages of AK::Checked
...
Specifically, explicitly specify the checked type, use the resulting
value instead of doing the same calculation twice, and break down
calculations to discrete operations to ensure no intermediary overflows
are missed.
2021-07-04 20:08:28 +01:00
Ali Mohammad Pur
b538e15548
LibWasm: Give traps a reason and display it when needed
...
This makes debugging wasm code a bit easier, as we now know what fails
instead of just "too bad, something went wrong".
2021-07-02 04:53:01 +04:30
Andreas Kling
beb43f673e
AK: Undo bogus Variant::downcast() rename
...
I accidentally renamed these to verify_cast() when doing the global
AK::downcast() rename.
2021-06-26 21:27:58 +02:00
Andreas Kling
ee3a73ddbb
AK: Rename downcast<T> => verify_cast<T>
...
This makes it much clearer what this cast actually does: it will
VERIFY that the thing we're casting is a T (using is<T>()).
2021-06-24 19:57:01 +02:00
Ali Mohammad Pur
c4b82ace74
LibWasm: Limit the call stack depth and the number of executed insts
...
These limits are described in the spec, and we're supposed to stop
execution at some point.
The limits are arbitrarily chosen.
2021-06-22 00:26:25 +04:30
Ali Mohammad Pur
9971d13844
LibWasm: Trap if a non-Value is used as a Value
...
Otherwise we'd just crash, which is not a good thing
2021-06-22 00:26:25 +04:30
Ali Mohammad Pur
9c5d38b7db
Meta+LibWasm: Add support for module linking tests
...
This commit makes the linking tests in the wasm spec test run.
2021-06-22 00:26:25 +04:30
Linus Groh
34b338702a
LibWasm: Remove empty AbstractMachine/Interpreter.cpp
...
This was moved to BytecodeInterpreter.cpp, so this is unused now.
2021-06-20 01:49:56 +01:00
Andreas Kling
dc65f54c06
AK: Rename Vector::append(Vector) => Vector::extend(Vector)
...
Let's make it a bit more clear when we're appending the elements from
one vector to the end of another vector.
2021-06-12 13:24:45 +02:00
Ali Mohammad Pur
aa2916c21b
LibWasm: ALWAYS_INLINE some very hot functions
...
These function couldn't be inlined before because the compiler would've
started flagging invalid paths in Variant as maybe-uninitialized.
2021-06-09 23:05:32 +04:30
Ali Mohammad Pur
45710d0724
LibWasm: Implement saturating float truncation instructions
...
With these, the only remaining unimplemented instructions are the
following:
- memory.init
- data.drop
- memory.copy
- memory.fill
- table.init
- elem.drop
- table.copy
- table.grow
- table.size
- table.fill
2021-06-09 23:05:32 +04:30
Ali Mohammad Pur
3a44011cd4
LibWasm: Implement sign extension instructions
2021-06-09 23:05:32 +04:30
Ali Mohammad Pur
a4c4dd928b
LibWasm: Implement spec-compliant float min/max ops
2021-06-09 23:05:32 +04:30
Sahan Fernando
d02e7b3811
LibWasm: Move Wasm::BytecodeInterpreter into its own header
2021-06-05 14:31:54 +04:30
Ali Mohammad Pur
1b083392fa
LibWasm+wasm: Switch to east-const to comply with project style
...
Against my better judgement, this change is mandated by the project code
style rules, even if it's not actually enforced.
2021-06-04 16:07:42 +04:30
Ali Mohammad Pur
be62e4d1d7
LibWasm: Load and instantiate tables
...
This commit is a fairly large refactor, mainly because it unified the
two different ways that existed to represent references.
Now Reference values are also a kind of value.
It also implements a printer for values/references instead of copying
the implementation everywhere.
2021-06-04 16:07:42 +04:30
Ali Mohammad Pur
c392a0cf7f
LibWasm: Implement the br.table instruction
...
Unlike its name, this instruction has nothing to do with tables, it's
just a very simple switch-case instruction.
2021-06-04 16:07:42 +04:30
Ali Mohammad Pur
9db418e1fb
LibWasm: Read from and write to memory as little-endian
...
The spec says so, we must do so.
2021-06-04 16:07:42 +04:30
BrandonKi
0d1481be7d
LibWasm: Use builtins for clz, ctz, and popcnt
2021-06-03 03:45:06 +04:30
BrandonKi
e53df2ca9d
LibWasm: Implement rotr and rotl
2021-06-03 03:45:06 +04:30
Ali Mohammad Pur
ea7ba34a31
AK+LibWasm+LibJS: Disallow Variant.has() on types that aren't contained
...
Checking for this (and get()'ing it) is always invalid, so let's just
disallow it.
This also finds two bugs where the code is checking for types that can
never actually be in the variant (which was actually a refactor
artifact).
2021-06-02 18:02:47 +02:00
Ali Mohammad Pur
b15a5d6ada
LibWasm: Ensure that value signs are preserved when casting
...
Also makes normal arithmetic operations more spec-compliant by actually
ignoring overflow on them.
2021-06-02 16:09:16 +04:30
Ali Mohammad Pur
02b3238c41
LibWasm: Parse the "extend" set of instructions
2021-06-02 16:09:16 +04:30
Ali Mohammad Pur
9a1853c388
LibWasm: Don't execute the last instruction in the frame after return
2021-06-02 16:09:16 +04:30
Ali Mohammad Pur
b250a6ae7e
wasm: Add a way to create dummy function exports
...
This should allow running modules with their imports stubbed out
in wasm, to debug them.
2021-06-02 16:09:16 +04:30
Ali Mohammad Pur
56bf80251c
LibWasm: Implement reference instructions (ref.{null,func,is_null})
2021-06-02 16:09:16 +04:30
Gunnar Beutner
5f18cf75c5
AK: Replace ByteBuffer::grow with resize()/ensure_capacity()
...
Previously ByteBuffer::grow() behaved like Vector<T>::resize().
However the function name was somewhat ambiguous - and so this patch
updates ByteBuffer to behave more like Vector<T> by replacing grow()
with resize() and adding an ensure_capacity() method.
This also lets the user change the buffer's capacity without affecting
the size which was not previously possible.
Additionally this patch makes the capacity() method public (again).
2021-05-31 14:49:00 +04:30
Ali Mohammad Pur
e0b17988bd
LibWasm: Make f32-add/sub actually perform addition/subtraction
...
Instead of applying a unary operator to the ToS.
This alone fixes 4% of the spec test issues.
2021-05-30 01:34:28 +04:30
Ali Mohammad Pur
08b567e137
LibWasm: Avoid OOB accesses caused by user input
...
Just trap instead of crashing.
2021-05-30 01:34:28 +04:30
Ali Mohammad Pur
8ce015742d
LibWasm: Fix logic error in Limits::parse()
...
The check was negated, and it errored out when the read actually
succeeded.
2021-05-29 23:03:18 +04:30
Ali Mohammad Pur
578bf6c45e
LibWasm: Avoid excessive pop()-then-push() on the stack
...
Also make the stack a lot bigger, since we now have only one of these
instead of one per function call.
2021-05-27 17:28:41 +04:30
Ali Mohammad Pur
477ab6dc4c
LibWasm: Let the interpreter itself manage the call frame
2021-05-27 17:28:41 +04:30
Ali Mohammad Pur
85794f8244
LibWasm: Add a copy assignment operator to Value
2021-05-27 17:28:41 +04:30