Commit graph

26 commits

Author SHA1 Message Date
Andreas Kling
8a8625b399 LibWasm: Require virtual storage for wasm32 memory
Reserve the wasm32 virtual address space when creating an i32 memory.
Crash if the reservation fails instead of using ByteBuffer storage.

This keeps wasm32 memory on the virtual path used for fault recovery.
2026-06-10 17:34:16 +02:00
Ali Mohammad Pur
c414f31ecf LibWasm: Correctly handle memory64's addr types in the interpreter 2026-06-10 14:10:57 +02:00
Ali Mohammad Pur
f81717d4c8 LibWasm: Allow allocating max-size wasm32 memories
We used to disallow allocating 65536 pages, but that's fine as per spec.
2026-06-10 14:10:57 +02:00
Ali Mohammad Pur
08221aebab LibWasm: Start execution immediately after validation
This adds a tier-up mechanism at loop edges, making it so we can
seamlessly (ish) transition between interpreted and native code so we
can start running wasm code immediately after validation while
compilation happens in the background, and switching to native code
eventually once we hit a big enough function that would benefit from
being compiled to begin with.
2026-06-05 00:08:11 +02:00
Ali Mohammad Pur
3c89c36158 LibWasm+LibWeb: Restore disk cache for compiled wasm modules
Also untangle the confusing validation layering on async compilation.
2026-06-05 00:08:11 +02:00
Andreas Kling
164ed80244 Meta: Enable exit-time destructor warnings for libraries
Enable -Wexit-time-destructors for all in-tree library targets and
update process-lifetime library statics so they no longer register
exit-time destructors. Long-lived caches, lookup tables, singleton
registries, and generated constants now use NeverDestroyed or leaked
references where the data is intended to live until process exit.

Update LibWeb, LibLine, and the binding generators so regenerated
sources follow the same rule instead of reintroducing destructed
statics.
2026-06-04 19:20:49 +02:00
Ali Mohammad Pur
841572f358 LibWeb+LibWasm: Don't wait for JIT-compilation of wasm modules
Return from the jsapi calls when we have a module that satisfies the
state required by the spec, and let jit compilation (if it's happening)
continue in the background.
This also means we no longer do the full compilation pipeline for
validate().
2026-06-03 11:51:43 +02:00
Ali Mohammad Pur
f54ad4ca25 LibWasm: Only build the compiled function table once per module 2026-05-27 09:52:34 +02:00
Ali Mohammad Pur
842e8a6796 LibWasm+LibWeb: Add per-module wasm compile stats 2026-05-27 09:52:34 +02:00
Ali Mohammad Pur
2419cce8d8 LibWasm+LibWeb: Serialize and save compiled wasm as a cache blob 2026-05-27 09:52:34 +02:00
Ali Mohammad Pur
a36f6abedb LibWasm+LibWeb: Properly track module lifetime with function refs 2026-05-10 16:41:42 +02:00
Ali Mohammad Pur
f181d24dc0 LibWasm: Prepare for VM and direct function calls
Introduce MemoryBuffer, a memory backing store that uses mmap to reserve
the full wasm32 address space (4 GiB + guard pages) upfront, growing
without a copy and falling back to a ByteBuffer when mmap fails.
Also let Frame know how to handle non-owned locals (to e.g. allow
allocating them on the native stack.)
2026-05-10 16:41:42 +02:00
Andreas Kling
eb789e790e Everywhere: Use AK::SaturatingMath and remove Checked saturating APIs
Port all callers of Checked<T>::saturating_add/sub/mul to the new
standalone functions in AK/SaturatingMath.h, and remove the old
APIs from Checked.
2026-03-21 18:20:09 -05:00
Marcus Nilsson
bfa51c2555 LibWasm: Parse struct types and support multiple types in type section
This patch adds support for parsing structs in the type section.

It also removes the assumption that all types in the type section are
function types, adding appropriate validation.

Spec tests struct.3 and struct.4 have been disable as this would
require expanding `ValueType` to include more heap-types.
2026-02-04 14:29:22 +01:00
Ali Mohammad Pur
921373a045 LibWasm: Implement call argument forwarding using call records 2026-02-02 14:11:49 +01:00
Ali Mohammad Pur
70f839ccb2 LibWasm: Take call arguments as references and recycle the allocations
This opens the way for a allocated-at-start call frame optimisation
(that will come in a future commit).
2026-02-02 14:11:49 +01:00
Ali Mohammad Pur
b89ecfc6bc LibWasm: Split parameters from locals 2026-02-02 14:11:49 +01:00
Ali Mohammad Pur
651c64ebac LibWasm: Better handle oversized table allocation requests 2025-12-12 19:12:53 +01:00
Ali Mohammad Pur
d99f663b1a LibWasm: Implement parsing/validation for proposal exception-handling
Actual execution traps for now.
2025-10-15 01:26:29 +02:00
Ali Mohammad Pur
8138c2f48b LibWasm: Follow the updated spec on instantiation
The spec now permits access to all globals for all segment initializers,
as well as previously-defined globals for the global initializers.
2025-10-15 01:26:29 +02:00
Ali Mohammad Pur
22448b0c35 LibWasm: Move the interpreter IP out of the configuration object
This, along with moving the sources and destination out of the config
object, makes it so we don't have to double-deref to get to them on each
instruction, leading to a ~15% perf improvement on dispatch.
2025-08-26 15:20:33 +02:00
Jelle Raaijmakers
58c3a391a3 LibWeb+LibWasm: Reject module instantiation with correct error type
The spec tells us to reject the promise with a RuntimeError instead of a
LinkError whenever the module's start function fails during module
instantiation. Fixes 1 WPT subtest in `wasm/core`.
2025-07-25 15:13:28 +02:00
Timothy Flynn
7280ed6312 Meta: Enforce newlines around namespaces
This has come up several times during code review, so let's just enforce
it using a new clang-format 20 option.
2025-05-14 02:01:59 -06:00
Ali Mohammad Pur
51bab5b186 LibWasm: Make traps hold on to externally-managed data
...instead of specially handling JS::Completion.
This makes it possible for LibWeb/LibJS to have full control over how
these things are made, stored, and visited (whenever).

Fixes an issue where we couldn't roundtrip a JS exception through Wasm.
2025-04-22 08:43:46 -06:00
Pavel Shliak
e08f6a69b2 LibWasm: Respect instance.types() bounds 2024-12-09 12:30:41 +01:00
Timothy Flynn
93712b24bf Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Renamed from Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp (Browse further)