Ali Mohammad Pur
2c0716e314
LibWasm: Simplify the return instruction execution code a bit
2022-04-22 21:12:47 +04:30
Ali Mohammad Pur
846b2c8a99
LibWasm: Push call results back in reverse order to preserve stack order
2022-04-22 21:12:47 +04:30
Ali Mohammad Pur
6760ea33a0
LibWasm: Make memory_grow validation push back the old memory size
2022-04-22 21:12:47 +04:30
Ali Mohammad Pur
6e07e74261
LibWasm: Make local_tee validation keep the value on the stack
2022-04-22 21:12:47 +04:30
Idan Horowitz
086969277e
Everywhere: Run clang-format
2022-04-01 21:24:45 +01:00
Ali Mohammad Pur
82a515a748
LibWasm: Increase the arbitrary local value count per type limit
...
It was arbitrary, it's still arbitrary, but now it's funny too :^)
2022-03-20 10:44:32 +03:30
Ali Mohammad Pur
a6c4b6848b
LibWasm: Use some template magic to greatly simplify stack validation
...
This also auto-fixes a few bugs that were present before as we were
manually checking the stack.
2022-03-20 10:44:32 +03:30
Ali Mohammad Pur
18c5b0f1cc
LibWasm: Allow Limits max value to be equal to 2^k-1
...
That value fits in k bits, so we should allow it.
2022-03-20 10:44:32 +03:30
Ali Mohammad Pur
eccdf4eb4b
LibWasm: Fix validation of if-else blocks
...
We were doing a number of things wrong:
- Switching to the parent context in the else meant that we couldn't
break out of the else section anymore
- We were not validating the resulting values, and so the stack was
in a relatively unknown state after 'else'
This commit fixes these issues :^)
2022-02-16 22:48:32 +03:30
Ali Mohammad Pur
4f2d898a51
LibWasm: Make MemoryInstance allocation fail if initial growth fails
...
...instead of silently ignoring the failure in the constructor.
2022-02-16 22:48:32 +03:30
mjz19910
3102d8e160
Everywhere: Fix many spelling errors
2022-01-07 10:56:59 +01:00
Andrew Kaster
d809637023
Userland: Resolve tautological-constant-out-of-range-compare warnings
...
Stop comparing platform-specific sized integer types to max() values of
other interger types. Enable the warning everywhere.
2022-01-04 07:51:31 +00:00
Nick Johnson
08e4a1a4dc
AK+Everywhere: Replace __builtin bit functions
...
In order to reduce our reliance on __builtin_{ffs, clz, ctz, popcount},
this commit removes all calls to these functions and replaces them with
the equivalent functions in AK/BuiltinWrappers.h.
2021-12-21 22:13:51 +01:00
Ali Mohammad Pur
ed9e7f1ad0
LibWasm: Tolerate modules with invalid sections and mark them as invalid
...
We should not crash, but rather just fail to verify them.
2021-12-21 05:03:44 +03:30
Ali Mohammad Pur
2db27be2df
LibWasm: Make shown instruction names match the names in the spec
2021-12-21 05:03:44 +03:30
Ali Mohammad Pur
afa3d06ea6
LibWasm: Add a instruction_from_name getter
2021-12-21 05:03:44 +03:30
Ali Mohammad Pur
d471405caf
LibWasm: Print the block type for structured arguments
2021-12-21 05:03:44 +03:30
Ali Mohammad Pur
76ed7f2b20
LibWasm: Fix silly typo in f32 reinterpret validation
2021-12-21 05:03:44 +03:30
Ali Mohammad Pur
fecbf0e03a
LibWasm: Make blocks that take arguments actually work
...
Previously we were ignoring the actual parameters and setting the arity
to an incorrect value, which could cause crashes (or unexpected traps).
2021-12-21 05:03:44 +03:30
Ali Mohammad Pur
b5ca290605
LibWasm: Implement memory.init and passive mode data
2021-12-21 05:03:44 +03:30
Andreas Kling
216e21a1fa
AK: Convert AK::Format formatting helpers to returning ErrorOr<void>
...
This isn't a complete conversion to ErrorOr<void>, but a good chunk.
The end goal here is to propagate buffer allocation failures to the
caller, and allow the use of TRY() with formatting functions.
2021-11-17 00:21:13 +01:00
Andreas Kling
03ddda7979
LibWasm: Fix broken build after merging un-rebased Validator changes
2021-11-11 09:27:00 +01:00
Ali Mohammad Pur
3680aa253d
LibWasm: Remove traps caught by validation
2021-11-11 09:20:04 +01:00
Ali Mohammad Pur
7d1142e2c8
LibWasm: Implement module validation
2021-11-11 09:20:04 +01:00
Ali Mohammad Pur
30736c39b9
LibWasm: Make opcode definitions enumerable through a macro
2021-11-11 09:20:04 +01:00
Andreas Kling
a15ed8743d
AK: Make ByteBuffer::try_* functions return ErrorOr<void>
...
Same as Vector, ByteBuffer now also signals allocation failure by
returning an ENOMEM Error instead of a bool, allowing us to use the
TRY() and MUST() patterns.
2021-11-10 21:58:58 +01:00
Andreas Kling
88b6428c25
AK: Make Vector::try_* functions return ErrorOr<void>
...
Instead of signalling allocation failure with a bool return value
(false), we now use ErrorOr<void> and return ENOMEM as appropriate.
This allows us to use TRY() and MUST() with Vector. :^)
2021-11-10 21:58:58 +01:00
Ben Wiederhake
0f35ae13fb
LibWasm: Add missing forward declaration to Printer/Printer.h
2021-10-06 23:52:40 +01:00
Ben Wiederhake
32e98d0924
Libraries: Use AK::Variant default initialization where appropriate
2021-09-21 04:22:52 +04:30
Ben Wiederhake
6c8eea6f5e
LibWasm: Avoid making StringView of temporary ByteBuffer
2021-09-11 13:22:51 +03:00
Andreas Kling
6ad427993a
Everywhere: Behaviour => Behavior
2021-09-07 13:53:14 +02:00
Ali Mohammad Pur
97e97bccab
Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safe
2021-09-06 01:53:26 +02:00
Ali Mohammad Pur
3a9f00c59b
Everywhere: Use OOM-safe ByteBuffer APIs where possible
...
If we can easily communicate failure, let's avoid asserting and report
failure instead.
2021-09-06 01:53:26 +02:00
Ali Mohammad Pur
09dd397160
LibWeb+LibWasm: Implement the WebAssembly.Table object
2021-09-05 15:42:50 +04:30
Ali Mohammad Pur
d52a26de3f
LibWasm: Move the vector size limit to Constants.h and increase it a bit
2021-09-05 15:42:50 +04:30
Ali Mohammad Pur
b64d6bb3a3
LibWasm: Limit the number of function locals
...
It's possible for the module to request too many locals, we now reject
such modules instead of trying to allocate space for them.
The value itself is chosen arbitrarily, so future tweaks _might_ be
necessary.
Found by OSS-Fuzz: https://oss-fuzz.com/testcase?key=4755809098661888
2021-08-31 16:37:49 +02:00
Ali Mohammad Pur
f492e98f19
LibWasm: Make the Truncate operator trap on undefined results
2021-08-30 22:47:02 +02:00
Ali Mohammad Pur
2c7e2e351a
LibWasm: Implement fx.nearest using nearbyint() instead of round()
...
This instruction wants RoundingMode::ToEven, so let's use the correct
function.
2021-08-30 22:47:02 +02:00
Ali Mohammad Pur
04e3965b09
LibWasm: Use Operators::BitShiftRight for i64.shru
...
Using a left-shift operator for a right shift operation is not exactly
the most correct action :P
2021-08-26 00:51:30 +02:00
Ali Mohammad Pur
8b6397446e
LibWasm: Move some Values and Vector<Value>s instead of copying them
2021-08-12 21:03:53 +02:00
Ali Mohammad Pur
fa2ae02564
LibWasm: Avoid calculating stack bounds on each wasm call
...
We only need to know the initial bounds, which we calculate by default
when the interpreter is constructed.
This cuts down on syscalls and makes wasm calls a lot cheaper.
2021-08-12 21:03:53 +02:00
Ali Mohammad Pur
2b35e9f9be
LibWasm: Generate Value::type() on the fly instead of storing it
...
The variant member already contains enough information to give us the
type when needed, so remove the type member and synthesize it when
needed, this allows lots of optimisation opportunaties when copying and
moving Values around.
2021-08-12 21:03:53 +02:00
Ali Mohammad Pur
4060f18d7e
LibWasm: Replace memory write macros with templated functions
2021-08-12 21:03:53 +02:00
Ali Mohammad Pur
b6381f785d
LibWasm: Make memory operation address calculation match the spec
...
...or rather, match what the spec _means_ to say, not what it actually
says.
2021-08-12 21:03:53 +02:00
Ali Mohammad Pur
ad3de4648a
LibWasm: Replace memory read macros with templated functions
2021-08-12 21:03:53 +02:00
Ali Mohammad Pur
563b402f04
LibWasm: Replace the numeric operation macros with templated functions
...
This should make debugging and profiling much better, at little to no
runtime cost.
Also moves off the operator definitions to a separate header, so it
should also improve the editing experience quite a bit.
2021-08-12 21:03:53 +02:00
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