2014-01-12 00:29:17 +01:00
|
|
|
/*
|
|
|
|
* \brief Server that aggregates reports and exposes them as ROM modules
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2014-01-11
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2014-2017 Genode Labs GmbH
|
2014-01-12 00:29:17 +01: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.
|
2014-01-12 00:29:17 +01:00
|
|
|
*/
|
|
|
|
|
2015-09-23 11:06:25 +02:00
|
|
|
#ifndef _INCLUDE__REPORT_ROM__REPORT_SERVICE_H_
|
|
|
|
#define _INCLUDE__REPORT_ROM__REPORT_SERVICE_H_
|
2014-01-12 00:29:17 +01:00
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <util/arg_string.h>
|
|
|
|
#include <report_session/report_session.h>
|
|
|
|
#include <root/component.h>
|
2015-09-23 11:06:25 +02:00
|
|
|
#include <util/print_lines.h>
|
|
|
|
#include <report_rom/rom_registry.h>
|
2016-07-07 10:13:39 +02:00
|
|
|
#include <base/log.h>
|
2014-01-12 00:29:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
namespace Report {
|
|
|
|
struct Session_component;
|
|
|
|
struct Root;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct Report::Session_component : Genode::Rpc_object<Session>, Rom::Writer
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
Rom::Registry_for_writer &_registry;
|
|
|
|
|
2015-09-23 11:06:25 +02:00
|
|
|
Genode::Session_label const _label;
|
|
|
|
|
2014-01-12 00:29:17 +01:00
|
|
|
Genode::Attached_ram_dataspace _ds;
|
|
|
|
|
|
|
|
Rom::Module &_module;
|
|
|
|
|
2015-06-10 11:01:13 +02:00
|
|
|
bool &_verbose;
|
|
|
|
|
2015-08-20 16:00:57 +02:00
|
|
|
Rom::Module &_create_module(Rom::Module::Name const &name)
|
|
|
|
{
|
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
|
|
|
try { return _registry.lookup(*this, name); }
|
|
|
|
catch (...) { throw Genode::Service_denied(); }
|
2015-08-20 16:00:57 +02:00
|
|
|
}
|
|
|
|
|
2015-09-22 11:05:45 +02:00
|
|
|
static void _log_lines(char const *string, size_t len)
|
|
|
|
{
|
|
|
|
Genode::print_lines<200>(string, len,
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
[&] (char const *line)
|
|
|
|
{ Genode::log(" ", line); });
|
2015-09-22 11:05:45 +02:00
|
|
|
}
|
|
|
|
|
2014-01-12 00:29:17 +01:00
|
|
|
public:
|
|
|
|
|
2016-07-07 10:13:39 +02:00
|
|
|
Session_component(Genode::Env &env,
|
|
|
|
Genode::Session_label const &label, size_t buffer_size,
|
2015-06-10 11:01:13 +02:00
|
|
|
Rom::Registry_for_writer ®istry, bool &verbose)
|
2014-01-12 00:29:17 +01:00
|
|
|
:
|
2015-09-23 11:06:25 +02:00
|
|
|
_registry(registry), _label(label),
|
2016-07-07 10:13:39 +02:00
|
|
|
_ds(env.ram(), env.rm(), buffer_size),
|
2015-09-23 11:06:25 +02:00
|
|
|
_module(_create_module(label.string())),
|
2015-06-10 11:01:13 +02:00
|
|
|
_verbose(verbose)
|
2014-01-12 00:29:17 +01:00
|
|
|
{ }
|
|
|
|
|
|
|
|
~Session_component()
|
|
|
|
{
|
|
|
|
_registry.release(*this, _module);
|
|
|
|
}
|
|
|
|
|
2015-09-23 11:06:25 +02:00
|
|
|
/**
|
|
|
|
* Rom::Writer interface
|
|
|
|
*/
|
|
|
|
Genode::Session_label label() const override { return _label; }
|
|
|
|
|
2014-01-12 00:29:17 +01:00
|
|
|
Dataspace_capability dataspace() override { return _ds.cap(); }
|
|
|
|
|
2015-06-10 11:01:13 +02:00
|
|
|
void submit(size_t length) override
|
2014-01-12 00:29:17 +01:00
|
|
|
{
|
2015-06-10 11:01:13 +02:00
|
|
|
length = Genode::min(length, _ds.size());
|
|
|
|
|
|
|
|
if (_verbose) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::log("report '", _module.name(), "'");
|
2015-09-22 11:05:45 +02:00
|
|
|
_log_lines(_ds.local_addr<char>(), length);
|
2015-06-10 11:01:13 +02:00
|
|
|
}
|
|
|
|
|
2015-09-23 11:06:25 +02:00
|
|
|
_module.write_content(*this, _ds.local_addr<char>(), length);
|
2014-01-12 00:29:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void response_sigh(Genode::Signal_context_capability) override { }
|
|
|
|
|
|
|
|
size_t obtain_response() override { return 0; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct Report::Root : Genode::Root_component<Session_component>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2016-07-07 10:13:39 +02:00
|
|
|
Genode::Env &_env;
|
2014-01-12 00:29:17 +01:00
|
|
|
Rom::Registry_for_writer &_rom_registry;
|
2015-06-10 11:01:13 +02:00
|
|
|
bool &_verbose;
|
2014-01-12 00:29:17 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
Session_component *_create_session(const char *args) override
|
|
|
|
{
|
|
|
|
using namespace Genode;
|
|
|
|
|
2016-07-07 10:13:39 +02:00
|
|
|
Session_label const label = label_from_args(args);
|
|
|
|
|
|
|
|
size_t const ram_quota =
|
|
|
|
Arg_string::find_arg(args, "ram_quota").aligned_size();
|
|
|
|
|
2014-01-12 00:29:17 +01:00
|
|
|
/* read report buffer size from session arguments */
|
|
|
|
size_t const buffer_size =
|
2016-07-07 10:13:39 +02:00
|
|
|
Arg_string::find_arg(args, "buffer_size").aligned_size();
|
|
|
|
|
|
|
|
size_t const session_size =
|
|
|
|
max(sizeof(Session_component), 4096U) + buffer_size;
|
|
|
|
|
|
|
|
if (ram_quota < session_size) {
|
|
|
|
Genode::error("insufficient ram donation from ", label.string());
|
2017-05-08 14:32:03 +02:00
|
|
|
throw Insufficient_ram_quota();
|
2016-07-07 10:13:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (buffer_size == 0) {
|
|
|
|
Genode::error("zero-length report requested by ", label.string());
|
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
|
|
|
throw Service_denied();
|
2016-07-07 10:13:39 +02:00
|
|
|
}
|
2014-01-12 00:29:17 +01:00
|
|
|
|
|
|
|
return new (md_alloc())
|
2016-07-07 10:13:39 +02:00
|
|
|
Session_component(_env, label, buffer_size,
|
2015-06-10 11:01:13 +02:00
|
|
|
_rom_registry, _verbose);
|
2014-01-12 00:29:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-07-07 10:13:39 +02:00
|
|
|
Root(Genode::Env &env,
|
2014-01-12 00:29:17 +01:00
|
|
|
Genode::Allocator &md_alloc,
|
2015-06-10 11:01:13 +02:00
|
|
|
Rom::Registry_for_writer &rom_registry,
|
|
|
|
bool &verbose)
|
2014-01-12 00:29:17 +01:00
|
|
|
:
|
2016-07-07 10:13:39 +02:00
|
|
|
Genode::Root_component<Session_component>(&env.ep().rpc_ep(), &md_alloc),
|
|
|
|
_env(env), _rom_registry(rom_registry), _verbose(verbose)
|
2014-01-12 00:29:17 +01:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2015-09-23 11:06:25 +02:00
|
|
|
#endif /* _INCLUDE__REPORT_ROM__REPORT_SERVICE_H_ */
|