2013-08-10 01:44:55 +00:00
|
|
|
/*
|
|
|
|
* \brief Client-side TRACE session interface
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2013-08-12
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-01-16 19:32:26 +00:00
|
|
|
* Copyright (C) 2013-2017 Genode Labs GmbH
|
2013-08-10 01:44:55 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 12:23:52 +00:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2013-08-10 01:44:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE__TRACE_SESSION__CLIENT_H_
|
|
|
|
#define _INCLUDE__TRACE_SESSION__CLIENT_H_
|
|
|
|
|
|
|
|
#include <trace_session/trace_session.h>
|
|
|
|
#include <base/rpc_client.h>
|
|
|
|
#include <base/env.h>
|
|
|
|
|
|
|
|
namespace Genode { namespace Trace { struct Session_client; } }
|
|
|
|
|
|
|
|
|
|
|
|
struct Genode::Trace::Session_client : Genode::Rpc_client<Genode::Trace::Session>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shared-memory buffer used for carrying the payload of the
|
|
|
|
* 'subjects()' RPC function.
|
|
|
|
*/
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 14:42:15 +00:00
|
|
|
class Argument_buffer
|
2013-08-10 01:44:55 +00:00
|
|
|
{
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 14:42:15 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Noncopyable
|
|
|
|
*/
|
|
|
|
Argument_buffer(Argument_buffer const &);
|
|
|
|
Argument_buffer &operator = (Argument_buffer const &);
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Region_map &rm;
|
|
|
|
char *base;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
Argument_buffer(Region_map &rm, Dataspace_capability ds)
|
|
|
|
:
|
|
|
|
rm(rm),
|
|
|
|
base(rm.attach(ds)),
|
|
|
|
size(ds.call<Dataspace::Rpc_size>())
|
|
|
|
{ }
|
|
|
|
|
|
|
|
~Argument_buffer()
|
|
|
|
{
|
|
|
|
rm.detach(base);
|
|
|
|
}
|
2013-08-10 01:44:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Argument_buffer _argument_buffer;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2017-01-16 19:32:26 +00:00
|
|
|
explicit Session_client(Region_map &rm, Capability<Trace::Session> session)
|
2013-08-10 01:44:55 +00:00
|
|
|
:
|
|
|
|
Rpc_client<Trace::Session>(session),
|
2017-01-16 19:32:26 +00:00
|
|
|
_argument_buffer(rm, call<Rpc_dataspace>())
|
2013-08-10 01:44:55 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve subject directory
|
2015-06-17 11:25:51 +00:00
|
|
|
*
|
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 20:03:22 +00:00
|
|
|
* \throw Out_of_ram
|
|
|
|
* \throw Out_of_caps
|
2013-08-10 01:44:55 +00:00
|
|
|
*/
|
2020-05-05 12:27:29 +00:00
|
|
|
virtual size_t subjects(Subject_id *dst, size_t dst_len)
|
2013-08-10 01:44:55 +00:00
|
|
|
{
|
|
|
|
size_t const num_subjects = min(call<Rpc_subjects>(), dst_len);
|
|
|
|
|
2020-01-17 10:05:09 +00:00
|
|
|
memcpy(dst, _argument_buffer.base, num_subjects*sizeof(Subject_id));
|
2013-08-10 01:44:55 +00:00
|
|
|
|
|
|
|
return num_subjects;
|
|
|
|
}
|
|
|
|
|
2020-07-07 14:48:04 +00:00
|
|
|
struct For_each_subject_info_result { size_t count; size_t limit; };
|
|
|
|
|
2020-01-16 17:00:30 +00:00
|
|
|
template <typename FN>
|
2020-07-07 14:48:04 +00:00
|
|
|
For_each_subject_info_result for_each_subject_info(FN const &fn)
|
2020-01-16 17:00:30 +00:00
|
|
|
{
|
|
|
|
size_t const num_subjects = call<Rpc_subject_infos>();
|
|
|
|
size_t const max_subjects = _argument_buffer.size / (sizeof(Subject_info) + sizeof(Subject_id));
|
|
|
|
|
|
|
|
Subject_info * const infos = reinterpret_cast<Subject_info *>(_argument_buffer.base);
|
|
|
|
Subject_id * const ids = reinterpret_cast<Subject_id *>(infos + max_subjects);
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < num_subjects; i++) {
|
|
|
|
fn(ids[i], infos[i]);
|
|
|
|
}
|
|
|
|
|
2020-07-07 14:48:04 +00:00
|
|
|
return { .count = num_subjects, .limit = max_subjects };
|
2020-01-16 17:00:30 +00:00
|
|
|
}
|
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
Policy_id alloc_policy(size_t size) override {
|
2013-08-10 01:44:55 +00:00
|
|
|
return call<Rpc_alloc_policy>(size); }
|
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
Dataspace_capability policy(Policy_id policy_id) override {
|
2013-08-10 01:44:55 +00:00
|
|
|
return call<Rpc_policy>(policy_id); }
|
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
void unload_policy(Policy_id policy_id) override {
|
2013-08-10 01:44:55 +00:00
|
|
|
call<Rpc_unload_policy>(policy_id); }
|
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
void trace(Subject_id s, Policy_id p, size_t buffer_size) override {
|
2013-08-10 01:44:55 +00:00
|
|
|
call<Rpc_trace>(s, p, buffer_size); }
|
|
|
|
|
|
|
|
void rule(Session_label const &label, Thread_name const &thread,
|
2015-03-04 20:12:14 +00:00
|
|
|
Policy_id policy, size_t buffer_size) override {
|
2013-08-10 01:44:55 +00:00
|
|
|
call<Rpc_rule>(label, thread, policy, buffer_size); }
|
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
void pause(Subject_id subject) override {
|
2013-08-10 01:44:55 +00:00
|
|
|
call<Rpc_pause>(subject); }
|
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
void resume(Subject_id subject) override {
|
2013-08-10 01:44:55 +00:00
|
|
|
call<Rpc_resume>(subject); }
|
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
Dataspace_capability buffer(Subject_id subject) override {
|
2013-08-10 01:44:55 +00:00
|
|
|
return call<Rpc_buffer>(subject); }
|
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
void free(Subject_id subject) override {
|
2013-08-10 01:44:55 +00:00
|
|
|
call<Rpc_free>(subject); }
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__TRACE_SESSION__CLIENT_H_ */
|