Commit graph

130 commits

Author SHA1 Message Date
Tim Schumacher
874c7bba28 LibCore: Remove Stream.h 2023-02-13 00:50:07 +00:00
Tim Schumacher
220fbcaa7e AK: Remove the fallible constructor from FixedMemoryStream 2023-02-08 17:44:32 +00:00
Tim Schumacher
093cf428a3 AK: Move memory streams from LibCore 2023-01-29 19:16:44 -07:00
Sam Atkins
53ebe607f8 LibWasm: Implement data.drop instruction 2023-01-28 22:57:25 +03:30
Sam Atkins
a2f42512c2 LibWasm: Move memory.init code together with other memory.foo impls
And add a spec link while I'm at it.
2023-01-28 22:57:25 +03:30
Sam Atkins
330911a274 LibWasm: Implement memory.copy instruction 2023-01-28 22:57:25 +03:30
Sam Atkins
42adba5ad4 LibWasm: Implement memory.fill instruction 2023-01-28 22:57:25 +03:30
Sam Atkins
8d31e04b8a LibWasm: Remove declarations for non-existent methods 2023-01-27 20:33:18 +00:00
Tim Schumacher
2552399bcd LibWasm: Use Core::Stream to read values in the bytecode interpreter 2023-01-25 17:10:05 +03:30
Tim Schumacher
409fb0fe79 LibWasm: Port Wasm::Printer to Core::Stream 2023-01-25 17:10:05 +03:30
Tim Schumacher
52cb066cae LibWasm: Use AllocatingMemoryStream around Wasm::Printer 2023-01-20 20:48:40 +00:00
Ben Wiederhake
8a331d4fa0 Everywhere: Move AK/Debug.h include to using files or remove 2023-01-02 20:27:20 -05:00
Andrew Kaster
9a66a9ac4a LibWasm: Split SaturatingTruncate conversion function by float/non-float
It's possible to construct a floating point value that when converted to
double is not larger than i64::max(), but when remaining a float is
larger. This patch avoids that edge case with some even less exciting if
constexpr branches to fix a float-cast-overflow UBSAN error on macOS
with llvm 15.0.6.
2022-12-25 07:58:58 -07:00
Linus Groh
57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
Linus Groh
d26aabff04 Everywhere: Run clang-format 2022-12-03 23:52:23 +00:00
Sam Atkins
c33eae24f9 AK+Everywhere: Replace DistinctNumeric bool parameters with named ones
This means that rather than this:

```
AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(u64, true, true, false, false,
    false, true, FunctionAddress);
```

We now have this:
```
AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(u64, FunctionAddress, Arithmetic,
    Comparison, Increment);
```

Which is a lot more readable. :^)

Co-authored-by: Ali Mohammad Pur <mpfard@serenityos.org>
2022-11-11 17:50:53 +03:30
Luke Wilde
8fdf4b43cd LibWasm: Specify which instruction opcode failed validation in error 2022-10-28 10:27:02 +03:30
Luke Wilde
805e6593b9 LibWasm: Add missing validation for memory.copy
This has the exact same validation as memory.fill
2022-10-28 10:27:02 +03:30
Ali Mohammad Pur
21c6e4c257 LibWasm: Calculate the max data segment size correctly
This is given in pages, we need to first convert to bytes before
comparing with bytes.
2022-10-24 15:54:20 +02:00
Linus Groh
5a106b6401 Everywhere: Prefix 'TYPEDEF_DISTINCT_NUMERIC_GENERAL' with 'AK_' 2022-07-22 23:09:43 +01:00
sin-ack
c8585b77d2 Everywhere: Replace single-char StringView op. arguments with chars
This prevents us from needing a sv suffix, and potentially reduces the
need to run generic code for a single character (as contains,
starts_with, ends_with etc. for a char will be just a length and
equality check).

No functional changes.
2022-07-12 23:11:35 +02:00
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
sin-ack
e5f09ea170 Everywhere: Split Error::from_string_literal and Error::from_string_view
Error::from_string_literal now takes direct char const*s, while
Error::from_string_view does what Error::from_string_literal used to do:
taking StringViews. This change will remove the need to insert `sv`
after error strings when returning string literal errors once
StringView(char const*) is removed.

No functional changes.
2022-07-12 23:11:35 +02:00
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
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
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
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
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
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