2013-08-10 03:44:55 +02:00
|
|
|
/*
|
|
|
|
* \brief TRACE session implementation
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2013-08-12
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2013-2017 Genode Labs GmbH
|
2013-08-10 03:44:55 +02:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2013-08-10 03:44:55 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* core-internal includes */
|
|
|
|
#include <trace/session_component.h>
|
|
|
|
#include <dataspace/capability.h>
|
|
|
|
#include <base/rpc_client.h>
|
|
|
|
|
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
using namespace Genode::Trace;
|
|
|
|
|
|
|
|
|
|
|
|
Dataspace_capability Session_component::dataspace()
|
|
|
|
{
|
2019-01-30 17:53:16 +01:00
|
|
|
return _argument_buffer.cap();
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t Session_component::subjects()
|
|
|
|
{
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 22:03:22 +02:00
|
|
|
_subjects.import_new_sources(_sources);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2019-01-30 17:53:16 +01:00
|
|
|
return _subjects.subjects(_argument_buffer.local_addr<Subject_id>(),
|
|
|
|
_argument_buffer.size()/sizeof(Subject_id));
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-16 18:00:30 +01:00
|
|
|
size_t Session_component::subject_infos()
|
|
|
|
{
|
|
|
|
_subjects.import_new_sources(_sources);
|
|
|
|
|
|
|
|
size_t const count = _argument_buffer.size() / (sizeof(Subject_info) + sizeof(Subject_id));
|
|
|
|
Subject_info *infos = _argument_buffer.local_addr<Subject_info>();
|
|
|
|
Subject_id *ids = reinterpret_cast<Subject_id *>(infos + count);
|
|
|
|
|
|
|
|
return _subjects.subjects(infos, ids, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-10 03:44:55 +02:00
|
|
|
Policy_id Session_component::alloc_policy(size_t size)
|
|
|
|
{
|
2019-01-30 17:53:16 +01:00
|
|
|
if (size > _argument_buffer.size())
|
2013-08-10 03:44:55 +02:00
|
|
|
throw Policy_too_large();
|
|
|
|
|
2014-01-28 16:19:10 +01:00
|
|
|
/*
|
|
|
|
* Using prefix incrementation makes sure a policy with id == 0 is
|
|
|
|
* invalid.
|
|
|
|
*/
|
|
|
|
Policy_id const id(++_policy_cnt);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2020-05-05 14:27:29 +02:00
|
|
|
Ram_quota const amount { size };
|
|
|
|
|
|
|
|
/*
|
|
|
|
* \throw Out_of_ram
|
|
|
|
*/
|
|
|
|
withdraw(amount);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
try {
|
2020-05-05 14:27:29 +02:00
|
|
|
Dataspace_capability ds_cap = _ram.alloc(size);
|
|
|
|
_policies.insert(*this, id, _policies_slab, ds_cap, size);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
} catch (...) {
|
2020-05-05 14:27:29 +02:00
|
|
|
|
2013-09-02 15:23:26 +02:00
|
|
|
/* revert withdrawal or quota */
|
2020-05-05 14:27:29 +02:00
|
|
|
replenish(amount);
|
|
|
|
throw;
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Dataspace_capability Session_component::policy(Policy_id id)
|
|
|
|
{
|
|
|
|
return _policies.dataspace(*this, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Session_component::unload_policy(Policy_id id)
|
|
|
|
{
|
|
|
|
_policies.remove(*this, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Session_component::trace(Subject_id subject_id, Policy_id policy_id,
|
|
|
|
size_t buffer_size)
|
|
|
|
{
|
2020-05-05 14:27:29 +02:00
|
|
|
size_t const policy_size = _policies.size(*this, policy_id);
|
|
|
|
|
|
|
|
Ram_quota const required_ram { buffer_size + policy_size };
|
2013-08-10 03:44:55 +02:00
|
|
|
|
2019-05-06 10:42:05 +02:00
|
|
|
Trace::Subject &subject = _subjects.lookup_by_id(subject_id);
|
2020-05-05 14:27:29 +02:00
|
|
|
|
2019-05-06 10:42:05 +02:00
|
|
|
/* revert quota from previous call to trace */
|
|
|
|
if (subject.allocated_memory()) {
|
2020-05-05 14:27:29 +02:00
|
|
|
replenish(Ram_quota{subject.allocated_memory()});
|
2019-05-06 10:42:05 +02:00
|
|
|
subject.reset_allocated_memory();
|
|
|
|
}
|
|
|
|
|
2013-08-10 03:44:55 +02:00
|
|
|
/*
|
|
|
|
* Account RAM needed for trace buffer and policy buffer to the trace
|
|
|
|
* session.
|
2020-05-05 14:27:29 +02:00
|
|
|
*
|
|
|
|
* \throw Out_of_ram
|
2013-08-10 03:44:55 +02:00
|
|
|
*/
|
2020-05-05 14:27:29 +02:00
|
|
|
withdraw(required_ram);
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
try {
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
subject.trace(policy_id, _policies.dataspace(*this, policy_id),
|
2019-01-30 17:53:16 +01:00
|
|
|
policy_size, _ram, _local_rm, buffer_size);
|
2013-08-10 03:44:55 +02:00
|
|
|
} catch (...) {
|
2013-09-02 15:23:26 +02:00
|
|
|
/* revert withdrawal or quota */
|
2020-05-05 14:27:29 +02:00
|
|
|
replenish(required_ram);
|
2019-05-06 10:42:05 +02:00
|
|
|
throw;
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Session_component::rule(Session_label const &, Thread_name const &,
|
|
|
|
Policy_id, size_t)
|
|
|
|
{
|
|
|
|
/* not implemented yet */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Session_component::pause(Subject_id subject_id)
|
|
|
|
{
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
_subjects.lookup_by_id(subject_id).pause();
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Session_component::resume(Subject_id subject_id)
|
|
|
|
{
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
_subjects.lookup_by_id(subject_id).resume();
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Subject_info Session_component::subject_info(Subject_id subject_id)
|
|
|
|
{
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
return _subjects.lookup_by_id(subject_id).info();
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Dataspace_capability Session_component::buffer(Subject_id subject_id)
|
|
|
|
{
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
return _subjects.lookup_by_id(subject_id).buffer();
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Session_component::free(Subject_id subject_id)
|
|
|
|
{
|
2020-05-05 14:27:29 +02:00
|
|
|
Ram_quota const released_ram { _subjects.release(subject_id) };
|
|
|
|
|
|
|
|
replenish(released_ram);
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-05 14:27:29 +02:00
|
|
|
Session_component::Session_component(Rpc_entrypoint &ep,
|
|
|
|
Resources const &resources,
|
|
|
|
Label const &label,
|
|
|
|
Diag const &diag,
|
|
|
|
Ram_allocator &ram,
|
|
|
|
Region_map &local_rm,
|
|
|
|
size_t arg_buffer_size,
|
|
|
|
unsigned parent_levels,
|
|
|
|
Source_registry &sources,
|
2013-08-10 03:44:55 +02:00
|
|
|
Policy_registry &policies)
|
|
|
|
:
|
2020-05-05 14:27:29 +02:00
|
|
|
Session_object(ep, resources, label, diag),
|
|
|
|
_ram(ram, _ram_quota_guard(), _cap_quota_guard()),
|
|
|
|
_local_rm(local_rm),
|
2013-08-10 03:44:55 +02:00
|
|
|
_subjects_slab(&_md_alloc),
|
|
|
|
_policies_slab(&_md_alloc),
|
|
|
|
_parent_levels(parent_levels),
|
|
|
|
_sources(sources),
|
|
|
|
_policies(policies),
|
|
|
|
_subjects(_subjects_slab, _ram, _sources),
|
2019-01-30 17:53:16 +01:00
|
|
|
_argument_buffer(_ram, local_rm, arg_buffer_size)
|
2013-08-10 03:44:55 +02:00
|
|
|
{
|
2020-05-05 14:27:29 +02:00
|
|
|
withdraw(Ram_quota{_argument_buffer.size()});
|
2013-08-10 03:44:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Session_component::~Session_component()
|
|
|
|
{
|
|
|
|
_policies.destroy_policies_owned_by(*this);
|
|
|
|
}
|