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 */
|
2015-05-19 14:18:40 +02:00
|
|
|
#include <platform_pd.h>
|
2015-04-16 11:25:23 +02:00
|
|
|
#include <kernel/ipc_node.h>
|
2015-05-19 14:18:40 +02:00
|
|
|
#include <kernel/pd.h>
|
|
|
|
#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
|
|
|
static inline void free_obj_id_ref(Pd &pd, void *ptr)
|
2016-03-31 18:17:07 +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
|
|
|
pd.platform_pd().capability_slab().free(ptr, sizeof(Object_identity_reference));
|
2016-03-31 18:17:07 +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::copy_msg(Ipc_node &sender)
|
2015-04-16 11:25:23 +02:00
|
|
|
{
|
2015-05-19 14:18:40 +02:00
|
|
|
using namespace Genode;
|
|
|
|
using Reference = Object_identity_reference;
|
2015-04-16 11:25:23 +02:00
|
|
|
|
2015-05-19 14:18:40 +02:00
|
|
|
/* copy payload and set destination capability id */
|
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
|
|
|
*_utcb = *sender._utcb;
|
|
|
|
_utcb->destination(sender._capid);
|
2015-05-19 14:18:40 +02:00
|
|
|
|
|
|
|
/* translate capabilities */
|
|
|
|
for (unsigned i = 0; i < _rcv_caps; i++) {
|
|
|
|
|
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
|
|
|
capid_t id = sender._utcb->cap_get(i);
|
2015-05-19 14:18:40 +02:00
|
|
|
|
|
|
|
/* if there is no capability to send, just free the pre-allocation */
|
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 (i >= sender._utcb->cap_cnt()) {
|
2016-03-31 18:17:07 +02:00
|
|
|
free_obj_id_ref(pd(), _obj_id_ref_ptr[i]);
|
2015-05-19 14:18:40 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* lookup the capability id within the caller's cap space */
|
|
|
|
Reference *oir = (id == cap_id_invalid())
|
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
|
|
|
? nullptr : sender.pd().cap_tree().find(id);
|
2015-05-19 14:18:40 +02:00
|
|
|
|
|
|
|
/* if the caller's capability is invalid, free the pre-allocation */
|
|
|
|
if (!oir) {
|
|
|
|
_utcb->cap_add(cap_id_invalid());
|
2016-03-31 18:17:07 +02:00
|
|
|
free_obj_id_ref(pd(), _obj_id_ref_ptr[i]);
|
2015-05-19 14:18:40 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* lookup the capability id within the callee's cap space */
|
|
|
|
Reference *dst_oir = oir->find(pd());
|
|
|
|
|
|
|
|
/* if it is not found, and the target is not core, create a 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
|
|
|
if (!dst_oir && (&pd() != &core_pd())) {
|
|
|
|
dst_oir = oir->factory(_obj_id_ref_ptr[i], pd());
|
2015-05-19 14:18:40 +02:00
|
|
|
if (!dst_oir)
|
2016-03-31 18:17:07 +02:00
|
|
|
free_obj_id_ref(pd(), _obj_id_ref_ptr[i]);
|
2015-05-19 14:18:40 +02:00
|
|
|
} else /* otherwise free the pre-allocation */
|
2016-03-31 18:17:07 +02:00
|
|
|
free_obj_id_ref(pd(), _obj_id_ref_ptr[i]);
|
2015-05-19 14:18:40 +02:00
|
|
|
|
2015-12-01 14:50:14 +01:00
|
|
|
if (dst_oir) dst_oir->add_to_utcb();
|
|
|
|
|
2015-05-19 14:18:40 +02:00
|
|
|
/* add the translated capability id to the target buffer */
|
|
|
|
_utcb->cap_add(dst_oir ? dst_oir->capid() : cap_id_invalid());
|
|
|
|
}
|
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::_receive_request(Ipc_node &caller)
|
2015-04-16 11:25:23 +02:00
|
|
|
{
|
2015-05-19 14:18:40 +02:00
|
|
|
copy_msg(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 = &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
|
|
|
{
|
|
|
|
copy_msg(callee);
|
2015-09-15 13:20:35 +02:00
|
|
|
_state = INACTIVE;
|
2015-04-16 11:25:23 +02:00
|
|
|
_send_request_succeeded();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
2015-04-16 11:25:23 +02:00
|
|
|
_await_request_succeeded();
|
|
|
|
return;
|
|
|
|
}
|
2015-05-19 14:18:40 +02:00
|
|
|
|
2015-04-16 11:25:23 +02:00
|
|
|
/* cannot receive yet, so queue request */
|
2019-01-29 19:29:03 +01:00
|
|
|
_request_queue.enqueue(node);
|
2015-04-16 11:25:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Ipc_node::_cancel_request_queue()
|
|
|
|
{
|
2019-01-29 19:29:03 +01:00
|
|
|
_request_queue.dequeue_all([] (Ipc_node &node) {
|
|
|
|
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-01-29 19:29:03 +01:00
|
|
|
else _request_queue.remove(node);
|
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;
|
2015-05-19 14:18:40 +02:00
|
|
|
_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
|
|
|
|
|
|
|
|
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::_init(Genode::Native_utcb &utcb, Ipc_node &starter)
|
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
|
|
|
_utcb = &utcb;
|
|
|
|
_rcv_caps = starter._utcb->cap_cnt();
|
|
|
|
Genode::Allocator &slab = pd().platform_pd().capability_slab();
|
2015-05-19 14:18:40 +02:00
|
|
|
for (unsigned i = 0; i < _rcv_caps; i++)
|
|
|
|
_obj_id_ref_ptr[i] = slab.alloc(sizeof(Object_identity_reference));
|
|
|
|
copy_msg(starter);
|
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::send_request(Ipc_node &callee, capid_t capid, bool help,
|
2015-05-19 14:18:40 +02:00
|
|
|
unsigned rcv_caps)
|
2015-04-16 11:25:23 +02:00
|
|
|
{
|
2015-09-15 13:20:35 +02:00
|
|
|
if (_state != INACTIVE) {
|
2019-04-05 13:50:34 +02:00
|
|
|
Genode::raw("IPC send request: bad state");
|
2015-09-15 13:20:35 +02:00
|
|
|
return;
|
|
|
|
}
|
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
|
|
|
Genode::Allocator &slab = pd().platform_pd().capability_slab();
|
2015-05-19 14:18:40 +02:00
|
|
|
for (unsigned i = 0; i < rcv_caps; i++)
|
|
|
|
_obj_id_ref_ptr[i] = slab.alloc(sizeof(Object_identity_reference));
|
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
|
|
|
_capid = capid;
|
|
|
|
_help = false;
|
|
|
|
_rcv_caps = rcv_caps;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ipc_node * Ipc_node::helping_sink() {
|
2015-05-19 14:18:40 +02:00
|
|
|
return _helps_outbuf_dst() ? _callee->helping_sink() : this; }
|
2015-04-16 11:25:23 +02:00
|
|
|
|
|
|
|
|
2015-05-19 14:18:40 +02:00
|
|
|
bool Ipc_node::await_request(unsigned rcv_caps)
|
2015-04-16 11:25:23 +02:00
|
|
|
{
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
if (_state != INACTIVE) {
|
2019-04-05 13:50:34 +02:00
|
|
|
Genode::raw("IPC await request: bad state");
|
2015-09-15 13:20:35 +02:00
|
|
|
return true;
|
|
|
|
}
|
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
|
|
|
Genode::Allocator &slab = pd().platform_pd().capability_slab();
|
2015-05-19 14:18:40 +02:00
|
|
|
for (unsigned i = 0; i < rcv_caps; i++)
|
|
|
|
_obj_id_ref_ptr[i] = slab.alloc(sizeof(Object_identity_reference));
|
|
|
|
|
|
|
|
_rcv_caps = rcv_caps;
|
2015-04-16 11:25:23 +02:00
|
|
|
|
2019-01-29 19:29:03 +01:00
|
|
|
/* if no request announced then wait */
|
|
|
|
bool announced = false;
|
2015-04-16 11:25:23 +02:00
|
|
|
_state = AWAIT_REQUEST;
|
2019-01-29 19:29:03 +01:00
|
|
|
|
|
|
|
/* if anybody already announced a request receive it */
|
|
|
|
_request_queue.dequeue([&] (Ipc_node &ipc) {
|
|
|
|
_receive_request(ipc);
|
|
|
|
announced = true;
|
|
|
|
});
|
|
|
|
return announced;
|
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;
|
|
|
|
_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;
|
|
|
|
_await_request_failed();
|
2015-05-19 14:18:40 +02:00
|
|
|
break;
|
2015-04-16 11:25:23 +02:00
|
|
|
return;
|
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ipc_node::~Ipc_node()
|
|
|
|
{
|
|
|
|
_cancel_request_queue();
|
|
|
|
_cancel_inbuf_request();
|
|
|
|
_cancel_outbuf_request();
|
|
|
|
}
|
2015-05-19 14:18:40 +02:00
|
|
|
|