Commit Graph

9 Commits

Author SHA1 Message Date
Ben Wiederhake
03526a7f2b AK: Make BumpAllocator work in multi-threaded environments
Fixes #10578.
2021-10-31 18:43:03 +01:00
Ben Wiederhake
50698a0db4 AK: Prevent accidental misuse of BumpAllocator
In particular, we implicitly required that the caller initializes the
returned instances themselves (solved by making
UniformBumpAllocator::allocate call the constructor), and BumpAllocator
itself cannot handle classes that are not trivially deconstructible
(solved by deleting the method).

Co-authored-by: Ali Mohammad Pur <ali.mpfard@gmail.com>
2021-10-23 19:02:54 +01:00
Ben Wiederhake
5d865d574a AK: Fix BumpAllocator iteration if last object doesn't align
This fixes two bugs:

1. `end_offset` was missing the alignment that might have been
   introduced while computing `base_ptr`.
2. Ignoring point 1, `end_offset` computed the offset of the first byte
   that is outside the current chunk. However, this might be in the
   middle of a (hypothetical) object! The loop treats `end_offset` as if
   it points to the first byte beyond the last (valid) object. So if the
   last few bytes of the chunk are unused, the loop iterates once too
   often.

Found by OSS Fuzz, long-standing issue (since 2021-07-31)
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=38733
(This probably also resolves some other issues that go through
RegexMatcher.)

See also: 0f1425c895
2021-10-23 19:02:54 +01:00
Ben Wiederhake
885b69c877 AK: Check consistency during BumpAllocator allocation 2021-10-23 19:02:54 +01:00
Ali Mohammad Pur
a72eea6408 AK: Give BumpAllocator a single-block cache
This avoid excessive mmap/munmap traffic in normal operation.
2021-09-13 14:38:53 +04:30
Ali Mohammad Pur
0f1425c895 AK: Avoid OOB access in UniformBumpAllocator::destroy_all()
Otherwise we would end up calling T::~T() on some random memory right
after our mapped block, which is most likely a pretty bad thing to do :P
2021-08-13 04:42:34 +04:30
Daniel Bertalan
301cab188c AK: Use explode_byte in BumpAllocator.h
When compiling this code with Clang, both branches of the ternary
operator get evaluated at compile-time, triggering a warning about a
narrowing implicit conversion. We can use `explode_byte` instead.
2021-08-08 10:55:36 +02:00
Timothy Flynn
dae7674ca9 AK: Allow configuring the BumpAllocator chunk size 2021-08-04 11:18:24 +02:00
Ali Mohammad Pur
b034fa9f1f AK: Add a simple bump allocator 2021-08-02 17:22:50 +04:30