2013-09-05 13:40:54 +02:00
|
|
|
/*
|
2013-09-13 01:06:54 +02:00
|
|
|
* \brief Backend for end points of synchronous interprocess communication
|
2013-09-05 13:40:54 +02:00
|
|
|
* \author Martin Stein
|
2015-05-19 14:18:40 +02:00
|
|
|
* \author Stefan Kalkowski
|
2013-09-05 13:40:54 +02:00
|
|
|
* \date 2012-11-30
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2019-01-29 19:29:03 +01:00
|
|
|
* Copyright (C) 2012-2019 Genode Labs GmbH
|
2013-09-05 13:40:54 +02: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.
|
2013-09-05 13:40:54 +02:00
|
|
|
*/
|
|
|
|
|
2017-04-12 10:06:29 +02:00
|
|
|
#ifndef _CORE__KERNEL__IPC_NODE_H_
|
|
|
|
#define _CORE__KERNEL__IPC_NODE_H_
|
2013-09-05 13:40:54 +02:00
|
|
|
|
2016-03-08 16:59:43 +01:00
|
|
|
/* base-local includes */
|
|
|
|
#include <base/internal/native_utcb.h>
|
|
|
|
|
2013-09-05 13:40:54 +02:00
|
|
|
/* core includes */
|
2015-04-16 11:25:23 +02:00
|
|
|
#include <kernel/interface.h>
|
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
|
|
|
#include <assertion.h>
|
2013-09-05 13:40:54 +02:00
|
|
|
|
2015-05-19 14:18:40 +02:00
|
|
|
namespace Genode { class Msgbuf_base; };
|
|
|
|
|
2013-09-05 13:40:54 +02:00
|
|
|
namespace Kernel
|
|
|
|
{
|
2015-05-19 14:18:40 +02:00
|
|
|
class Pd;
|
|
|
|
|
2013-09-05 13:40:54 +02:00
|
|
|
/**
|
2013-09-13 01:06:54 +02:00
|
|
|
* Backend for end points of synchronous interprocess communication
|
2013-09-05 13:40:54 +02:00
|
|
|
*/
|
|
|
|
class Ipc_node;
|
2015-05-19 14:18:40 +02:00
|
|
|
|
2019-01-29 19:29:03 +01:00
|
|
|
using Ipc_node_queue = Genode::Fifo<Ipc_node>;
|
2013-09-05 13:40:54 +02: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 15:42:15 +01:00
|
|
|
class Kernel::Ipc_node : private Ipc_node_queue::Element
|
2013-09-05 13:40:54 +02:00
|
|
|
{
|
2013-11-28 00:44:54 +01:00
|
|
|
protected:
|
2013-09-05 13:40:54 +02:00
|
|
|
|
|
|
|
enum State
|
|
|
|
{
|
2015-09-15 13:20:35 +02:00
|
|
|
INACTIVE = 1,
|
|
|
|
AWAIT_REPLY = 2,
|
|
|
|
AWAIT_REQUEST = 3,
|
2013-09-05 13:40:54 +02:00
|
|
|
};
|
|
|
|
|
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
|
|
|
void _init(Genode::Native_utcb &utcb, Ipc_node &callee);
|
2015-05-19 14:18:40 +02:00
|
|
|
|
2013-11-28 00:44:54 +01:00
|
|
|
private:
|
|
|
|
|
2015-05-19 14:18:40 +02:00
|
|
|
friend class Core_thread;
|
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 15:42:15 +01:00
|
|
|
friend class Genode::Fifo<Ipc_node>;
|
2013-11-28 00:44:54 +01:00
|
|
|
|
2015-05-19 14:18:40 +02:00
|
|
|
State _state = INACTIVE;
|
|
|
|
capid_t _capid = cap_id_invalid();
|
|
|
|
Ipc_node * _caller = nullptr;
|
|
|
|
Ipc_node * _callee = nullptr;
|
|
|
|
bool _help = false;
|
|
|
|
size_t _rcv_caps = 0; /* max capability num to receive */
|
|
|
|
Genode::Native_utcb * _utcb = nullptr;
|
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 15:42:15 +01:00
|
|
|
Ipc_node_queue _request_queue { };
|
2013-11-28 00:44:54 +01:00
|
|
|
|
2015-05-19 14:18:40 +02:00
|
|
|
/* pre-allocation array for obkject identity references */
|
2016-03-18 22:53:25 +01:00
|
|
|
void * _obj_id_ref_ptr[Genode::Msgbuf_base::MAX_CAPS_PER_MSG];
|
2013-09-13 01:06:54 +02:00
|
|
|
|
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
|
|
|
inline void copy_msg(Ipc_node &sender);
|
2013-09-05 13:40:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Buffer next request from request queue in 'r' to handle it
|
|
|
|
*/
|
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
|
|
|
void _receive_request(Ipc_node &caller);
|
2013-09-05 13:40:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Receive a given reply if one is expected
|
|
|
|
*/
|
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
|
|
|
void _receive_reply(Ipc_node &callee);
|
2013-09-05 13:40:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert 'r' into request queue, buffer it if we were waiting for it
|
|
|
|
*/
|
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
|
|
|
void _announce_request(Ipc_node &node);
|
2013-09-05 13:40:54 +02:00
|
|
|
|
|
|
|
/**
|
2013-09-16 17:01:52 +02:00
|
|
|
* Cancel all requests in request queue
|
2013-09-05 13:40:54 +02:00
|
|
|
*/
|
2015-04-16 11:25:23 +02:00
|
|
|
void _cancel_request_queue();
|
2013-09-05 13:40:54 +02:00
|
|
|
|
|
|
|
/**
|
2013-09-16 17:01:52 +02:00
|
|
|
* Cancel request in outgoing buffer
|
2013-09-05 13:40:54 +02:00
|
|
|
*/
|
2015-04-16 11:25:23 +02:00
|
|
|
void _cancel_outbuf_request();
|
2013-09-05 13:40:54 +02:00
|
|
|
|
2013-09-16 17:01:52 +02:00
|
|
|
/**
|
|
|
|
* Cancel request in incoming buffer
|
|
|
|
*/
|
2015-04-16 11:25:23 +02:00
|
|
|
void _cancel_inbuf_request();
|
2013-09-05 13:40:54 +02:00
|
|
|
|
|
|
|
/**
|
2013-09-16 17:01:52 +02:00
|
|
|
* A request 'r' in inbuf or request queue was cancelled by sender
|
2013-09-05 13:40:54 +02:00
|
|
|
*/
|
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
|
|
|
void _announced_request_cancelled(Ipc_node &node);
|
2013-09-05 13:40:54 +02:00
|
|
|
|
|
|
|
/**
|
2013-09-16 17:01:52 +02:00
|
|
|
* The request in the outbuf was cancelled by receiver
|
|
|
|
*/
|
2015-04-16 11:25:23 +02:00
|
|
|
void _outbuf_request_cancelled();
|
2013-09-16 17:01:52 +02:00
|
|
|
|
2014-12-01 15:10:33 +01:00
|
|
|
/**
|
|
|
|
* Return wether we are the source of a helping relationship
|
|
|
|
*/
|
2015-04-16 11:25:23 +02:00
|
|
|
bool _helps_outbuf_dst();
|
2014-12-01 15:10:33 +01:00
|
|
|
|
2013-09-16 17:01:52 +02:00
|
|
|
/**
|
2014-04-04 13:41:04 +02:00
|
|
|
* IPC node returned from waiting due to reply receipt
|
2013-09-16 17:01:52 +02:00
|
|
|
*/
|
2014-04-04 13:41:04 +02:00
|
|
|
virtual void _send_request_succeeded() = 0;
|
2013-09-16 17:01:52 +02:00
|
|
|
|
|
|
|
/**
|
2014-04-04 13:41:04 +02:00
|
|
|
* IPC node returned from waiting due to reply cancellation
|
2013-09-16 17:01:52 +02:00
|
|
|
*/
|
2014-04-04 13:41:04 +02:00
|
|
|
virtual void _send_request_failed() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IPC node returned from waiting due to request receipt
|
|
|
|
*/
|
|
|
|
virtual void _await_request_succeeded() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IPC node returned from waiting due to request cancellation
|
|
|
|
*/
|
|
|
|
virtual void _await_request_failed() = 0;
|
2013-09-16 17:01:52 +02:00
|
|
|
|
2013-11-28 00:44:54 +01:00
|
|
|
protected:
|
|
|
|
|
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 15:42:15 +01:00
|
|
|
Pd * _pd = nullptr; /* pointer to PD this IPC node is part of */
|
2015-05-19 14:18:40 +02:00
|
|
|
|
|
|
|
|
2013-11-28 00:44:54 +01:00
|
|
|
/***************
|
|
|
|
** Accessors **
|
|
|
|
***************/
|
|
|
|
|
2015-05-19 14:18:40 +02:00
|
|
|
Ipc_node * callee() { return _callee; }
|
|
|
|
State state() { return _state; }
|
2013-11-28 00:44:54 +01:00
|
|
|
|
2013-09-16 17:01:52 +02: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 15:42:15 +01:00
|
|
|
virtual ~Ipc_node();
|
2013-09-05 13:40:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a request and wait for the according reply
|
|
|
|
*
|
2015-05-19 14:18:40 +02:00
|
|
|
* \param callee targeted IPC node
|
2014-12-01 15:10:33 +01:00
|
|
|
* \param help wether the request implies a helping relationship
|
2013-09-05 13:40:54 +02:00
|
|
|
*/
|
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
|
|
|
void send_request(Ipc_node &callee, capid_t capid, bool help,
|
2015-05-19 14:18:40 +02:00
|
|
|
unsigned rcv_caps);
|
2014-12-01 15:10:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return root destination of the helping-relation tree we are in
|
|
|
|
*/
|
2015-04-16 11:25:23 +02:00
|
|
|
Ipc_node * helping_sink();
|
2014-12-01 15:10:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Call function 'f' of type 'void (Ipc_node *)' for each helper
|
|
|
|
*/
|
|
|
|
template <typename F> void for_each_helper(F f)
|
|
|
|
{
|
|
|
|
/* if we have a helper in the receive buffer, call 'f' for it */
|
2019-01-29 19:29:03 +01:00
|
|
|
if (_caller && _caller->_help) f(*_caller);
|
2014-12-01 15:10:33 +01:00
|
|
|
|
|
|
|
/* call 'f' for each helper in our request queue */
|
2019-01-29 19:29:03 +01:00
|
|
|
_request_queue.for_each([f] (Ipc_node &node) {
|
|
|
|
if (node._help) f(node); });
|
2013-09-05 13:40:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wait until a request has arrived and load it for handling
|
|
|
|
*
|
2014-03-27 12:20:55 +01:00
|
|
|
* \return wether a request could be received already
|
2013-09-05 13:40:54 +02:00
|
|
|
*/
|
2015-05-19 14:18:40 +02:00
|
|
|
bool await_request(unsigned rcv_caps);
|
2013-09-05 13:40:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reply to last request if there's any
|
|
|
|
*/
|
2015-05-19 14:18:40 +02:00
|
|
|
void send_reply();
|
2013-09-16 17:01:52 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If IPC node waits, cancel '_outbuf' to stop waiting
|
2013-09-05 13:40:54 +02:00
|
|
|
*/
|
2015-04-16 11:25:23 +02:00
|
|
|
void cancel_waiting();
|
2015-05-19 14:18:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
/***************
|
|
|
|
** Accessors **
|
|
|
|
***************/
|
|
|
|
|
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
|
|
|
Pd &pd() const
|
|
|
|
{
|
|
|
|
if (_pd)
|
|
|
|
return *_pd;
|
|
|
|
|
|
|
|
ASSERT_NEVER_CALLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
Genode::Native_utcb *utcb() { return _utcb; }
|
2013-09-05 13:40:54 +02:00
|
|
|
};
|
|
|
|
|
2017-04-12 10:06:29 +02:00
|
|
|
#endif /* _CORE__KERNEL__IPC_NODE_H_ */
|