2015-09-23 09:06:25 +00:00
|
|
|
/*
|
|
|
|
* \brief ROM service
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2014-01-11
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2014-2017 Genode Labs GmbH
|
2015-09-23 09:06:25 +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.
|
2015-09-23 09:06:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE__REPORT_ROM__ROM_SERVICE_H_
|
|
|
|
#define _INCLUDE__REPORT_ROM__ROM_SERVICE_H_
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <util/arg_string.h>
|
|
|
|
#include <util/xml_node.h>
|
|
|
|
#include <rom_session/rom_session.h>
|
|
|
|
#include <root/component.h>
|
|
|
|
#include <report_rom/rom_registry.h>
|
|
|
|
|
|
|
|
namespace Rom {
|
|
|
|
class Session_component;
|
|
|
|
class Module_name_fn;
|
|
|
|
class Root;
|
|
|
|
|
|
|
|
using Genode::Xml_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Rom::Session_component : public Genode::Rpc_object<Genode::Rom_session>,
|
|
|
|
public Reader
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2019-01-21 09:48:39 +00:00
|
|
|
Genode::Ram_allocator &_ram;
|
|
|
|
Genode::Region_map &_rm;
|
2017-01-10 13:13:35 +00:00
|
|
|
|
2015-09-23 09:06:25 +00:00
|
|
|
Registry_for_reader &_registry;
|
|
|
|
|
|
|
|
Genode::Session_label const _label;
|
|
|
|
|
|
|
|
Readable_module &_module;
|
|
|
|
|
|
|
|
Readable_module &_init_module(Genode::Session_label const &label)
|
|
|
|
{
|
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
|
|
|
try { return _registry.lookup(*this, label.string()); }
|
2015-09-23 09:06:25 +00:00
|
|
|
catch (Registry_for_reader::Lookup_failed) {
|
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 Genode::Service_denied(); }
|
2015-09-23 09:06:25 +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
|
|
|
Constructible<Genode::Attached_ram_dataspace> _ds { };
|
2015-09-23 09:06:25 +00:00
|
|
|
|
|
|
|
size_t _content_size = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Keep state of valid content to notify the client only once when
|
|
|
|
* the ROM module becomes invalid.
|
|
|
|
*/
|
|
|
|
bool _valid = false;
|
|
|
|
|
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
|
|
|
Genode::Signal_context_capability _sigh { };
|
2015-09-23 09:06:25 +00:00
|
|
|
|
|
|
|
void _notify_client()
|
|
|
|
{
|
|
|
|
if (_sigh.valid())
|
|
|
|
Genode::Signal_transmitter(_sigh).submit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2019-01-21 09:48:39 +00:00
|
|
|
Session_component(Genode::Ram_allocator &ram, Genode::Region_map &rm,
|
2017-01-10 13:13:35 +00:00
|
|
|
Registry_for_reader ®istry,
|
2015-09-23 09:06:25 +00:00
|
|
|
Genode::Session_label const &label)
|
|
|
|
:
|
2017-01-10 13:13:35 +00:00
|
|
|
_ram(ram), _rm(rm),
|
|
|
|
_registry(registry), _label(label), _module(_init_module(label))
|
|
|
|
{ }
|
|
|
|
|
2015-09-23 09:06:25 +00:00
|
|
|
~Session_component()
|
|
|
|
{
|
|
|
|
_registry.release(*this, _module);
|
|
|
|
}
|
|
|
|
|
|
|
|
Genode::Session_label label() const { return _label; }
|
|
|
|
|
|
|
|
Genode::Rom_dataspace_capability dataspace() override
|
|
|
|
{
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
/* replace dataspace by new one */
|
|
|
|
/* XXX we could keep the old dataspace if the size fits */
|
2017-01-10 13:13:35 +00:00
|
|
|
_ds.construct(_ram, _rm, _module.size());
|
2015-09-23 09:06:25 +00:00
|
|
|
|
|
|
|
/* fill dataspace content with report contained in module */
|
|
|
|
_content_size =
|
|
|
|
_module.read_content(*this, _ds->local_addr<char>(), _ds->size());
|
|
|
|
|
|
|
|
_valid = _content_size > 0;
|
|
|
|
|
|
|
|
/* cast RAM into ROM dataspace capability */
|
|
|
|
Dataspace_capability ds_cap = static_cap_cast<Dataspace>(_ds->cap());
|
|
|
|
return static_cap_cast<Rom_dataspace>(ds_cap);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool update() override
|
|
|
|
{
|
2016-05-11 16:21:47 +00:00
|
|
|
if (!_ds.constructed() || _module.size() > _ds->size())
|
2015-09-23 09:06:25 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
size_t const new_content_size =
|
|
|
|
_module.read_content(*this, _ds->local_addr<char>(), _ds->size());
|
|
|
|
|
|
|
|
/* clear difference between old and new content */
|
|
|
|
if (new_content_size < _content_size)
|
|
|
|
Genode::memset(_ds->local_addr<char>() + new_content_size, 0,
|
|
|
|
_content_size - new_content_size);
|
|
|
|
|
|
|
|
_content_size = new_content_size;
|
|
|
|
|
|
|
|
_valid = _content_size > 0;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sigh(Genode::Signal_context_capability sigh) override
|
|
|
|
{
|
|
|
|
_sigh = sigh;
|
2015-11-23 16:00:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Notify client initially to enforce a client-side ROM update.
|
|
|
|
* Otherwise, a server-side ROM update between session creation and
|
|
|
|
* signal-handler registration would go unnoticed.
|
|
|
|
*/
|
|
|
|
_notify_client();
|
2015-09-23 09:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reader interface
|
|
|
|
*/
|
|
|
|
void notify_module_changed() override
|
|
|
|
{
|
|
|
|
_notify_client();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reader interface
|
|
|
|
*/
|
|
|
|
void notify_module_invalidated() override
|
|
|
|
{
|
|
|
|
/* deliver a signal for an invalidated module only once */
|
|
|
|
if (!_valid)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_valid = false;
|
|
|
|
_notify_client();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Rom::Root : public Genode::Root_component<Session_component>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2017-01-10 13:13:35 +00:00
|
|
|
Genode::Env &_env;
|
2015-09-23 09:06:25 +00:00
|
|
|
Registry_for_reader &_registry;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
Session_component *_create_session(const char *args) override
|
|
|
|
{
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
return new (md_alloc())
|
2017-01-10 13:13:35 +00:00
|
|
|
Session_component(_env.ram(), _env.rm(), _registry, label_from_args(args));
|
2015-09-23 09:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-07-07 08:13:39 +00:00
|
|
|
Root(Genode::Env &env,
|
2015-09-23 09:06:25 +00:00
|
|
|
Genode::Allocator &md_alloc,
|
|
|
|
Registry_for_reader ®istry)
|
|
|
|
:
|
2016-07-07 08:13:39 +00:00
|
|
|
Genode::Root_component<Session_component>(&env.ep().rpc_ep(), &md_alloc),
|
2017-01-10 13:13:35 +00:00
|
|
|
_env(env), _registry(registry)
|
2015-09-23 09:06:25 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__REPORT_ROM__ROM_SERVICE_H_ */
|