mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-31 08:25:38 +00:00
server/report_rom: componentize
* Check report RAM donation and buffer size. * Use explicit config ROM attachment. * Pass Env to session connections. * Replace logging macros. Issue #2036
This commit is contained in:
parent
02e50ce5d7
commit
0efd5a3078
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2014-2016 Genode Labs GmbH
|
||||
* Copyright (C) 2014 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
@ -20,6 +20,7 @@
|
||||
#include <root/component.h>
|
||||
#include <util/print_lines.h>
|
||||
#include <report_rom/rom_registry.h>
|
||||
#include <base/log.h>
|
||||
|
||||
|
||||
namespace Report {
|
||||
@ -54,16 +55,17 @@ struct Report::Session_component : Genode::Rpc_object<Session>, Rom::Writer
|
||||
static void _log_lines(char const *string, size_t len)
|
||||
{
|
||||
Genode::print_lines<200>(string, len,
|
||||
[&] (char const *line) { PLOG(" %s", line); });
|
||||
[&] (char const *line) { Genode::log(" ", line); });
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
Session_component(Genode::Session_label const &label, size_t buffer_size,
|
||||
Session_component(Genode::Env &env,
|
||||
Genode::Session_label const &label, size_t buffer_size,
|
||||
Rom::Registry_for_writer ®istry, bool &verbose)
|
||||
:
|
||||
_registry(registry), _label(label),
|
||||
_ds(Genode::env()->ram_session(), buffer_size),
|
||||
_ds(env.ram(), env.rm(), buffer_size),
|
||||
_module(_create_module(label.string())),
|
||||
_verbose(verbose)
|
||||
{ }
|
||||
@ -85,7 +87,7 @@ struct Report::Session_component : Genode::Rpc_object<Session>, Rom::Writer
|
||||
length = Genode::min(length, _ds.size());
|
||||
|
||||
if (_verbose) {
|
||||
PLOG("report '%s'", _module.name().string());
|
||||
Genode::log("report '", _module.name().string(), "'");
|
||||
_log_lines(_ds.local_addr<char>(), length);
|
||||
}
|
||||
|
||||
@ -102,6 +104,7 @@ struct Report::Root : Genode::Root_component<Session_component>
|
||||
{
|
||||
private:
|
||||
|
||||
Genode::Env &_env;
|
||||
Rom::Registry_for_writer &_rom_registry;
|
||||
bool &_verbose;
|
||||
|
||||
@ -111,24 +114,42 @@ struct Report::Root : Genode::Root_component<Session_component>
|
||||
{
|
||||
using namespace Genode;
|
||||
|
||||
Session_label const label = label_from_args(args);
|
||||
|
||||
size_t const ram_quota =
|
||||
Arg_string::find_arg(args, "ram_quota").aligned_size();
|
||||
|
||||
/* read report buffer size from session arguments */
|
||||
size_t const buffer_size =
|
||||
Arg_string::find_arg(args, "buffer_size").ulong_value(0);
|
||||
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());
|
||||
throw Root::Quota_exceeded();
|
||||
}
|
||||
|
||||
if (buffer_size == 0) {
|
||||
Genode::error("zero-length report requested by ", label.string());
|
||||
throw Root::Invalid_args();
|
||||
}
|
||||
|
||||
return new (md_alloc())
|
||||
Session_component(label_from_args(args), buffer_size,
|
||||
Session_component(_env, label, buffer_size,
|
||||
_rom_registry, _verbose);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
Root(Server::Entrypoint &ep,
|
||||
Root(Genode::Env &env,
|
||||
Genode::Allocator &md_alloc,
|
||||
Rom::Registry_for_writer &rom_registry,
|
||||
bool &verbose)
|
||||
:
|
||||
Genode::Root_component<Session_component>(&ep.rpc_ep(), &md_alloc),
|
||||
_rom_registry(rom_registry), _verbose(verbose)
|
||||
Genode::Root_component<Session_component>(&env.ep().rpc_ep(), &md_alloc),
|
||||
_env(env), _rom_registry(rom_registry), _verbose(verbose)
|
||||
{ }
|
||||
};
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2014 Genode Labs GmbH
|
||||
* Copyright (C) 2014-2016 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
@ -16,8 +16,8 @@
|
||||
|
||||
/* Genode includes */
|
||||
#include <util/volatile_object.h>
|
||||
#include <os/attached_ram_dataspace.h>
|
||||
#include <os/session_policy.h>
|
||||
#include <base/attached_ram_dataspace.h>
|
||||
|
||||
namespace Rom {
|
||||
using Genode::size_t;
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2014 Genode Labs GmbH
|
||||
* Copyright (C) 2014-2016 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
@ -20,7 +20,6 @@
|
||||
#include <rom_session/rom_session.h>
|
||||
#include <root/component.h>
|
||||
#include <report_rom/rom_registry.h>
|
||||
#include <os/session_policy.h>
|
||||
|
||||
namespace Rom {
|
||||
class Session_component;
|
||||
@ -175,11 +174,11 @@ class Rom::Root : public Genode::Root_component<Session_component>
|
||||
|
||||
public:
|
||||
|
||||
Root(Server::Entrypoint &ep,
|
||||
Root(Genode::Env &env,
|
||||
Genode::Allocator &md_alloc,
|
||||
Registry_for_reader ®istry)
|
||||
:
|
||||
Genode::Root_component<Session_component>(&ep.rpc_ep(), &md_alloc),
|
||||
Genode::Root_component<Session_component>(&env.ep().rpc_ep(), &md_alloc),
|
||||
_registry(registry)
|
||||
{ }
|
||||
};
|
||||
|
@ -13,14 +13,12 @@
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/heap.h>
|
||||
#include <base/env.h>
|
||||
#include <os/server.h>
|
||||
#include <os/config.h>
|
||||
#include <base/component.h>
|
||||
#include <os/attached_rom_dataspace.h>
|
||||
#include <report_rom/rom_service.h>
|
||||
#include <report_rom/report_service.h>
|
||||
|
||||
namespace Server { struct Main; }
|
||||
namespace Clipboard { struct Main; }
|
||||
|
||||
|
||||
/**
|
||||
@ -69,16 +67,19 @@ struct Rom::Registry : Rom::Registry_for_reader, Rom::Registry_for_writer
|
||||
};
|
||||
|
||||
|
||||
struct Server::Main : Rom::Module::Read_policy, Rom::Module::Write_policy
|
||||
struct Clipboard::Main : Rom::Module::Read_policy, Rom::Module::Write_policy
|
||||
{
|
||||
Entrypoint &_ep;
|
||||
Genode::Env &_env;
|
||||
|
||||
Genode::Sliced_heap _sliced_heap = { Genode::env()->ram_session(),
|
||||
Genode::env()->rm_session() };
|
||||
|
||||
Genode::Attached_rom_dataspace _config { _env, "config" };
|
||||
|
||||
bool _verbose_config()
|
||||
{
|
||||
char const *attr = "verbose";
|
||||
return Genode::config()->xml_node().attribute_value(attr, false);
|
||||
return _config.xml().attribute_value(attr, false);
|
||||
}
|
||||
|
||||
bool verbose = _verbose_config();
|
||||
@ -87,8 +88,8 @@ struct Server::Main : Rom::Module::Read_policy, Rom::Module::Write_policy
|
||||
|
||||
Genode::Attached_rom_dataspace _focus_ds { "focus" };
|
||||
|
||||
Genode::Signal_rpc_member<Main> _focus_dispatcher =
|
||||
{ _ep, *this, &Main::_handle_focus };
|
||||
Genode::Signal_handler<Main> _focus_handler =
|
||||
{ _env.ep(), *this, &Main::_handle_focus };
|
||||
|
||||
Domain _focused_domain;
|
||||
|
||||
@ -97,7 +98,7 @@ struct Server::Main : Rom::Module::Read_policy, Rom::Module::Write_policy
|
||||
*
|
||||
* We only accept reports from the currently focused domain.
|
||||
*/
|
||||
void _handle_focus(unsigned)
|
||||
void _handle_focus()
|
||||
{
|
||||
_focus_ds.update();
|
||||
|
||||
@ -117,7 +118,7 @@ struct Server::Main : Rom::Module::Read_policy, Rom::Module::Write_policy
|
||||
using namespace Genode;
|
||||
|
||||
try {
|
||||
return Session_policy(label).attribute_value("domain", Domain());
|
||||
return Session_policy(label, _config.xml()).attribute_value("domain", Domain());
|
||||
} catch (Session_policy::No_policy_defined) { }
|
||||
|
||||
return Domain();
|
||||
@ -154,9 +155,9 @@ struct Server::Main : Rom::Module::Read_policy, Rom::Module::Write_policy
|
||||
auto match_flow = [&] (Genode::Xml_node flow) {
|
||||
if (flow.attribute_value("from", Domain()) == from
|
||||
&& flow.attribute_value("to", Domain()) == to)
|
||||
result = true; };
|
||||
result = true; };
|
||||
|
||||
Genode::config()->xml_node().for_each_sub_node("flow", match_flow);
|
||||
_config.xml().for_each_sub_node("flow", match_flow);
|
||||
|
||||
} catch (Genode::Xml_node::Nonexistent_sub_node) { }
|
||||
|
||||
@ -197,30 +198,29 @@ struct Server::Main : Rom::Module::Read_policy, Rom::Module::Write_policy
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Rom::Registry _rom_registry { *this, *this };
|
||||
|
||||
Report::Root report_root = { _ep, _sliced_heap, _rom_registry, verbose };
|
||||
Rom ::Root rom_root = { _ep, _sliced_heap, _rom_registry };
|
||||
Report::Root report_root = { _env, _sliced_heap, _rom_registry, verbose };
|
||||
Rom ::Root rom_root = { _env, _sliced_heap, _rom_registry };
|
||||
|
||||
Main(Entrypoint &ep) : _ep(ep)
|
||||
Main(Genode::Env &env) : _env(env)
|
||||
{
|
||||
_focus_ds.sigh(_focus_dispatcher);
|
||||
_focus_ds.sigh(_focus_handler);
|
||||
|
||||
Genode::env()->parent()->announce(_ep.manage(report_root));
|
||||
Genode::env()->parent()->announce(_ep.manage(rom_root));
|
||||
env.parent().announce(env.ep().manage(report_root));
|
||||
env.parent().announce(env.ep().manage(rom_root));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
namespace Server {
|
||||
/***************
|
||||
** Component **
|
||||
***************/
|
||||
|
||||
char const *name() { return "report_rom_ep"; }
|
||||
namespace Component {
|
||||
|
||||
size_t stack_size() { return 4*1024*sizeof(long); }
|
||||
Genode::size_t stack_size() { return 4*1024*sizeof(long); }
|
||||
|
||||
void construct(Entrypoint &ep)
|
||||
{
|
||||
static Main main(ep);
|
||||
}
|
||||
void construct(Genode::Env &env) { static Clipboard::Main main(env); }
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
TARGET = clipboard
|
||||
SRC_CC = main.cc
|
||||
LIBS = base server config
|
||||
LIBS = base
|
||||
INC_DIR += $(PRG_DIR)
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2014 Genode Labs GmbH
|
||||
* Copyright (C) 2014-2016 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
@ -14,51 +14,46 @@
|
||||
/* Genode includes */
|
||||
#include <base/heap.h>
|
||||
#include <base/env.h>
|
||||
#include <os/server.h>
|
||||
#include <os/config.h>
|
||||
#include <report_rom/rom_service.h>
|
||||
#include <report_rom/report_service.h>
|
||||
#include <base/attached_rom_dataspace.h>
|
||||
#include <base/component.h>
|
||||
|
||||
/* local includes */
|
||||
#include "rom_registry.h"
|
||||
|
||||
|
||||
namespace Server {
|
||||
using Genode::env;
|
||||
struct Main;
|
||||
}
|
||||
namespace Report_rom { struct Main; }
|
||||
|
||||
|
||||
struct Server::Main
|
||||
struct Report_rom::Main
|
||||
{
|
||||
Entrypoint &ep;
|
||||
Genode::Env &env;
|
||||
|
||||
Genode::Sliced_heap sliced_heap = { env()->ram_session(),
|
||||
env()->rm_session() };
|
||||
Genode::Sliced_heap sliced_heap { env.ram(), env.rm() };
|
||||
|
||||
Rom::Registry rom_registry = { sliced_heap };
|
||||
Rom::Registry rom_registry { sliced_heap, config_rom };
|
||||
|
||||
bool verbose = Genode::config()->xml_node().attribute_value("verbose", false);
|
||||
Genode::Attached_rom_dataspace config_rom { env, "config" };
|
||||
|
||||
Report::Root report_root = { ep, sliced_heap, rom_registry, verbose };
|
||||
Rom ::Root rom_root = { ep, sliced_heap, rom_registry };
|
||||
bool verbose = config_rom.xml().attribute_value("verbose", false);
|
||||
|
||||
Main(Entrypoint &ep) : ep(ep)
|
||||
Report::Root report_root { env, sliced_heap, rom_registry, verbose };
|
||||
Rom ::Root rom_root { env, sliced_heap, rom_registry };
|
||||
|
||||
Main(Genode::Env &env) : env(env)
|
||||
{
|
||||
env()->parent()->announce(ep.manage(report_root));
|
||||
env()->parent()->announce(ep.manage(rom_root));
|
||||
env.parent().announce(env.ep().manage(report_root));
|
||||
env.parent().announce(env.ep().manage(rom_root));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
namespace Server {
|
||||
/***************
|
||||
** Component **
|
||||
***************/
|
||||
|
||||
char const *name() { return "report_rom_ep"; }
|
||||
Genode::size_t Component::stack_size() { return 4*1024*sizeof(long); }
|
||||
|
||||
size_t stack_size() { return 4*1024*sizeof(long); }
|
||||
void Component::construct(Genode::Env &env) { static Report_rom::Main main(env); }
|
||||
|
||||
void construct(Entrypoint &ep)
|
||||
{
|
||||
static Main main(ep);
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2014 Genode Labs GmbH
|
||||
* Copyright (C) 2014-2016 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
@ -26,6 +26,7 @@ struct Rom::Registry : Registry_for_reader, Registry_for_writer, Genode::Noncopy
|
||||
private:
|
||||
|
||||
Genode::Allocator &_md_alloc;
|
||||
Genode::Attached_rom_dataspace &_config_rom;
|
||||
|
||||
Module_list _modules;
|
||||
|
||||
@ -118,15 +119,16 @@ struct Rom::Registry : Registry_for_reader, Registry_for_writer, Genode::Noncopy
|
||||
|
||||
String<Rom::Module::Name::capacity()> report;
|
||||
|
||||
_config_rom.update();
|
||||
try {
|
||||
Session_policy policy(rom_label);
|
||||
Session_policy policy(rom_label, _config_rom.xml());
|
||||
policy.attribute("report").value(&report);
|
||||
return Rom::Module::Name(report.string());
|
||||
} catch (Session_policy::No_policy_defined) {
|
||||
/* FIXME backwards compatibility, remove at next release */
|
||||
try {
|
||||
Xml_node rom_node = config()->xml_node().sub_node("rom");
|
||||
PWRN("parsing legacy <rom> policies");
|
||||
Xml_node rom_node = _config_rom.xml().sub_node("rom");
|
||||
warning("parsing legacy <rom> policies");
|
||||
|
||||
Session_policy policy(rom_label, rom_node);
|
||||
policy.attribute("report").value(&report);
|
||||
@ -135,15 +137,16 @@ struct Rom::Registry : Registry_for_reader, Registry_for_writer, Genode::Noncopy
|
||||
catch (Session_policy::No_policy_defined) { }
|
||||
}
|
||||
|
||||
PWRN("no valid policy for label \"%s\"", rom_label.string());
|
||||
warning("no valid policy for ROM request \", rom_label.string(), \"");
|
||||
throw Root::Invalid_args();
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
Registry(Genode::Allocator &md_alloc)
|
||||
Registry(Genode::Allocator &md_alloc,
|
||||
Genode::Attached_rom_dataspace &config_rom)
|
||||
:
|
||||
_md_alloc(md_alloc)
|
||||
_md_alloc(md_alloc), _config_rom(config_rom)
|
||||
{ }
|
||||
|
||||
Module &lookup(Writer &writer, Module::Name const &name) override
|
||||
|
@ -1,4 +1,4 @@
|
||||
TARGET = report_rom
|
||||
SRC_CC = main.cc
|
||||
LIBS = base server config
|
||||
LIBS = base
|
||||
INC_DIR += $(PRG_DIR)
|
||||
|
Loading…
x
Reference in New Issue
Block a user