From f02c8328db55a785de2c73293011653f213b617c Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Mon, 8 May 2017 15:37:14 +0200 Subject: [PATCH] init: access Ram_session as const This is now possible because the new 'used_ram' and 'ram_quota' RPC functions are declared as const. Issue #2398 --- repos/base/include/base/child.h | 10 ++++++---- repos/base/include/base/local_connection.h | 5 +++++ repos/os/src/init/child.cc | 7 +------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/repos/base/include/base/child.h b/repos/base/include/base/child.h index c304872b30..d071cd4655 100644 --- a/repos/base/include/base/child.h +++ b/repos/base/include/base/child.h @@ -535,7 +535,8 @@ class Genode::Child : protected Rpc_object, typedef typename CONNECTION::Session_type SESSION; - SESSION &session() { return _connection->session(); } + SESSION &session() { return _connection->session(); } + SESSION const &session() const { return _connection->session(); } Capability cap() const { return _connection.constructed() ? _connection->cap() @@ -661,9 +662,10 @@ class Genode::Child : protected Rpc_object, Parent_capability parent_cap() const { return cap(); } - Ram_session &ram() { return _ram.session(); } - Cpu_session &cpu() { return _cpu.session(); } - Pd_session &pd() { return _pd .session(); } + Ram_session &ram() { return _ram.session(); } + Ram_session const &ram() const { return _ram.session(); } + Cpu_session &cpu() { return _cpu.session(); } + Pd_session &pd() { return _pd .session(); } /** * Request factory for creating session-state objects diff --git a/repos/base/include/base/local_connection.h b/repos/base/include/base/local_connection.h index 65305d9ff7..3866ccbe1e 100644 --- a/repos/base/include/base/local_connection.h +++ b/repos/base/include/base/local_connection.h @@ -135,6 +135,11 @@ class Genode::Local_connection : Local_connection_base throw Parent::Service_denied(); } + SESSION const &session() const + { + return const_cast(this)->session(); + } + Local_connection(Service &service, Id_space &id_space, Parent::Client::Id id, Args const &args, Affinity const &affinity, diff --git a/repos/os/src/init/child.cc b/repos/os/src/init/child.cc index b585b6c019..548609d601 100644 --- a/repos/os/src/init/child.cc +++ b/repos/os/src/init/child.cc @@ -287,12 +287,7 @@ void Init::Child::report_state(Xml_generator &xml, Report_detail const &detail) xml.attribute("assigned", String<32> { Number_of_bytes(_resources.assigned_ram_quota.value) }); - /* - * The const cast is needed because there is no const - * accessor for the RAM session of the child. - */ - auto &nonconst_child = const_cast(_child); - generate_ram_info(xml, nonconst_child.ram()); + generate_ram_info(xml, _child.ram()); if (_requested_resources.constructed()) xml.attribute("requested", String<32> {