2013-08-26 10:42:12 +00:00
|
|
|
/*
|
|
|
|
* \brief Mapping of Genode's capability names to capabilities selectors.
|
|
|
|
* \author Alexander Boettcher
|
|
|
|
* \date 2013-08-26
|
|
|
|
*
|
2016-06-15 13:04:54 +00:00
|
|
|
* This header is public to allow user-level VMMs to manually allocate windows
|
|
|
|
* of consecutive selectors (for virtualization event portals) in the
|
|
|
|
* component's capability space.
|
2013-08-26 10:42:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2013-2017 Genode Labs GmbH
|
2013-08-26 10:42:12 +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-26 10:42:12 +00:00
|
|
|
*/
|
|
|
|
|
2016-06-15 13:04:54 +00:00
|
|
|
#ifndef _INCLUDE__NOVA__CAP_MAP_H_
|
|
|
|
#define _INCLUDE__NOVA__CAP_MAP_H_
|
2013-08-26 10:42:12 +00:00
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/stdint.h>
|
|
|
|
|
|
|
|
#include <base/lock.h>
|
|
|
|
|
|
|
|
#include <util/avl_tree.h>
|
|
|
|
#include <util/noncopyable.h>
|
|
|
|
|
|
|
|
namespace Genode {
|
|
|
|
|
|
|
|
class Cap_range : public Avl_node<Cap_range> {
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
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
|
|
|
Lock _lock { };
|
|
|
|
addr_t _base = 0;
|
|
|
|
addr_t _last = 0;
|
2013-08-26 10:42:12 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
HEADER = sizeof(_base) + sizeof(_lock) + sizeof(_last),
|
|
|
|
CAP_RANGE_SIZE = 4096,
|
|
|
|
WORDS = (CAP_RANGE_SIZE - HEADER - sizeof(Avl_node<Cap_range>)) / sizeof(addr_t),
|
|
|
|
};
|
|
|
|
|
2015-07-02 18:28:19 +00:00
|
|
|
uint16_t _cap_array[WORDS * sizeof(addr_t) / 2];
|
2013-08-26 10:42:12 +00:00
|
|
|
|
|
|
|
bool _match(addr_t id) {
|
2015-07-02 18:28:19 +00:00
|
|
|
return _base <= id && id < _base + elements(); };
|
2013-08-26 10:42:12 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
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
|
|
|
Cap_range(addr_t base) : _base(base)
|
|
|
|
{
|
2013-08-26 10:42:12 +00:00
|
|
|
static_assert(sizeof(*this) == CAP_RANGE_SIZE,
|
|
|
|
"Cap_range misconfigured");
|
|
|
|
|
2015-07-02 18:28:19 +00:00
|
|
|
for (unsigned i = 0; i < elements(); i++)
|
2013-08-26 10:42:12 +00:00
|
|
|
_cap_array[i] = 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
addr_t base() const { return _base; }
|
|
|
|
unsigned elements() const { return sizeof(_cap_array) / sizeof(_cap_array[0]); }
|
2013-08-26 10:42:12 +00:00
|
|
|
|
|
|
|
Cap_range *find_by_id(addr_t);
|
|
|
|
|
2016-04-19 15:48:04 +00:00
|
|
|
void inc(unsigned id);
|
2015-09-22 12:39:48 +00:00
|
|
|
void dec(unsigned id, bool revoke = true, unsigned num_log2 = 0);
|
2013-08-26 10:42:12 +00:00
|
|
|
|
|
|
|
addr_t alloc(size_t const num_log2);
|
|
|
|
|
|
|
|
/************************
|
|
|
|
** Avl node interface **
|
|
|
|
************************/
|
|
|
|
|
|
|
|
bool higher(Cap_range *n) { return n->_base > _base; }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Cap_index
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
Cap_range * _range;
|
|
|
|
addr_t _local_name;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Cap_index(Cap_range *range, addr_t local_name)
|
|
|
|
: _range(range), _local_name(local_name) {}
|
|
|
|
|
|
|
|
bool valid() const { return _range; }
|
|
|
|
|
2016-04-19 15:48:04 +00:00
|
|
|
inline void inc()
|
2013-08-26 10:42:12 +00:00
|
|
|
{
|
|
|
|
if (_range)
|
2016-04-19 15:48:04 +00:00
|
|
|
_range->inc(_local_name - _range->base());
|
2013-08-26 10:42:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void dec()
|
|
|
|
{
|
|
|
|
if (_range)
|
|
|
|
_range->dec(_local_name - _range->base());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-01-28 13:30:36 +00:00
|
|
|
class Capability_map : private Noncopyable
|
2013-08-26 10:42:12 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
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
|
|
|
Avl_tree<Cap_range> _tree { };
|
2013-08-26 10:42:12 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Cap_index find(addr_t local_sel);
|
|
|
|
|
|
|
|
void insert(Cap_range * range) { _tree.insert(range); }
|
|
|
|
|
|
|
|
addr_t insert(size_t num_log_2 = 0, addr_t cap = ~0UL);
|
|
|
|
|
|
|
|
void remove(addr_t sel, uint8_t num_log_2 = 0, bool revoke = true);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the global Capability_map of the process.
|
|
|
|
*/
|
|
|
|
Capability_map *cap_map();
|
|
|
|
}
|
|
|
|
|
2016-06-15 13:04:54 +00:00
|
|
|
#endif /* _INCLUDE__NOVA__CAP_MAP_H_ */
|