mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-18 10:46:25 +00:00
parent
365bec38a0
commit
9c6de44f98
87
repos/base/src/core/include/constrained_core_ram.h
Normal file
87
repos/base/src/core/include/constrained_core_ram.h
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* \brief Quota-bounds-checking implementation of the 'Ram_allocator'
|
||||
* interface specifically for core
|
||||
* \author Norman Feske
|
||||
* \date 2017-05-02
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2017 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU Affero General Public License version 3.
|
||||
*/
|
||||
|
||||
#ifndef _CORE__INCLUDE__CORE_CONSTRAINED_CORE_RAM_H_
|
||||
#define _CORE__INCLUDE__CORE_CONSTRAINED_CORE_RAM_H_
|
||||
|
||||
#include <base/allocator.h>
|
||||
|
||||
namespace Genode { class Constrained_core_ram; }
|
||||
|
||||
class Genode::Constrained_core_ram : public Allocator
|
||||
{
|
||||
private:
|
||||
|
||||
Ram_quota_guard &_ram_guard;
|
||||
Cap_quota_guard &_cap_guard;
|
||||
Range_allocator &_core_mem;
|
||||
|
||||
uint64_t core_mem_allocated { 0 };
|
||||
|
||||
public:
|
||||
|
||||
Constrained_core_ram(Ram_quota_guard &ram_guard,
|
||||
Cap_quota_guard &cap_guard,
|
||||
Range_allocator &core_mem)
|
||||
:
|
||||
_ram_guard(ram_guard), _cap_guard(cap_guard), _core_mem(core_mem)
|
||||
{ }
|
||||
|
||||
~Constrained_core_ram()
|
||||
{
|
||||
if (!core_mem_allocated)
|
||||
return;
|
||||
|
||||
error(this, " memory leaking of size ", core_mem_allocated,
|
||||
" in core !");
|
||||
}
|
||||
|
||||
bool alloc(size_t const size, void **ptr) override
|
||||
{
|
||||
size_t const page_aligned_size = align_addr(size, 12);
|
||||
|
||||
Ram_quota_guard::Reservation ram (_ram_guard,
|
||||
Ram_quota{page_aligned_size});
|
||||
/* on some kernels we require a cap, on some not XXX */
|
||||
Cap_quota_guard::Reservation caps(_cap_guard, Cap_quota{1});
|
||||
|
||||
if (!_core_mem.alloc(page_aligned_size, ptr))
|
||||
return false;
|
||||
|
||||
ram.acknowledge();
|
||||
caps.acknowledge();
|
||||
|
||||
core_mem_allocated += page_aligned_size;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void free(void *ptr, size_t const size) override
|
||||
{
|
||||
size_t const page_aligned_size = align_addr(size, 12);
|
||||
|
||||
_core_mem.free(ptr, page_aligned_size);
|
||||
|
||||
_ram_guard.replenish(Ram_quota{page_aligned_size});
|
||||
/* on some kernels we require a cap, on some not XXX */
|
||||
_cap_guard.replenish(Cap_quota{1});
|
||||
|
||||
core_mem_allocated -= page_aligned_size;
|
||||
}
|
||||
|
||||
size_t consumed() const override { return core_mem_allocated; }
|
||||
size_t overhead(size_t size) const override { return 0; }
|
||||
bool need_size_for_free() const override { return true; }
|
||||
};
|
||||
#endif /* _CORE__INCLUDE__CORE_CONSTRAINED_CORE_RAM_H_ */
|
@ -70,7 +70,8 @@ class Genode::Core_env : public Env_deprecated
|
||||
Ram_dataspace_factory::Virt_range { platform()->vm_start(), platform()->vm_size() },
|
||||
_region_map,
|
||||
*((Pager_entrypoint *)nullptr),
|
||||
"" /* args to native PD */)
|
||||
"" /* args to native PD */,
|
||||
*platform_specific()->core_mem_alloc())
|
||||
{
|
||||
_pd_session.init_cap_and_ram_accounts();
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ class Genode::Pd_root : public Genode::Root_component<Genode::Pd_session_compone
|
||||
Pager_entrypoint &_pager_ep;
|
||||
Range_allocator &_phys_alloc;
|
||||
Region_map &_local_rm;
|
||||
Range_allocator &_core_mem;
|
||||
|
||||
static Ram_dataspace_factory::Phys_range _phys_range_from_args(char const *args)
|
||||
{
|
||||
@ -67,7 +68,8 @@ class Genode::Pd_root : public Genode::Root_component<Genode::Pd_session_compone
|
||||
_phys_alloc,
|
||||
_phys_range_from_args(args),
|
||||
_virt_range_from_args(args),
|
||||
_local_rm, _pager_ep, args);
|
||||
_local_rm, _pager_ep, args,
|
||||
_core_mem);
|
||||
}
|
||||
|
||||
void _upgrade_session(Pd_session_component *pd, const char *args)
|
||||
@ -85,10 +87,12 @@ class Genode::Pd_root : public Genode::Root_component<Genode::Pd_session_compone
|
||||
Pager_entrypoint &pager_ep,
|
||||
Range_allocator &phys_alloc,
|
||||
Region_map &local_rm,
|
||||
Allocator &md_alloc)
|
||||
Allocator &md_alloc,
|
||||
Range_allocator &core_mem)
|
||||
:
|
||||
Root_component<Pd_session_component>(&ep, &md_alloc),
|
||||
_ep(ep), _pager_ep(pager_ep), _phys_alloc(phys_alloc), _local_rm(local_rm)
|
||||
_ep(ep), _pager_ep(pager_ep), _phys_alloc(phys_alloc),
|
||||
_local_rm(local_rm), _core_mem(core_mem)
|
||||
{ }
|
||||
};
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <base/internal/stack_area.h>
|
||||
|
||||
/* core includes */
|
||||
#include <constrained_core_ram.h>
|
||||
#include <platform_pd.h>
|
||||
#include <signal_broker.h>
|
||||
#include <rpc_cap_factory.h>
|
||||
@ -47,6 +48,7 @@ class Genode::Pd_session_component : public Session_object<Pd_session>
|
||||
|
||||
Rpc_entrypoint &_ep;
|
||||
Constrained_ram_allocator _constrained_md_ram_alloc;
|
||||
Constrained_core_ram _constrained_core_ram_alloc;
|
||||
Sliced_heap _sliced_heap;
|
||||
Capability<Parent> _parent;
|
||||
Signal_broker _signal_broker;
|
||||
@ -122,14 +124,17 @@ class Genode::Pd_session_component : public Session_object<Pd_session>
|
||||
Virt_range virt_range,
|
||||
Region_map &local_rm,
|
||||
Pager_entrypoint &pager_ep,
|
||||
char const *args)
|
||||
char const *args,
|
||||
Range_allocator &core_mem)
|
||||
:
|
||||
Session_object(ep, resources, label, diag),
|
||||
_ep(ep),
|
||||
_constrained_md_ram_alloc(*this, *this, *this),
|
||||
_constrained_core_ram_alloc(*this, *this, core_mem),
|
||||
_sliced_heap(_constrained_md_ram_alloc, local_rm),
|
||||
_signal_broker(_sliced_heap, ep, ep),
|
||||
_ram_ds_factory(ep, phys_alloc, phys_range, local_rm, _sliced_heap),
|
||||
_ram_ds_factory(ep, phys_alloc, phys_range, local_rm,
|
||||
_constrained_core_ram_alloc),
|
||||
_rpc_cap_factory(_sliced_heap),
|
||||
_native_pd(*this, args),
|
||||
_address_space(ep, _sliced_heap, pager_ep,
|
||||
|
@ -37,12 +37,7 @@ class Genode::Ram_dataspace_factory : public Ram_allocator,
|
||||
|
||||
struct Virt_range { addr_t start, size; };
|
||||
|
||||
/*
|
||||
* Dimension '_ds_slab' such that slab blocks (including the
|
||||
* meta-data overhead of the sliced-heap blocks) are page sized.
|
||||
*/
|
||||
static constexpr size_t SLAB_BLOCK_SIZE =
|
||||
get_page_size() - Sliced_heap::meta_data_size();
|
||||
static constexpr size_t SLAB_BLOCK_SIZE = 4096;
|
||||
|
||||
private:
|
||||
|
||||
@ -92,10 +87,10 @@ class Genode::Ram_dataspace_factory : public Ram_allocator,
|
||||
Range_allocator &phys_alloc,
|
||||
Phys_range phys_range,
|
||||
Region_map &local_rm,
|
||||
Sliced_heap &sliced_heap)
|
||||
Allocator &allocator)
|
||||
:
|
||||
_ep(ep), _phys_alloc(phys_alloc), _phys_range(phys_range),
|
||||
_ds_slab(sliced_heap, _initial_sb)
|
||||
_ds_slab(allocator, _initial_sb)
|
||||
{ }
|
||||
|
||||
~Ram_dataspace_factory()
|
||||
|
@ -256,7 +256,9 @@ int main()
|
||||
static Rm_root rm_root (&ep, &sliced_heap, pager_ep);
|
||||
static Cpu_root cpu_root (&ep, &ep, &pager_ep, &sliced_heap,
|
||||
Trace::sources());
|
||||
static Pd_root pd_root (ep, pager_ep, *platform()->ram_alloc(), local_rm, sliced_heap);
|
||||
static Pd_root pd_root (ep, pager_ep, *platform()->ram_alloc(),
|
||||
local_rm, sliced_heap,
|
||||
*platform_specific()->core_mem_alloc());
|
||||
static Log_root log_root (&ep, &sliced_heap);
|
||||
static Io_mem_root io_mem_root (&ep, &ep, platform()->io_mem_alloc(),
|
||||
platform()->ram_alloc(), &sliced_heap);
|
||||
|
Loading…
Reference in New Issue
Block a user