genode/repos/base-hw/src/core/kernel/ipc_node.h

213 lines
4.6 KiB
C
Raw Normal View History

2013-09-05 13:40:54 +02:00
/*
* \brief Backend for end points of synchronous interprocess communication
2013-09-05 13:40:54 +02:00
* \author Martin Stein
* \author Stefan Kalkowski
2013-09-05 13:40:54 +02:00
* \date 2012-11-30
*/
/*
* 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
* under the terms of the GNU Affero General Public License version 3.
2013-09-05 13:40:54 +02:00
*/
#ifndef _CORE__KERNEL__IPC_NODE_H_
#define _CORE__KERNEL__IPC_NODE_H_
2013-09-05 13:40:54 +02:00
/* base-local includes */
#include <base/internal/native_utcb.h>
2013-09-05 13:40:54 +02:00
/* core includes */
#include <kernel/interface.h>
#include <assertion.h>
2013-09-05 13:40:54 +02:00
namespace Genode { class Msgbuf_base; };
2013-09-05 13:40:54 +02:00
namespace Kernel
{
class Pd;
2013-09-05 13:40:54 +02:00
/**
* Backend for end points of synchronous interprocess communication
2013-09-05 13:40:54 +02:00
*/
class Ipc_node;
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
{
protected:
2013-09-05 13:40:54 +02:00
enum State
{
INACTIVE = 1,
AWAIT_REPLY = 2,
AWAIT_REQUEST = 3,
2013-09-05 13:40:54 +02:00
};
void _init(Genode::Native_utcb &utcb, Ipc_node &callee);
private:
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>;
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 { };
/* pre-allocation array for obkject identity references */
void * _obj_id_ref_ptr[Genode::Msgbuf_base::MAX_CAPS_PER_MSG];
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
*/
void _receive_request(Ipc_node &caller);
2013-09-05 13:40:54 +02:00
/**
* Receive a given reply if one is expected
*/
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
*/
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
*/
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
*/
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
*/
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
*/
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
*/
void _outbuf_request_cancelled();
2013-09-16 17:01:52 +02:00
/**
* Return wether we are the source of a helping relationship
*/
bool _helps_outbuf_dst();
2013-09-16 17:01:52 +02:00
/**
* IPC node returned from waiting due to reply receipt
2013-09-16 17:01:52 +02:00
*/
virtual void _send_request_succeeded() = 0;
2013-09-16 17:01:52 +02:00
/**
* IPC node returned from waiting due to reply cancellation
2013-09-16 17:01:52 +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
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 */
/***************
** Accessors **
***************/
Ipc_node * callee() { return _callee; }
State state() { return _state; }
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
*
* \param callee targeted IPC node
* \param help wether the request implies a helping relationship
2013-09-05 13:40:54 +02:00
*/
void send_request(Ipc_node &callee, capid_t capid, bool help,
unsigned rcv_caps);
/**
* Return root destination of the helping-relation tree we are in
*/
Ipc_node * helping_sink();
/**
* 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 */
if (_caller && _caller->_help) f(*_caller);
/* call 'f' for each helper in our request queue */
_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
*
* \return wether a request could be received already
2013-09-05 13:40:54 +02:00
*/
bool await_request(unsigned rcv_caps);
2013-09-05 13:40:54 +02:00
/**
* Reply to last request if there's any
*/
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
*/
void cancel_waiting();
/***************
** Accessors **
***************/
Pd &pd() const
{
if (_pd)
return *_pd;
ASSERT_NEVER_CALLED;
}
Genode::Native_utcb *utcb() { return _utcb; }
2013-09-05 13:40:54 +02:00
};
#endif /* _CORE__KERNEL__IPC_NODE_H_ */