Commit graph

26 commits

Author SHA1 Message Date
Andreas Kling
956a2b96d5 LibWeb: Allocate layout and painting objects with mimalloc
Add class-local allocation macros for operator new/delete through AK's
malloc helpers. The macros can optionally choose a HeapPartition.
Add Layout and Painting partitions, plus basic partition stats helpers.

Use the new partitions for LibWeb layout and painting object hierarchies
and layout-state side data.
2026-06-13 19:08:08 +02:00
Andreas Kling
fc02ab95fe AK: Allocate string data in a dedicated heap partition
Add a string heap partition and route long AK string backing
allocations through it.

Give StringBuilder partition-aware outlined storage so adopted String
and Utf16String buffers are allocated from the string heap. Keep the
string heap thread-local because mimalloc heaps may only allocate from
their creating thread, while cross-thread frees are handled by mimalloc.
2026-06-10 20:38:18 +02:00
Andreas Kling
19dd5bef60 LibJS: Isolate object property storage
Add a JSObjectStorage heap partition and route heap-backed property
storage (both named and indexed element buffers) through it.

These buffers are directly shaped by script-visible object and array
operations, so keeping them separate from the general heap makes a
corruption primitive less useful against unrelated allocations.
2026-06-10 17:36:54 +02:00
Andreas Kling
45c499d185 LibJS: Isolate ArrayBuffer backing stores
Move owned ArrayBuffer and SharedArrayBuffer data blocks into the
ArrayBuffer heap partition. Keep unowned and host storage explicit, so
Wasm memory and external LibWeb buffers stay outside this partition.

Introduce DataBlock::OwnedBackingStore as the LibJS-owned byte storage
representation. Expose byte spans instead of a ByteBuffer object, giving
ArrayBuffer one allocation boundary that can later grow toward guarded
or caged storage.

Let callers that need ByteBuffer data copy from backing-store bytes.
Keep TransferArrayBuffer zero-copy by moving the DataBlock directly
instead of materializing a ByteBuffer in between.

Update the Wasm typed-array test helper to compare viewed byte ranges
after ArrayBuffer stops exposing ByteBuffer identity.
2026-06-10 14:50:10 +02:00
Andreas Kling
058c0ca6ed AK: Add partition-aware kmalloc overloads
Introduce HeapPartition and overload kmalloc and krealloc so allocation
sites can opt into a specific heap partition. Keep the default allocator
API unchanged. The only initial partition is General, which maps to the
regular allocator path.

Keep sanitizer builds on the system allocator so LeakSanitizer can still
trace AK container allocations. Remove the obsolete Serenity-specific
allocator branch while updating this file.
2026-06-10 14:50:10 +02:00
Andreas Kling
b23aa38546 AK: Adopt mimalloc v2 as main allocator
Use mimalloc for Ladybird-owned allocations without overriding malloc().
Route kmalloc(), kcalloc(), krealloc(), and kfree() through mimalloc,
and put the embedded Rust crates on the same allocator via a shared
shim in AK/kmalloc.cpp.

This also lets us drop kfree_sized(), since it no longer used its size
argument. StringData, Utf16StringData, JS object storage, Rust error
strings, and the CoreAudio playback helpers can all free their AK-backed
storage with plain kfree().

Sanitizer builds still use the system allocator. LeakSanitizer does not
reliably trace references stored in mimalloc-managed AK containers, so
static caches and other long-lived roots can look leaked. Pass the old
size into the Rust realloc shim so aligned fallback reallocations can
move posix_memalign-backed blocks safely.

Static builds still need a little linker help. macOS app binaries need
the Rust allocator entry points forced in from liblagom-ak.a, while
static ELF links can pull in identical allocator shim definitions from
multiple Rust staticlibs. Keep the Apple -u flags and allow those
duplicate shim symbols for LibJS and LibRegex links on Linux and BSD.
2026-04-08 09:57:53 +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
Andreas Kling
cc4b3cbacc Meta: Update my e-mail address everywhere 2024-10-04 13:19:50 +02:00
Tim Ledbetter
5ca2f4dfd7 Everywhere: Remove all KERNEL #defines 2024-06-18 09:36:25 +02:00
Dan Klishch
5ed7cd6e32 Everywhere: Use east const in more places
These changes are compatible with clang-format 16 and will be mandatory
when we eventually bump clang-format version. So, since there are no
real downsides, let's commit them now.
2024-04-19 06:31:19 -04:00
Tim Schumacher
22f0d04f43 AK: Provide a fallback definition for std::nothrow 2023-01-29 19:16:44 -07:00
Andrew Kaster
828441852f Everywhere: Replace uses of __serenity__ with AK_OS_SERENITY
Now that we have OS macros for essentially every supported OS, let's try
to use them everywhere.
2022-10-10 12:23:12 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Daniel Bertalan
a482a3e609 AK: Declare operators new and delete as global functions
This fixes a build issue introduced in 23d66fe, where the compiler
statically detected that that mismatching new and delete operators were
used.

Clang generates a warning for this, for the reasons described in the
comment in `AK/kmalloc.cpp`, but GCC does not.

Besides moving the allocator functions into a `.cpp` file, declarations
in `AK/kmalloc.cpp` were reordered to have imports at the top, in order
to make the code more readable.
2021-07-05 20:23:42 +02:00
Andreas Kling
6d4874cb2e LibC: Get rid of the now-unneeded AK/kmalloc.cpp 2019-04-20 13:00:25 +02:00
Andreas Kling
301a269ca0 Get rid of SERENITY macro since the compiler already defines __serenity__
This makes it a bit easier to use AK templates out-of-tree.
2019-04-20 12:58:49 +02:00
Andreas Kling
60f236b285 AK: Clean up some of the confusion that is AK/kmalloc.{cpp,h} 2019-04-03 12:07:41 +02:00
Andreas Kling
23bb276fcd LibC: Run constructors on process startup.
Cooperate with the compiler to generate and execute the _init_array list
of constructor functions on userspace program statup. This took two days
to get working, my goodness. :^)
2019-03-27 12:48:21 +01:00
Andreas Kling
ffab6897aa Big, possibly complete sweep of naming changes. 2019-01-31 17:31:23 +01:00
Andreas Kling
4914f3b837 Build LibC and Userland with clang as well. 2018-11-09 14:29:00 +01:00
Andreas Kling
9a086b2d35 Add a kmalloc_eternal() for things that will never be destroyed. 2018-10-31 23:19:15 +01:00
Andreas Kling
16f318408d ELFLoader should fail with an error message for unresolved symbols. 2018-10-25 10:02:04 +02:00
Andreas Kling
9171521752 Integrate ext2 from VFS into Kernel. 2018-10-17 10:57:23 +02:00
Andreas Kling
5d465582a3 Start fixing up AK to work inside the kernel. 2018-10-16 13:59:28 +02:00
Andreas Kling
a181a8f6e7 Run without SimpleMalloc locally for now. 2018-10-10 15:11:43 +02:00
Andreas Kling
5a30055157 Import all this stuff into a single repo called Serenity. 2018-10-10 11:53:07 +02:00