mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-18 07:08:18 +00:00
base: new 'Ram_allocator' interface
The 'Ram_allocator' interface contains the subset of the RAM session interface that is needed to satisfy the needs of the 'Heap' and 'Sliced_heap'. Its small size makes it ideal for intercepting memory allocations as done by the new 'Constrained_ram_allocator' wrapper class, which is meant to replace the existing 'base/allocator_guard.h' and 'os/ram_session_guard.h'. Issue #2398
This commit is contained in:
committed by
Christian Helmuth
parent
5a468919bb
commit
ff68d77c7d
@ -58,7 +58,7 @@ void Heap::Dataspace_pool::remove_and_free(Dataspace &ds)
|
||||
ds.~Dataspace();
|
||||
|
||||
region_map->detach(ds_local_addr);
|
||||
ram_session->free(ds_cap);
|
||||
ram_alloc->free(ds_cap);
|
||||
}
|
||||
|
||||
|
||||
@ -87,13 +87,13 @@ Heap::Dataspace *Heap::_allocate_dataspace(size_t size, bool enforce_separate_me
|
||||
|
||||
/* make new ram dataspace available at our local address space */
|
||||
try {
|
||||
new_ds_cap = _ds_pool.ram_session->alloc(size);
|
||||
new_ds_cap = _ds_pool.ram_alloc->alloc(size);
|
||||
ds_addr = _ds_pool.region_map->attach(new_ds_cap);
|
||||
} catch (Ram_session::Alloc_failed) {
|
||||
return 0;
|
||||
} catch (Region_map::Attach_failed) {
|
||||
warning("could not attach dataspace");
|
||||
_ds_pool.ram_session->free(new_ds_cap);
|
||||
_ds_pool.ram_alloc->free(new_ds_cap);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -258,14 +258,14 @@ void Heap::free(void *addr, size_t)
|
||||
}
|
||||
|
||||
|
||||
Heap::Heap(Ram_session *ram_session,
|
||||
Region_map *region_map,
|
||||
size_t quota_limit,
|
||||
void *static_addr,
|
||||
size_t static_size)
|
||||
Heap::Heap(Ram_allocator *ram_alloc,
|
||||
Region_map *region_map,
|
||||
size_t quota_limit,
|
||||
void *static_addr,
|
||||
size_t static_size)
|
||||
:
|
||||
_alloc(nullptr),
|
||||
_ds_pool(ram_session, region_map),
|
||||
_ds_pool(ram_alloc, region_map),
|
||||
_quota_limit(quota_limit), _quota_used(0),
|
||||
_chunk_size(MIN_CHUNK_SIZE)
|
||||
{
|
||||
|
@ -18,9 +18,9 @@
|
||||
using namespace Genode;
|
||||
|
||||
|
||||
Sliced_heap::Sliced_heap(Ram_session &ram_session, Region_map ®ion_map)
|
||||
Sliced_heap::Sliced_heap(Ram_allocator &ram_alloc, Region_map ®ion_map)
|
||||
:
|
||||
_ram_session(ram_session), _region_map(region_map), _consumed(0)
|
||||
_ram_alloc(ram_alloc), _region_map(region_map), _consumed(0)
|
||||
{ }
|
||||
|
||||
|
||||
@ -47,13 +47,13 @@ bool Sliced_heap::alloc(size_t size, void **out_addr)
|
||||
Block *block = nullptr;
|
||||
|
||||
try {
|
||||
ds_cap = _ram_session.alloc(size);
|
||||
ds_cap = _ram_alloc.alloc(size);
|
||||
block = _region_map.attach(ds_cap);
|
||||
} catch (Region_map::Attach_failed) {
|
||||
error("could not attach dataspace to local address space");
|
||||
_ram_session.free(ds_cap);
|
||||
_ram_alloc.free(ds_cap);
|
||||
return false;
|
||||
} catch (Ram_session::Alloc_failed) {
|
||||
} catch (Ram_allocator::Alloc_failed) {
|
||||
error("could not allocate dataspace with size ", size);
|
||||
return false;
|
||||
}
|
||||
@ -101,7 +101,7 @@ void Sliced_heap::free(void *addr, size_t size)
|
||||
}
|
||||
|
||||
_region_map.detach(local_addr);
|
||||
_ram_session.free(ds_cap);
|
||||
_ram_alloc.free(ds_cap);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user