Introduce new 'Ram' API types

The new types in base/ram.h model different allocation scenarios and
error cases by mere C++ types without using exceptions. They are meant
to replace the former 'Ram_allocator' interface. As of now, the
'Unmapped_allocator' closely captures the former 'Ram_allocator'
semantics. The 'Constrained_allocator' is currently an alias for
'Unmapped_allocator' but is designated for eventually allocating
mapped RAM.

In contrast to the 'Ram_allocator' interface, which talked about
dataspace capabilites but left the lifetime management of the
allocated RAM to the caller, the new API represents an allocation
as a guard type 'Allocation', which deallocates on destruction by
default.

Allocation errors are captured by a 'Result' type that follows
the 'Attempt' pattern.

As a transitionary feature, the patch largely maintains API
compatibility with the original 'Ram_allocator' by providing
the original (exception-based) 'Ram_allocator::alloc' and
'Ram_allocator::free' methods as a wrapper around the new
'Ram::Constrained_allocator'. So components can be gradually
updated to the new 'Ram::' interface.

Issue #5502
This commit is contained in:
Norman Feske
2025-04-02 11:11:01 +02:00
parent e9558a36f9
commit 689fc1eb93
40 changed files with 593 additions and 502 deletions

View File

@ -76,12 +76,9 @@ class Stack_area_region_map : public Genode::Region_map
struct Stack_area_ram_allocator : Genode::Ram_allocator
{
Alloc_result try_alloc(Genode::size_t, Genode::Cache) override {
return Genode::Ram_dataspace_capability(); }
Result try_alloc(Genode::size_t, Genode::Cache) override { return { *this, { } }; }
void free(Genode::Ram_dataspace_capability) override { }
Genode::size_t dataspace_size(Genode::Ram_dataspace_capability) override { return 0; }
void _free(Genode::Ram::Allocation &) override { }
};