2015-05-19 14:18:40 +02:00
|
|
|
#include <kernel/object.h>
|
|
|
|
#include <kernel/pd.h>
|
|
|
|
#include <kernel/kernel.h>
|
|
|
|
|
|
|
|
#include <util/construct_at.h>
|
|
|
|
|
|
|
|
using namespace Kernel;
|
|
|
|
|
|
|
|
|
2015-09-11 13:43:51 +02:00
|
|
|
/************
|
|
|
|
** Object **
|
|
|
|
************/
|
2015-05-19 14:18:40 +02:00
|
|
|
|
2015-09-11 13:43:51 +02:00
|
|
|
Object::~Object()
|
|
|
|
{
|
|
|
|
for (Object_identity * oi = first(); oi; oi = first())
|
|
|
|
oi->invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
** Object_identity **
|
|
|
|
*********************/
|
|
|
|
|
|
|
|
void Object_identity::invalidate()
|
2015-05-19 14:18:40 +02:00
|
|
|
{
|
|
|
|
for (Object_identity_reference * oir = first(); oir; oir = first())
|
|
|
|
oir->invalidate();
|
2017-11-28 15:59:07 +01:00
|
|
|
|
|
|
|
if (_object) {
|
|
|
|
_object->remove(this);
|
|
|
|
_object = nullptr;
|
|
|
|
}
|
2015-05-19 14:18:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-11 13:43:51 +02:00
|
|
|
Object_identity::Object_identity(Object & object)
|
2017-11-28 15:59:07 +01:00
|
|
|
: _object(&object) { _object->insert(this); }
|
2015-09-11 13:43:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
Object_identity::~Object_identity() { invalidate(); }
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************
|
|
|
|
** Object_identity_reference **
|
|
|
|
*******************************/
|
|
|
|
|
2015-05-19 14:18:40 +02:00
|
|
|
Object_identity_reference *
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
Object_identity_reference::find(Pd &pd)
|
2015-05-19 14:18:40 +02:00
|
|
|
{
|
|
|
|
if (!_identity) return nullptr;
|
|
|
|
|
|
|
|
for (Object_identity_reference * oir = _identity->first();
|
|
|
|
oir; oir = oir->next())
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
if (&pd == &(oir->_pd)) return oir;
|
2015-05-19 14:18:40 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Object_identity_reference *
|
|
|
|
Object_identity_reference::find(capid_t capid)
|
|
|
|
{
|
|
|
|
using Avl_node_base = Genode::Avl_node<Object_identity_reference>;
|
|
|
|
|
|
|
|
if (capid == _capid) return this;
|
|
|
|
Object_identity_reference * subtree =
|
|
|
|
Avl_node_base::child(capid > _capid);
|
|
|
|
return (subtree) ? subtree->find(capid) : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Object_identity_reference * Object_identity_reference::factory(void * dst,
|
|
|
|
Pd & pd)
|
|
|
|
{
|
|
|
|
using namespace Genode;
|
|
|
|
return !_identity ?
|
|
|
|
nullptr : construct_at<Object_identity_reference>(dst, _identity, pd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Object_identity_reference::invalidate() {
|
2015-09-11 13:43:51 +02:00
|
|
|
if (_identity) _identity->remove(this);
|
|
|
|
_identity = nullptr;
|
|
|
|
}
|
2015-05-19 14:18:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
Object_identity_reference::Object_identity_reference(Object_identity *oi,
|
|
|
|
Pd &pd)
|
2015-12-01 14:50:14 +01:00
|
|
|
: _capid(pd.capid_alloc().alloc()), _identity(oi), _pd(pd), _in_utcbs(0)
|
2015-05-19 14:18:40 +02:00
|
|
|
{
|
|
|
|
if (_identity) _identity->insert(this);
|
|
|
|
_pd.cap_tree().insert(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Object_identity_reference::~Object_identity_reference()
|
|
|
|
{
|
|
|
|
invalidate();
|
|
|
|
_pd.cap_tree().remove(this);
|
|
|
|
_pd.capid_alloc().free(_capid);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Object_identity_reference * Object_identity_reference_tree::find(capid_t id) {
|
|
|
|
return (first()) ? first()->find(id) : nullptr; }
|