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

@ -22,13 +22,17 @@ namespace Genode { template <typename> class Allocation; }
/**
* Representation of an allocation
*
* The 'Allocation' base class provides a guard mechanism for reverting the
* allocation at destruction time of an 'Allocation' object, unless the
* 'deallocate' member is manually set to false. The 'ALLOCATOR' is expected
* to implement a '_free' method performing the deallocation.
* An 'Allocation' object holds allocator-type-specific attributes ('Attr'),
* which are directly accessible in the scope of the 'Allocation' object.
* It provides a guard mechanism for reverting the allocation at destruction
* time of an 'Allocation' object. The automatic deallocation can be manually
* discharged by setting the 'deallocate' member to 'false'.
*
* An 'Allocation' object holds allocator-type-specific attributes ('Attr')
* that are directly accessible in the scope of the 'Allocation' object.
* The 'ALLOCATOR' type is expected to implement a '_free' method performing
* the deallocation. This method is prefixed with '_' to indicate that it is
* not meant to be explicitly called. It is supposed to be called only at the
* destruction time of an 'Allocation' or by allocator wrappers such as
* 'Ram::Accounted_allocator'.
*/
template <typename ALLOC>
class Genode::Allocation : Noncopyable, public ALLOC::Attr