2012-05-30 20:13:09 +02:00
|
|
|
/*
|
|
|
|
* \brief Implementation of the Genode IPC-framework
|
|
|
|
* \author Martin Stein
|
|
|
|
* \date 2012-02-12
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 21:44:47 +01:00
|
|
|
* Copyright (C) 2012-2013 Genode Labs GmbH
|
2012-05-30 20:13:09 +02:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/ipc.h>
|
|
|
|
#include <base/thread.h>
|
2013-11-14 17:29:34 +01:00
|
|
|
|
|
|
|
/* base-hw includes */
|
|
|
|
#include <kernel/interface.h>
|
2012-05-30 20:13:09 +02:00
|
|
|
#include <kernel/log.h>
|
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* size of the callee-local name of a targeted RPC object */
|
|
|
|
RPC_OBJECT_ID_SIZE = sizeof(umword_t),
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The RPC framework marshalls a return value into reply messages to
|
|
|
|
* deliver exceptions, wich occured during the RPC call to the caller.
|
|
|
|
* This defines the size of this value.
|
|
|
|
*/
|
|
|
|
RPC_RETURN_VALUE_SIZE = sizeof(umword_t),
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*****************
|
|
|
|
** Ipc_ostream **
|
|
|
|
*****************/
|
|
|
|
|
|
|
|
Ipc_ostream::Ipc_ostream(Native_capability dst, Msgbuf_base *snd_msg)
|
|
|
|
:
|
|
|
|
Ipc_marshaller(&snd_msg->buf[0], snd_msg->size()),
|
|
|
|
_snd_msg(snd_msg), _dst(dst)
|
|
|
|
{
|
|
|
|
_write_offset = RPC_OBJECT_ID_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************
|
|
|
|
** Ipc_istream **
|
|
|
|
*****************/
|
|
|
|
|
|
|
|
void Ipc_istream::_wait()
|
|
|
|
{
|
2013-10-17 16:07:47 +02:00
|
|
|
/* FIXME: this shall be not supported */
|
2014-03-16 16:00:55 +01:00
|
|
|
Kernel::pause_current_thread();
|
2012-05-30 20:13:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ipc_istream::Ipc_istream(Msgbuf_base *rcv_msg)
|
|
|
|
:
|
|
|
|
Ipc_unmarshaller(&rcv_msg->buf[0], rcv_msg->size()),
|
|
|
|
Native_capability(Genode::thread_get_my_native_id(), 0),
|
|
|
|
_rcv_msg(rcv_msg), _rcv_cs(-1)
|
|
|
|
{ _read_offset = RPC_OBJECT_ID_SIZE; }
|
|
|
|
|
|
|
|
|
|
|
|
Ipc_istream::~Ipc_istream() { }
|
|
|
|
|
|
|
|
|
|
|
|
/****************
|
|
|
|
** Ipc_client **
|
|
|
|
****************/
|
|
|
|
|
|
|
|
void Ipc_client::_call()
|
|
|
|
{
|
2013-11-21 12:04:21 +01:00
|
|
|
/* send request and receive corresponding reply */
|
2013-10-17 00:41:14 +02:00
|
|
|
unsigned const local_name = Ipc_ostream::_dst.local_name();
|
2013-11-21 16:43:35 +01:00
|
|
|
Native_utcb * const utcb = Thread_base::myself()->utcb();
|
2013-11-21 17:26:44 +01:00
|
|
|
utcb->message()->prepare_send(_snd_msg->buf, _write_offset, local_name);
|
2013-11-21 12:04:21 +01:00
|
|
|
if (Kernel::send_request_msg(Ipc_ostream::_dst.dst())) {
|
2013-10-17 16:07:47 +02:00
|
|
|
PERR("failed to receive reply");
|
|
|
|
throw Blocking_canceled();
|
|
|
|
}
|
2013-11-21 17:26:44 +01:00
|
|
|
utcb->message()->finish_receive(_rcv_msg->buf, _rcv_msg->size());
|
2012-05-30 20:13:09 +02:00
|
|
|
|
|
|
|
/* reset unmarshaller */
|
|
|
|
_write_offset = _read_offset = RPC_OBJECT_ID_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-16 10:50:15 +02:00
|
|
|
Ipc_client::Ipc_client(Native_capability const &srv, Msgbuf_base *snd_msg,
|
|
|
|
Msgbuf_base *rcv_msg, unsigned short)
|
2012-05-30 20:13:09 +02:00
|
|
|
: Ipc_istream(rcv_msg), Ipc_ostream(srv, snd_msg), _result(0) { }
|
|
|
|
|
|
|
|
|
|
|
|
/****************
|
|
|
|
** Ipc_server **
|
|
|
|
****************/
|
|
|
|
|
|
|
|
Ipc_server::Ipc_server(Msgbuf_base *snd_msg,
|
|
|
|
Msgbuf_base *rcv_msg) :
|
|
|
|
Ipc_istream(rcv_msg),
|
|
|
|
Ipc_ostream(Native_capability(), snd_msg),
|
|
|
|
_reply_needed(false)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
void Ipc_server::_prepare_next_reply_wait()
|
|
|
|
{
|
|
|
|
/* now we have a request to reply */
|
|
|
|
_reply_needed = true;
|
|
|
|
|
|
|
|
/* leave space for RPC method return value */
|
|
|
|
_write_offset = RPC_OBJECT_ID_SIZE + RPC_RETURN_VALUE_SIZE;
|
|
|
|
|
|
|
|
/* reset unmarshaller */
|
|
|
|
_read_offset = RPC_OBJECT_ID_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Ipc_server::_wait()
|
|
|
|
{
|
2013-11-21 12:04:21 +01:00
|
|
|
/* receive request */
|
|
|
|
if (Kernel::await_request_msg()) {
|
2013-10-17 13:51:17 +02:00
|
|
|
PERR("failed to receive request");
|
|
|
|
throw Blocking_canceled();
|
|
|
|
}
|
2013-11-21 16:43:35 +01:00
|
|
|
Native_utcb * const utcb = Thread_base::myself()->utcb();
|
2013-11-21 17:26:44 +01:00
|
|
|
utcb->message()->finish_receive(_rcv_msg->buf, _rcv_msg->size());
|
2013-10-17 16:07:47 +02:00
|
|
|
|
2012-05-30 20:13:09 +02:00
|
|
|
/* update server state */
|
|
|
|
_prepare_next_reply_wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-17 13:51:17 +02:00
|
|
|
void Ipc_server::_reply()
|
|
|
|
{
|
2013-11-21 16:43:35 +01:00
|
|
|
unsigned const local_name = Ipc_ostream::_dst.local_name();
|
2013-10-17 13:51:17 +02:00
|
|
|
Native_utcb * const utcb = Thread_base::myself()->utcb();
|
2013-11-21 17:26:44 +01:00
|
|
|
utcb->message()->prepare_send(_snd_msg->buf, _write_offset, local_name);
|
2014-01-22 15:45:51 +01:00
|
|
|
Kernel::send_reply_msg(false);
|
2013-10-17 13:51:17 +02:00
|
|
|
}
|
2012-05-30 20:13:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
void Ipc_server::_reply_wait()
|
|
|
|
{
|
2013-10-17 16:07:47 +02:00
|
|
|
/* if there is no reply, wait for request */
|
2012-05-30 20:13:09 +02:00
|
|
|
if (!_reply_needed) {
|
|
|
|
_wait();
|
|
|
|
return;
|
|
|
|
}
|
2013-11-21 12:04:21 +01:00
|
|
|
/* send reply and receive next request */
|
2013-10-17 13:51:17 +02:00
|
|
|
unsigned const local_name = Ipc_ostream::_dst.local_name();
|
2013-11-21 16:43:35 +01:00
|
|
|
Native_utcb * const utcb = Thread_base::myself()->utcb();
|
2013-11-21 17:26:44 +01:00
|
|
|
utcb->message()->prepare_send(_snd_msg->buf, _write_offset, local_name);
|
2014-01-22 15:45:51 +01:00
|
|
|
if (Kernel::send_reply_msg(true)) {
|
2013-10-17 13:51:17 +02:00
|
|
|
PERR("failed to receive request");
|
|
|
|
throw Blocking_canceled();
|
|
|
|
}
|
2013-11-21 17:26:44 +01:00
|
|
|
utcb->message()->finish_receive(_rcv_msg->buf, _rcv_msg->size());
|
2013-10-17 16:07:47 +02:00
|
|
|
|
2012-05-30 20:13:09 +02:00
|
|
|
/* update server state */
|
|
|
|
_prepare_next_reply_wait();
|
|
|
|
}
|