Commit graph

25 commits

Author SHA1 Message Date
sin-ack
3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02:00
mjz19910
3102d8e160 Everywhere: Fix many spelling errors 2022-01-07 10:56:59 +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
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
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
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
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
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
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
02b3238c41 LibWasm: Parse the "extend" set of instructions 2021-06-02 16:09:16 +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
207379165f LibWasm: Fix nested structured instruction parsing
Previously, the ip would not be propagated correctly, and we would
produce invalid jumps when more than one level of nesting was involved.
This makes loops work :P
2021-05-21 00:15:23 +01:00
Ali Mohammad Pur
7fec66dd1c LibWasm: Make clang happy by removing an 'extra' set of parenthesis
These aren't actually an extra set, without them the fold operation
would be syntactically invalid.
Also remove possible cast of float->double/double->float in Value::to()
2021-05-17 23:25:30 +02:00
Ali Mohammad Pur
faa34a0a8b LibWasm: Do not resize() the function signature list to preallocate
Instead, use `ensure_capacity()`.
2021-05-17 23:25:30 +02:00
Ali Mohammad Pur
025b3349e4 LibWasm: Make structured_end() jump to the instruction after itself 2021-05-17 23:25:30 +02:00
Ali Mohammad Pur
a5194274af LibWasm: Stub out/implement parsing of all ElementSection segments
Previously, this was parsing only one kind because I mistakenly assumed
that they all had the same shape, now it can parse two kinds, and will
return NotImplemented for the rest.
2021-05-13 19:44:32 +01:00
Ali Mohammad Pur
2b755f1fbf LibWasm: Make the Module ctor generate a list of module functions
This list is supposed to be accessed rather frequently, so there's no
reason to make things slower by generating it many times on the spot.
2021-05-13 19:44:32 +01:00
Ali Mohammad Pur
6e891822c5 LibWasm: Implement parsing of the DataCount section
With this, the parser should technically be able to parse all wasm
modules. Any parse failure on correct modules should henceforth be
labelled a bug :^)
2021-05-13 19:44:32 +01:00
Ali Mohammad Pur
7a12f23c28 LibWasm: Un-nest the structured instructions 2021-05-13 19:44:32 +01:00
Ali Mohammad Pur
50cb80649f LibWasm: Implement parsing all remaining instructions
With this, we can parse a module at least as simple as the following C
code would generate:
```c
int add(int x, int y) {
    if (x > y)
        return x + y;
    return y - x; // Haha goteeem
}
```
2021-05-08 22:14:39 +02:00
Ali Mohammad Pur
426878c884 LibWasm: Add some more descriptive parse errors
It's much better to tell the user "hey, the magic numbers don't check
out" than "oh there was a problem with your input" :P
Also refactors some stuff to make it possible to efficiently use the
parser error enum without it getting in the way.
2021-05-08 22:14:39 +02:00
Ali Mohammad Pur
aa4d8d26b9 LibWasm: Start implementing a basic WebAssembly binary format parser
This can currently parse a really simple module.
Note that it cannot parse the DataCount section, and it's still missing
almost all of the instructions.
This commit also adds a 'wasm' test utility that tries to parse a given
webassembly binary file.
It currently does nothing but exit when the parse fails, but it's a
start :^)
2021-05-08 22:14:39 +02:00