2015-04-16 11:25:23 +02:00
|
|
|
/*
|
|
|
|
* \brief Backend for end points of synchronous interprocess communication
|
|
|
|
* \author Martin Stein
|
2015-05-19 14:18:40 +02:00
|
|
|
* \author Stefan Kalkowski
|
2015-04-16 11:25:23 +02:00
|
|
|
* \date 2012-11-30
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2019-01-29 19:29:03 +01:00
|
|
|
* Copyright (C) 2012-2019 Genode Labs GmbH
|
2015-04-16 11:25:23 +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.
|
2015-04-16 11:25:23 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <util/string.h>
|
|
|
|
|
2016-03-08 16:59:43 +01:00
|
|
|
/* base-internal includes */
|
|
|
|
#include <base/internal/native_utcb.h>
|
|
|
|
|
2015-04-16 11:25:23 +02:00
|
|
|
/* core includes */
|
|
|
|
#include <kernel/ipc_node.h>
|
2015-05-19 14:18:40 +02:00
|
|
|
#include <kernel/kernel.h>
|
|
|
|
#include <kernel/thread.h>
|
2015-04-16 11:25:23 +02:00
|
|
|
|
|
|
|
using namespace Kernel;
|
|
|
|
|
|
|
|
|
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 Ipc_node::_receive_request(Ipc_node &caller)
|
2015-04-16 11:25:23 +02:00
|
|
|
{
|
2019-04-19 18:41:14 +02:00
|
|
|
_thread.ipc_copy_msg(caller._thread);
|
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
|
|
|
_caller = &caller;
|
|
|
|
_state = INACTIVE;
|
2015-05-19 14:18:40 +02:00
|
|
|
}
|
2015-04-16 11:25:23 +02:00
|
|
|
|
2015-05-19 14:18:40 +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 Ipc_node::_receive_reply(Ipc_node &callee)
|
2015-05-19 14:18:40 +02:00
|
|
|
{
|
2019-04-19 18:41:14 +02:00
|
|
|
_thread.ipc_copy_msg(callee._thread);
|
2015-09-15 13:20:35 +02:00
|
|
|
_state = INACTIVE;
|
2019-04-19 18:41:14 +02:00
|
|
|
_thread.ipc_send_request_succeeded();
|
2015-04-16 11:25:23 +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 Ipc_node::_announce_request(Ipc_node &node)
|
2015-04-16 11:25:23 +02:00
|
|
|
{
|
|
|
|
/* directly receive request if we've awaited it */
|
|
|
|
if (_state == AWAIT_REQUEST) {
|
2015-05-19 14:18:40 +02:00
|
|
|
_receive_request(node);
|
2019-04-19 18:41:14 +02:00
|
|
|
_thread.ipc_await_request_succeeded();
|
2015-04-16 11:25:23 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-05-19 14:18:40 +02:00
|
|
|
|
2015-04-16 11:25:23 +02:00
|
|
|
/* cannot receive yet, so queue request */
|
2019-04-20 02:44:59 +02:00
|
|
|
_request_queue.enqueue(node._request_queue_item);
|
2015-04-16 11:25:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Ipc_node::_cancel_request_queue()
|
|
|
|
{
|
2019-04-20 02:44:59 +02:00
|
|
|
_request_queue.dequeue_all([] (Queue_item &item) {
|
|
|
|
Ipc_node &node { item.object() };
|
|
|
|
node._outbuf_request_cancelled();
|
|
|
|
});
|
2015-04-16 11:25:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Ipc_node::_cancel_outbuf_request()
|
|
|
|
{
|
2015-05-19 14:18:40 +02:00
|
|
|
if (_callee) {
|
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
|
|
|
_callee->_announced_request_cancelled(*this);
|
2015-05-19 14:18:40 +02:00
|
|
|
_callee = nullptr;
|
2015-04-16 11:25:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Ipc_node::_cancel_inbuf_request()
|
|
|
|
{
|
2015-05-19 14:18:40 +02:00
|
|
|
if (_caller) {
|
|
|
|
_caller->_outbuf_request_cancelled();
|
|
|
|
_caller = nullptr;
|
2015-04-16 11:25:23 +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 Ipc_node::_announced_request_cancelled(Ipc_node &node)
|
2015-04-16 11:25:23 +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
|
|
|
if (_caller == &node) _caller = nullptr;
|
2019-04-20 02:44:59 +02:00
|
|
|
else _request_queue.remove(node._request_queue_item);
|
2015-04-16 11:25:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Ipc_node::_outbuf_request_cancelled()
|
|
|
|
{
|
2015-05-19 14:18:40 +02:00
|
|
|
if (_callee == nullptr) return;
|
|
|
|
|
|
|
|
_callee = nullptr;
|
2015-09-15 13:20:35 +02:00
|
|
|
_state = INACTIVE;
|
2019-04-19 18:41:14 +02:00
|
|
|
_thread.ipc_send_request_failed();
|
2015-04-16 11:25:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-15 13:20:35 +02:00
|
|
|
bool Ipc_node::_helps_outbuf_dst() { return (_state == AWAIT_REPLY) && _help; }
|
2015-05-19 14:18:40 +02:00
|
|
|
|
|
|
|
|
2019-04-19 18:41:14 +02:00
|
|
|
bool Ipc_node::can_send_request()
|
2015-05-19 14:18:40 +02:00
|
|
|
{
|
2019-04-19 18:41:14 +02:00
|
|
|
return _state == INACTIVE;
|
2015-04-16 11:25:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-19 18:41:14 +02:00
|
|
|
void Ipc_node::send_request(Ipc_node &callee, bool help)
|
2015-04-16 11:25:23 +02:00
|
|
|
{
|
2015-09-15 13:20:35 +02:00
|
|
|
_state = AWAIT_REPLY;
|
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
|
|
|
_callee = &callee;
|
2015-05-19 14:18:40 +02:00
|
|
|
_help = false;
|
2015-04-16 11:25:23 +02:00
|
|
|
|
|
|
|
/* announce request */
|
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
|
|
|
_callee->_announce_request(*this);
|
2015-04-16 11:25:23 +02:00
|
|
|
|
2015-05-19 14:18:40 +02:00
|
|
|
_help = help;
|
2015-04-16 11:25:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-25 02:45:03 +02:00
|
|
|
Thread &Ipc_node::helping_sink() {
|
|
|
|
return _helps_outbuf_dst() ? _callee->helping_sink() : _thread; }
|
2015-04-16 11:25:23 +02:00
|
|
|
|
|
|
|
|
2019-04-19 18:41:14 +02:00
|
|
|
bool Ipc_node::can_await_request()
|
2015-04-16 11:25:23 +02:00
|
|
|
{
|
2019-04-19 18:41:14 +02:00
|
|
|
return _state == INACTIVE;
|
|
|
|
}
|
2015-05-19 14:18:40 +02:00
|
|
|
|
2015-04-16 11:25:23 +02:00
|
|
|
|
2019-04-25 02:45:03 +02:00
|
|
|
void Ipc_node::await_request()
|
2019-04-19 18:41:14 +02:00
|
|
|
{
|
2015-04-16 11:25:23 +02:00
|
|
|
_state = AWAIT_REQUEST;
|
2019-04-20 02:44:59 +02:00
|
|
|
_request_queue.dequeue([&] (Queue_item &item) {
|
|
|
|
_receive_request(item.object());
|
2019-01-29 19:29:03 +01:00
|
|
|
});
|
2015-04-16 11:25:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-19 14:18:40 +02:00
|
|
|
void Ipc_node::send_reply()
|
2015-04-16 11:25:23 +02:00
|
|
|
{
|
|
|
|
/* reply to the last request if we have to */
|
2015-09-15 13:20:35 +02:00
|
|
|
if (_state == INACTIVE && _caller) {
|
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
|
|
|
_caller->_receive_reply(*this);
|
2015-09-15 13:20:35 +02:00
|
|
|
_caller = nullptr;
|
2015-04-16 11:25:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Ipc_node::cancel_waiting()
|
|
|
|
{
|
|
|
|
switch (_state) {
|
|
|
|
case AWAIT_REPLY:
|
|
|
|
_cancel_outbuf_request();
|
|
|
|
_state = INACTIVE;
|
2019-04-19 18:41:14 +02:00
|
|
|
_thread.ipc_send_request_failed();
|
2015-05-19 14:18:40 +02:00
|
|
|
break;
|
2015-04-16 11:25:23 +02:00
|
|
|
case AWAIT_REQUEST:
|
|
|
|
_state = INACTIVE;
|
2019-04-19 18:41:14 +02:00
|
|
|
_thread.ipc_await_request_failed();
|
2015-05-19 14:18:40 +02:00
|
|
|
break;
|
2015-04-16 11:25:23 +02:00
|
|
|
return;
|
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-19 18:41:14 +02:00
|
|
|
Ipc_node::Ipc_node(Thread &thread)
|
|
|
|
:
|
|
|
|
_thread(thread)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
2015-04-16 11:25:23 +02:00
|
|
|
Ipc_node::~Ipc_node()
|
|
|
|
{
|
|
|
|
_cancel_request_queue();
|
|
|
|
_cancel_inbuf_request();
|
|
|
|
_cancel_outbuf_request();
|
|
|
|
}
|
2015-05-19 14:18:40 +02:00
|
|
|
|